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: Created Nov. 9, 2015, 3:37 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,52 @@
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)
+ {
+ return sendSyncMessage(messageName, {data})[0];
+ }
+
+ 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);
+ }
+ }
Wladimir Palant 2015/11/09 15:41:08 The functions and variables above merely moved bec
+
+ function init(info)
{
removeMessageListener("AdblockPlus:Info", init);
Thomas Greiner 2015/12/01 15:40:27 You removed `addMessageListener("AdblockPlus:Info"
Wladimir Palant 2015/12/01 19:12:21 Done.
- let callbackPrefix = Services.appinfo.processID + " ";
- let maxCallbackID = 0;
- let callbacks = new Map();
-
- function sendSyncMessageSingleResponse(messageName, data)
- {
- return sendSyncMessage(messageName, {data})[0];
- }
-
- 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;
loader = Loader({
paths: {
"": info.addonRoot + "lib/"
},
globals: {
Components, Cc, Ci, Cu, Cr, atob, btoa, onShutdown,
addMessageListener, removeMessageListener,
sendAsyncMessage: sendAsyncMessageWithResponse,
@@ -103,27 +97,33 @@
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