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

Delta Between Two Patch Sets: lib/crawler.js

Issue 29338242: Issue 3792 - Fix to support multiprocess firefox (Closed)
Left Patch Set: address comments Created Sept. 29, 2016, 9:52 a.m.
Right Patch Set: change comment Created Sept. 30, 2016, 12:43 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/frameScript.js ('k') | no next file » | 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 Source Code is subject to the terms of the Mozilla Public License 2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 'use strict'; 7 "use strict";
8 8
9 /** 9 /**
10 * @module crawler 10 * @module crawler
11 */ 11 */
12 12
13 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
13 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); 14 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
14 const {Task} = Cu.import("resource://gre/modules/Task.jsm"); 15 const {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
15 const {setTimeout, clearTimeout} = Cu.import("resource://gre/modules/Timer.jsm", {}); 16 const {setTimeout, clearTimeout} = Cu.import("resource://gre/modules/Timer.jsm", {});
16 17
17 function abprequire(module) 18 function abprequire(module)
18 { 19 {
19 let result = {}; 20 let result = {};
20 result.wrappedJSObject = result; 21 result.wrappedJSObject = result;
21 Services.obs.notifyObservers(result, "adblockplus-require", module); 22 Services.obs.notifyObservers(result, "adblockplus-require", module);
22 return result.exports; 23 return result.exports;
23 } 24 }
24 25
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 * @param {tab} tab 103 * @param {tab} tab
103 */ 104 */
104 releaseTab: function(tab) 105 releaseTab: function(tab)
105 { 106 {
106 // If we are about to close last tab don't close it immediately to keep 107 // If we are about to close last tab don't close it immediately to keep
107 // the window alive. It will be closed when a new tab is created. 108 // the window alive. It will be closed when a new tab is created.
108 if (this._tabs > 1) 109 if (this._tabs > 1)
109 this._browser.removeTab(tab); 110 this._browser.removeTab(tab);
110 else 111 else
111 { 112 {
112 // navigate away from early opened URL 113 // navigate away from previously opened URL
Wladimir Palant 2016/09/29 11:44:59 early => previously
sergei 2016/09/29 15:36:22 Done.
113 tab.linkedBrowser.loadURI('about:blank', null, null); 114 tab.linkedBrowser.loadURI("about:blank", null, null);
Wladimir Palant 2016/09/29 11:44:59 Double quotation marks please.
sergei 2016/09/29 15:36:22 Done.
114 this._tabKeepingWindowAlive = tab; 115 this._tabKeepingWindowAlive = tab;
115 } 116 }
116 117
117 this._tabs--; 118 this._tabs--;
118 if (this._resolvers.length && this._tabs < this._maxtabs) 119 if (this._resolvers.length && this._tabs < this._maxtabs)
119 { 120 {
120 this._resolvers.shift()(this._createTab()); 121 this._resolvers.shift()(this._createTab());
121 } 122 }
122 }, 123 },
123 }; 124 };
(...skipping 29 matching lines...) Expand all
153 window.close(); 154 window.close();
154 }, false); 155 }, false);
155 }, 156 },
156 157
157 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence]) 158 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence])
158 }; 159 };
159 160
160 function configureFrameScript() 161 function configureFrameScript()
161 { 162 {
162 const info = require("info"); 163 const info = require("info");
163 const frameScriptPath = info.addonRoot + '/lib/child/frameScript.js?' + Math.r andom() + 164 let frameScriptPath = info.addonRoot + "/lib/child/frameScript.js";
164 '&info=' + encodeURIComponent(JSON.stringify(info));
Wladimir Palant 2016/09/29 11:44:59 Double quotation marks please. What's the point o
sergei 2016/09/29 15:36:22 Done.
165 Services.mm.loadFrameScript(frameScriptPath, true); 165 Services.mm.loadFrameScript(frameScriptPath, true);
166 166
167 onShutdown.add(() => 167 onShutdown.add(() =>
168 { 168 {
169 Services.mm.removeDelayedFrameScript(frameScriptPath); 169 Services.mm.removeDelayedFrameScript(frameScriptPath);
170 }); 170 });
171 } 171 }
172 172
173 /** 173 /**
174 * Starts the crawling session. The crawler opens each URL in a tab and stores 174 * Starts the crawling session. The crawler opens each URL in a tab and stores
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 * @param tab 277 * @param tab
278 * Tab in which we are interested in 278 * Tab in which we are interested in
279 * @param {int} timeout 279 * @param {int} timeout
280 * Timeout in milliseconds 280 * Timeout in milliseconds
281 * @return {Promise} promise which will be resolved with the received page info 281 * @return {Promise} promise which will be resolved with the received page info
282 */ 282 */
283 function getPageInfo(tab, timeout) 283 function getPageInfo(tab, timeout)
284 { 284 {
285 return new Promise((resolve, result) => 285 return new Promise((resolve, result) =>
286 { 286 {
287 const mm = tab.linkedBrowser.messageManager; 287 let mm = tab.linkedBrowser.messageManager;
288 let timerID; 288 let timerID;
289 let onDone = (msg) => 289 let onDone = (msg) =>
290 { 290 {
291 mm.removeMessageListener("abpcrawler:pageInfoGathered", onDone); 291 mm.removeMessageListener("abpcrawler:pageInfoGathered", onDone);
292 clearTimeout(timerID); 292 clearTimeout(timerID);
293 resolve(msg.data); 293 resolve(msg.data);
294 } 294 }
295 mm.addMessageListener("abpcrawler:pageInfoGathered", onDone); 295 mm.addMessageListener("abpcrawler:pageInfoGathered", onDone);
296 timerID = setTimeout(() => onDone({data: {error: "timeout"}}), timeout); 296 timerID = setTimeout(() => onDone({data: {error: "timeout"}}), timeout);
297 }); 297 });
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 341
342 function reportException(e) 342 function reportException(e)
343 { 343 {
344 let stack = ""; 344 let stack = "";
345 if (e && typeof e == "object" && "stack" in e) 345 if (e && typeof e == "object" && "stack" in e)
346 stack = e.stack + "\n"; 346 stack = e.stack + "\n";
347 347
348 Cu.reportError(e); 348 Cu.reportError(e);
349 dump(e + "\n" + stack + "\n"); 349 dump(e + "\n" + stack + "\n");
350 } 350 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld