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: Created March 13, 2014, 11:49 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; 156 let currentThread = Services.tm.currentThread;
157 157
158 let doc = wnd.document; 158 let doc = wnd.document;
159 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul l, false); 159 let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, nul l, false);
160 160
161 let runnable = 161 let process = function()
162 { 162 {
163 notifier: null, 163 if (!this.listener)
164 return;
164 165
165 run: function() 166 let node = walker.currentNode;
167 let data = getEntry(nodeData, node);
168 if (typeof data != "undefined")
169 for (let k in data)
170 this.notifyListener(wnd, node, data[k]);
171
172 if (walker.nextNode())
173 Utils.runAsync(process);
174 else
166 { 175 {
167 if (!this.notifier.listener) 176 // Done with the current window, start the scan for its frames
168 return; 177 for (let i = 0; i < wnd.frames.length; i++)
178 this.startScan(wnd.frames[i]);
169 179
170 let node = walker.currentNode; 180 this.eventsPosted--;
171 let data = getEntry(nodeData, node); 181 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 { 182 {
180 // Done with the current window, start the scan for its frames 183 this.scanComplete = true;
181 for (let i = 0; i < wnd.frames.length; i++) 184 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 } 185 }
193 } 186 }
194 }; 187 }.bind(this);
195 runnable.notifier = this;
196 188
197 // Process each node in a separate event on current thread to allow other 189 // Process each node in a separate event on current thread to allow other
198 // events to process 190 // events to process
199 this.eventsPosted++; 191 this.eventsPosted++;
200 currentThread.dispatch(runnable, Ci.nsIEventTarget.DISPATCH_NORMAL); 192 Utils.runAsync(process);
201 } 193 }
202 }; 194 };
203 195
204 RequestNotifier.storeSelection = function(/**Window*/ wnd, /**String*/ selection ) 196 RequestNotifier.storeSelection = function(/**Window*/ wnd, /**String*/ selection )
205 { 197 {
206 setEntry(windowSelection, wnd.document, selection); 198 setEntry(windowSelection, wnd.document, selection);
207 }; 199 };
208 RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/ 200 RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/
209 { 201 {
210 if (hasEntry(windowSelection, wnd.document)) 202 if (hasEntry(windowSelection, wnd.document))
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 if (typeof existingData == "undefined") 367 if (typeof existingData == "undefined")
376 { 368 {
377 existingData = {}; 369 existingData = {};
378 setEntry(nodeData, node, existingData); 370 setEntry(nodeData, node, existingData);
379 } 371 }
380 372
381 // Add this request to the node data 373 // Add this request to the node data
382 existingData[this.type + " " + this.location] = this; 374 existingData[this.type + " " + this.location] = this;
383 } 375 }
384 }; 376 };
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