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

Unified Diff: lib/child/bootstrap.js

Issue 29338425: Issue 3499 - Remove old messaging API (Closed)
Patch Set: Created March 16, 2016, 12:33 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') | lib/main.js » ('J')
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
@@ -20,18 +20,16 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;
let {Loader, main, unload} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
- let loader = null;
-
let shutdownHandlers = [];
let onShutdown =
{
done: false,
add: function(handler)
{
if (shutdownHandlers.indexOf(handler) < 0)
shutdownHandlers.push(handler);
@@ -39,59 +37,24 @@
remove: function(handler)
{
let index = shutdownHandlers.indexOf(handler);
if (index >= 0)
shutdownHandlers.splice(index, 1);
}
};
- let callbackPrefix = Services.appinfo.processID + " ";
- let maxCallbackID = 0;
- let callbacks = new Map();
-
- function sendSyncMessageSingleResponse(messageName, data)
- {
- return sendRpcMessage(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);
- }
- }
-
function init(info)
{
- loader = Loader({
+ let loader = Loader({
paths: {
"": info.addonRoot + "lib/"
},
globals: {
- Components, Cc, Ci, Cu, Cr, atob, btoa, onShutdown,
- addMessageListener, removeMessageListener,
- sendAsyncMessage: sendAsyncMessageWithResponse,
- sendSyncMessage: sendSyncMessageSingleResponse
+ Components, Cc, Ci, Cu, Cr, atob, btoa, onShutdown
},
modules: {"info": info, "messageManager": this},
id: info.addonID
});
onShutdown.add(() => unload(loader, "disable"))
main(loader, "child/main");
}
@@ -111,16 +74,17 @@
{
Cu.reportError(e);
}
}
shutdownHandlers = null;
}
}
- sendAsyncMessageWithResponse("AdblockPlus:GetInfo", null, init);
- addMessageListener("AdblockPlus:Response", onResponse);
addMessageListener("AdblockPlus:Shutdown", shutdown);
- onShutdown.add(() => {
- removeMessageListener("AdblockPlus:Response", onResponse);
+ onShutdown.add(() =>
+ {
removeMessageListener("AdblockPlus:Shutdown", shutdown);
});
+
+ let param = Components.stack.filename.split("#", 2)[1];
+ init(JSON.parse(decodeURIComponent(param)));
})();
« no previous file with comments | « no previous file | lib/main.js » ('j') | lib/main.js » ('J')

Powered by Google App Engine
This is Rietveld