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

Unified Diff: lib/inspectorObserver.js

Issue 4780225334345728: Element Hiding Helper inspector tool fix (Closed)
Patch Set: Created April 8, 2014, 5:23 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/inspectorObserver.js
===================================================================
--- a/lib/inspectorObserver.js
+++ b/lib/inspectorObserver.js
@@ -4,26 +4,16 @@
* http://mozilla.org/MPL/2.0/.
*/
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource:///modules/devtools/gDevTools.jsm");
Wladimir Palant 2014/04/11 11:06:08 While you are at it, please don't use a blind impo
saroyanm 2014/04/11 16:09:10 Got it.
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));
},
@@ -37,27 +27,24 @@
this.__defineGetter__("inspectorButton", function() result);
return this.inspectorButton;
},
-
- observe: function(subject, topic, data)
+
+ inspectorReady: function(eventName, listener)
Wladimir Palant 2014/04/11 11:06:08 The second parameter here isn't listener but panel
saroyanm 2014/04/11 16:09:10 Good catch, actually I've tested and seams like th
{
- if (topic != "inspector-opened")
+ let toolbox = gDevTools.getToolbox(listener.target);
Wladimir Palant 2014/04/11 11:06:08 I checked why the documentation mentions getToolbo
saroyanm 2014/04/11 16:09:10 Good point: I've tested with FF19 and there is an
+ if (!toolbox)
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 panel = toolbox.getToolPanels().get("inspector");
+ if (!panel)
return;
Wladimir Palant 2014/04/11 11:06:08 So you are going from the panel to the toolbox to
saroyanm 2014/04/11 16:09:10 Lol :)
-
- let parent = window.document.getElementById("inspector-tools");
+
+ let panelWindow = panel.panelWin;
+ let parent = panelWindow.document.getElementById("inspector-toolbar");
if (!parent)
return;
-
- let [label, accesskey, tooltiptext] = this.inspectorButton;
- button = window.document.createElement("toolbarbutton");
+
+ let [label, accesskey, tooltiptext] = InspectorObserver.inspectorButton;
+ button = panelWindow.document.createElement("toolbarbutton");
button.setAttribute("id", "inspector-abp-elemhide-toolbutton");
button.setAttribute("label", label);
button.setAttribute("class", "devtools-toolbarbutton");
@@ -66,14 +53,11 @@
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);
Wladimir Palant 2014/04/11 11:06:08 Adding the button at the end probably isn't the be
saroyanm 2014/04/11 16:09:10 Good point changed. Thanks for pointing.
- },
-
- QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver])
+ }
};
InspectorObserver.init();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld