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(); |
})(); |