| LEFT | RIGHT |
| (no file at all) | |
| 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 {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
| 14 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); | 14 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); |
| 15 const {Task} = Cu.import("resource://gre/modules/Task.jsm", {}); | 15 const {Task} = Cu.import("resource://gre/modules/Task.jsm", {}); |
| 16 const {Promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); | |
| 17 | 16 |
| 18 function abprequire(module) | 17 function abprequire(module) |
| 19 { | 18 { |
| 20 let result = {}; | 19 let result = {}; |
| 21 result.wrappedJSObject = result; | 20 result.wrappedJSObject = result; |
| 22 Services.obs.notifyObservers(result, "adblockplus-require", module); | 21 Services.obs.notifyObservers(result, "adblockplus-require", module); |
| 23 return result.exports; | 22 return result.exports; |
| 24 } | 23 } |
| 25 | 24 |
| 26 let {RequestNotifier} = abprequire("requestNotifier"); | 25 let {RequestNotifier} = abprequire("requestNotifier"); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 * | 127 * |
| 129 * @param {tabbrowser} browser | 128 * @param {tabbrowser} browser |
| 130 * The tabbed browser to be observed | 129 * The tabbed browser to be observed |
| 131 * @param {int} timeout | 130 * @param {int} timeout |
| 132 * Load timeout in milliseconds | 131 * Load timeout in milliseconds |
| 133 * @constructor | 132 * @constructor |
| 134 */ | 133 */ |
| 135 function LoadListener(browser, timeout) | 134 function LoadListener(browser, timeout) |
| 136 { | 135 { |
| 137 this._browser = browser; | 136 this._browser = browser; |
| 138 this._deferred = new Map(); | 137 this._deferred = new Map(); |
| 139 this._timeout = timeout; | 138 this._timeout = timeout; |
| 140 browser.addTabsProgressListener(this); | 139 browser.addTabsProgressListener(this); |
| 141 } | 140 } |
| 142 LoadListener.prototype = { | 141 LoadListener.prototype = { |
| 143 /** | 142 /** |
| 144 * Returns a promise that will be resolved when the page in the specified tab | 143 * Returns a promise that will be resolved when the page in the specified tab |
| 145 * finishes loading. Loading will be stopped if the timeout is reached. | 144 * finishes loading. Loading will be stopped if the timeout is reached. |
| 146 * | 145 * |
| 147 * @param {tab} tab | 146 * @param {tab} tab |
| 148 * @result {Promise} | 147 * @result {Promise} |
| 149 */ | 148 */ |
| 150 waitForLoad: function(tab) | 149 waitForLoad: function(tab) |
| 151 { | 150 { |
| 152 let deferred = Promise.defer(); | 151 return new Promise((resolve, reject) => |
| 153 this._deferred.set(tab.linkedBrowser, deferred); | 152 { |
| 154 | 153 this._deferred.set(tab.linkedBrowser, resolve); |
| 155 tab.ownerDocument.defaultView.setTimeout(function() | 154 |
| 156 { | 155 tab.ownerDocument.defaultView.setTimeout(function() |
| 157 tab.linkedBrowser.stop(); | 156 { |
| 158 }, this._timeout); | 157 tab.linkedBrowser.stop(); |
| 159 | 158 }, this._timeout); |
| 160 return deferred.promise; | 159 }); |
| 161 }, | 160 }, |
| 162 | 161 |
| 163 /** | 162 /** |
| 164 * Deactivates this object. | 163 * Deactivates this object. |
| 165 */ | 164 */ |
| 166 stop: function() | 165 stop: function() |
| 167 { | 166 { |
| 168 this._browser.removeTabsProgressListener(this); | 167 this._browser.removeTabsProgressListener(this); |
| 169 }, | 168 }, |
| 170 | 169 |
| 171 onStateChange: function(browser, progress, request, flags, status) | 170 onStateChange: function(browser, progress, request, flags, status) |
| 172 { | 171 { |
| 173 if ((flags & Ci.nsIWebProgressListener.STATE_STOP) && (flags & Ci.nsIWebProg
ressListener.STATE_IS_WINDOW)) | 172 if ((flags & Ci.nsIWebProgressListener.STATE_STOP) && (flags & Ci.nsIWebProg
ressListener.STATE_IS_WINDOW)) |
| 174 { | 173 { |
| 175 let deferred = this._deferred.get(browser); | 174 let resolve = this._deferred.get(browser); |
| 176 if (deferred) | 175 if (resolve) |
| 177 { | 176 { |
| 178 this._deferred.delete(browser); | 177 this._deferred.delete(browser); |
| 179 | 178 |
| 180 let headers = []; | 179 let headers = []; |
| 181 if (request instanceof Ci.nsIHttpChannel) | 180 if (request instanceof Ci.nsIHttpChannel) |
| 182 { | 181 { |
| 183 try | 182 try |
| 184 { | 183 { |
| 185 headers.push("HTTP/x.x " + request.responseStatus + " " + request.re
sponseStatusText); | 184 headers.push("HTTP/x.x " + request.responseStatus + " " + request.re
sponseStatusText); |
| 186 request.visitResponseHeaders((header, value) => headers.push(header
+ ": " + value)); | 185 request.visitResponseHeaders((header, value) => headers.push(header
+ ": " + value)); |
| 187 } | 186 } |
| 188 catch (e) | 187 catch (e) |
| 189 { | 188 { |
| 190 // Exceptions are expected here | 189 // Exceptions are expected here |
| 191 } | 190 } |
| 192 } | 191 } |
| 193 deferred.resolve([status, headers]); | 192 resolve([status, headers]); |
| 194 } | 193 } |
| 195 } | 194 } |
| 196 } | 195 } |
| 197 }; | 196 }; |
| 198 | 197 |
| 199 /** | 198 /** |
| 200 * Once created, this object will make sure all new windows are dismissed | 199 * Once created, this object will make sure all new windows are dismissed |
| 201 * immediately. | 200 * immediately. |
| 202 * | 201 * |
| 203 * @constructor | 202 * @constructor |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 396 |
| 398 function reportException(e) | 397 function reportException(e) |
| 399 { | 398 { |
| 400 let stack = ""; | 399 let stack = ""; |
| 401 if (e && typeof e == "object" && "stack" in e) | 400 if (e && typeof e == "object" && "stack" in e) |
| 402 stack = e.stack + "\n"; | 401 stack = e.stack + "\n"; |
| 403 | 402 |
| 404 Cu.reportError(e); | 403 Cu.reportError(e); |
| 405 dump(e + "\n" + stack + "\n"); | 404 dump(e + "\n" + stack + "\n"); |
| 406 } | 405 } |
| LEFT | RIGHT |