[Pkg-mozext-commits] [adblock-plus] 24/52: Issue 1765 - Align Firefox messaging implementation with Safari

David Prévot taffit at moszumanska.debian.org
Thu Jan 22 21:43:45 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.

commit edbffa6596b8cadfc84abb3021c9a6a4f7467b3a
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Thu Jan 8 16:14:07 2015 +0100

    Issue 1765 - Align Firefox messaging implementation with Safari
---
 ext/common.js | 41 ++++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/ext/common.js b/ext/common.js
index f767ffe..42480f3 100644
--- a/ext/common.js
+++ b/ext/common.js
@@ -62,35 +62,38 @@
       this._messageManager.removeMessageListener("AdblockPlus:Response", this._handleResponse);
     },
 
-    _sendResponse: function(sender, callbackId, response)
+    _sendResponse: function(sender, callbackId, message)
     {
-      this._responseSent = true;
-
-      if (sender instanceof Ci.nsIMessageSender)
-      {
-        sender.sendAsyncMessage("AdblockPlus:Response", {
-          callbackId: callbackId,
-          responseSent: typeof response != "undefined",
-          payload: response
-        });
-      }
+      var response = {
+        callbackId: callbackId
+      };
+      if (typeof response != "undefined")
+        response.payload = message;
+      sender.sendAsyncMessage("AdblockPlus:Response", response);
     },
 
     _handleRequest: function(message)
     {
       var sender = getSender(message.target);
       var request = message.data;
+
+      var sent = false;
       var sendResponse;
       if (sender && "callbackId" in request)
-        sendResponse = this._sendResponse.bind(this, sender, request.callbackId);
+      {
+        sendResponse = function(message)
+        {
+          this._sendResponse(sender, request.callbackId, message);
+          sent = true;
+        }.bind(this);
+      }
       else
         sendResponse = function() {};
 
-      this._responseSent = false;
-      var result = this._messageTarget._dispatch(request.payload, {
+      var results = this._messageTarget._dispatch(request.payload, {
         page: new holder.Page(sender)
       }, sendResponse);
-      if (!result && !this._responseSent)
+      if (!sent && results.indexOf(true) == -1)
         sendResponse(undefined);
     },
 
@@ -101,7 +104,7 @@
       if (callback)
       {
         this._callbacks.delete(response.callbackId);
-        if (response.responseSent)
+        if ("payload" in response)
           callback(response.payload);
       }
     },
@@ -142,12 +145,12 @@
     },
     _dispatch: function()
     {
-      var result = null;
+      var results = [];
 
       for (var i = 0; i < this._listeners.length; i++)
-        result = this._listeners[i].apply(null, arguments);
+        results.push(this._listeners[i].apply(null, arguments));
 
-      return result;
+      return results;
     }
   };
 

-- 
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