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

Side by Side Diff: lib/child/requestNotifier.js

Issue 29329786: Issue 3258 - Blockable items: fix Size column (Closed)
Patch Set: Cleaner approach: split up getItemSize into sync and async parts Created Nov. 26, 2015, 11:06 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/content/ui/sidebar.js ('k') | lib/requestNotifier.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 18 matching lines...) Expand all
29 29
30 /** 30 /**
31 * Active RequestNotifier instances by their ID 31 * Active RequestNotifier instances by their ID
32 * @type Map.<number,RequestNotifier> 32 * @type Map.<number,RequestNotifier>
33 */ 33 */
34 let notifiers = new Map(); 34 let notifiers = new Map();
35 35
36 addMessageListener("AdblockPlus:StartWindowScan", onStartScan); 36 addMessageListener("AdblockPlus:StartWindowScan", onStartScan);
37 addMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown); 37 addMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown);
38 addMessageListener("AdblockPlus:FlashNodes", onFlashNodes); 38 addMessageListener("AdblockPlus:FlashNodes", onFlashNodes);
39 addMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize);
39 40
40 onShutdown.add(() => { 41 onShutdown.add(() => {
41 removeMessageListener("AdblockPlus:StartWindowScan", onStartScan); 42 removeMessageListener("AdblockPlus:StartWindowScan", onStartScan);
42 removeMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown); 43 removeMessageListener("AdblockPlus:ShutdownNotifier", onNotifierShutdown);
43 removeMessageListener("AdblockPlus:FlashNodes", onFlashNodes); 44 removeMessageListener("AdblockPlus:FlashNodes", onFlashNodes);
45 removeMessageListener("AdblockPlus:RetrieveNodeSize", onRetrieveNodeSize);
44 }); 46 });
45 47
46 function onStartScan(message) 48 function onStartScan(message)
47 { 49 {
48 let {notifierID, outerWindowID} = message.data; 50 let {notifierID, outerWindowID} = message.data;
49 let window = Services.wm.getOuterWindowWithId(outerWindowID); 51 let window = Services.wm.getOuterWindowWithId(outerWindowID);
50 if (window) 52 if (window)
51 new RequestNotifier(window, notifierID); 53 new RequestNotifier(window, notifierID);
52 } 54 }
53 55
54 function onNotifierShutdown(message) 56 function onNotifierShutdown(message)
55 { 57 {
56 let notifier = notifiers.get(message.data); 58 let notifier = notifiers.get(message.data);
57 if (notifier) 59 if (notifier)
58 notifier.shutdown(); 60 notifier.shutdown();
59 } 61 }
60 62
61 function onFlashNodes(message) 63 function onFlashNodes(message)
62 { 64 {
63 let {notifierID, requests, scrollToItem} = message.data; 65 let {notifierID, requests, scrollToItem} = message.data;
64 let notifier = notifiers.get(notifierID); 66 let notifier = notifiers.get(notifierID);
65 if (notifier) 67 if (notifier)
66 notifier.flashNodes(requests, scrollToItem); 68 notifier.flashNodes(requests, scrollToItem);
67 } 69 }
68 70
71 function onRetrieveNodeSize(message)
72 {
73 let {notifierID, responseID, requests} = message.data;
74 let notifier = notifiers.get(notifierID);
75 if (notifier)
76 notifier.retrieveNodeSize(requests, responseID);
77 }
78
69 /** 79 /**
70 * Creates a notifier object for a particular window. After creation the window 80 * Creates a notifier object for a particular window. After creation the window
71 * will first be scanned for previously saved requests. Once that scan is 81 * will first be scanned for previously saved requests. Once that scan is
72 * complete only new requests for this window will be reported. 82 * complete only new requests for this window will be reported.
73 * @param {Window} window window to attach the notifier to 83 * @param {Window} window window to attach the notifier to
74 * @param {Integer} notifierID Parent notifier ID to be messaged 84 * @param {Integer} notifierID Parent notifier ID to be messaged
75 */ 85 */
76 function RequestNotifier(window, notifierID) 86 function RequestNotifier(window, notifierID)
77 { 87 {
78 this.window = window; 88 this.window = window;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 }, 221 },
212 222
213 /** 223 /**
214 * Stops flashing nodes after a previous flashNodes() call. 224 * Stops flashing nodes after a previous flashNodes() call.
215 */ 225 */
216 stopFlashing: function() 226 stopFlashing: function()
217 { 227 {
218 if (this.flasher) 228 if (this.flasher)
219 this.flasher.stop(); 229 this.flasher.stop();
220 this.flasher = null; 230 this.flasher = null;
231 },
232
233 /**
234 * Attempts to calculate the size of the nodes associated with the requests,
235 * Sends message to parent when complete.
236 * @param {number[]} requests list of request IDs that were previously
237 * reported by this notifier.
238 * @param {number} responseID ID to be sent with the response.
239 */
240 retrieveNodeSize: function(requests, responseID)
241 {
242 function getNodeSize(node)
243 {
244 if (node instanceof Ci.nsIDOMHTMLImageElement && (node.naturalWidth || nod e.naturalHeight))
245 return [node.naturalWidth, node.naturalHeight];
246 else if (node instanceof Ci.nsIDOMHTMLElement && (node.offsetWidth || node .offsetHeight))
247 return [node.offsetWidth, node.offsetHeight];
248 else
249 return null;
250 }
251
252 let size = null;
253 for (let id of requests)
254 {
255 if (!this.nodes.has(id))
256 continue;
257
258 let node = this.nodes.get(id);
259 if (Cu.isDeadWrapper(node))
260 this.nodes.delete(node);
261 else
262 {
263 size = getNodeSize(node);
264 if (size)
265 break;
266 }
267 }
268 sendAsyncMessage("AdblockPlus:RetrieveNodeSizeResponse", {
269 notifierID: this.id,
270 responseID,
271 size
272 });
221 } 273 }
222 }; 274 };
223 275
224 /** 276 /**
225 * Attaches request data to a DOM node. 277 * Attaches request data to a DOM node.
226 * @param {Node} node node to attach data to 278 * @param {Node} node node to attach data to
227 * @param {Window} topWnd top-level window the node belongs to 279 * @param {Window} topWnd top-level window the node belongs to
228 * @param {Object} hitData 280 * @param {Object} hitData
229 * @param {String} hitData.contentType request type, e.g. "IMAGE" 281 * @param {String} hitData.contentType request type, e.g. "IMAGE"
230 * @param {String} hitData.docDomain domain of the document that initiated the request 282 * @param {String} hitData.docDomain domain of the document that initiated the request
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 stats.filters[filter]++; 331 stats.filters[filter]++;
280 else 332 else
281 stats.filters[filter] = 1; 333 stats.filters[filter] = 1;
282 } 334 }
283 335
284 // Notify listeners 336 // Notify listeners
285 for (let notifier of notifiers.values()) 337 for (let notifier of notifiers.values())
286 if (!notifier.window || notifier.window == topWnd) 338 if (!notifier.window || notifier.window == topWnd)
287 notifier.notifyListener(node, entry); 339 notifier.notifyListener(node, entry);
288 } 340 }
OLDNEW
« no previous file with comments | « chrome/content/ui/sidebar.js ('k') | lib/requestNotifier.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld