Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/main.js

Issue 8402021: Crawler frontend (Closed)
Patch Set: Created Sept. 21, 2012, 1:16 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/main.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/main.js
@@ -0,0 +1,95 @@
+/*
+ * This Source Code is subject to the terms of the Mozilla Public License
+ * version 2.0 (the "License"). You can obtain a copy of the License at
+ * http://mozilla.org/MPL/2.0/.
+ */
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+let {Prefs} = require("prefs");
Wladimir Palant 2012/09/21 15:36:18 You aren't using prefs so you should remove that l
+let {WindowObserver} = require("windowObserver");
+
+let knownWindowTypes =
+{
+ "navigator:browser": true,
+ "mail:3pane": true,
+ "mail:messageWindow": true,
Wladimir Palant 2012/09/21 15:36:18 I think that you only know navigator:browser - mea
+ __proto__: null
+};
+
+new WindowObserver({
+ applyToWindow: function(window)
+ {
+ let type = window.document.documentElement.getAttribute("windowtype");
+ if (!(type in knownWindowTypes))
+ return;
+
+ window.addEventListener("popupshowing", popupShowingHandler, false);
+ window.addEventListener("popuphidden", popupHiddenHandler, false);
+ },
+
+ removeFromWindow: function(window)
+ {
+ let type = window.document.documentElement.getAttribute("windowtype");
+ if (!(type in knownWindowTypes))
+ return;
+
+ window.removeEventListener("popupshowing", popupShowingHandler, false);
+ window.removeEventListener("popuphidden", popupHiddenHandler, false);
+ }
+});
+
+function getMenuItem()
+{
+ // Randomize URI to work around bug 719376
+ let stringBundle = Services.strings.createBundle("chrome://abpcrawler/locale/global.properties?" + Math.random());
+ let result = [stringBundle.GetStringFromName("crawler.label")];
+
+ getMenuItem = function() result;
+ return getMenuItem();
+}
+
+function popupShowingHandler(event)
+{
+ let popup = event.target;
+ if (!/^(abp-(?:toolbar|status|menuitem)-)popup$/.test(popup.id))
+ return;
+
+ popupHiddenHandler(event);
+
+ let [label] = getMenuItem();
+ let item = popup.ownerDocument.createElement("menuitem");
+ item.setAttribute("label", label);
+ item.setAttribute("class", "abpcrawler-item");
+
+ item.addEventListener("command", popupCommandHandler, false);
+
+ let insertBefore = null;
+ for (let child = popup.firstChild; child; child = child.nextSibling)
+ if (/-options$/.test(child.id))
+ insertBefore = child;
+ popup.insertBefore(item, insertBefore);
+}
+
+function popupHiddenHandler(event)
+{
+ let popup = event.target;
+ if (!/^(abp-(?:toolbar|status|menuitem)-)popup$/.test(popup.id))
+ return;
+
+ let items = popup.getElementsByClassName("abpcrawler-item");
+ while (items.length)
+ items[0].parentNode.removeChild(items[0]);
+}
+
+function popupCommandHandler(event)
+{
+ if (!("@adblockplus.org/abp/public;1" in Cc))
+ return;
+
+ let crawlerWnd = Services.wm.getMostRecentWindow("abpcrawler:crawl");
+ if (crawlerWnd)
+ crawlerWnd.focus();
+ else
+ event.target.ownerDocument.defaultView.openDialog("chrome://abpcrawler/content/crawler.xul", "_blank", "chrome,centerscreen,resizable,dialog=no");
+}

Powered by Google App Engine
This is Rietveld