LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 * Stops the periodic checks. | 167 * Stops the periodic checks. |
168 */ | 168 */ |
169 cancel() | 169 cancel() |
170 { | 170 { |
171 this._timer.cancel(); | 171 this._timer.cancel(); |
172 } | 172 } |
173 | 173 |
174 /** | 174 /** |
175 * Checks whether an address is currently being downloaded. | 175 * Checks whether an address is currently being downloaded. |
176 * @param {string} url | 176 * @param {string} url |
177 * @return {boolean} | 177 * @returns {boolean} |
178 */ | 178 */ |
179 isDownloading(url) | 179 isDownloading(url) |
180 { | 180 { |
181 return this._downloading.has(url); | 181 return this._downloading.has(url); |
182 } | 182 } |
183 | 183 |
184 /** | 184 /** |
185 * Starts downloading for an object. | 185 * Starts downloading for an object. |
186 * @param {Downloadable} downloadable | 186 * @param {Downloadable} downloadable |
187 */ | 187 */ |
188 download(downloadable) | 188 download(downloadable) |
189 { | 189 { |
190 // Make sure to detach download from the current execution context | 190 // Make sure to detach download from the current execution context |
191 Utils.runAsync(this._download.bind(this, downloadable, 0)); | 191 Utils.runAsync(this._download.bind(this, downloadable, 0)); |
192 } | 192 } |
193 | 193 |
194 /** | 194 /** |
195 * Generates the real download URL for an object by appending various | 195 * Generates the real download URL for an object by appending various |
196 * parameters. | 196 * parameters. |
197 * @param {Downloadable} downloadable | 197 * @param {Downloadable} downloadable |
198 * @return {string} | 198 * @returns {string} |
199 */ | 199 */ |
200 getDownloadUrl(downloadable) | 200 getDownloadUrl(downloadable) |
201 { | 201 { |
202 const {addonName, addonVersion, application, applicationVersion, | 202 const {addonName, addonVersion, application, applicationVersion, |
203 platform, platformVersion} = require("info"); | 203 platform, platformVersion} = require("info"); |
204 let url = downloadable.redirectURL || downloadable.url; | 204 let url = downloadable.redirectURL || downloadable.url; |
205 if (url.includes("?")) | 205 if (url.includes("?")) |
206 url += "&"; | 206 url += "&"; |
207 else | 207 else |
208 url += "?"; | 208 url += "?"; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 336 |
337 this._downloading.add(downloadable.url); | 337 this._downloading.add(downloadable.url); |
338 if (this.onDownloadStarted) | 338 if (this.onDownloadStarted) |
339 this.onDownloadStarted(downloadable); | 339 this.onDownloadStarted(downloadable); |
340 } | 340 } |
341 | 341 |
342 /** | 342 /** |
343 * Produces a soft and a hard expiration interval for a given supplied | 343 * Produces a soft and a hard expiration interval for a given supplied |
344 * expiration interval. | 344 * expiration interval. |
345 * @param {number} interval | 345 * @param {number} interval |
346 * @return {Array} soft and hard expiration interval | 346 * @returns {Array.<number>} soft and hard expiration interval |
347 */ | 347 */ |
348 processExpirationInterval(interval) | 348 processExpirationInterval(interval) |
349 { | 349 { |
350 interval = Math.min(Math.max(interval, 0), this.maxExpirationInterval); | 350 interval = Math.min(Math.max(interval, 0), this.maxExpirationInterval); |
351 let soft = Math.round(interval * (Math.random() * 0.4 + 0.8)); | 351 let soft = Math.round(interval * (Math.random() * 0.4 + 0.8)); |
352 let hard = interval * 2; | 352 let hard = interval * 2; |
353 let now = Date.now(); | 353 let now = Date.now(); |
354 return [now + soft, now + hard]; | 354 return [now + soft, now + hard]; |
355 } | 355 } |
356 } | 356 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 | 410 |
411 /** | 411 /** |
412 * URL that has to be requested for the object. | 412 * URL that has to be requested for the object. |
413 * @type {string} | 413 * @type {string} |
414 */ | 414 */ |
415 this.url = url; | 415 this.url = url; |
416 } | 416 } |
417 } | 417 } |
418 | 418 |
419 exports.Downloadable = Downloadable; | 419 exports.Downloadable = Downloadable; |
LEFT | RIGHT |