[Pkg-mozext-commits] [adblock-plus-element-hiding-helper] 456/483: issue 5 - changed nsIObserver to DevToolsAPI

David Prévot taffit at moszumanska.debian.org
Thu Jan 22 21:42:06 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus-element-hiding-helper.

commit e61e2ef76acb1df47c0fb86c95d24c397ccaa124
Author: Manvel Saroyan <manvel at adblockplus.org>
Date:   Sun Apr 13 01:20:57 2014 +0400

    issue 5 - changed nsIObserver to DevToolsAPI
---
 chrome/locale/en-US/global.properties |  2 -
 lib/inspectorObserver.js              | 69 ++++++++++++-----------------------
 metadata.gecko                        |  6 +--
 3 files changed, 26 insertions(+), 51 deletions(-)

diff --git a/chrome/locale/en-US/global.properties b/chrome/locale/en-US/global.properties
index 186e77b..4ad994a 100644
--- a/chrome/locale/en-US/global.properties
+++ b/chrome/locale/en-US/global.properties
@@ -31,6 +31,4 @@ command.showMenu.alternativeKey=
 selectelement.label=Select an element to hide
 stopselection.label=Abort element selection
 
-inspector.button.label=Hide with ABP
-inspector.button.accesskey=A
 inspector.button.tooltiptext=Create an element hiding rule to hide this element and similar ones with Adblock Plus
diff --git a/lib/inspectorObserver.js b/lib/inspectorObserver.js
index dd01c88..f6fd747 100644
--- a/lib/inspectorObserver.js
+++ b/lib/inspectorObserver.js
@@ -4,76 +4,53 @@
  * http://mozilla.org/MPL/2.0/.
  */
 
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", null);
 
 let InspectorObserver =
 {
   init: function()
   {
-    Services.obs.addObserver(this, "inspector-opened", true);
+    gDevTools.on("inspector-ready", this.inspectorReady);
     onShutdown.add(function()
     {
-      Services.obs.removeObserver(this, "inspector-opened");
-
-      let e = Services.ww.getWindowEnumerator();
-      while (e.hasMoreElements())
-      {
-        let window = e.getNext().QueryInterface(Ci.nsIDOMWindow);
-        let button = window.document.getElementById("inspector-abp-elemhide-toolbutton");
-        if (button)
-          button.parentNode.removeChild(button);
-      }
+      gDevTools.off("inspector-ready", this.inspectorReady);
     }.bind(this));
   },
 
-  get inspectorButton()
+  get inspectorButtonTooltip()
   {
     // Randomize URI to work around bug 719376
     let stringBundle = Services.strings.createBundle("chrome://elemhidehelper/locale/global.properties?" + Math.random());
-    let result = [stringBundle.GetStringFromName("inspector.button.label"), stringBundle.GetStringFromName("inspector.button.accesskey"), stringBundle.GetStringFromName("inspector.button.tooltiptext")];
+    let result = stringBundle.GetStringFromName("inspector.button.tooltiptext");
 
-    delete this.inspectorButton;
-    this.__defineGetter__("inspectorButton", function() result);
-    return this.inspectorButton;
+    delete this.inspectorButtonTooltip;
+    this.__defineGetter__("inspectorButtonTooltip", function() result);
+    return this.inspectorButtonTooltip;
   },
-
-  observe: function(subject, topic, data)
+  
+  inspectorReady: function(eventName, toolbox, panel)
   {
-    if (topic != "inspector-opened")
-      return;
-
-    let InspectorUI = subject.wrappedJSObject;
-    let window = InspectorUI.chromeWin;
-    let button = window.document.getElementById("inspector-abp-elemhide-toolbutton");
-    if (button)
-      button.parentNode.removeChild(button);
-
-    if (!("@adblockplus.org/abp/public;1" in Cc) || !window._ehhWrapper || !require("aardvark").Aardvark.canSelect(window._ehhWrapper.browser))
+    let panelWindow = panel.panelWin;
+    let inspectBtn = panelWindow.document.getElementById("inspector-inspect-toolbutton");
+    if (!inspectBtn)
       return;
-
-    let parent = window.document.getElementById("inspector-tools");
-    if (!parent)
-      return;
-
-    let [label, accesskey, tooltiptext] = this.inspectorButton;
-    button = window.document.createElement("toolbarbutton");
+    
+    let tooltiptext = InspectorObserver.inspectorButtonTooltip;
+    button = panelWindow.document.createElement("toolbarbutton");
     button.setAttribute("id", "inspector-abp-elemhide-toolbutton");
-    button.setAttribute("label", label);
+    button.style.listStyleImage = "url('chrome://adblockplus/skin/abp-status-16.png')";
+    button.style.MozImageRegion = "rect(0px, 16px, 16px, 0px)";
+    button.style.paddingTop = "4px";
     button.setAttribute("class", "devtools-toolbarbutton");
-    button.setAttribute("accesskey", accesskey);
     button.setAttribute("tooltiptext", tooltiptext);
     button.setAttribute("tabindex", "0");
     button.addEventListener("command", function()
     {
-      InspectorUI.chromeWin.openDialog("chrome://elemhidehelper/content/composer.xul", "_blank",
-                                       "chrome,centerscreen,resizable,dialog=no", InspectorUI.selection);
-      InspectorUI.closeInspectorUI();
+      panelWindow.openDialog("chrome://elemhidehelper/content/composer.xul", "_blank", 
+                             "chrome,centerscreen,resizable,dialog=no", panel.selection.node);
     }, false);
-    parent.appendChild(button);
-  },
-
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver])
+    inspectBtn.parentNode.insertBefore(button, inspectBtn.nextSibling);
+  }
 };
 
 InspectorObserver.init();
diff --git a/metadata.gecko b/metadata.gecko
index af103c3..964d8c1 100644
--- a/metadata.gecko
+++ b/metadata.gecko
@@ -20,7 +20,7 @@ zh-CN=http://adblockplus.org/zh_CN/elemhidehelper
 zh-TW=http://adblockplus.org/zh_TW/elemhidehelper
 
 [compat]
-firefox=16.0/32.0
-thunderbird=16.0/32.0
-seamonkey=2.13/2.29
+firefox=20.0/32.0
+thunderbird=20.0/32.0
+seamonkey=2.17/2.29
 conkeror=0.1/100.0

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus-element-hiding-helper.git



More information about the Pkg-mozext-commits mailing list