[Pkg-mozext-commits] [adblock-plus] 38/87: Issue 3499 - Use the new messaging API for object tabs

David Prévot taffit at moszumanska.debian.org
Sat Apr 30 17:59:06 UTC 2016


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

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

commit 865fe21e17d239287867e9d683ecb9a14dda5603
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Wed Mar 16 13:09:39 2016 +0100

    Issue 3499 - Use the new messaging API for object tabs
---
 lib/child/objectTabs.js | 51 ++++++++++++++++++++++++++++---------------------
 lib/objectTabs.js       |  7 ++++---
 2 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/lib/child/objectTabs.js b/lib/child/objectTabs.js
index fac05f6..1071126 100644
--- a/lib/child/objectTabs.js
+++ b/lib/child/objectTabs.js
@@ -19,6 +19,8 @@
  * @fileOverview Code responsible for showing and hiding object tabs.
  */
 
+let {port} = require("messaging");
+
 /**
  * Class responsible for showing and hiding object tabs.
  * @class
@@ -74,7 +76,8 @@ var objTabs =
   hideTargetTime: 0,
 
   /**
-   * Localized texts and class names to be used for the tab.
+   * Localized texts and class names to be used for the tab. This will be set
+   * when showTabFor is called for the first time.
    * @type Object
    */
   texts: null,
@@ -90,27 +93,34 @@ var objTabs =
         application == "adblockbrowser")
       return;
 
-    if (!sendSyncMessage("AdblockPlus:GetObjectTabsStatus"))
-      return;
-
-    if (this.hideTimer)
+    if (!this.texts)
+      this.texts = port.emitWithResponse("getObjectTabsTexts");
+    Promise.all([port.emitWithResponse("getObjectTabsStatus"), this.texts])
+        .then(([status, texts]) =>
     {
-      this.hideTimer.cancel();
-      this.hideTimer = null;
-    }
+      this.texts = texts;
+      if (!status)
+        return;
 
-    if (this.objtabElement)
-      this.objtabElement.style.setProperty("opacity", "1", "important");
+      if (this.hideTimer)
+      {
+        this.hideTimer.cancel();
+        this.hideTimer = null;
+      }
 
-    if (this.currentElement != element)
-    {
-      this._hideTab();
+      if (this.objtabElement)
+        this.objtabElement.style.setProperty("opacity", "1", "important");
 
-      let {RequestNotifier} = require("child/requestNotifier");
-      let data = RequestNotifier.getDataForNode(element, true, "OBJECT");
-      if (data)
-        this._showTab(element, data[1]);
-    }
+      if (this.currentElement != element)
+      {
+        this._hideTab();
+
+        let {RequestNotifier} = require("child/requestNotifier");
+        let data = RequestNotifier.getDataForNode(element, true, "OBJECT");
+        if (data)
+          this._showTab(element, data[1]);
+      }
+    });
   },
 
   /**
@@ -133,9 +143,6 @@ var objTabs =
    */
   _showTab: function(element, data)
   {
-    if (!this.texts)
-      this.texts = sendSyncMessage("AdblockPlus:GetObjectTabsTexts");
-
     let doc = element.ownerDocument.defaultView.top.document;
 
     this.objtabElement = doc.createElementNS("http://www.w3.org/1999/xhtml", "a");
@@ -315,7 +322,7 @@ var objTabs =
   {
     let {storeNodes} = require("child/contentPolicy");
     let nodesID = storeNodes([this.currentElement]);
-    sendAsyncMessage("AdblockPlus:BlockItem", {
+    port.emit("blockItem", {
       request: this.objtabElement.nodeData,
       nodesID
     });
diff --git a/lib/objectTabs.js b/lib/objectTabs.js
index 09f317c..628e69a 100644
--- a/lib/objectTabs.js
+++ b/lib/objectTabs.js
@@ -21,6 +21,7 @@
 
 let {Prefs} = require("prefs");
 let {Utils} = require("utils");
+let {port} = require("messaging");
 
 /**
  * Random element class, to be used for object tabs displayed on top of the
@@ -42,14 +43,14 @@ let classVisibleBottom = null;
  */
 let classHidden = null;
 
-Utils.addChildMessageListener("AdblockPlus:GetObjectTabsStatus", function()
+port.on("getObjectTabsStatus", function(message, sender)
 {
   let {UI} = require("ui");
 
   return !!(Prefs.enabled && Prefs.frameobjects && UI.overlay && classHidden);
 });
 
-Utils.addChildMessageListener("AdblockPlus:GetObjectTabsTexts", function()
+port.on("getObjectTabsTexts", function(message, sender)
 {
   let {UI} = require("ui");
 
@@ -60,7 +61,7 @@ Utils.addChildMessageListener("AdblockPlus:GetObjectTabsTexts", function()
   };
 });
 
-Utils.addChildMessageListener("AdblockPlus:BlockItem", function({request, nodesID})
+port.on("blockItem", function({request, nodesID}, sender)
 {
   let {UI} = require("ui");
   UI.blockItem(UI.currentWindow, nodesID, request);

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



More information about the Pkg-mozext-commits mailing list