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

Unified Diff: lib/requestNotifier.js

Issue 29329815: Issue 3274 - Unbreak toolbar icon tooltip (Closed)
Patch Set: Fixed JSDoc comment Created Nov. 25, 2015, 10:32 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 | « lib/child/requestNotifier.js ('k') | lib/ui.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/requestNotifier.js
===================================================================
--- a/lib/requestNotifier.js
+++ b/lib/requestNotifier.js
@@ -19,29 +19,33 @@
* @fileOverview Stores Adblock Plus data to be attached to a window.
*/
let {Utils} = require("utils");
let windowSelection = new WeakMap();
let requestNotifierMaxId = 0;
+let windowStatsMaxResponseID = 0;
+let windowStatsCallbacks = new Map();
+
/**
* Active RequestNotifier instances by their ID
* @type Map.<number,RequestNotifier>
*/
let notifiers = new Map();
let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager)
.QueryInterface(Ci.nsIMessageBroadcaster);
Utils.addChildMessageListener("AdblockPlus:FoundNodeData", onNodeData);
Utils.addChildMessageListener("AdblockPlus:ScanComplete", onScanComplete);
Utils.addChildMessageListener("AdblockPlus:RetrieveNodeSizeResponse", onNodeSizeReceived);
+Utils.addChildMessageListener("AdblockPlus:RetrieveWindowStatsResponse", onWindowStatsReceived);
function onNodeData({notifierID, data})
{
let notifier = notifiers.get(notifierID);
if (notifier)
notifier.notifyListener(data);
}
@@ -54,16 +58,24 @@ function onScanComplete(notifierID)
function onNodeSizeReceived({notifierID, responseID, size})
{
let notifier = notifiers.get(notifierID);
if (notifier)
notifier.onNodeSizeReceived(responseID, size);
}
+function onWindowStatsReceived({responseID, stats})
+{
+ let callback = windowStatsCallbacks.get(responseID);
+ windowStatsCallbacks.delete(responseID);
+ if (typeof callback == "function")
+ callback(stats);
+}
+
/**
* Creates a notifier object for a particular window. After creation the window
* will first be scanned for previously saved requests. Once that scan is
* complete only new requests for this window will be reported.
* @param {Integer} outerWindowID ID of the window to attach the notifier to
* @param {Function} listener listener to be called whenever a new request is found
* @param {Object} [listenerObj] "this" pointer to be used when calling the listener
*/
@@ -194,33 +206,39 @@ RequestNotifier.getSelection = function(
if (windowSelection.has(wnd.document))
return windowSelection.get(wnd.document);
else
return null;
};
/**
* Retrieves the statistics for a window.
- * @result {Object} Object with the properties items, blocked, whitelisted, hidden, filters containing statistics for the window (might be null)
+ * @param {number} outerWindowID the ID of the window
+ * @param {Function} callback the callback to be called with the resulting
+ * object (object properties will be items, blocked,
+ * whitelisted, hidden, filters) or null.
*/
-RequestNotifier.getWindowStatistics = function(/**Window*/ wnd)
+RequestNotifier.getWindowStatistics = function(outerWindowID, callback)
{
- if (windowStats.has(wnd.document))
- return windowStats.get(wnd.document);
- else
- return null;
+ let id = ++windowStatsMaxResponseID;
+ windowStatsCallbacks.set(id, callback);
+
+ messageManager.broadcastAsyncMessage("AdblockPlus:RetrieveWindowStats", {
+ responseID: id,
+ outerWindowID
+ });
}
/**
* Retrieves the request data associated with a DOM node.
* @param {Node} node
* @param {Boolean} noParent if missing or false, the search will extend to the parent nodes until one is found that has data associated with it
* @param {Integer} [type] request type to be looking for
* @param {String} [location] request location to be looking for
- * @result {[Node, Object]}
+ * @return {[Node, Object]}
* @static
*/
RequestNotifier.getDataForNode = function(node, noParent, type, location)
{
while (node)
{
let data = nodeData.get(node);
if (typeof data != "undefined")
« no previous file with comments | « lib/child/requestNotifier.js ('k') | lib/ui.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld