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

Delta Between Two Patch Sets: lib/child/requestNotifier.js

Issue 29329779: Issue 3258 - Blockable items: restore item flashing functionality (Closed)
Left Patch Set: Better handling of dead objects Created Nov. 5, 2015, 11:06 p.m.
Right Patch Set: Addressed comments Created Nov. 25, 2015, 7:05 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/child/flasher.js ('k') | lib/requestNotifier.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 let {notifierID, requests, scrollToItem} = message.data; 63 let {notifierID, requests, scrollToItem} = message.data;
64 let notifier = notifiers.get(notifierID); 64 let notifier = notifiers.get(notifierID);
65 if (notifier) 65 if (notifier)
66 notifier.flashNodes(requests, scrollToItem); 66 notifier.flashNodes(requests, scrollToItem);
67 } 67 }
68 68
69 /** 69 /**
70 * Creates a notifier object for a particular window. After creation the window 70 * 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 71 * will first be scanned for previously saved requests. Once that scan is
72 * complete only new requests for this window will be reported. 72 * complete only new requests for this window will be reported.
73 * @param {Window} wnd window to attach the notifier to 73 * @param {Window} window window to attach the notifier to
74 * @param {Integer} id Parent notifier ID to be messaged 74 * @param {Integer} notifierID Parent notifier ID to be messaged
75 */ 75 */
76 function RequestNotifier(window, notifierID) 76 function RequestNotifier(window, notifierID)
77 { 77 {
78 this.window = window; 78 this.window = window;
79 this.id = notifierID; 79 this.id = notifierID;
80 notifiers.set(this.id, this); 80 notifiers.set(this.id, this);
81 this.nodes = new Map(); 81 this.nodes = new Map();
82 this.startScan(window); 82 this.startScan(window);
83 } 83 }
84 exports.RequestNotifier = RequestNotifier; 84 exports.RequestNotifier = RequestNotifier;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 * Starts the initial scan of the window (will recurse into frames). 145 * Starts the initial scan of the window (will recurse into frames).
146 * @param {Window} wnd the window to be scanned 146 * @param {Window} wnd the window to be scanned
147 */ 147 */
148 startScan: function(wnd) 148 startScan: function(wnd)
149 { 149 {
150 let doc = wnd.document; 150 let doc = wnd.document;
151 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul l, false); 151 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul l, false);
152 152
153 let process = function() 153 let process = function()
154 { 154 {
155 // Don't do anything if the notifier was shut down already.
155 if (!this.window) 156 if (!this.window)
156 return; 157 return;
157 158
158 let node = walker.currentNode; 159 let node = walker.currentNode;
159 let data = nodeData.get(node); 160 let data = nodeData.get(node);
160 if (typeof data != "undefined") 161 if (typeof data != "undefined")
161 for (let k in data) 162 for (let k in data)
162 this.notifyListener(node, data[k]); 163 this.notifyListener(node, data[k]);
163 164
164 if (walker.nextNode()) 165 if (walker.nextNode())
(...skipping 15 matching lines...) Expand all
180 181
181 // Process each node in a separate event to allow other events to process 182 // Process each node in a separate event to allow other events to process
182 this.eventsPosted++; 183 this.eventsPosted++;
183 Utils.runAsync(process); 184 Utils.runAsync(process);
184 }, 185 },
185 186
186 /** 187 /**
187 * Makes the nodes associated with the given requests blink. 188 * Makes the nodes associated with the given requests blink.
188 * @param {number[]} requests list of request IDs that were previously 189 * @param {number[]} requests list of request IDs that were previously
189 * reported by this notifier. 190 * reported by this notifier.
190 * @param {Boolean} scrollToItem if true, scroll to first node 191 * @param {boolean} scrollToItem if true, scroll to first node
191 */ 192 */
192 flashNodes: function(requests, scrollToItem) 193 flashNodes: function(requests, scrollToItem)
193 { 194 {
194 this.stopFlashing(); 195 this.stopFlashing();
195 196
196 let nodes = []; 197 let nodes = [];
197 for (let id of requests) 198 for (let id of requests)
198 { 199 {
199 if (!this.nodes.has(id)) 200 if (!this.nodes.has(id))
200 continue; 201 continue;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 stats.filters[filter.text]++; 278 stats.filters[filter.text]++;
278 else 279 else
279 stats.filters[filter.text] = 1; 280 stats.filters[filter.text] = 1;
280 } 281 }
281 282
282 // Notify listeners 283 // Notify listeners
283 for (let notifier of notifiers.values()) 284 for (let notifier of notifiers.values())
284 if (!notifier.window || notifier.window == topWnd) 285 if (!notifier.window || notifier.window == topWnd)
285 notifier.notifyListener(node, entry); 286 notifier.notifyListener(node, entry);
286 } 287 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld