| 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"); | 27 const {extend} = require("./coreUtils"); | 
| 28 | 28 | 
| 29 /** | 29 /** | 
| 30  * Abstract base class for filter subscriptions | 30  * Abstract base class for filter subscriptions | 
| 31  * | 31  * | 
| 32  * @param {string} url    download location of the subscription | 32  * @param {string} url    download location of the subscription | 
| 33  * @param {string} [title]  title of the filter subscription | 33  * @param {string} [title]  title of the filter subscription | 
| 34  * @constructor | 34  * @constructor | 
| 35  */ | 35  */ | 
| 36 function Subscription(url, title) | 36 function Subscription(url, title) | 
| 37 { | 37 { | 
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 253    * 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 | 
| 254    * @param {Filter} filter filter to be tested | 254    * @param {Filter} filter filter to be tested | 
| 255    * @return {boolean} | 255    * @return {boolean} | 
| 256    */ | 256    */ | 
| 257   isDefaultFor(filter) | 257   isDefaultFor(filter) | 
| 258   { | 258   { | 
| 259     if (this.defaults && this.defaults.length) | 259     if (this.defaults && this.defaults.length) | 
| 260     { | 260     { | 
| 261       for (let type of this.defaults) | 261       for (let type of this.defaults) | 
| 262       { | 262       { | 
| 263         if (filter instanceof SpecialSubscription.defaultsMap[type]) | 263         if (filter instanceof SpecialSubscription.defaultsMap.get(type)) | 
| 264           return true; | 264           return true; | 
| 265         if (!(filter instanceof ActiveFilter) && type == "blacklist") | 265         if (!(filter instanceof ActiveFilter) && type == "blacklist") | 
| 266           return true; | 266           return true; | 
| 267       } | 267       } | 
| 268     } | 268     } | 
| 269 | 269 | 
| 270     return false; | 270     return false; | 
| 271   }, | 271   }, | 
| 272 | 272 | 
| 273   /** | 273   /** | 
| 274    * See Subscription.serialize() | 274    * See Subscription.serialize() | 
| 275    * @inheritdoc | 275    * @inheritdoc | 
| 276    */ | 276    */ | 
| 277   serialize(buffer) | 277   serialize(buffer) | 
| 278   { | 278   { | 
| 279     Subscription.prototype.serialize.call(this, buffer); | 279     Subscription.prototype.serialize.call(this, buffer); | 
| 280     if (this.defaults && this.defaults.length) | 280     if (this.defaults && this.defaults.length) | 
| 281     { | 281     { | 
| 282       buffer.push("defaults=" + | 282       buffer.push("defaults=" + | 
| 283         this.defaults.filter( | 283         this.defaults.filter( | 
| 284           type => type in SpecialSubscription.defaultsMap | 284           type => SpecialSubscription.defaultsMap.has(type) | 
| 285         ).join(" ") | 285         ).join(" ") | 
| 286       ); | 286       ); | 
| 287     } | 287     } | 
| 288     if (this._lastDownload) | 288     if (this._lastDownload) | 
| 289       buffer.push("lastDownload=" + this._lastDownload); | 289       buffer.push("lastDownload=" + this._lastDownload); | 
| 290   } | 290   } | 
| 291 }); | 291 }); | 
| 292 | 292 | 
| 293 SpecialSubscription.defaultsMap = Object.create(null, desc({ | 293 SpecialSubscription.defaultsMap = new Map([ | 
| 294   whitelist: WhitelistFilter, | 294   ["whitelist", WhitelistFilter], | 
| 295   blocking: BlockingFilter, | 295   ["blocking", BlockingFilter], | 
| 296   elemhide: ElemHideBase | 296   ["elemhide", ElemHideBase] | 
| 297 })); | 297 ]); | 
| 298 | 298 | 
| 299 /** | 299 /** | 
| 300  * Creates a new user-defined filter group. | 300  * Creates a new user-defined filter group. | 
| 301  * @param {string} [title]  title of the new filter group | 301  * @param {string} [title]  title of the new filter group | 
| 302  * @return {SpecialSubscription} | 302  * @return {SpecialSubscription} | 
| 303  */ | 303  */ | 
| 304 SpecialSubscription.create = function(title) | 304 SpecialSubscription.create = function(title) | 
| 305 { | 305 { | 
| 306   let url; | 306   let url; | 
| 307   do | 307   do | 
| 308   { | 308   { | 
| 309     url = "~user~" + Math.round(Math.random() * 1000000); | 309     url = "~user~" + Math.round(Math.random() * 1000000); | 
| 310   } while (Subscription.knownSubscriptions.has(url)); | 310   } while (Subscription.knownSubscriptions.has(url)); | 
| 311   return new SpecialSubscription(url, title); | 311   return new SpecialSubscription(url, title); | 
| 312 }; | 312 }; | 
| 313 | 313 | 
| 314 /** | 314 /** | 
| 315  * Creates a new user-defined filter group and adds the given filter to it. | 315  * Creates a new user-defined filter group and adds the given filter to it. | 
| 316  * This group will act as the default group for this filter type. | 316  * This group will act as the default group for this filter type. | 
| 317  * @param {Filter} filter | 317  * @param {Filter} filter | 
| 318  * @return {SpecialSubscription} | 318  * @return {SpecialSubscription} | 
| 319  */ | 319  */ | 
| 320 SpecialSubscription.createForFilter = function(filter) | 320 SpecialSubscription.createForFilter = function(filter) | 
| 321 { | 321 { | 
| 322   let subscription = SpecialSubscription.create(); | 322   let subscription = SpecialSubscription.create(); | 
| 323   subscription.filters.push(filter); | 323   subscription.filters.push(filter); | 
| 324   for (let type in SpecialSubscription.defaultsMap) | 324   for (let [type, class_] of SpecialSubscription.defaultsMap) | 
| 325   { | 325   { | 
| 326     if (filter instanceof SpecialSubscription.defaultsMap[type]) | 326     if (filter instanceof class_) | 
| 327       subscription.defaults = [type]; | 327       subscription.defaults = [type]; | 
| 328   } | 328   } | 
| 329   if (!subscription.defaults) | 329   if (!subscription.defaults) | 
| 330     subscription.defaults = ["blocking"]; | 330     subscription.defaults = ["blocking"]; | 
| 331   return subscription; | 331   return subscription; | 
| 332 }; | 332 }; | 
| 333 | 333 | 
| 334 /** | 334 /** | 
| 335  * Abstract base class for regular filter subscriptions (both | 335  * Abstract base class for regular filter subscriptions (both | 
| 336  * internally and externally updated) | 336  * internally and externally updated) | 
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 566     if (this.errors) | 566     if (this.errors) | 
| 567       buffer.push("errors=" + this.errors); | 567       buffer.push("errors=" + this.errors); | 
| 568     if (this.version) | 568     if (this.version) | 
| 569       buffer.push("version=" + this.version); | 569       buffer.push("version=" + this.version); | 
| 570     if (this.requiredVersion) | 570     if (this.requiredVersion) | 
| 571       buffer.push("requiredVersion=" + this.requiredVersion); | 571       buffer.push("requiredVersion=" + this.requiredVersion); | 
| 572     if (this.downloadCount) | 572     if (this.downloadCount) | 
| 573       buffer.push("downloadCount=" + this.downloadCount); | 573       buffer.push("downloadCount=" + this.downloadCount); | 
| 574   } | 574   } | 
| 575 }); | 575 }); | 
| OLD | NEW | 
|---|