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: Created Nov. 5, 2015, 9:28 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
« 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} wnd window to attach the notifier to 83 * @param {Window} wnd window to attach the notifier to
74 * @param {Integer} id Parent notifier ID to be messaged 84 * @param {Integer} id 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 }, 215 },
206 216
207 /** 217 /**
208 * Stops flashing nodes after a previous flashNodes() call. 218 * Stops flashing nodes after a previous flashNodes() call.
209 */ 219 */
210 stopFlashing: function() 220 stopFlashing: function()
211 { 221 {
212 if (this.flasher) 222 if (this.flasher)
213 this.flasher.stop(); 223 this.flasher.stop();
214 this.flasher = null; 224 this.flasher = null;
225 },
226
227 /**
228 * Attempts to calculate the size of the nodes associated with the requests,
229 * Sends message to parent when complete.
230 * @param {number[]} requests list of request IDs that were previously
231 * reported by this notifier.
232 * @param {number} responseID ID to be sent with the response.
233 */
234 retrieveNodeSize: function(requests, responseID)
235 {
236 function getNodeSize(node)
237 {
238 if (typeof node != "undefined" && !Cu.isDeadWrapper(node))
239 {
240 if (node instanceof Ci.nsIDOMHTMLImageElement && (node.naturalWidth || n ode.naturalHeight))
241 return [node.naturalWidth, node.naturalHeight];
242 else if (node instanceof Ci.nsIDOMHTMLElement && (node.offsetWidth || no de.offsetHeight))
243 return [node.offsetWidth, node.offsetHeight];
244 }
245 return null;
246 }
247
248 let size = null;
249 for (let id of requests)
250 {
251 size = getNodeSize(this.nodes.get(id));
252 if (size)
253 break;
254 }
255 sendAsyncMessage("AdblockPlus:RetrieveNodeSizeResponse", {
256 notifierID: this.id,
257 responseID,
258 size
259 });
215 } 260 }
216 }; 261 };
217 262
218 /** 263 /**
219 * Attaches request data to a DOM node. 264 * Attaches request data to a DOM node.
220 * @param {Node} node node to attach data to 265 * @param {Node} node node to attach data to
221 * @param {Window} topWnd top-level window the node belongs to 266 * @param {Window} topWnd top-level window the node belongs to
222 * @param {String} contentType request type, e.g. "IMAGE" 267 * @param {String} contentType request type, e.g. "IMAGE"
223 * @param {String} docDomain domain of the document that initiated the request 268 * @param {String} docDomain domain of the document that initiated the request
224 * @param {Boolean} thirdParty will be true if a third-party server has been re quested 269 * @param {Boolean} thirdParty will be true if a third-party server has been re quested
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 stats.filters[filter.text]++; 317 stats.filters[filter.text]++;
273 else 318 else
274 stats.filters[filter.text] = 1; 319 stats.filters[filter.text] = 1;
275 } 320 }
276 321
277 // Notify listeners 322 // Notify listeners
278 for (let notifier of notifiers.values()) 323 for (let notifier of notifiers.values())
279 if (!notifier.window || notifier.window == topWnd) 324 if (!notifier.window || notifier.window == topWnd)
280 notifier.notifyListener(node, entry); 325 notifier.notifyListener(node, entry);
281 } 326 }
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