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

Unified Diff: lib/child/bootstrap.js

Issue 29329895: Issue 3290 - Adblock Plus child modules don`t always start up (Closed)
Patch Set: Removed unnecessary statement Created Dec. 1, 2015, 7:12 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 | lib/main.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+ });
})();
-
« no previous file with comments | « no previous file | lib/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld