Index: lib/child/bootstrap.js |
=================================================================== |
--- a/lib/child/bootstrap.js |
+++ b/lib/child/bootstrap.js |
@@ -39,58 +39,50 @@ |
remove: function(handler) |
{ |
let index = shutdownHandlers.indexOf(handler); |
if (index >= 0) |
shutdownHandlers.splice(index, 1); |
} |
}; |
- addMessageListener("AdblockPlus:Info", init); |
- addMessageListener("AdblockPlus:Shutdown", shutdown); |
+ let callbackPrefix = Services.appinfo.processID + " "; |
+ let maxCallbackID = 0; |
+ let callbacks = new Map(); |
- function init(message) |
+ function sendSyncMessageSingleResponse(messageName, data) |
{ |
- removeMessageListener("AdblockPlus:Info", init); |
+ return sendSyncMessage(messageName, {data})[0]; |
+ } |
- let callbackPrefix = Services.appinfo.processID + " "; |
- let maxCallbackID = 0; |
- let callbacks = new Map(); |
+ function sendAsyncMessageWithResponse(messageName, data, callback) |
+ { |
+ data = {data}; |
+ if (callback) |
+ { |
+ let callbackID = callbackPrefix + (++maxCallbackID); |
+ callbacks.set(callbackID, callback); |
+ data.callbackID = callbackID; |
+ } |
+ sendAsyncMessage(messageName, data); |
+ } |
- function sendSyncMessageSingleResponse(messageName, data) |
+ function onResponse(message) |
+ { |
+ let {callbackID, response} = message.data; |
+ if (callbacks.has(callbackID)) |
{ |
- return sendSyncMessage(messageName, {data})[0]; |
+ let callback = callbacks.get(callbackID); |
+ callbacks.delete(callbackID); |
+ callback(response); |
} |
+ } |
- function sendAsyncMessageWithResponse(messageName, data, callback) |
- { |
- data = {data}; |
- if (callback) |
- { |
- let callbackID = callbackPrefix + (++maxCallbackID); |
- callbacks.set(callbackID, callback); |
- data.callbackID = callbackID; |
- } |
- sendAsyncMessage(messageName, data); |
- } |
- |
- function onResponse(message) |
- { |
- let {callbackID, response} = message.data; |
- if (callbacks.has(callbackID)) |
- { |
- let callback = callbacks.get(callbackID); |
- callbacks.delete(callbackID); |
- callback(response); |
- } |
- } |
- addMessageListener("AdblockPlus:Response", onResponse); |
- onShutdown.add(() => removeMessageListener("AdblockPlus:Response", onResponse)); |
- |
- let info = message.data; |
+ function init(info) |
+ { |
loader = Loader({ |
paths: { |
"": info.addonRoot + "lib/" |
}, |
globals: { |
Components, Cc, Ci, Cu, Cr, atob, btoa, onShutdown, |
addMessageListener, removeMessageListener, |
sendAsyncMessage: sendAsyncMessageWithResponse, |
@@ -103,27 +95,32 @@ |
main(loader, "child/main"); |
} |
function shutdown(message) |
{ |
if (message.data == Components.stack.filename) |
{ |
- removeMessageListener("AdblockPlus:Shutdown", shutdown); |
- |
onShutdown.done = true; |
for (let i = shutdownHandlers.length - 1; i >= 0; i --) |
{ |
try |
{ |
shutdownHandlers[i](); |
} |
catch (e) |
{ |
Cu.reportError(e); |
} |
} |
shutdownHandlers = null; |
} |
} |
+ |
+ sendAsyncMessageWithResponse("AdblockPlus:GetInfo", null, init); |
+ addMessageListener("AdblockPlus:Response", onResponse); |
+ addMessageListener("AdblockPlus:Shutdown", shutdown); |
+ onShutdown.add(() => { |
+ removeMessageListener("AdblockPlus:Response", onResponse); |
+ removeMessageListener("AdblockPlus:Shutdown", shutdown); |
+ }); |
})(); |
- |