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

Unified Diff: lib/child/requestNotifier.js

Issue 29329884: Issue 3224 - Unbreak filter assistant (Closed)
Patch Set: Rebased Created Nov. 12, 2015, 3:10 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
Index: lib/child/requestNotifier.js
===================================================================
--- a/lib/child/requestNotifier.js
+++ b/lib/child/requestNotifier.js
@@ -32,23 +32,25 @@ let requestEntryMaxId = 0;
* @type Map.<number,RequestNotifier>
*/
let notifiers = new Map();
addMessageListener("AdblockPlus:StartWindowScan", onStartScan);
addMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown);
addMessageListener("AdblockPlus:FlashNodes", onFlashNodes);
addMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize);
+addMessageListener("AdblockPlus:StoreNodesForEntries", onStoreNodes);
addMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats);
onShutdown.add(() => {
removeMessageListener("AdblockPlus:StartWindowScan", onStartScan);
removeMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown);
removeMessageListener("AdblockPlus:FlashNodes", onFlashNodes);
removeMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize);
+ removeMessageListener("AdblockPlus:StoreNodesForEntries", onStoreNodes);
removeMessageListener("AdblockPlus:RetrieveWindowStats", onRetrieveWindowStats);
});
function onStartScan(message)
{
let {notifierID, outerWindowID} = message.data;
let window = Services.wm.getOuterWindowWithId(outerWindowID);
if (window)
@@ -73,16 +75,24 @@ function onFlashNodes(message)
function onRetrieveNodeSize(message)
{
let {notifierID, responseID, requests} = message.data;
let notifier = notifiers.get(notifierID);
if (notifier)
notifier.retrieveNodeSize(requests, responseID);
}
+function onStoreNodes(message)
+{
+ let {notifierID, responseID, requests} = message.data;
+ let notifier = notifiers.get(notifierID);
+ if (notifier)
+ notifier.storeNodesForEntries(requests, responseID);
+}
+
function onRetrieveWindowStats(message)
{
let {responseID, outerWindowID} = message.data;
let window = Services.wm.getOuterWindowWithId(outerWindowID);
if (window)
{
let stats = RequestNotifier.getWindowStatistics(window);
sendAsyncMessage("AdblockPlus:RetrieveWindowStatsResponse", {
@@ -276,20 +286,52 @@ RequestNotifier.prototype =
this.nodes.delete(node);
else
{
size = getNodeSize(node);
if (size)
break;
}
}
- sendAsyncMessage("AdblockPlus:RetrieveNodeSizeResponse", {
+ sendAsyncMessage("AdblockPlus:NotifierResponse", {
notifierID: this.id,
responseID,
- size
+ response: size
+ });
+ },
+
+ /**
+ * Stores the nodes associated with the requests and generates a unique ID
+ * for them that can be used with Policy.refilterNodes(). Sends message to
+ * parent when complete.
+ * @param {number[]} requests list of request IDs that were previously
+ * reported by this notifier.
+ * @param {number} responseID ID to be sent with the response.
+ */
+ storeNodesForEntries: function(requests, responseID)
+ {
+ let nodes = [];
+ for (let id of requests)
+ {
+ if (!this.nodes.has(id))
+ continue;
+
+ let node = this.nodes.get(id);
+ if (Cu.isDeadWrapper(node))
+ this.nodes.delete(node);
+ else
+ nodes.push(node);
+ }
+
+ let {storeNodes} = require("child/contentPolicy");
+ let id = storeNodes(nodes);
+ sendAsyncMessage("AdblockPlus:NotifierResponse", {
+ notifierID: this.id,
+ responseID,
+ response: id
});
}
};
/**
* Attaches request data to a DOM node.
* @param {Node} node node to attach data to
* @param {Window} topWnd top-level window the node belongs to
« lib/child/contentPolicy.js ('K') | « lib/child/objectTabs.js ('k') | lib/contentPolicy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld