Index: lib/requestNotifier.js |
=================================================================== |
--- a/lib/requestNotifier.js |
+++ b/lib/requestNotifier.js |
@@ -31,45 +31,54 @@ let requestNotifierMaxId = 0; |
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); |
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}) |
+{ |
+ let notifier = notifiers.get(notifierID); |
+ if (notifier) |
+ notifier.onNodeSizeReceived(responseID, size); |
+} |
+ |
/** |
* 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 |
*/ |
function RequestNotifier(outerWindowID, listener, listenerObj) |
{ |
this.listener = listener; |
this.listenerObj = listenerObj || null; |
this.id = ++requestNotifierMaxId; |
notifiers.set(this.id, this); |
+ this._nodeSizeCallbacks = new Map(); |
messageManager.broadcastAsyncMessage("AdblockPlus:StartWindowScan", { |
notifierID: this.id, |
outerWindowID: outerWindowID |
}); |
} |
exports.RequestNotifier = RequestNotifier; |
@@ -135,16 +144,49 @@ RequestNotifier.prototype = |
if (!requests) |
requests = []; |
messageManager.broadcastAsyncMessage("AdblockPlus:FlashNodes", { |
notifierID: this.id, |
requests, |
scrollToItem |
}); |
+ }, |
+ |
+ _nodeSizeMaxResponseID: 0, |
+ _nodeSizeCallbacks: 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); |
+ |
+ messageManager.broadcastAsyncMessage("AdblockPlus:RetrieveNodeSize", { |
+ notifierID: this.id, |
+ responseID: id, |
+ requests, |
+ }); |
+ }, |
+ |
+ onNodeSizeReceived: function(responseID, size) |
+ { |
+ let callback = this._nodeSizeCallbacks.get(responseID); |
+ this._nodeSizeCallbacks.delete(responseID); |
+ if (size && typeof callback == "function") |
+ callback(size); |
} |
}; |
RequestNotifier.storeSelection = function(/**Window*/ wnd, /**String*/ selection) |
{ |
windowSelection.set(wnd.document, selection); |
}; |
RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/ |