OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 18 matching lines...) Expand all Loading... |
29 * @type Map.<number,RequestNotifier> | 29 * @type Map.<number,RequestNotifier> |
30 */ | 30 */ |
31 let notifiers = new Map(); | 31 let notifiers = new Map(); |
32 | 32 |
33 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] | 33 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] |
34 .getService(Ci.nsIMessageListenerManager) | 34 .getService(Ci.nsIMessageListenerManager) |
35 .QueryInterface(Ci.nsIMessageBroadcaster); | 35 .QueryInterface(Ci.nsIMessageBroadcaster); |
36 | 36 |
37 Utils.addChildMessageListener("AdblockPlus:FoundNodeData", onNodeData); | 37 Utils.addChildMessageListener("AdblockPlus:FoundNodeData", onNodeData); |
38 Utils.addChildMessageListener("AdblockPlus:ScanComplete", onScanComplete); | 38 Utils.addChildMessageListener("AdblockPlus:ScanComplete", onScanComplete); |
| 39 Utils.addChildMessageListener("AdblockPlus:RetrieveNodeSizeResponse", onNodeSize
Received); |
39 | 40 |
40 function onNodeData({notifierID, data}) | 41 function onNodeData({notifierID, data}) |
41 { | 42 { |
42 let notifier = notifiers.get(notifierID); | 43 let notifier = notifiers.get(notifierID); |
43 if (notifier) | 44 if (notifier) |
44 notifier.notifyListener(data); | 45 notifier.notifyListener(data); |
45 } | 46 } |
46 | 47 |
47 function onScanComplete(notifierID) | 48 function onScanComplete(notifierID) |
48 { | 49 { |
49 let notifier = notifiers.get(notifierID); | 50 let notifier = notifiers.get(notifierID); |
50 if (notifier) | 51 if (notifier) |
51 notifier.onComplete(); | 52 notifier.onComplete(); |
52 } | 53 } |
53 | 54 |
| 55 function onNodeSizeReceived({notifierID, responseID, size}) |
| 56 { |
| 57 let notifier = notifiers.get(notifierID); |
| 58 if (notifier) |
| 59 notifier.onNodeSizeReceived(responseID, size); |
| 60 } |
| 61 |
54 /** | 62 /** |
55 * Creates a notifier object for a particular window. After creation the window | 63 * Creates a notifier object for a particular window. After creation the window |
56 * will first be scanned for previously saved requests. Once that scan is | 64 * will first be scanned for previously saved requests. Once that scan is |
57 * complete only new requests for this window will be reported. | 65 * complete only new requests for this window will be reported. |
58 * @param {Integer} outerWindowID ID of the window to attach the notifier to | 66 * @param {Integer} outerWindowID ID of the window to attach the notifier to |
59 * @param {Function} listener listener to be called whenever a new request is f
ound | 67 * @param {Function} listener listener to be called whenever a new request is f
ound |
60 * @param {Object} [listenerObj] "this" pointer to be used when calling the lis
tener | 68 * @param {Object} [listenerObj] "this" pointer to be used when calling the lis
tener |
61 */ | 69 */ |
62 function RequestNotifier(outerWindowID, listener, listenerObj) | 70 function RequestNotifier(outerWindowID, listener, listenerObj) |
63 { | 71 { |
64 this.listener = listener; | 72 this.listener = listener; |
65 this.listenerObj = listenerObj || null; | 73 this.listenerObj = listenerObj || null; |
66 this.id = ++requestNotifierMaxId; | 74 this.id = ++requestNotifierMaxId; |
67 notifiers.set(this.id, this); | 75 notifiers.set(this.id, this); |
| 76 this._nodeSizeCallbacks = new Map(); |
68 | 77 |
69 messageManager.broadcastAsyncMessage("AdblockPlus:StartWindowScan", { | 78 messageManager.broadcastAsyncMessage("AdblockPlus:StartWindowScan", { |
70 notifierID: this.id, | 79 notifierID: this.id, |
71 outerWindowID: outerWindowID | 80 outerWindowID: outerWindowID |
72 }); | 81 }); |
73 } | 82 } |
74 exports.RequestNotifier = RequestNotifier; | 83 exports.RequestNotifier = RequestNotifier; |
75 | 84 |
76 RequestNotifier.prototype = | 85 RequestNotifier.prototype = |
77 { | 86 { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 flashNodes: function(requests, scrollToItem) | 142 flashNodes: function(requests, scrollToItem) |
134 { | 143 { |
135 if (!requests) | 144 if (!requests) |
136 requests = []; | 145 requests = []; |
137 | 146 |
138 messageManager.broadcastAsyncMessage("AdblockPlus:FlashNodes", { | 147 messageManager.broadcastAsyncMessage("AdblockPlus:FlashNodes", { |
139 notifierID: this.id, | 148 notifierID: this.id, |
140 requests, | 149 requests, |
141 scrollToItem | 150 scrollToItem |
142 }); | 151 }); |
| 152 }, |
| 153 |
| 154 _nodeSizeMaxResponseID: 0, |
| 155 _nodeSizeCallbacks: null, |
| 156 |
| 157 /** |
| 158 * Attempts to calculate the size of the nodes associated with the requests. |
| 159 * Callback will only be called on success. |
| 160 * @param {number[]} requests list of request IDs that were previously |
| 161 * reported by this notifier. |
| 162 * @param {Function} callback function to be called with two parameters (x,y) |
| 163 */ |
| 164 retrieveNodeSize: function(requests, callback) |
| 165 { |
| 166 if (!requests) |
| 167 requests = []; |
| 168 |
| 169 let id = ++this._nodeSizeMaxResponseID; |
| 170 this._nodeSizeCallbacks.set(id, callback); |
| 171 |
| 172 messageManager.broadcastAsyncMessage("AdblockPlus:RetrieveNodeSize", { |
| 173 notifierID: this.id, |
| 174 responseID: id, |
| 175 requests, |
| 176 }); |
| 177 }, |
| 178 |
| 179 onNodeSizeReceived: function(responseID, size) |
| 180 { |
| 181 let callback = this._nodeSizeCallbacks.get(responseID); |
| 182 this._nodeSizeCallbacks.delete(responseID); |
| 183 if (size && typeof callback == "function") |
| 184 callback(size); |
143 } | 185 } |
144 }; | 186 }; |
145 | 187 |
146 RequestNotifier.storeSelection = function(/**Window*/ wnd, /**String*/ selection
) | 188 RequestNotifier.storeSelection = function(/**Window*/ wnd, /**String*/ selection
) |
147 { | 189 { |
148 windowSelection.set(wnd.document, selection); | 190 windowSelection.set(wnd.document, selection); |
149 }; | 191 }; |
150 RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/ | 192 RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/ |
151 { | 193 { |
152 if (windowSelection.has(wnd.document)) | 194 if (windowSelection.has(wnd.document)) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 node = node.parentNode; | 247 node = node.parentNode; |
206 } | 248 } |
207 else | 249 else |
208 { | 250 { |
209 node = null; | 251 node = null; |
210 } | 252 } |
211 } | 253 } |
212 | 254 |
213 return null; | 255 return null; |
214 }; | 256 }; |
OLD | NEW |