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