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

Side by Side Diff: lib/requestNotifier.js

Issue 29329815: Issue 3274 - Unbreak toolbar icon tooltip (Closed)
Patch Set: Created Nov. 6, 2015, 12:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** 18 /**
19 * @fileOverview Stores Adblock Plus data to be attached to a window. 19 * @fileOverview Stores Adblock Plus data to be attached to a window.
20 */ 20 */
21 21
22 let {Utils} = require("utils"); 22 let {Utils} = require("utils");
23 23
24 let windowSelection = new WeakMap(); 24 let windowSelection = new WeakMap();
25 let requestNotifierMaxId = 0; 25 let requestNotifierMaxId = 0;
26 26
27 let windowStatsMaxResponseID = 0;
28 let windowStatsCallbacks = new Map();
29
27 /** 30 /**
28 * Active RequestNotifier instances by their ID 31 * Active RequestNotifier instances by their ID
29 * @type Map.<number,RequestNotifier> 32 * @type Map.<number,RequestNotifier>
30 */ 33 */
31 let notifiers = new Map(); 34 let notifiers = new Map();
32 35
33 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] 36 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
34 .getService(Ci.nsIMessageListenerManager) 37 .getService(Ci.nsIMessageListenerManager)
35 .QueryInterface(Ci.nsIMessageBroadcaster); 38 .QueryInterface(Ci.nsIMessageBroadcaster);
36 39
37 Utils.addChildMessageListener("AdblockPlus:FoundNodeData", onNodeData); 40 Utils.addChildMessageListener("AdblockPlus:FoundNodeData", onNodeData);
38 Utils.addChildMessageListener("AdblockPlus:ScanComplete", onScanComplete); 41 Utils.addChildMessageListener("AdblockPlus:ScanComplete", onScanComplete);
39 Utils.addChildMessageListener("AdblockPlus:RetrieveNodeSizeResponse", onNodeSize Received); 42 Utils.addChildMessageListener("AdblockPlus:RetrieveNodeSizeResponse", onNodeSize Received);
43 Utils.addChildMessageListener("AdblockPlus:RetrieveWindowStatsResponse", onWindo wStatsReceived);
40 44
41 function onNodeData({notifierID, data}) 45 function onNodeData({notifierID, data})
42 { 46 {
43 let notifier = notifiers.get(notifierID); 47 let notifier = notifiers.get(notifierID);
44 if (notifier) 48 if (notifier)
45 notifier.notifyListener(data); 49 notifier.notifyListener(data);
46 } 50 }
47 51
48 function onScanComplete(notifierID) 52 function onScanComplete(notifierID)
49 { 53 {
50 let notifier = notifiers.get(notifierID); 54 let notifier = notifiers.get(notifierID);
51 if (notifier) 55 if (notifier)
52 notifier.onComplete(); 56 notifier.onComplete();
53 } 57 }
54 58
55 function onNodeSizeReceived({notifierID, responseID, size}) 59 function onNodeSizeReceived({notifierID, responseID, size})
56 { 60 {
57 let notifier = notifiers.get(notifierID); 61 let notifier = notifiers.get(notifierID);
58 if (notifier) 62 if (notifier)
59 notifier.onNodeSizeReceived(responseID, size); 63 notifier.onNodeSizeReceived(responseID, size);
60 } 64 }
61 65
66 function onWindowStatsReceived({responseID, stats})
67 {
68 let callback = windowStatsCallbacks.get(responseID);
69 windowStatsCallbacks.delete(responseID);
70 if (typeof callback == "function")
71 callback(stats);
72 }
73
62 /** 74 /**
63 * Creates a notifier object for a particular window. After creation the window 75 * Creates a notifier object for a particular window. After creation the window
64 * will first be scanned for previously saved requests. Once that scan is 76 * will first be scanned for previously saved requests. Once that scan is
65 * complete only new requests for this window will be reported. 77 * complete only new requests for this window will be reported.
66 * @param {Integer} outerWindowID ID of the window to attach the notifier to 78 * @param {Integer} outerWindowID ID of the window to attach the notifier to
67 * @param {Function} listener listener to be called whenever a new request is f ound 79 * @param {Function} listener listener to be called whenever a new request is f ound
68 * @param {Object} [listenerObj] "this" pointer to be used when calling the lis tener 80 * @param {Object} [listenerObj] "this" pointer to be used when calling the lis tener
69 */ 81 */
70 function RequestNotifier(outerWindowID, listener, listenerObj) 82 function RequestNotifier(outerWindowID, listener, listenerObj)
71 { 83 {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/ 204 RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/
193 { 205 {
194 if (windowSelection.has(wnd.document)) 206 if (windowSelection.has(wnd.document))
195 return windowSelection.get(wnd.document); 207 return windowSelection.get(wnd.document);
196 else 208 else
197 return null; 209 return null;
198 }; 210 };
199 211
200 /** 212 /**
201 * Retrieves the statistics for a window. 213 * Retrieves the statistics for a window.
202 * @result {Object} Object with the properties items, blocked, whitelisted, hidd en, filters containing statistics for the window (might be null) 214 * @param {number} outerWindowID the ID of the window
215 * @param {Function} callback the callback to be called with the resulting
216 * object (object properties will be items, blocked,
217 * whitelisted, hidden, filters) or null.
203 */ 218 */
204 RequestNotifier.getWindowStatistics = function(/**Window*/ wnd) 219 RequestNotifier.getWindowStatistics = function(outerWindowID, callback)
205 { 220 {
206 if (windowStats.has(wnd.document)) 221 let id = ++windowStatsMaxResponseID;
207 return windowStats.get(wnd.document); 222 windowStatsCallbacks.set(id, callback);
208 else 223
209 return null; 224 messageManager.broadcastAsyncMessage("AdblockPlus:RetrieveWindowStats", {
225 responseID: id,
226 outerWindowID
227 });
210 } 228 }
211 229
212 /** 230 /**
213 * Retrieves the request data associated with a DOM node. 231 * Retrieves the request data associated with a DOM node.
214 * @param {Node} node 232 * @param {Node} node
215 * @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 233 * @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
216 * @param {Integer} [type] request type to be looking for 234 * @param {Integer} [type] request type to be looking for
217 * @param {String} [location] request location to be looking for 235 * @param {String} [location] request location to be looking for
218 * @result {[Node, Object]} 236 * @result {[Node, Object]}
219 * @static 237 * @static
(...skipping 27 matching lines...) Expand all
247 node = node.parentNode; 265 node = node.parentNode;
248 } 266 }
249 else 267 else
250 { 268 {
251 node = null; 269 node = null;
252 } 270 }
253 } 271 }
254 272
255 return null; 273 return null;
256 }; 274 };
OLDNEW
« lib/child/requestNotifier.js ('K') | « lib/child/requestNotifier.js ('k') | lib/ui.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld