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

Side by Side Diff: lib/requestNotifier.js

Issue 5743717579227136: Get rid of Utils.threadManager (Closed)
Patch Set: Removed a line that is no longer in use Created March 13, 2014, 11:52 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/sendReport.js ('k') | lib/utils.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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 * running). 146 * running).
147 */ 147 */
148 eventsPosted: 0, 148 eventsPosted: 0,
149 149
150 /** 150 /**
151 * Starts the initial scan of the window (will recurse into frames). 151 * Starts the initial scan of the window (will recurse into frames).
152 * @param {Window} wnd the window to be scanned 152 * @param {Window} wnd the window to be scanned
153 */ 153 */
154 startScan: function(wnd) 154 startScan: function(wnd)
155 { 155 {
156 let currentThread = Utils.threadManager.currentThread;
157
158 let doc = wnd.document; 156 let doc = wnd.document;
159 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul l, false); 157 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul l, false);
160 158
161 let runnable = 159 let process = function()
162 { 160 {
163 notifier: null, 161 if (!this.listener)
162 return;
164 163
165 run: function() 164 let node = walker.currentNode;
165 let data = getEntry(nodeData, node);
166 if (typeof data != "undefined")
167 for (let k in data)
168 this.notifyListener(wnd, node, data[k]);
169
170 if (walker.nextNode())
171 Utils.runAsync(process);
172 else
166 { 173 {
167 if (!this.notifier.listener) 174 // Done with the current window, start the scan for its frames
168 return; 175 for (let i = 0; i < wnd.frames.length; i++)
176 this.startScan(wnd.frames[i]);
169 177
170 let node = walker.currentNode; 178 this.eventsPosted--;
171 let data = getEntry(nodeData, node); 179 if (!this.eventsPosted)
172 if (typeof data != "undefined")
173 for (let k in data)
174 this.notifier.notifyListener(wnd, node, data[k]);
175
176 if (walker.nextNode())
177 currentThread.dispatch(runnable, Ci.nsIEventTarget.DISPATCH_NORMAL);
178 else
179 { 180 {
180 // Done with the current window, start the scan for its frames 181 this.scanComplete = true;
181 for (let i = 0; i < wnd.frames.length; i++) 182 this.notifyListener(wnd, null, null);
182 this.notifier.startScan(wnd.frames[i]);
183
184 this.notifier.eventsPosted--;
185 if (!this.notifier.eventsPosted)
186 {
187 this.notifier.scanComplete = true;
188 this.notifier.notifyListener(wnd, null, null);
189 }
190
191 this.notifier = null;
192 } 183 }
193 } 184 }
194 }; 185 }.bind(this);
195 runnable.notifier = this;
196 186
197 // Process each node in a separate event on current thread to allow other 187 // Process each node in a separate event to allow other events to process
198 // events to process
199 this.eventsPosted++; 188 this.eventsPosted++;
200 currentThread.dispatch(runnable, Ci.nsIEventTarget.DISPATCH_NORMAL); 189 Utils.runAsync(process);
201 } 190 }
202 }; 191 };
203 192
204 RequestNotifier.storeSelection = function(/**Window*/ wnd, /**String*/ selection ) 193 RequestNotifier.storeSelection = function(/**Window*/ wnd, /**String*/ selection )
205 { 194 {
206 setEntry(windowSelection, wnd.document, selection); 195 setEntry(windowSelection, wnd.document, selection);
207 }; 196 };
208 RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/ 197 RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/
209 { 198 {
210 if (hasEntry(windowSelection, wnd.document)) 199 if (hasEntry(windowSelection, wnd.document))
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 if (typeof existingData == "undefined") 364 if (typeof existingData == "undefined")
376 { 365 {
377 existingData = {}; 366 existingData = {};
378 setEntry(nodeData, node, existingData); 367 setEntry(nodeData, node, existingData);
379 } 368 }
380 369
381 // Add this request to the node data 370 // Add this request to the node data
382 existingData[this.type + " " + this.location] = this; 371 existingData[this.type + " " + this.location] = this;
383 } 372 }
384 }; 373 };
OLDNEW
« no previous file with comments | « chrome/content/ui/sendReport.js ('k') | lib/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld