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

Delta Between Two Patch Sets: lib/crawler.js

Issue 29338442: Issue 3815 - Fix TabAllocator. Now it returns tab with initialized outerWindowID (Closed)
Left Patch Set: Address comment about tab keeping window alive Created Sept. 15, 2016, 3:31 p.m.
Right Patch Set: remove additional empty line Created Sept. 16, 2016, 12:33 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 | « no previous file | run.py » ('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 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 /** 7 /**
8 * @module crawler 8 * @module crawler
9 */ 9 */
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 * 58 *
59 * @return {Promise.<tab>} promise which resolves once the tab is fully initia lized. 59 * @return {Promise.<tab>} promise which resolves once the tab is fully initia lized.
60 */ 60 */
61 _createTab: function() 61 _createTab: function()
62 { 62 {
63 this._tabs++; 63 this._tabs++;
64 let tab = this._browser.addTab("about:blank"); 64 let tab = this._browser.addTab("about:blank");
65 if (tab.linkedBrowser.outerWindowID) 65 if (tab.linkedBrowser.outerWindowID)
66 { 66 {
67 this._removeTabKeepingWindowAlive(); 67 this._removeTabKeepingWindowAlive();
68 return Promise.resolve(tab); 68 return Promise.resolve(tab);
Wladimir Palant 2016/09/16 07:10:37 I think that rather than introducing a _removeTabK
sergei 2016/09/16 12:34:13 It's a valid point but I would like to keep it thi
69 } 69 }
70 return new Promise((resolve, reject) => 70 return new Promise((resolve, reject) =>
71 { 71 {
72 let onBrowserInit = (msg) => 72 let onBrowserInit = (msg) =>
73 { 73 {
74 tab.linkedBrowser.messageManager.removeMessageListener("Browser:Init", o nBrowserInit); 74 tab.linkedBrowser.messageManager.removeMessageListener("Browser:Init", o nBrowserInit);
75 this._removeTabKeepingWindowAlive(); 75 this._removeTabKeepingWindowAlive();
76 resolve(tab); 76 resolve(tab);
77 }; 77 };
78 // "Browser:Init" message is sent once the browser is ready, see 78 // "Browser:Init" message is sent once the browser is ready, see
79 // https://bugzil.la/1256602#c1 79 // https://bugzil.la/1256602#c1
80 tab.linkedBrowser.messageManager.addMessageListener("Browser:Init", onBrow serInit); 80 tab.linkedBrowser.messageManager.addMessageListener("Browser:Init", onBrow serInit);
81 }); 81 });
82 }, 82 },
83
Wladimir Palant 2016/09/16 07:10:37 Nit: Don't add this extra newline please.
sergei 2016/09/16 12:34:13 Done.
84 83
85 /** 84 /**
86 * Returns a promise that will resolve into a tab once a tab is allocated. 85 * Returns a promise that will resolve into a tab once a tab is allocated.
87 * The tab cannot be used by other tasks until releaseTab() is called. 86 * The tab cannot be used by other tasks until releaseTab() is called.
88 * 87 *
89 * @result {Promise.<tab>} 88 * @result {Promise.<tab>}
90 */ 89 */
91 getTab: function() 90 getTab: function()
92 { 91 {
93 if (this._tabs < this._maxtabs) 92 if (this._tabs < this._maxtabs)
94 return this._createTab(); 93 return this._createTab();
95 return new Promise((resolve, reject) => this._resolvers.push(resolve)); 94 return new Promise((resolve, reject) => this._resolvers.push(resolve));
96 }, 95 },
97 96
98 /** 97 /**
99 * Adds a tab back to the pool so that it can be used by other tasks. 98 * Adds a tab back to the pool so that it can be used by other tasks.
100 * 99 *
101 * @param {tab} tab 100 * @param {tab} tab
102 */ 101 */
103 releaseTab: function(tab) 102 releaseTab: function(tab)
104 { 103 {
105 // If we are about to close last tab don't close it immediately to keep 104 // If we are about to close last tab don't close it immediately to keep
106 // the window alive. It will be closed when a new tab is created. 105 // the window alive. It will be closed when a new tab is created.
107 if (this._tabs > 1) 106 if (this._tabs > 1)
108 this._browser.removeTab(tab); 107 this._browser.removeTab(tab);
109 else 108 else
110 { 109 {
111 // navigate away from early opened URL 110 // navigate away from early opened URL
112 tab.linkedBrowser.loadURI('about:blank', null, null); 111 tab.linkedBrowser.loadURI('about:blank', null, null);
Wladimir Palant 2016/09/16 07:10:37 What's the point of navigating away if we are igno
sergei 2016/09/16 12:34:13 I have a version when the crawler is always runnin
113 this._tabKeepingWindowAlive = tab; 112 this._tabKeepingWindowAlive = tab;
114 } 113 }
115 114
116 this._tabs--; 115 this._tabs--;
117 if (this._resolvers.length && this._tabs < this._maxtabs) 116 if (this._resolvers.length && this._tabs < this._maxtabs)
118 { 117 {
119 this._resolvers.shift()(this._createTab()); 118 this._resolvers.shift()(this._createTab());
120 } 119 }
121 }, 120 },
122 }; 121 };
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 394
396 function reportException(e) 395 function reportException(e)
397 { 396 {
398 let stack = ""; 397 let stack = "";
399 if (e && typeof e == "object" && "stack" in e) 398 if (e && typeof e == "object" && "stack" in e)
400 stack = e.stack + "\n"; 399 stack = e.stack + "\n";
401 400
402 Cu.reportError(e); 401 Cu.reportError(e);
403 dump(e + "\n" + stack + "\n"); 402 dump(e + "\n" + stack + "\n");
404 } 403 }
LEFTRIGHT
« no previous file | run.py » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld