Index: lib/requestNotifier.js |
=================================================================== |
--- a/lib/requestNotifier.js |
+++ b/lib/requestNotifier.js |
@@ -34,38 +34,38 @@ let windowStatsCallbacks = new Map(); |
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:NotifierResponse", onNotifierResponse); |
Utils.addChildMessageListener("AdblockPlus:RetrieveWindowStatsResponse", onWindowStatsReceived); |
function onNodeData({notifierID, data}) |
{ |
let notifier = notifiers.get(notifierID); |
if (notifier) |
notifier.notifyListener(data); |
} |
function onScanComplete(notifierID) |
{ |
let notifier = notifiers.get(notifierID); |
if (notifier) |
notifier.onComplete(); |
} |
-function onNodeSizeReceived({notifierID, responseID, size}) |
+function onNotifierResponse({notifierID, responseID, response}) |
{ |
let notifier = notifiers.get(notifierID); |
if (notifier) |
- notifier.onNodeSizeReceived(responseID, size); |
+ notifier.onResponse(responseID, response); |
} |
function onWindowStatsReceived({responseID, stats}) |
{ |
let callback = windowStatsCallbacks.get(responseID); |
windowStatsCallbacks.delete(responseID); |
if (typeof callback == "function") |
callback(stats); |
@@ -80,17 +80,17 @@ function onWindowStatsReceived({response |
* @param {Object} [listenerObj] "this" pointer to be used when calling the listener |
*/ |
function RequestNotifier(outerWindowID, listener, listenerObj) |
{ |
this.listener = listener; |
this.listenerObj = listenerObj || null; |
this.id = ++requestNotifierMaxId; |
notifiers.set(this.id, this); |
- this._nodeSizeCallbacks = new Map(); |
+ this._callbacks = new Map(); |
messageManager.broadcastAsyncMessage("AdblockPlus:StartWindowScan", { |
notifierID: this.id, |
outerWindowID: outerWindowID |
}); |
} |
exports.RequestNotifier = RequestNotifier; |
@@ -158,47 +158,69 @@ RequestNotifier.prototype = |
messageManager.broadcastAsyncMessage("AdblockPlus:FlashNodes", { |
notifierID: this.id, |
requests, |
scrollToItem |
}); |
}, |
- _nodeSizeMaxResponseID: 0, |
- _nodeSizeCallbacks: null, |
+ _maxResponseID: 0, |
+ _callbacks: null, |
/** |
* Attempts to calculate the size of the nodes associated with the requests. |
- * Callback will only be called on success. |
* @param {number[]} requests list of request IDs that were previously |
* reported by this notifier. |
* @param {Function} callback function to be called with two parameters (x,y) |
*/ |
retrieveNodeSize: function(requests, callback) |
{ |
if (!requests) |
requests = []; |
- let id = ++this._nodeSizeMaxResponseID; |
- this._nodeSizeCallbacks.set(id, callback); |
+ let id = ++this._maxResponseID; |
+ this._callbacks.set(id, callback); |
messageManager.broadcastAsyncMessage("AdblockPlus:RetrieveNodeSize", { |
notifierID: this.id, |
responseID: id, |
requests, |
}); |
}, |
- onNodeSizeReceived: function(responseID, size) |
+ onResponse: function(responseID, response) |
{ |
- let callback = this._nodeSizeCallbacks.get(responseID); |
- this._nodeSizeCallbacks.delete(responseID); |
- if (size && typeof callback == "function") |
- callback(size); |
+ let callback = this._callbacks.get(responseID); |
+ this._callbacks.delete(responseID); |
+ if (typeof callback == "function") |
+ callback(response); |
+ }, |
+ |
+ /** |
+ * Stores the nodes associated with the requests and generates a unique ID |
+ * for them that can be used with Policy.refilterNodes(). Note that |
+ * Policy.deleteNodes() always has to be called to release the memory. |
+ * @param {number[]} requests list of request IDs that were previously |
+ * reported by this notifier. |
+ * @param {Function} callback function to be called with the nodes ID. |
+ */ |
+ storeNodesForEntries: function(requests, callback) |
+ { |
+ if (!requests) |
+ requests = []; |
+ |
+ let id = ++this._maxResponseID; |
+ this._callbacks.set(id, callback); |
+ |
+ messageManager.broadcastAsyncMessage("AdblockPlus:StoreNodesForEntries", { |
+ notifierID: this.id, |
+ responseID: id, |
+ requests, |
+ }); |
} |
}; |
RequestNotifier.storeSelection = function(/**Window*/ wnd, /**String*/ selection) |
{ |
windowSelection.set(wnd.document, selection); |
}; |
RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/ |