[Pkg-mozext-commits] [adblock-plus-element-hiding-helper] 09/10: Issue 2816 - Partial fix for EHH button in inspector tool, preview functionality still broken

David Prévot taffit at moszumanska.debian.org
Fri Jan 22 01:02:31 UTC 2016


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

taffit pushed a commit to tag pre-hg-git-0.8
in repository adblock-plus-element-hiding-helper.

commit 0e6eaa71836f86ce73d87ce952c36ee5c28989e1
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Tue Jul 28 11:48:02 2015 +0200

    Issue 2816 - Partial fix for EHH button in inspector tool, preview functionality still broken
---
 chrome/content/actor.jsm      | 110 ++++++++++++++++++++++++++++++++++++++++++
 chrome/content/composer.js    |  67 ++++---------------------
 chrome/content/frameScript.js |  31 ++++++++++++
 lib/aardvark.js               |  17 +++++--
 lib/inspectorObserver.js      |  22 +++++++--
 lib/main.js                   |  10 +++-
 metadata.gecko                |   6 +--
 7 files changed, 196 insertions(+), 67 deletions(-)

diff --git a/chrome/content/actor.jsm b/chrome/content/actor.jsm
new file mode 100644
index 0000000..b3de0e7
--- /dev/null
+++ b/chrome/content/actor.jsm
@@ -0,0 +1,110 @@
+/*
+ * 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/.
+ */
+
+let EXPORTED_SYMBOLS = ["shutdown", "getNodeInfo"];
+
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+
+let {console} = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
+let {DebuggerServer} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
+let name = "elemhidehelper";
+let actor = {
+  constructorFun: Actor,
+  constructorName: name,
+  name: name
+};
+
+DebuggerServer.addTabActor(actor, name);
+
+let shutdown = (function()
+{
+  let executed = false;
+  return function()
+  {
+    if (!executed)
+      DebuggerServer.removeTabActor(actor);
+    executed = true;
+  }
+})();
+
+function Actor(connection, tabActor)
+{
+}
+
+Actor.prototype = {
+  requestTypes: {
+    nodeinfo: function(request, connection)
+    {
+      let nodeActor = connection.getActor(request.nodeActor);
+      if (!nodeActor || !nodeActor.rawNode ||
+          nodeActor.rawNode.nodeType != Ci.nsIDOMNode.ELEMENT_NODE)
+      {
+        return {};
+      }
+
+      return getNodeInfo(nodeActor.rawNode);
+    }
+  }
+};
+
+function getNodeInfo(node)
+{
+  return {
+    host: node.ownerDocument.defaultView.location.hostname,
+    nodeData: getNodeData(node)
+  };
+}
+
+function getNodeData(node, parentNode)
+{
+  if (!node)
+    return null;
+
+  let result = {};
+  result.tagName = {value: node.tagName, checked: false};
+
+  if (typeof parentNode != "undefined")
+    result.parentNode = parentNode;
+  else
+    result.parentNode = getNodeData(node.parentElement);
+
+  let prevSibling = node.previousElementSibling;
+  result.prevSibling = getNodeData(prevSibling, result.parentNode);
+
+  if (result.parentNode && !prevSibling)
+    result.firstChild = {checked: false};
+
+  let nextSibling = node.nextElementSibling;
+  if (result.parentNode && !nextSibling)
+    result.lastChild = {checked: false};
+
+  result.attributes = [];
+  for (let attribute of node.attributes)
+  {
+    let data = {
+      name: attribute.name,
+      value: attribute.value,
+      selected: attribute.value,
+      checked: false
+    };
+    if (data.name == "id" || data.name == "class")
+      result.attributes.unshift(data);
+    else
+      result.attributes.push(data);
+  }
+
+  if (result.attributes.length >= 2 && result.attributes[1].name == "id")
+  {
+    // Make sure ID attribute comes first
+    let tmp = result.attributes[1];
+    result.attributes[1] = result.attributes[0];
+    result.attributes[0] = tmp;
+  }
+
+  result.customCSS = {selected: "", checked: false};
+  return result;
+}
diff --git a/chrome/content/composer.js b/chrome/content/composer.js
index d8a45f7..1b8c5e9 100644
--- a/chrome/content/composer.js
+++ b/chrome/content/composer.js
@@ -19,51 +19,6 @@ let abpURL = Cc["@adblockplus.org/abp/public;1"].getService(Ci.nsIURI);
 Cu.import(abpURL.spec);
 
 /*******************
- * NodeData object *
- *******************/
-
-function NodeData(node, parentNode) {
-  this.tagName = {value: node.tagName, checked: false};
-
-  if (typeof parentNode == "undefined")
-    parentNode = (node.parentNode && node.parentNode.nodeType == node.ELEMENT_NODE ? new NodeData(node.parentNode) : null);
-  this.parentNode = parentNode;
-
-  var prevSibling = node.previousSibling;
-  while (prevSibling && prevSibling.nodeType != node.ELEMENT_NODE)
-    prevSibling = prevSibling.previousSibling;
-  this.prevSibling = (prevSibling ? new NodeData(prevSibling, this.parentNode) : null);
-
-  if (parentNode && !prevSibling)
-    this.firstChild = {checked: false};
-
-  var nextSibling = node.nextSibling;
-  while (nextSibling && nextSibling.nodeType != node.ELEMENT_NODE)
-    nextSibling = nextSibling.nextSibling;
-  if (parentNode && !nextSibling)
-    this.lastChild = {checked: false};
-
-  this.attributes = [];
-  for (var i = 0; i < node.attributes.length; i++) {
-    var attribute = node.attributes[i];
-    var data = {name: attribute.name, value: attribute.value, selected: attribute.value, checked: false};
-    if (data.name == "id" || data.name == "class")
-      this.attributes.unshift(data);
-    else
-      this.attributes.push(data);
-  }
-
-  if (this.attributes.length >= 2 && this.attributes[1].name == "id") {
-    // Make sure ID attribute comes first
-    var tmp = this.attributes[1];
-    this.attributes[1] = this.attributes[0];
-    this.attributes[0] = tmp;
-  }
-
-  this.customCSS = {selected: "", checked: false};
-}
-
-/*******************
  * TreeView object *
  *******************/
 
@@ -127,10 +82,10 @@ function TreeView_getCellProperties(row, col) {
  * General functions *
  *********************/
 
-function init() {
-  var element = window.arguments[0];
-  doc = element.ownerDocument;
-  var wnd = doc.defaultView;
+function init()
+{
+  nodeData = window.arguments[0];
+  let host = window.arguments[1];
 
   // Check whether element hiding group is disabled
   let subscription = AdblockPlus.getSubscription("~eh~");
@@ -142,7 +97,6 @@ function init() {
     warning.hidden = false;
   }
 
-  nodeData = new NodeData(element);
   nodeData.tagName.checked = true;
   if (nodeData.attributes.length > 0)
   {
@@ -169,7 +123,6 @@ function init() {
     }
   }
 
-  let domain = wnd.location.hostname;
   let selectedDomain;
   switch (Prefs.composer_defaultDomain)
   {
@@ -181,7 +134,7 @@ function init() {
       {
         // EffectiveTLDService will throw for IP addresses, just go to the next case then
         let effectiveTLD = Cc["@mozilla.org/network/effective-tld-service;1"].getService(Ci.nsIEffectiveTLDService);
-        selectedDomain = effectiveTLD.getPublicSuffixFromHost(domain);
+        selectedDomain = effectiveTLD.getPublicSuffixFromHost(host);
         break;
       } catch (e) {}
     case 2:
@@ -189,17 +142,17 @@ function init() {
       {
         // EffectiveTLDService will throw for IP addresses, just go to the next case then
         let effectiveTLD = Cc["@mozilla.org/network/effective-tld-service;1"].getService(Ci.nsIEffectiveTLDService);
-        selectedDomain = effectiveTLD.getBaseDomainFromHost(domain);
+        selectedDomain = effectiveTLD.getBaseDomainFromHost(host);
         break;
       } catch (e) {}
     case 3:
-      selectedDomain = domain.replace(/^www\./, "");
+      selectedDomain = host.replace(/^www\./, "");
       break;
     default:
-      selectedDomain = domain;
+      selectedDomain = host;
       break;
   }
-  domainData = {value: domain, selected: selectedDomain};
+  domainData = {value: host, selected: selectedDomain};
 
   fillDomains(domainData);
   fillNodes(nodeData);
@@ -242,7 +195,7 @@ function updateExpression()
             op = "^=";
           else if (attr.value.substr(attr.value.length - attr.selected.length) == attr.selected)
             op = "$=";
-  
+
           let useFallback = false;
           if (attr.name == "id" && op == "=")
             expression += "#" + escapeName(attr.selected).replace(/^([^a-zA-Z\\])/, escapeChar).replace(/\\(\s)$/, escapeChar);
diff --git a/chrome/content/frameScript.js b/chrome/content/frameScript.js
new file mode 100644
index 0000000..7763553
--- /dev/null
+++ b/chrome/content/frameScript.js
@@ -0,0 +1,31 @@
+/*
+ * 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/.
+ */
+
+(function()
+{
+  const Cu = Components.utils;
+
+  let rand = Components.stack.filename.replace(/.*\?/, "");
+  let module = "chrome://elemhidehelper/content/actor.jsm?" + rand;
+  let {shutdown, getNodeInfo} = Cu.import(module, {});
+
+  addMessageListener("ElemHideHelper:Shutdown", onShutdown);
+  addMessageListener("ElemHideHelper:GetNodeInfo", onGetNodeInfo);
+
+  function onShutdown()
+  {
+    shutdown();
+    Cu.unload(module);
+    removeMessageListener("ElemHideHelper:Shutdown", onShutdown);
+    removeMessageListener("ElemHideHelper:GetNodeInfo", onGetNodeInfo);
+  }
+
+  function onGetNodeInfo(message)
+  {
+    let info = getNodeInfo(message.objects.element);
+    message.objects.callback(info.nodeData, info.host);
+  }
+})();
diff --git a/lib/aardvark.js b/lib/aardvark.js
index 899ba2a..2ed4add 100644
--- a/lib/aardvark.js
+++ b/lib/aardvark.js
@@ -572,9 +572,20 @@ let Aardvark = exports.Aardvark =
     if (!elem)
       return false;
 
-    this.window.openDialog("chrome://elemhidehelper/content/composer.xul", "_blank",
-                           "chrome,centerscreen,resizable,dialog=no", elem);
-    this.quit();
+    this.browser.selectedBrowser.messageManager.sendAsyncMessage(
+      "ElemHideHelper:GetNodeInfo",
+      null,
+      {
+        element: elem,
+        callback: (nodeData, host) =>
+        {
+          this.window.openDialog("chrome://elemhidehelper/content/composer.xul",
+              "_blank", "chrome,centerscreen,resizable,dialog=no", nodeData,
+              host);
+          this.quit();
+        }
+      }
+    );
     return false;
   },
 
diff --git a/lib/inspectorObserver.js b/lib/inspectorObserver.js
index 5ec01c2..c07d659 100644
--- a/lib/inspectorObserver.js
+++ b/lib/inspectorObserver.js
@@ -49,10 +49,26 @@ let InspectorObserver =
     button.setAttribute("class", "devtools-toolbarbutton");
     button.setAttribute("tooltiptext", tooltiptext);
     button.setAttribute("tabindex", "0");
-    button.addEventListener("command", function()
+    button.addEventListener("command", () =>
     {
-      panelWindow.openDialog("chrome://elemhidehelper/content/composer.xul", "_blank",
-                             "chrome,centerscreen,resizable,dialog=no", panel.selection.node);
+      let node = panel.selection.nodeFront;
+      let target = panel.target;
+      if (node && target.form.elemhidehelper)
+      {
+        target.client.request({
+          to: target.form.elemhidehelper,
+          type: "nodeinfo",
+          nodeActor: node.actorID
+        }, function(response)
+        {
+          if (!response.nodeData)
+            return;
+
+          panelWindow.openDialog("chrome://elemhidehelper/content/composer.xul",
+              "_blank", "chrome,centerscreen,resizable,dialog=no",
+              response.nodeData, response.host);
+        });
+      }
     }, false);
 
     //Override button style for light DevTools theme
diff --git a/lib/main.js b/lib/main.js
index e8ca127..b8822ec 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -4,7 +4,7 @@
  * http://mozilla.org/MPL/2.0/.
  */
 
-Cu.import("resource://gre/modules/Services.jsm");
+let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
 
 let {Prefs} = require("prefs");
 let {WindowObserver} = require("windowObserver");
@@ -46,6 +46,14 @@ request.addEventListener("load", function(event)
 }, false);
 request.send(null);
 
+// Load our developer tools actor
+let frameScript = "chrome://elemhidehelper/content/frameScript.js?" + elementMarkerClass;
+Services.mm.loadFrameScript(frameScript, true);
+onShutdown.add(() => {
+  Services.mm.removeDelayedFrameScript(frameScript);
+  Services.mm.broadcastAsyncMessage("ElemHideHelper:Shutdown");
+});
+
 // Load overlay asynchonously and start attaching to windows once done
 request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIJSXMLHttpRequest);
 request.open("GET", "chrome://elemhidehelper/content/overlay.xul");
diff --git a/metadata.gecko b/metadata.gecko
index f415217..ae242af 100644
--- a/metadata.gecko
+++ b/metadata.gecko
@@ -20,7 +20,7 @@ zh-CN=https://adblockplus.org/zh_CN/elemhidehelper
 zh-TW=https://adblockplus.org/zh_TW/elemhidehelper
 
 [compat]
-firefox=22.0/42.0
-thunderbird=22.0/42.0
-seamonkey=2.19/2.39
+firefox=29.0/42.0
+thunderbird=29.0/42.0
+seamonkey=2.26/2.39
 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