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: Use URLSearchParams Created March 23, 2016, 3:26 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
@@ -20,17 +20,18 @@
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;
+ Cu.importGlobalProperties(["atob", "btoa", "File", "URL", "URLSearchParams",
+ "TextDecoder", "TextEncoder"]);
Wladimir Palant 2016/03/23 15:29:33 Added quite a few more classes here, for consisten
let shutdownHandlers = [];
let onShutdown =
{
done: false,
add: function(handler)
{
if (shutdownHandlers.indexOf(handler) < 0)
@@ -39,59 +40,29 @@
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 init()
+ {
+ let url = new URL(Components.stack.filename);
+ let params = new URLSearchParams(url.search.substr(1));
+ let info = JSON.parse(params.get("info"));
- 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, File, URL, URLSearchParams,
+ TextDecoder, TextEncoder, onShutdown
},
modules: {"info": info, "messageManager": this},
id: info.addonID
});
onShutdown.add(() => unload(loader, "disable"))
main(loader, "child/main");
}
@@ -111,16 +82,16 @@
{
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);
});
+
+ init();
})();
« 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