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

Unified Diff: ext/common.js

Issue 5772325207146496: Issue 1765 - Align Firefox messaging implementation with Safari (Closed)
Patch Set: Created Jan. 8, 2015, 3:14 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: ext/common.js
===================================================================
--- a/ext/common.js
+++ b/ext/common.js
@@ -57,56 +57,59 @@
}
MessageProxy.prototype = {
_disconnect: function()
{
this._messageManager.removeMessageListener("AdblockPlus:Message", this._handleRequest);
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);
},
_handleResponse: function(message)
{
var response = message.data;
var callback = this._callbacks.get(response.callbackId);
if (callback)
{
this._callbacks.delete(response.callbackId);
- if (response.responseSent)
+ if ("payload" in response)
callback(response.payload);
}
},
sendMessage: function(message, responseCallback)
{
if (!(this._messageManager instanceof Ci.nsIMessageSender))
throw new Error("Not implemented");
@@ -137,20 +140,20 @@
removeListener: function(listener)
{
var idx = this._listeners.indexOf(listener);
if (idx != -1)
this._listeners.splice(idx, 1);
},
_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;
}
};
if (typeof exports == "object")
exports = global.ext;
})(this);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld