[Pkg-mozext-commits] [adblock-plus] 35/87: Issue 3499 - Use new messaging API in the content policy implementation
David Prévot
taffit at moszumanska.debian.org
Sat Apr 30 17:59:05 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 86f663412922464ddd2392a20938cffc88f61dcc
Author: Wladimir Palant <trev at adblockplus.org>
Date: Wed Mar 16 11:07:04 2016 +0100
Issue 3499 - Use new messaging API in the content policy implementation
---
lib/child/contentPolicy.js | 86 +++++++++++++++++++++++-----------------------
lib/contentPolicy.js | 13 +++----
2 files changed, 48 insertions(+), 51 deletions(-)
diff --git a/lib/child/contentPolicy.js b/lib/child/contentPolicy.js
index 800d756..b273553 100644
--- a/lib/child/contentPolicy.js
+++ b/lib/child/contentPolicy.js
@@ -37,6 +37,7 @@ catch (e)
let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+let {port} = require("messaging");
let {Utils} = require("utils");
let {getFrames, isPrivate} = require("child/utils");
let {objectMouseEventHander} = require("child/objectTabs");
@@ -44,9 +45,9 @@ let {RequestNotifier} = require("child/requestNotifier");
/**
* Randomly generated class name, to be applied to collapsed nodes.
- * @type string
+ * @type Promise.<string>
*/
-let collapsedClass = null;
+let collapsedClass = port.emitWithResponse("getCollapsedClass");
/**
* Maps numerical content type IDs to strings.
@@ -73,13 +74,8 @@ let nodesIDPrefix = Services.appinfo.processID + " ";
*/
let maxNodesID = 0;
-addMessageListener("AdblockPlus:DeleteNodes", onDeleteNodes);
-addMessageListener("AdblockPlus:RefilterNodes", onRefilterNodes);
-
-onShutdown.add(() => {
- removeMessageListener("AdblockPlus:DeleteNodes", onDeleteNodes);
- removeMessageListener("AdblockPlus:RefilterNodes", onRefilterNodes);
-});
+port.on("deleteNodes", onDeleteNodes);
+port.on("refilterNodes", onRefilterNodes);
/**
* Processes parent's response to the ShouldAllow message.
@@ -136,7 +132,7 @@ function processPolicyResponse(window, node, response)
*/
let shouldAllow = exports.shouldAllow = function(window, node, contentType, location)
{
- return processPolicyResponse(window, node, sendSyncMessage("AdblockPlus:ShouldAllow", {
+ return processPolicyResponse(window, node, port.emitSync("shouldAllow", {
contentType,
location,
frames: getFrames(window),
@@ -155,12 +151,15 @@ let shouldAllow = exports.shouldAllow = function(window, node, contentType, loca
*/
let shouldAllowAsync = exports.shouldAllowAsync = function(window, node, contentType, location, callback)
{
- sendAsyncMessage("AdblockPlus:ShouldAllow", {
+ port.emitWithResponse("shouldAllow", {
contentType,
location,
frames: getFrames(window),
isPrivate: isPrivate(window)
- }, response => callback(processPolicyResponse(window, node, response)));
+ }).then(response =>
+ {
+ callback(processPolicyResponse(window, node, response));
+ });
};
/**
@@ -180,17 +179,16 @@ let storeNodes = exports.storeNodes = function(nodes)
/**
* Called via message whenever Policy.deleteNodes() is called in the parent.
*/
-function onDeleteNodes(message)
+function onDeleteNodes(id, sender)
{
- storedNodes.delete(message.data);
+ storedNodes.delete(id);
}
/**
* Called via message whenever Policy.refilterNodes() is called in the parent.
*/
-function onRefilterNodes(message)
+function onRefilterNodes({nodesID, entry}, sender)
{
- let {nodesID, entry} = message.data;
let nodes = storedNodes.get(nodesID);
if (nodes)
for (let node of nodes)
@@ -458,37 +456,39 @@ function schedulePostProcess(/**Element*/ node)
*/
function postProcessNodes()
{
- if (!collapsedClass)
- collapsedClass = sendSyncMessage("AdblockPlus:GetCollapsedClass");
-
- let nodes = scheduledNodes;
- scheduledNodes = null;
+ collapsedClass.then(cls =>
+ {
+ let nodes = scheduledNodes;
+ scheduledNodes = null;
- if (!collapsedClass)
- return;
+ // Resolving class is async initially so the nodes might have already been
+ // processed in the meantime.
+ if (!nodes)
+ return;
- for (let node of nodes)
- {
- // adjust frameset's cols/rows for frames
- let parentNode = node.parentNode;
- if (parentNode && parentNode instanceof Ci.nsIDOMHTMLFrameSetElement)
+ for (let node of nodes)
{
- let hasCols = (parentNode.cols && parentNode.cols.indexOf(",") > 0);
- let hasRows = (parentNode.rows && parentNode.rows.indexOf(",") > 0);
- if ((hasCols || hasRows) && !(hasCols && hasRows))
+ // adjust frameset's cols/rows for frames
+ let parentNode = node.parentNode;
+ if (parentNode && parentNode instanceof Ci.nsIDOMHTMLFrameSetElement)
{
- let index = -1;
- for (let frame = node; frame; frame = frame.previousSibling)
- if (frame instanceof Ci.nsIDOMHTMLFrameElement || frame instanceof Ci.nsIDOMHTMLFrameSetElement)
- index++;
-
- let property = (hasCols ? "cols" : "rows");
- let weights = parentNode[property].split(",");
- weights[index] = "0";
- parentNode[property] = weights.join(",");
+ let hasCols = (parentNode.cols && parentNode.cols.indexOf(",") > 0);
+ let hasRows = (parentNode.rows && parentNode.rows.indexOf(",") > 0);
+ if ((hasCols || hasRows) && !(hasCols && hasRows))
+ {
+ let index = -1;
+ for (let frame = node; frame; frame = frame.previousSibling)
+ if (frame instanceof Ci.nsIDOMHTMLFrameElement || frame instanceof Ci.nsIDOMHTMLFrameSetElement)
+ index++;
+
+ let property = (hasCols ? "cols" : "rows");
+ let weights = parentNode[property].split(",");
+ weights[index] = "0";
+ parentNode[property] = weights.join(",");
+ }
}
+ else
+ node.classList.add(cls);
}
- else
- node.classList.add(collapsedClass);
- }
+ });
}
diff --git a/lib/contentPolicy.js b/lib/contentPolicy.js
index 528eafb..e416634 100644
--- a/lib/contentPolicy.js
+++ b/lib/contentPolicy.js
@@ -25,6 +25,7 @@ let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
let {Utils} = require("utils");
+let {port} = require("messaging");
let {Prefs} = require("prefs");
let {FilterStorage} = require("filterStorage");
let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses");
@@ -87,7 +88,7 @@ var Policy = exports.Policy =
for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" "))
this.whitelistSchemes.add(scheme);
- Utils.addChildMessageListener("AdblockPlus:ShouldAllow", message => this.shouldAllow(message));
+ port.on("shouldAllow", (message, sender) => this.shouldAllow(message));
// Generate class identifier used to collapse nodes and register
// corresponding stylesheet.
@@ -95,7 +96,7 @@ var Policy = exports.Policy =
let offset = "a".charCodeAt(0);
for (let i = 0; i < 20; i++)
collapsedClass += String.fromCharCode(offset + Math.random() * 26);
- Utils.addChildMessageListener("AdblockPlus:GetCollapsedClass", () => collapsedClass);
+ port.on("getCollapsedClass", (message, sender) => collapsedClass);
let collapseStyle = Services.io.newURI("data:text/css," +
encodeURIComponent("." + collapsedClass +
@@ -273,9 +274,7 @@ var Policy = exports.Policy =
*/
deleteNodes: function(id)
{
- let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
- .getService(Ci.nsIMessageBroadcaster);
- messageManager.broadcastAsyncMessage("AdblockPlus:DeleteNodes", id);
+ port.emit("deleteNodes", id);
},
/**
@@ -286,9 +285,7 @@ var Policy = exports.Policy =
*/
refilterNodes: function(id, entry)
{
- let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
- .getService(Ci.nsIMessageBroadcaster);
- messageManager.broadcastAsyncMessage("AdblockPlus:RefilterNodes", {
+ port.emit("refilterNodes", {
nodesID: id,
entry: entry
});
--
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