[Pkg-mozext-commits] [adblock-plus] 48/87: Issue 3499 - Remove old messaging API
David Prévot
taffit at moszumanska.debian.org
Sat Apr 30 17:59:07 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit ce4b490de1b94d5c8b050b26ada5aa47353c9bb6
Author: Wladimir Palant <trev at adblockplus.org>
Date: Wed Mar 23 16:18:25 2016 +0100
Issue 3499 - Remove old messaging API
---
lib/child/bootstrap.js | 55 ++++++++++++--------------------------------------
lib/main.js | 5 ++---
lib/utils.js | 38 ----------------------------------
3 files changed, 15 insertions(+), 83 deletions(-)
diff --git a/lib/child/bootstrap.js b/lib/child/bootstrap.js
index 8bee66f..d1e73a7 100644
--- a/lib/child/bootstrap.js
+++ b/lib/child/bootstrap.js
@@ -25,7 +25,8 @@
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"]);
let shutdownHandlers = [];
let onShutdown =
@@ -44,49 +45,19 @@
}
};
- 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)
+ function init()
{
- data = {data};
- if (callback)
- {
- let callbackID = callbackPrefix + (++maxCallbackID);
- callbacks.set(callbackID, callback);
- data.callbackID = callbackID;
- }
- sendAsyncMessage(messageName, data);
- }
+ let url = new URL(Components.stack.filename);
+ let params = new URLSearchParams(url.search.substr(1));
+ let info = JSON.parse(params.get("info"));
- 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
@@ -116,11 +87,11 @@
}
}
- 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();
})();
diff --git a/lib/main.js b/lib/main.js
index 67ec2aa..742a9fb 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -36,10 +36,9 @@ require("objectTabs");
function bootstrapChildProcesses()
{
let info = require("info");
- let {Utils} = require("utils");
- Utils.addChildMessageListener("AdblockPlus:GetInfo", () => info);
- let processScript = info.addonRoot + "lib/child/bootstrap.js?" + Math.random();
+ let processScript = info.addonRoot + "lib/child/bootstrap.js?" +
+ Math.random() + "&info=" + encodeURIComponent(JSON.stringify(info));
let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
.getService(Ci.nsIProcessScriptLoader)
.QueryInterface(Ci.nsIMessageBroadcaster);
diff --git a/lib/utils.js b/lib/utils.js
index c998916..3c9071a 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -513,44 +513,6 @@ let Utils = exports.Utils =
if (element.localName != "label")
element.accessKey = accesskey;
}
- },
-
- /**
- * Adds a message handler that will respond to both synchronous and
- * asynchonous messages.
- * @param {string} messageName name of the message to listen to
- * @param {Function} handler handler to be called with the message data. The
- * return value will be sent back to the child.
- */
- addChildMessageListener: function(messageName, handler)
- {
- let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
- .getService(Ci.nsIMessageListenerManager);
- let wrapper = (message) => {
- let {callbackID, data} = message.data;
- let response = undefined;
- try
- {
- response = handler(data);
- }
- catch (e)
- {
- Cu.reportError(e);
- }
-
- if (callbackID)
- {
- let target = message.target.QueryInterface(Ci.nsIMessageSender);
- target.sendAsyncMessage("AdblockPlus:Response", {
- callbackID,
- response
- });
- }
- else
- return response;
- };
- messageManager.addMessageListener(messageName, wrapper);
- onShutdown.add(() => messageManager.removeMessageListener(messageName, wrapper));
}
};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list