OLD | NEW |
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 /** | 20 /** |
21 * @fileOverview Definition of Subscription class and its subclasses. | 21 * @fileOverview Definition of Subscription class and its subclasses. |
22 */ | 22 */ |
23 | 23 |
24 const {ActiveFilter, BlockingFilter, | 24 const {ActiveFilter, BlockingFilter, |
25 WhitelistFilter, ElemHideBase} = require("./filterClasses"); | 25 WhitelistFilter, ElemHideBase} = require("./filterClasses"); |
26 const {FilterNotifier} = require("./filterNotifier"); | 26 const {FilterNotifier} = require("./filterNotifier"); |
27 const {desc, extend} = require("./coreUtils"); | |
28 | 27 |
29 /** | 28 /** |
30 * Abstract base class for filter subscriptions | 29 * Abstract base class for filter subscriptions |
31 * | 30 * |
32 * @param {string} url download location of the subscription | 31 * @param {string} url download location of the subscription |
33 * @param {string} [title] title of the filter subscription | 32 * @param {string} [title] title of the filter subscription |
34 * @constructor | 33 * @constructor |
35 */ | 34 */ |
36 function Subscription(url, title) | 35 function Subscription(url, title) |
37 { | 36 { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 * @param {string} [title] see Subscription() | 232 * @param {string} [title] see Subscription() |
234 * @constructor | 233 * @constructor |
235 * @augments Subscription | 234 * @augments Subscription |
236 */ | 235 */ |
237 function SpecialSubscription(url, title) | 236 function SpecialSubscription(url, title) |
238 { | 237 { |
239 Subscription.call(this, url, title); | 238 Subscription.call(this, url, title); |
240 } | 239 } |
241 exports.SpecialSubscription = SpecialSubscription; | 240 exports.SpecialSubscription = SpecialSubscription; |
242 | 241 |
243 SpecialSubscription.prototype = extend(Subscription, { | 242 SpecialSubscription.prototype = { |
| 243 __proto__: Subscription.prototype, |
| 244 |
244 /** | 245 /** |
245 * Filter types that should be added to this subscription by default | 246 * Filter types that should be added to this subscription by default |
246 * (entries should correspond to keys in SpecialSubscription.defaultsMap). | 247 * (entries should correspond to keys in SpecialSubscription.defaultsMap). |
247 * @type {string[]} | 248 * @type {string[]} |
248 */ | 249 */ |
249 defaults: null, | 250 defaults: null, |
250 | 251 |
251 /** | 252 /** |
252 * Tests whether a filter should be added to this group by default | 253 * Tests whether a filter should be added to this group by default |
253 * @param {Filter} filter filter to be tested | 254 * @param {Filter} filter filter to be tested |
(...skipping 26 matching lines...) Expand all Loading... |
280 { | 281 { |
281 buffer.push("defaults=" + | 282 buffer.push("defaults=" + |
282 this.defaults.filter( | 283 this.defaults.filter( |
283 type => type in SpecialSubscription.defaultsMap | 284 type => type in SpecialSubscription.defaultsMap |
284 ).join(" ") | 285 ).join(" ") |
285 ); | 286 ); |
286 } | 287 } |
287 if (this._lastDownload) | 288 if (this._lastDownload) |
288 buffer.push("lastDownload=" + this._lastDownload); | 289 buffer.push("lastDownload=" + this._lastDownload); |
289 } | 290 } |
290 }); | 291 }; |
291 | 292 |
292 SpecialSubscription.defaultsMap = Object.create(null, desc({ | 293 SpecialSubscription.defaultsMap = { |
| 294 __proto__: null, |
293 whitelist: WhitelistFilter, | 295 whitelist: WhitelistFilter, |
294 blocking: BlockingFilter, | 296 blocking: BlockingFilter, |
295 elemhide: ElemHideBase | 297 elemhide: ElemHideBase |
296 })); | 298 }; |
297 | 299 |
298 /** | 300 /** |
299 * Creates a new user-defined filter group. | 301 * Creates a new user-defined filter group. |
300 * @param {string} [title] title of the new filter group | 302 * @param {string} [title] title of the new filter group |
301 * @return {SpecialSubscription} | 303 * @return {SpecialSubscription} |
302 */ | 304 */ |
303 SpecialSubscription.create = function(title) | 305 SpecialSubscription.create = function(title) |
304 { | 306 { |
305 let url; | 307 let url; |
306 do | 308 do |
(...skipping 30 matching lines...) Expand all Loading... |
337 * @param {string} [title] see Subscription() | 339 * @param {string} [title] see Subscription() |
338 * @constructor | 340 * @constructor |
339 * @augments Subscription | 341 * @augments Subscription |
340 */ | 342 */ |
341 function RegularSubscription(url, title) | 343 function RegularSubscription(url, title) |
342 { | 344 { |
343 Subscription.call(this, url, title || url); | 345 Subscription.call(this, url, title || url); |
344 } | 346 } |
345 exports.RegularSubscription = RegularSubscription; | 347 exports.RegularSubscription = RegularSubscription; |
346 | 348 |
347 RegularSubscription.prototype = extend(Subscription, { | 349 RegularSubscription.prototype = { |
| 350 __proto__: Subscription.prototype, |
| 351 |
348 _homepage: null, | 352 _homepage: null, |
349 _lastDownload: 0, | 353 _lastDownload: 0, |
350 | 354 |
351 /** | 355 /** |
352 * Filter subscription homepage if known | 356 * Filter subscription homepage if known |
353 * @type {string} | 357 * @type {string} |
354 */ | 358 */ |
355 get homepage() | 359 get homepage() |
356 { | 360 { |
357 return this._homepage; | 361 return this._homepage; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 * @inheritdoc | 398 * @inheritdoc |
395 */ | 399 */ |
396 serialize(buffer) | 400 serialize(buffer) |
397 { | 401 { |
398 Subscription.prototype.serialize.call(this, buffer); | 402 Subscription.prototype.serialize.call(this, buffer); |
399 if (this._homepage) | 403 if (this._homepage) |
400 buffer.push("homepage=" + this._homepage); | 404 buffer.push("homepage=" + this._homepage); |
401 if (this._lastDownload) | 405 if (this._lastDownload) |
402 buffer.push("lastDownload=" + this._lastDownload); | 406 buffer.push("lastDownload=" + this._lastDownload); |
403 } | 407 } |
404 }); | 408 }; |
405 | 409 |
406 /** | 410 /** |
407 * Class for filter subscriptions updated externally (by other extension) | 411 * Class for filter subscriptions updated externally (by other extension) |
408 * @param {string} url see Subscription() | 412 * @param {string} url see Subscription() |
409 * @param {string} [title] see Subscription() | 413 * @param {string} [title] see Subscription() |
410 * @constructor | 414 * @constructor |
411 * @augments RegularSubscription | 415 * @augments RegularSubscription |
412 */ | 416 */ |
413 function ExternalSubscription(url, title) | 417 function ExternalSubscription(url, title) |
414 { | 418 { |
415 RegularSubscription.call(this, url, title); | 419 RegularSubscription.call(this, url, title); |
416 } | 420 } |
417 exports.ExternalSubscription = ExternalSubscription; | 421 exports.ExternalSubscription = ExternalSubscription; |
418 | 422 |
419 ExternalSubscription.prototype = extend(RegularSubscription, { | 423 ExternalSubscription.prototype = { |
| 424 __proto__: RegularSubscription.prototype, |
| 425 |
420 /** | 426 /** |
421 * See Subscription.serialize() | 427 * See Subscription.serialize() |
422 * @inheritdoc | 428 * @inheritdoc |
423 */ | 429 */ |
424 serialize(buffer) | 430 serialize(buffer) |
425 { | 431 { |
426 throw new Error( | 432 throw new Error( |
427 "Unexpected call, external subscriptions should not be serialized" | 433 "Unexpected call, external subscriptions should not be serialized" |
428 ); | 434 ); |
429 } | 435 } |
430 }); | 436 }; |
431 | 437 |
432 /** | 438 /** |
433 * Class for filter subscriptions updated externally (by other extension) | 439 * Class for filter subscriptions updated externally (by other extension) |
434 * @param {string} url see Subscription() | 440 * @param {string} url see Subscription() |
435 * @param {string} [title] see Subscription() | 441 * @param {string} [title] see Subscription() |
436 * @constructor | 442 * @constructor |
437 * @augments RegularSubscription | 443 * @augments RegularSubscription |
438 */ | 444 */ |
439 function DownloadableSubscription(url, title) | 445 function DownloadableSubscription(url, title) |
440 { | 446 { |
441 RegularSubscription.call(this, url, title); | 447 RegularSubscription.call(this, url, title); |
442 } | 448 } |
443 exports.DownloadableSubscription = DownloadableSubscription; | 449 exports.DownloadableSubscription = DownloadableSubscription; |
444 | 450 |
445 DownloadableSubscription.prototype = extend(RegularSubscription, { | 451 DownloadableSubscription.prototype = { |
| 452 __proto__: RegularSubscription.prototype, |
| 453 |
446 _downloadStatus: null, | 454 _downloadStatus: null, |
447 _lastCheck: 0, | 455 _lastCheck: 0, |
448 _errors: 0, | 456 _errors: 0, |
449 | 457 |
450 /** | 458 /** |
451 * Status of the last download (ID of a string) | 459 * Status of the last download (ID of a string) |
452 * @type {string} | 460 * @type {string} |
453 */ | 461 */ |
454 get downloadStatus() | 462 get downloadStatus() |
455 { | 463 { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 buffer.push("softExpiration=" + this.softExpiration); | 572 buffer.push("softExpiration=" + this.softExpiration); |
565 if (this.errors) | 573 if (this.errors) |
566 buffer.push("errors=" + this.errors); | 574 buffer.push("errors=" + this.errors); |
567 if (this.version) | 575 if (this.version) |
568 buffer.push("version=" + this.version); | 576 buffer.push("version=" + this.version); |
569 if (this.requiredVersion) | 577 if (this.requiredVersion) |
570 buffer.push("requiredVersion=" + this.requiredVersion); | 578 buffer.push("requiredVersion=" + this.requiredVersion); |
571 if (this.downloadCount) | 579 if (this.downloadCount) |
572 buffer.push("downloadCount=" + this.downloadCount); | 580 buffer.push("downloadCount=" + this.downloadCount); |
573 } | 581 } |
574 }); | 582 }; |
OLD | NEW |