From ad87ad529947e29adbee0dc2016069b71495a609 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Mon, 7 Jun 2010 16:48:07 +0200 Subject: Adding JEP-10 support. --- lib/clipboard.js | 128 +++++++++++++++++++++++++++++++++++++++++++++ lib/main.js | 28 +++++++++- lib/persistent-page-mod.js | 56 ++++++++++++++++++++ tests/test-util.js | 2 +- 4 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 lib/clipboard.js create mode 100644 lib/persistent-page-mod.js diff --git a/lib/clipboard.js b/lib/clipboard.js new file mode 100644 index 0000000..e5b4ac8 --- /dev/null +++ b/lib/clipboard.js @@ -0,0 +1,128 @@ +// Released under the MIT/X11 license +// http://www.opensource.org/licenses/mit-license.php + +/** + * returns content of the system clipboard + * @return string with the content of the clipboard or "" if empty. + * originally from + * https://developer.mozilla.org/en/Using_the_Clipboard + * + */ +// TODO to-be-replaced by +// var contents = jetpack.clipboard.get(); +// http://hsivonen.iki.fi/kesakoodi/clipboard/ +// https://wiki.mozilla.org/Labs/Jetpack/JEP/10 + +function getClipboard() { + const kClipboardContractID = "@mozilla.org/widget/clipboard;1"; + const kClipboardIID = Ci.nsIClipboard; + var clip = Cc[kClipboardContractID].getService(kClipboardIID); + if (!clip) { + throw new Error("No access to the clipboard!"); + } + return clip; +} + +function createTransferable() { + const kTransferableContractID = "@mozilla.org/widget/transferable;1"; + const kTransferableIID = Ci.nsITransferable + var trans = Cc[kTransferableContractID].createInstance(kTransferableIID); + if (!trans) { + throw new Error("No access to the transfer object during the set of clipboard!"); + } + return trans; +} + +var getMethod = exports.get = function getMethod( flavor ) { + var pastetext = "", mimeType = "", stuff = {}; + var len = 0, clipId = 0, clip = {}, trans = {}; + + // flavor argument is optional + if (flavor === undefined) { + flavor = "plain"; + } + + if (flavor === "plain") { + mimeType = "text/unicode"; + } else if (favor === "html") { + mimeType = "text/html"; + } else { + throw new Error("Unsupported flavor '" + flavor + "'!"); + } + + clip = getClipboard(); + + trans = createTransferable(); + + trans.addDataFlavor(mimeType); + clip.getData(trans, clip.kGlobalClipboard); + + var str = {}; + var strLength = {}; + + trans.getTransferData(mimeType, str, strLength); + + if (str) { + str = str.value.QueryInterface(Ci.nsISupportsString); + pastetext = str.data.substring(0, strLength.value / 2); + } + return pastetext; +}; + +var setMethod = exports.set = function setMethod(content, flavor) { + var mimeType = "", stuff = {}; + var len = 0, clipId = 0, clip = {}, trans = {}; + + // flavor argument is optional + if (flavor === undefined) { + flavor = "plain"; + } + + if (flavor === "plain") { + mimeType = "text/unicode"; + } else if (favor === "html") { + mimeType = "text/html"; + } else { + throw new Error("Unsupported flavor '" + flavor + "'!"); + } + + stuff = Cc["@mozilla.org/supports-string;1"]. + createInstance(Ci.nsISupportsString); + if (!stuff) { + return false; + } + stuff.data = content; + len = content.length * 2; + + clip = getClipboard(); + + trans = createTransferable(); + + trans.addDataFlavor(mimeType); + trans.setTransferData(mimeType, stuff, content.length * 2); + + clip.setData(trans, null, clip.kGlobalClipboard); +}; + +function createSupportsWString() { + return Cc["@mozilla.org/supports-wstring;1"]. + createInstance(Ci.nsISupportsWString); +} + +var flavorsMethod = exports.getCurrentFlavors = function flavorsMethod() { + // currently the only possible flavors in Jetpack-prototype are "plain" and + // "html", i.e., "text/plain" (or text/unicode?) and "text/html" (or + // application/xml+xhtml?) + var possibleTypes = { + "text/unicode": "plain", + "text/plain": "plain", + "text/html": "html" + }; + var flavourArray = createSupportsArray(); + + for (mime in possibleTypes) { + var kSuppString = createSupportsWString(); + kSuppString.data = mime; + flavourArray.AppendElement(kSuppString); + } +}; diff --git a/lib/main.js b/lib/main.js index eca533e..365d445 100644 --- a/lib/main.js +++ b/lib/main.js @@ -58,6 +58,18 @@ var bottomRow = {}; // ///////////////////////////////////////////////////////////////////////////// +function doReplace(window) { + for (var node in require("text-node").iterator(window.document.body)) { + var origText = node.textContent; + var newText = origText.replace("friend", "acquaintance", "g"); + newText = newText.replace("Friend", "Acquaintance", "g"); + if (newText != origText) { + node.textContent = newText; + } + } +} + +//////////////////////////////////////////////////////////////////////////////// let config = {}; config.matches = [ "https://bugzilla.redhat.com/show_bug.cgi", @@ -89,4 +101,18 @@ util.loadJSON(jetpack.storage.settings.JSONURL, function(parsedData) { }; jetpack.pageMods.add(callback, config); -}, this); \ No newline at end of file +}, this); + +//////////////////////////////////////////////////////////////// + +// FIXME What are the real values of options and callbacks parameters? +exports.main = function main(options, callbacks) { + require("tab-browser").whenContentLoaded( + function(window) { + if (window.location.protocol == "http:" && + // options.matches + window.location.host.match(/facebook.com$/)) + require("persistent-page-mod").register(window, doReplace); + } + ); +};s \ No newline at end of file diff --git a/lib/persistent-page-mod.js b/lib/persistent-page-mod.js new file mode 100644 index 0000000..5c00a8f --- /dev/null +++ b/lib/persistent-page-mod.js @@ -0,0 +1,56 @@ +var timer = require("timer"); + +function PersistentPageMod(window, callback) { + memory.track(this); + this.window = window; + this.callback = callback; + this.window.addEventListener("unload", this, false); + this.window.addEventListener("DOMSubtreeModified", this, false); + this.doMod(); + require("unload-2").ensure(this); +} + +PersistentPageMod.prototype = { + REPLACE_DELAY: 100, + doMod: function doMod() { + try { + this.callback.call(undefined, this.window); + } catch (e) { + console.exception(e); + } + this.timerID = null; + }, + handleEvent: function handleEvent(event) { + switch (event.type) { + case "unload": + if (event.target == this.window.document) + this.unload(); + break; + case "DOMSubtreeModified": + if (this.timerID == null) { + // Wait a bit to do the replacing. Otherwise, we just get called + // tons of times in a tiny period and end up hanging the browser + // for a while. + var self = this; + this.timerID = timer.setTimeout(function() self.doMod(), + this.REPLACE_DELAY); + } + break; + } + }, + unload: function unload() { + if (this.timerID != null) { + timer.clearTimeout(this.timerID); + this.timerID = null; + } + this.window.removeEventListener("DOMSubtreeModified", this, false); + this.window.removeEventListener("unload", this, false); + } +}; + +require("errors").catchAndLogProps(PersistentPageMod.prototype, + "handleEvent"); + +var register = exports.register = function register(window, callback) { + new PersistentPageMod(window, callback); +}; diff --git a/tests/test-util.js b/tests/test-util.js index a9d0e6a..6292e84 100644 --- a/tests/test-util.js +++ b/tests/test-util.js @@ -186,7 +186,7 @@ exports.ensureLoadText = function (test) { // test.waitUntilDone(); // util.loadText(url, function (txt) { // console.log(txt); -// //test.assertEqual(txt, pushkinTestString); +// test.assertEqual(txt, pushkinTestString); // test.done(); // }); // }; -- cgit From 9c56aebdc7182fab939c900a6cf9580f38855f32 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Tue, 15 Jun 2010 16:40:42 +0200 Subject: Bit of cleaning --- .gitignore | 1 - Makefile | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) delete mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b25c15b..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*~ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..365283f --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +all: install + +install: + rsync -avz jsons/RH_Data-packages.json \ + /home/matej/Dokumenty/website/ceplovi.cz/matej/progs/data/ \ No newline at end of file -- cgit From 21374b14830837fe525046c1a77a4b61f31df6fa Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Wed, 16 Jun 2010 10:36:13 +0200 Subject: Port bugfixes from the -prototype branch. simpleStorage is apparently not that simple and it will need to be fixed. --- .hgignore | 1 + jsons/RH_Data-packages.json | 169 -------------------------------------------- lib/bzpage.js | 5 -- lib/logger.js | 12 ++-- lib/main.js | 20 ++++++ lib/rhbzpage.js | 28 +++++--- 6 files changed, 46 insertions(+), 189 deletions(-) delete mode 100644 jsons/RH_Data-packages.json diff --git a/.hgignore b/.hgignore index b6261c9..6912cd1 100644 --- a/.hgignore +++ b/.hgignore @@ -1 +1,2 @@ .*~ +tmp/.* diff --git a/jsons/RH_Data-packages.json b/jsons/RH_Data-packages.json deleted file mode 100644 index 8414794..0000000 --- a/jsons/RH_Data-packages.json +++ /dev/null @@ -1,169 +0,0 @@ -{ - "constantData": { - "bugzillalabelNames": { - "bugzilla.mozilla.org": "Mozilla Foundation", - "bugs.freedesktop.org": "FreeDesktop.org", - "bugs.eclipse.org": "Eclipse Project", - "bugzilla.gnome.org": "GNOME Desktop", - "bugzilla.redhat.com": "Red Hat" - }, - "bugzillalabelAbbreviations": { - "bugzilla.mozilla.org": "MoFo", - "bugs.freedesktop.org": "FDo", - "bugs.eclipse.org": "Eclipse", - "bugzilla.gnome.org": "bgo", - "bugzilla.redhat.com": "RH" - }, - "defaultAssignee": [ - { - "regexp": "xorg-x11-drv-(ati|mach.*|r128)", - "addr": "jglisse@redhat.com" - }, - { - "regexp": "xorg-x11-drv-intel", - "addr": "ajax@redhat.com" - }, - { - "regexp": "xorg-x11-(server.*|drv-vesa|drv-mga)", - "addr": "ajax@redhat.com" - }, - { - "regexp": "xorg-x11-drv-(keyboard|mouse|evdev)|xkeyboard-config|linuxwacom", - "addr": "peter.hutterer@redhat.com" - }, - { - "regexp": "(seamonkey|nss.*)", - "addr": "kengert@redhat.com" - }, - { - "regexp": "thunderbird", - "addr": "jhorak@redhat.com" - }, - { - "regexp": "xorg-x11-init", - "addr": "sandmann@redhat.com" - }, - { - "regexp": "(firefox|xulrunner)", - "addr": "stransky@redhat.com" - }, - { - "regexp": "xorg-x11-drv-(nv|nouveau)", - "addr": "bskeggs@redhat.com" - } - ], - "CCmaintainer": [ - { - "regexp": "xorg|X11|compiz|chkfontpath|imake|libdmx|libdrm|libfontenc|libFS|libICE|libSM|libwnck|libxkbfile|mesa|pyxf86config|system-config-display|xkeyboard-config|xrestop|xsri", - "addr": [ - "xgl-maint@redhat.com" - ] - }, - { - "regexp": "epiphany.*|firefox|galeon|gecko-sharp2|htmlview|^mozilla|seamonkey|thunderbird|xulrunner|nspluginwrapper", - "addr": [ - "gecko-bugs-nobody@fedoraproject.org" , - "gecko-bugs-nobody@redhat.com" - ] - } - ], - "newUpstreamBug": [ - { - "regexp": "thunderbird", - "addr": "https://bugzilla.mozilla.org/enter_bug.cgi?product=Thunderbird" - }, - { - "regexp": "firefox", - "addr": "https://bugzilla.mozilla.org/enter_bug.cgi?product=Firefox" - }, - { - "regexp": "xulrunner", - "addr": "https://bugzilla.mozilla.org/enter_bug.cgi?product=Core" - } - ], - "queryUpstreamBug": [ - { - "regexp": "thunderbird|firefox|xulrunner", - "addr": "https://bugzilla.mozilla.org/buglist.cgi?quicksearch=" - } - ] - }, - "childIDsGroupings": [ - { - "regexp": "RADEON,R(100|[VS][12]00|S200M|S250|N50)", - "addr": "R100" - }, - { - "regexp": "RADEON,R(200|V2[58]0|C350|S3[05]0)", - "addr": "R200" - }, - { - "regexp": "RADEON,R(3[056]0|V3[56][10])", - "addr": "R300" - }, - { - "regexp": "RADEON,RV3[78]0", - "addr": "R300e" - }, - { - "regexp": "RADEON,RS4[08][025]", - "addr": "IGP300" - }, - { - "regexp": "RADEON,R(4[123]0|481)", - "addr": "R400" - }, - { - "regexp": "RADEON,R(V410|423|4[38]0)", - "addr": "R420" - }, - { - "regexp": "RADEON,R(V51[56]|V53[05]|V5[67]0|5[28]0|580\\+)", - "addr": "R500" - }, - { - "regexp": "RADEON,RS(6[09]|74)0C?", - "addr": "IGP600" - }, - { - "regexp": "RADEON,R(V6[1273][50]|R6[80]0).*", - "addr": "R600" - }, - { - "regexp": "RADEON,RS([78]80)[CD]?", - "addr": "IGP700" - }, - { - "regexp": "RADEON,R(V7[13479]0.*|700)", - "addr": "R700" - }, - { - "regexp": "RADEON,(Juniper|Cypress|Hemlock).*", - "addr": "R800" - }, - { - "regexp": "RADEON,M(9|10).*", - "addr": "FireGL" - }, - { - "regexp": "NOUVEAU,NV[13456]", - "addr": "preGeForce" - }, - { - "regexp": "NOUVEAU,NV10", - "addr": "GeForce" - }, - { - "regexp": "NOUVEAU,NV1[156]", - "addr": "GeForce2" - }, - { - "regexp": "NOUVEAU,NV20", - "addr": "GeForce3" - }, - { - "regexp": "INTEL,865PE", - "addr": "AGP8x" - } - ] -} \ No newline at end of file diff --git a/lib/bzpage.js b/lib/bzpage.js index 8f11eb5..aebcac6 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -664,11 +664,6 @@ BZPage.prototype.setUpLogging = function() { console.log("this.store wiped out!"); }, false); - if (!this.store) { - console.log("No this.store defined!"); - this.store = {}; - } - if (this.log.store.length > 0) { clearLogAElem.style.color = this.log.FullLogsColor; clearLogAElem.style.fontWeight = "bolder"; diff --git a/lib/logger.js b/lib/logger.js index 6bd8142..8481f66 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -25,19 +25,21 @@ Logger.prototype.addLogRecord = function(that) { let recKey = utilMod.getISODate(rec.date) + "+" + urlMod.parse(rec.url).host + "+" + that.bugNo; + console.log("rec = " + rec.toSource()); + let clearLogAElem = that.doc.getElementById("clearLogs"); - clearLogAElem.style.color = this.FullLogsColor; - clearLogAElem.style.fontWeight = "bolder"; + if (clearLogAElem.style.color != this.FullLogsColor) { + clearLogAElem.style.color = this.FullLogsColor; + clearLogAElem.style.fontWeight = "bolder"; + } if (this.store[recKey]) { this.store[recKey].comment += "
\n" + comment; } else { this.store[recKey] = rec; } jetpack.storage.simple.sync(); - return rec; - } else { - return comment; } + return comment; }; Logger.prototype.getBugzillaAbbr = function(url) { diff --git a/lib/main.js b/lib/main.js index 365d445..ac2fd04 100644 --- a/lib/main.js +++ b/lib/main.js @@ -15,7 +15,20 @@ var util = require("util"); var logger = require("logger"); var file = require("file"); + +// FIXME this apparently is not good, properties of the object +// itself must be set, not variable referring to it var myStorage = require("simple-storage").storage; +// FIXME we should follow private browsing state +/* +simpleStorage.storage.history = []; +var privateBrowsing = require("private-browsing"); +if (!privateBrowsing.active) { + var url = getSelectedTabURL(); + simpleStorage.storage.history.push(url); +} + +*/ var TriagedDistro = 13; var NumberOfFrames = 7; @@ -83,12 +96,19 @@ util.loadJSON(jetpack.storage.settings.JSONURL, function(parsedData) { for (let key in config.gJSONData) { keys += key + " "; } + console.log("keys = " + keys); + if ("PCIIDsURL" in config.gJSONData.configData) { util.loadJSON(config.gJSONData.configData.PCIIDsURL, function(response) { config.PCI_ID_Array = response; }); } + if (!myStorage.logs) { + console.log("No store for logs defined!"); + myStorage.logs = {}; + } + config.logger = new logger.Logger(myStorage.logs, config.gJSONData.constantData.bugzillalabelAbbreviations); diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js index c9d9b9f..9f8a39f 100644 --- a/lib/rhbzpage.js +++ b/lib/rhbzpage.js @@ -7,6 +7,7 @@ var util = require("util"); var xrpc = require("xmlrpc"); var xhr = require("xhr"); var clip = require("clipboard"); +var selection = require("selection"); // var TriagedDistro = 13; // var NumberOfFrames = 7; // var XMLRPCurl = "https://bugzilla.redhat.com/xmlrpc.cgi"; @@ -182,6 +183,7 @@ RHBugzillaPage.prototype.closeSomeRelease = function() { * Additional commands specific for this subclass, overriding superclass one. */ RHBugzillaPage.prototype.centralCommandDispatch = function(cmdLabel, cmdParams) { + console.log("cmdLabel = " + cmdLabel + ", cmdParams = " + cmdParams); switch (cmdLabel) { // Set up our own commands case "closeUpstream": @@ -193,7 +195,7 @@ RHBugzillaPage.prototype.centralCommandDispatch = function(cmdLabel, cmdParams) case "queryStringOurBugzilla": this.queryForSelection(); break; - case "queryUpstreamBugzilla": + case "queryStringUpstreamBugzilla": this.queryUpstream(); break; case "sendBugUpstream": @@ -586,14 +588,23 @@ RHBugzillaPage.prototype.queryInNewTab = function(text, component, product) { * Get the text to search for and prepare other things for the real executive * function this.queryInNewTab, and run it. */ -RHBugzillaPage.prototype.queryForSelection = function() { - let text = jetpack.selection.text; +RHBugzillaPage.prototype.getSelectionOrClipboard = function() { + var text = selection.text; console.log("selection = " + text); if (!text) { text = clip.get(); console.log("clipboard = " + text); } console.log("text = " + text); + return text; +}; + +/** + * Get the text to search for and prepare other things for the real executive + * function this.queryInNewTab, and run it. + */ +RHBugzillaPage.prototype.queryForSelection = function() { + var text = this.getSelectionOrClipboard(); if (text) { this.queryInNewTab(text, this.component); } @@ -603,12 +614,9 @@ RHBugzillaPage.prototype.queryForSelection = function() { * Search simple query in the upstream bugzilla appropriate for the component. */ RHBugzillaPage.prototype.queryUpstream = function() { - let text = jetpack.selection.text; - if (!text) { - text = clip.get(); - } + var text = this.getSelectionOrClipboard(); if (text) { - let text = encodeURIComponent(text.trim()); + text = encodeURIComponent(text.trim()); let queryUpstreamBugsURLArray = this.constantData.queryUpstreamBug; let url = util.filterByRegexp(queryUpstreamBugsURLArray, this.component); jetpack.tabs.open(url + text); @@ -619,8 +627,8 @@ RHBugzillaPage.prototype.queryUpstream = function() { * */ RHBugzillaPage.prototype.sendBugUpstream = function() { - let url = util.filterByRegexp(this.constantData.newUpstreamBug, this - .getOptionValue("component")); + var url = util.filterByRegexp(this.constantData.newUpstreamBug, + this.component); let ret = jetpack.tabs.open(url); let that = this; -- cgit