| Left: | ||
| Right: |
| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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"; | |
| 19 | |
| 18 /** | 20 /** |
| 19 * @fileOverview Definition of Subscription class and its subclasses. | 21 * @fileOverview Definition of Subscription class and its subclasses. |
| 20 */ | 22 */ |
| 21 | 23 |
| 22 let {ActiveFilter, BlockingFilter, WhitelistFilter, ElemHideBase} = require("fil terClasses"); | 24 const {ActiveFilter, BlockingFilter, |
| 23 let {FilterNotifier} = require("filterNotifier"); | 25 WhitelistFilter, ElemHideBase} = require("filterClasses"); |
| 24 let {desc, extend} = require("coreUtils"); | 26 const {FilterNotifier} = require("filterNotifier"); |
| 27 const {desc, extend} = require("coreUtils"); | |
| 25 | 28 |
| 26 /** | 29 /** |
| 27 * Abstract base class for filter subscriptions | 30 * Abstract base class for filter subscriptions |
| 28 * | 31 * |
| 29 * @param {String} url download location of the subscription | 32 * @param {string} url download location of the subscription |
| 30 * @param {String} [title] title of the filter subscription | 33 * @param {string} [title] title of the filter subscription |
| 31 * @constructor | 34 * @constructor |
| 32 */ | 35 */ |
| 33 function Subscription(url, title) | 36 function Subscription(url, title) |
| 34 { | 37 { |
| 35 this.url = url; | 38 this.url = url; |
| 36 this.filters = []; | 39 this.filters = []; |
| 37 if (title) | 40 if (title) |
| 38 this._title = title; | 41 this._title = title; |
| 39 Subscription.knownSubscriptions[url] = this; | 42 Subscription.knownSubscriptions[url] = this; |
| 40 } | 43 } |
| 41 exports.Subscription = Subscription; | 44 exports.Subscription = Subscription; |
| 42 | 45 |
| 43 Subscription.prototype = | 46 Subscription.prototype = |
| 44 { | 47 { |
| 45 /** | 48 /** |
| 46 * Download location of the subscription | 49 * Download location of the subscription |
| 47 * @type String | 50 * @type {string} |
| 48 */ | 51 */ |
| 49 url: null, | 52 url: null, |
| 50 | 53 |
| 51 /** | 54 /** |
| 52 * Filters contained in the filter subscription | 55 * Filters contained in the filter subscription |
| 53 * @type Filter[] | 56 * @type {Filter[]} |
| 54 */ | 57 */ |
| 55 filters: null, | 58 filters: null, |
| 56 | 59 |
| 57 _title: null, | 60 _title: null, |
| 58 _fixedTitle: false, | 61 _fixedTitle: false, |
| 59 _disabled: false, | 62 _disabled: false, |
| 60 | 63 |
| 61 /** | 64 /** |
| 62 * Title of the filter subscription | 65 * Title of the filter subscription |
| 63 * @type String | 66 * @type {string} |
| 64 */ | 67 */ |
| 65 get title() | 68 get title() |
| 66 { | 69 { |
| 67 return this._title; | 70 return this._title; |
| 68 }, | 71 }, |
| 69 set title(value) | 72 set title(value) |
| 70 { | 73 { |
| 71 if (value != this._title) | 74 if (value != this._title) |
| 72 { | 75 { |
| 73 let oldValue = this._title; | 76 let oldValue = this._title; |
| 74 this._title = value; | 77 this._title = value; |
| 75 FilterNotifier.triggerListeners("subscription.title", this, value, oldValu e); | 78 FilterNotifier.triggerListeners("subscription.title", |
| 79 this, value, oldValue); | |
| 76 } | 80 } |
| 77 return this._title; | 81 return this._title; |
| 78 }, | 82 }, |
| 79 | 83 |
| 80 /** | 84 /** |
| 81 * Determines whether the title should be editable | 85 * Determines whether the title should be editable |
| 82 * @type Boolean | 86 * @type {boolean} |
| 83 */ | 87 */ |
| 84 get fixedTitle() | 88 get fixedTitle() |
| 85 { | 89 { |
| 86 return this._fixedTitle; | 90 return this._fixedTitle; |
| 87 }, | 91 }, |
| 88 set fixedTitle(value) | 92 set fixedTitle(value) |
| 89 { | 93 { |
| 90 if (value != this._fixedTitle) | 94 if (value != this._fixedTitle) |
| 91 { | 95 { |
| 92 let oldValue = this._fixedTitle; | 96 let oldValue = this._fixedTitle; |
| 93 this._fixedTitle = value; | 97 this._fixedTitle = value; |
| 94 FilterNotifier.triggerListeners("subscription.fixedTitle", this, value, ol dValue); | 98 FilterNotifier.triggerListeners("subscription.fixedTitle", |
| 99 this, value, oldValue); | |
| 95 } | 100 } |
| 96 return this._fixedTitle; | 101 return this._fixedTitle; |
| 97 }, | 102 }, |
| 98 | 103 |
| 99 /** | 104 /** |
| 100 * Defines whether the filters in the subscription should be disabled | 105 * Defines whether the filters in the subscription should be disabled |
| 101 * @type Boolean | 106 * @type {boolean} |
| 102 */ | 107 */ |
| 103 get disabled() | 108 get disabled() |
| 104 { | 109 { |
| 105 return this._disabled; | 110 return this._disabled; |
| 106 }, | 111 }, |
| 107 set disabled(value) | 112 set disabled(value) |
| 108 { | 113 { |
| 109 if (value != this._disabled) | 114 if (value != this._disabled) |
| 110 { | 115 { |
| 111 let oldValue = this._disabled; | 116 let oldValue = this._disabled; |
| 112 this._disabled = value; | 117 this._disabled = value; |
| 113 FilterNotifier.triggerListeners("subscription.disabled", this, value, oldV alue); | 118 FilterNotifier.triggerListeners("subscription.disabled", |
| 119 this, value, oldValue); | |
| 114 } | 120 } |
| 115 return this._disabled; | 121 return this._disabled; |
| 116 }, | 122 }, |
| 117 | 123 |
| 118 /** | 124 /** |
| 119 * Serializes the subscription to an array of strings for writing out on the d isk. | 125 * Serializes the subscription to an array of strings for writing |
| 126 * out on the disk. | |
| 120 * @param {string[]} buffer buffer to push the serialization results into | 127 * @param {string[]} buffer buffer to push the serialization results into |
| 121 */ | 128 */ |
| 122 serialize: function(buffer) | 129 serialize(buffer) |
| 123 { | 130 { |
| 124 buffer.push("[Subscription]"); | 131 buffer.push("[Subscription]"); |
| 125 buffer.push("url=" + this.url); | 132 buffer.push("url=" + this.url); |
| 126 if (this._title) | 133 if (this._title) |
| 127 buffer.push("title=" + this._title); | 134 buffer.push("title=" + this._title); |
| 128 if (this._fixedTitle) | 135 if (this._fixedTitle) |
| 129 buffer.push("fixedTitle=true"); | 136 buffer.push("fixedTitle=true"); |
| 130 if (this._disabled) | 137 if (this._disabled) |
| 131 buffer.push("disabled=true"); | 138 buffer.push("disabled=true"); |
| 132 }, | 139 }, |
| 133 | 140 |
| 134 serializeFilters: function(buffer) | 141 serializeFilters(buffer) |
| 135 { | 142 { |
| 136 for (let filter of this.filters) | 143 for (let filter of this.filters) |
| 137 buffer.push(filter.text.replace(/\[/g, "\\[")); | 144 buffer.push(filter.text.replace(/\[/g, "\\[")); |
| 138 }, | 145 }, |
| 139 | 146 |
| 140 toString: function() | 147 toString() |
| 141 { | 148 { |
| 142 let buffer = []; | 149 let buffer = []; |
| 143 this.serialize(buffer); | 150 this.serialize(buffer); |
| 144 return buffer.join("\n"); | 151 return buffer.join("\n"); |
| 145 } | 152 } |
| 146 }; | 153 }; |
| 147 | 154 |
| 148 /** | 155 /** |
| 149 * Cache for known filter subscriptions, maps URL to subscription objects. | 156 * Cache for known filter subscriptions, maps URL to subscription objects. |
| 150 * @type Object | 157 * @type {Object} |
| 151 */ | 158 */ |
| 152 Subscription.knownSubscriptions = Object.create(null); | 159 Subscription.knownSubscriptions = Object.create(null); |
| 153 | 160 |
| 154 /** | 161 /** |
| 155 * Returns a subscription from its URL, creates a new one if necessary. | 162 * Returns a subscription from its URL, creates a new one if necessary. |
| 156 * @param {String} url URL of the subscription | 163 * @param {string} url URL of the subscription |
| 157 * @return {Subscription} subscription or null if the subscription couldn't be c reated | 164 * @return {Subscription} subscription or null if the subscription couldn't be |
| 165 * created | |
|
Wladimir Palant
2017/03/02 14:07:05
Messy indentation here.
kzar
2017/03/08 12:33:50
Done.
| |
| 158 */ | 166 */ |
| 159 Subscription.fromURL = function(url) | 167 Subscription.fromURL = function(url) |
| 160 { | 168 { |
| 161 if (url in Subscription.knownSubscriptions) | 169 if (url in Subscription.knownSubscriptions) |
| 162 return Subscription.knownSubscriptions[url]; | 170 return Subscription.knownSubscriptions[url]; |
| 163 | 171 |
| 164 if (url[0] != "~") | 172 if (url[0] != "~") |
| 165 return new DownloadableSubscription(url, null); | 173 return new DownloadableSubscription(url, null); |
| 166 else | 174 return new SpecialSubscription(url); |
| 167 return new SpecialSubscription(url); | |
| 168 }; | 175 }; |
| 169 | 176 |
| 170 /** | 177 /** |
| 171 * Deserializes a subscription | 178 * Deserializes a subscription |
| 172 * | 179 * |
| 173 * @param {Object} obj map of serialized properties and their values | 180 * @param {Object} obj map of serialized properties and their values |
| 174 * @return {Subscription} subscription or null if the subscription couldn't be c reated | 181 * @return {Subscription} subscription or null if the subscription couldn't be |
| 182 * created | |
|
Wladimir Palant
2017/03/02 14:07:05
Messy indentation here.
kzar
2017/03/08 12:33:50
Done.
| |
| 175 */ | 183 */ |
| 176 Subscription.fromObject = function(obj) | 184 Subscription.fromObject = function(obj) |
| 177 { | 185 { |
| 178 let result; | 186 let result; |
| 179 if (obj.url[0] != "~") | 187 if (obj.url[0] != "~") |
| 180 { | 188 { |
| 181 // URL is valid - this is a downloadable subscription | 189 // URL is valid - this is a downloadable subscription |
| 182 result = new DownloadableSubscription(obj.url, obj.title); | 190 result = new DownloadableSubscription(obj.url, obj.title); |
| 183 if ("downloadStatus" in obj) | 191 if ("downloadStatus" in obj) |
| 184 result._downloadStatus = obj.downloadStatus; | 192 result._downloadStatus = obj.downloadStatus; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 212 if ("fixedTitle" in obj) | 220 if ("fixedTitle" in obj) |
| 213 result._fixedTitle = (obj.fixedTitle == "true"); | 221 result._fixedTitle = (obj.fixedTitle == "true"); |
| 214 if ("disabled" in obj) | 222 if ("disabled" in obj) |
| 215 result._disabled = (obj.disabled == "true"); | 223 result._disabled = (obj.disabled == "true"); |
| 216 | 224 |
| 217 return result; | 225 return result; |
| 218 }; | 226 }; |
| 219 | 227 |
| 220 /** | 228 /** |
| 221 * Class for special filter subscriptions (user's filters) | 229 * Class for special filter subscriptions (user's filters) |
| 222 * @param {String} url see Subscription() | 230 * @param {string} url see Subscription() |
| 223 * @param {String} [title] see Subscription() | 231 * @param {string} [title] see Subscription() |
| 224 * @constructor | 232 * @constructor |
| 225 * @augments Subscription | 233 * @augments Subscription |
| 226 */ | 234 */ |
| 227 function SpecialSubscription(url, title) | 235 function SpecialSubscription(url, title) |
| 228 { | 236 { |
| 229 Subscription.call(this, url, title); | 237 Subscription.call(this, url, title); |
| 230 } | 238 } |
| 231 exports.SpecialSubscription = SpecialSubscription; | 239 exports.SpecialSubscription = SpecialSubscription; |
| 232 | 240 |
| 233 SpecialSubscription.prototype = extend(Subscription, { | 241 SpecialSubscription.prototype = extend(Subscription, { |
| 234 /** | 242 /** |
| 235 * Filter types that should be added to this subscription by default | 243 * Filter types that should be added to this subscription by default |
| 236 * (entries should correspond to keys in SpecialSubscription.defaultsMap). | 244 * (entries should correspond to keys in SpecialSubscription.defaultsMap). |
| 237 * @type string[] | 245 * @type {string[]} |
| 238 */ | 246 */ |
| 239 defaults: null, | 247 defaults: null, |
| 240 | 248 |
| 241 /** | 249 /** |
| 242 * Tests whether a filter should be added to this group by default | 250 * Tests whether a filter should be added to this group by default |
| 243 * @param {Filter} filter filter to be tested | 251 * @param {Filter} filter filter to be tested |
| 244 * @return {Boolean} | 252 * @return {boolean} |
| 245 */ | 253 */ |
| 246 isDefaultFor: function(filter) | 254 isDefaultFor(filter) |
| 247 { | 255 { |
| 248 if (this.defaults && this.defaults.length) | 256 if (this.defaults && this.defaults.length) |
| 249 { | 257 { |
| 250 for (let type of this.defaults) | 258 for (let type of this.defaults) |
| 251 { | 259 { |
| 252 if (filter instanceof SpecialSubscription.defaultsMap[type]) | 260 if (filter instanceof SpecialSubscription.defaultsMap[type]) |
| 253 return true; | 261 return true; |
| 254 if (!(filter instanceof ActiveFilter) && type == "blacklist") | 262 if (!(filter instanceof ActiveFilter) && type == "blacklist") |
| 255 return true; | 263 return true; |
| 256 } | 264 } |
| 257 } | 265 } |
| 258 | 266 |
| 259 return false; | 267 return false; |
| 260 }, | 268 }, |
| 261 | 269 |
| 262 /** | 270 /** |
| 263 * See Subscription.serialize() | 271 * See Subscription.serialize() |
| 272 * @param {string[]} buffer buffer to push the serialization results into | |
|
Wladimir Palant
2017/03/02 14:07:04
Please don't duplicate this documentation all over
kzar
2017/03/08 12:33:53
OK but now we're getting ESLint errors "Missing JS
Wladimir Palant
2017/03/09 14:37:11
What if you use @inheritDoc here?
kzar
2017/03/10 06:56:12
Done.
| |
| 264 */ | 273 */ |
| 265 serialize: function(buffer) | 274 serialize(buffer) |
| 266 { | 275 { |
| 267 Subscription.prototype.serialize.call(this, buffer); | 276 Subscription.prototype.serialize.call(this, buffer); |
| 268 if (this.defaults && this.defaults.length) | 277 if (this.defaults && this.defaults.length) |
| 269 buffer.push("defaults=" + this.defaults.filter((type) => type in SpecialSu bscription.defaultsMap).join(" ")); | 278 { |
| 279 buffer.push("defaults=" + this.defaults.filter( | |
|
Wladimir Palant
2017/03/02 14:07:04
Please move everything after "defaults=" to the ne
kzar
2017/03/08 12:33:51
Done.
| |
| 280 type => type in SpecialSubscription.defaultsMap).join(" ") | |
| 281 ); | |
| 282 } | |
| 270 if (this._lastDownload) | 283 if (this._lastDownload) |
| 271 buffer.push("lastDownload=" + this._lastDownload); | 284 buffer.push("lastDownload=" + this._lastDownload); |
| 272 } | 285 } |
| 273 }); | 286 }); |
| 274 | 287 |
| 275 SpecialSubscription.defaultsMap = Object.create(null, desc({ | 288 SpecialSubscription.defaultsMap = Object.create(null, desc({ |
| 276 "whitelist": WhitelistFilter, | 289 whitelist: WhitelistFilter, |
| 277 "blocking": BlockingFilter, | 290 blocking: BlockingFilter, |
| 278 "elemhide": ElemHideBase | 291 elemhide: ElemHideBase |
| 279 })); | 292 })); |
| 280 | 293 |
| 281 /** | 294 /** |
| 282 * Creates a new user-defined filter group. | 295 * Creates a new user-defined filter group. |
| 283 * @param {String} [title] title of the new filter group | 296 * @param {string} [title] title of the new filter group |
| 284 * @result {SpecialSubscription} | 297 * @return {SpecialSubscription} |
| 285 */ | 298 */ |
| 286 SpecialSubscription.create = function(title) | 299 SpecialSubscription.create = function(title) |
| 287 { | 300 { |
| 288 let url; | 301 let url; |
| 289 do | 302 do |
| 290 { | 303 url = "~user~" + Math.round(Math.random() * 1000000); |
| 291 url = "~user~" + Math.round(Math.random()*1000000); | 304 while (url in Subscription.knownSubscriptions); |
|
Wladimir Palant
2017/03/02 14:07:04
Another case where I just don't know how to fix it
kzar
2017/03/08 12:33:52
Fixed now since we removed the curl rule.
| |
| 292 } while (url in Subscription.knownSubscriptions); | |
| 293 return new SpecialSubscription(url, title); | 305 return new SpecialSubscription(url, title); |
| 294 }; | 306 }; |
| 295 | 307 |
| 296 /** | 308 /** |
| 297 * Creates a new user-defined filter group and adds the given filter to it. | 309 * Creates a new user-defined filter group and adds the given filter to it. |
| 298 * This group will act as the default group for this filter type. | 310 * This group will act as the default group for this filter type. |
| 311 * @param {Filter} filter | |
| 312 * @return {SpecialSubscription} | |
| 299 */ | 313 */ |
| 300 SpecialSubscription.createForFilter = function(/**Filter*/ filter) /**SpecialSub scription*/ | 314 SpecialSubscription.createForFilter = function(filter) |
| 301 { | 315 { |
| 302 let subscription = SpecialSubscription.create(); | 316 let subscription = SpecialSubscription.create(); |
| 303 subscription.filters.push(filter); | 317 subscription.filters.push(filter); |
| 304 for (let type in SpecialSubscription.defaultsMap) | 318 for (let type in SpecialSubscription.defaultsMap) |
| 305 { | 319 { |
| 306 if (filter instanceof SpecialSubscription.defaultsMap[type]) | 320 if (filter instanceof SpecialSubscription.defaultsMap[type]) |
| 307 subscription.defaults = [type]; | 321 subscription.defaults = [type]; |
| 308 } | 322 } |
| 309 if (!subscription.defaults) | 323 if (!subscription.defaults) |
| 310 subscription.defaults = ["blocking"]; | 324 subscription.defaults = ["blocking"]; |
| 311 return subscription; | 325 return subscription; |
| 312 }; | 326 }; |
| 313 | 327 |
| 314 /** | 328 /** |
| 315 * Abstract base class for regular filter subscriptions (both internally and ext ernally updated) | 329 * Abstract base class for regular filter subscriptions (both |
| 316 * @param {String} url see Subscription() | 330 * internally and externally updated) |
| 317 * @param {String} [title] see Subscription() | 331 * @param {string} url see Subscription() |
| 332 * @param {string} [title] see Subscription() | |
| 318 * @constructor | 333 * @constructor |
| 319 * @augments Subscription | 334 * @augments Subscription |
| 320 */ | 335 */ |
| 321 function RegularSubscription(url, title) | 336 function RegularSubscription(url, title) |
| 322 { | 337 { |
| 323 Subscription.call(this, url, title || url); | 338 Subscription.call(this, url, title || url); |
| 324 } | 339 } |
| 325 exports.RegularSubscription = RegularSubscription; | 340 exports.RegularSubscription = RegularSubscription; |
| 326 | 341 |
| 327 RegularSubscription.prototype = extend(Subscription, { | 342 RegularSubscription.prototype = extend(Subscription, { |
| 328 _homepage: null, | 343 _homepage: null, |
| 329 _lastDownload: 0, | 344 _lastDownload: 0, |
| 330 | 345 |
| 331 /** | 346 /** |
| 332 * Filter subscription homepage if known | 347 * Filter subscription homepage if known |
| 333 * @type String | 348 * @type {string} |
| 334 */ | 349 */ |
| 335 get homepage() | 350 get homepage() |
| 336 { | 351 { |
| 337 return this._homepage; | 352 return this._homepage; |
| 338 }, | 353 }, |
| 339 set homepage(value) | 354 set homepage(value) |
| 340 { | 355 { |
| 341 if (value != this._homepage) | 356 if (value != this._homepage) |
| 342 { | 357 { |
| 343 let oldValue = this._homepage; | 358 let oldValue = this._homepage; |
| 344 this._homepage = value; | 359 this._homepage = value; |
| 345 FilterNotifier.triggerListeners("subscription.homepage", this, value, oldV alue); | 360 FilterNotifier.triggerListeners("subscription.homepage", |
| 361 this, value, oldValue); | |
| 346 } | 362 } |
| 347 return this._homepage; | 363 return this._homepage; |
| 348 }, | 364 }, |
| 349 | 365 |
| 350 /** | 366 /** |
| 351 * Time of the last subscription download (in seconds since the beginning of t he epoch) | 367 * Time of the last subscription download (in seconds since the |
| 352 * @type Number | 368 * beginning of the epoch) |
| 369 * @type {number} | |
| 353 */ | 370 */ |
| 354 get lastDownload() | 371 get lastDownload() |
| 355 { | 372 { |
| 356 return this._lastDownload; | 373 return this._lastDownload; |
| 357 }, | 374 }, |
| 358 set lastDownload(value) | 375 set lastDownload(value) |
| 359 { | 376 { |
| 360 if (value != this._lastDownload) | 377 if (value != this._lastDownload) |
| 361 { | 378 { |
| 362 let oldValue = this._lastDownload; | 379 let oldValue = this._lastDownload; |
| 363 this._lastDownload = value; | 380 this._lastDownload = value; |
| 364 FilterNotifier.triggerListeners("subscription.lastDownload", this, value, oldValue); | 381 FilterNotifier.triggerListeners("subscription.lastDownload", |
| 382 this, value, oldValue); | |
| 365 } | 383 } |
| 366 return this._lastDownload; | 384 return this._lastDownload; |
| 367 }, | 385 }, |
| 368 | 386 |
| 369 /** | 387 /** |
| 370 * See Subscription.serialize() | 388 * See Subscription.serialize() |
| 389 * @param {string[]} buffer | |
| 371 */ | 390 */ |
| 372 serialize: function(buffer) | 391 serialize(buffer) |
| 373 { | 392 { |
| 374 Subscription.prototype.serialize.call(this, buffer); | 393 Subscription.prototype.serialize.call(this, buffer); |
| 375 if (this._homepage) | 394 if (this._homepage) |
| 376 buffer.push("homepage=" + this._homepage); | 395 buffer.push("homepage=" + this._homepage); |
| 377 if (this._lastDownload) | 396 if (this._lastDownload) |
| 378 buffer.push("lastDownload=" + this._lastDownload); | 397 buffer.push("lastDownload=" + this._lastDownload); |
| 379 } | 398 } |
| 380 }); | 399 }); |
| 381 | 400 |
| 382 /** | 401 /** |
| 383 * Class for filter subscriptions updated externally (by other extension) | 402 * Class for filter subscriptions updated externally (by other extension) |
| 384 * @param {String} url see Subscription() | 403 * @param {string} url see Subscription() |
| 385 * @param {String} [title] see Subscription() | 404 * @param {string} [title] see Subscription() |
| 386 * @constructor | 405 * @constructor |
| 387 * @augments RegularSubscription | 406 * @augments RegularSubscription |
| 388 */ | 407 */ |
| 389 function ExternalSubscription(url, title) | 408 function ExternalSubscription(url, title) |
| 390 { | 409 { |
| 391 RegularSubscription.call(this, url, title); | 410 RegularSubscription.call(this, url, title); |
| 392 } | 411 } |
| 393 exports.ExternalSubscription = ExternalSubscription; | 412 exports.ExternalSubscription = ExternalSubscription; |
| 394 | 413 |
| 395 ExternalSubscription.prototype = extend(RegularSubscription, { | 414 ExternalSubscription.prototype = extend(RegularSubscription, { |
| 396 /** | 415 /** |
| 397 * See Subscription.serialize() | 416 * See Subscription.serialize() |
| 417 * @param {string[]} buffer | |
| 398 */ | 418 */ |
| 399 serialize: function(buffer) | 419 serialize(buffer) |
| 400 { | 420 { |
| 401 throw new Error("Unexpected call, external subscriptions should not be seria lized"); | 421 throw new Error( |
| 422 "Unexpected call, external subscriptions should not be serialized" | |
| 423 ); | |
| 402 } | 424 } |
| 403 }); | 425 }); |
| 404 | 426 |
| 405 /** | 427 /** |
| 406 * Class for filter subscriptions updated externally (by other extension) | 428 * Class for filter subscriptions updated externally (by other extension) |
| 407 * @param {String} url see Subscription() | 429 * @param {string} url see Subscription() |
| 408 * @param {String} [title] see Subscription() | 430 * @param {string} [title] see Subscription() |
| 409 * @constructor | 431 * @constructor |
| 410 * @augments RegularSubscription | 432 * @augments RegularSubscription |
| 411 */ | 433 */ |
| 412 function DownloadableSubscription(url, title) | 434 function DownloadableSubscription(url, title) |
| 413 { | 435 { |
| 414 RegularSubscription.call(this, url, title); | 436 RegularSubscription.call(this, url, title); |
| 415 } | 437 } |
| 416 exports.DownloadableSubscription = DownloadableSubscription; | 438 exports.DownloadableSubscription = DownloadableSubscription; |
| 417 | 439 |
| 418 DownloadableSubscription.prototype = extend(RegularSubscription, { | 440 DownloadableSubscription.prototype = extend(RegularSubscription, { |
| 419 _downloadStatus: null, | 441 _downloadStatus: null, |
| 420 _lastCheck: 0, | 442 _lastCheck: 0, |
| 421 _errors: 0, | 443 _errors: 0, |
| 422 | 444 |
| 423 /** | 445 /** |
| 424 * Status of the last download (ID of a string) | 446 * Status of the last download (ID of a string) |
| 425 * @type String | 447 * @type {string} |
| 426 */ | 448 */ |
| 427 get downloadStatus() | 449 get downloadStatus() |
| 428 { | 450 { |
| 429 return this._downloadStatus; | 451 return this._downloadStatus; |
| 430 }, | 452 }, |
| 431 set downloadStatus(value) | 453 set downloadStatus(value) |
| 432 { | 454 { |
| 433 let oldValue = this._downloadStatus; | 455 let oldValue = this._downloadStatus; |
| 434 this._downloadStatus = value; | 456 this._downloadStatus = value; |
| 435 FilterNotifier.triggerListeners("subscription.downloadStatus", this, value, oldValue); | 457 FilterNotifier.triggerListeners("subscription.downloadStatus", |
| 458 this, value, oldValue); | |
| 436 return this._downloadStatus; | 459 return this._downloadStatus; |
| 437 }, | 460 }, |
| 438 | 461 |
| 439 /** | 462 /** |
| 440 * Time of the last successful download (in seconds since the beginning of the | 463 * Time of the last successful download (in seconds since the beginning of the |
| 441 * epoch). | 464 * epoch). |
| 442 */ | 465 */ |
| 443 lastSuccess: 0, | 466 lastSuccess: 0, |
| 444 | 467 |
| 445 /** | 468 /** |
| 446 * Time when the subscription was considered for an update last time (in secon ds | 469 * Time when the subscription was considered for an update last time |
| 447 * since the beginning of the epoch). This will be used to increase softExpira tion | 470 * (in seconds since the beginning of the epoch). This will be used |
| 448 * if the user doesn't use Adblock Plus for some time. | 471 * to increase softExpiration if the user doesn't use Adblock Plus |
| 449 * @type Number | 472 * for some time. |
| 473 * @type {number} | |
| 450 */ | 474 */ |
| 451 get lastCheck() | 475 get lastCheck() |
| 452 { | 476 { |
| 453 return this._lastCheck; | 477 return this._lastCheck; |
| 454 }, | 478 }, |
| 455 set lastCheck(value) | 479 set lastCheck(value) |
| 456 { | 480 { |
| 457 if (value != this._lastCheck) | 481 if (value != this._lastCheck) |
| 458 { | 482 { |
| 459 let oldValue = this._lastCheck; | 483 let oldValue = this._lastCheck; |
| 460 this._lastCheck = value; | 484 this._lastCheck = value; |
| 461 FilterNotifier.triggerListeners("subscription.lastCheck", this, value, old Value); | 485 FilterNotifier.triggerListeners("subscription.lastCheck", |
| 486 this, value, oldValue); | |
| 462 } | 487 } |
| 463 return this._lastCheck; | 488 return this._lastCheck; |
| 464 }, | 489 }, |
| 465 | 490 |
| 466 /** | 491 /** |
| 467 * Hard expiration time of the filter subscription (in seconds since the begin ning of the epoch) | 492 * Hard expiration time of the filter subscription (in seconds since |
| 468 * @type Number | 493 * the beginning of the epoch) |
| 494 * @type {number} | |
| 469 */ | 495 */ |
| 470 expires: 0, | 496 expires: 0, |
| 471 | 497 |
| 472 /** | 498 /** |
| 473 * Soft expiration time of the filter subscription (in seconds since the begin ning of the epoch) | 499 * Soft expiration time of the filter subscription (in seconds since |
| 474 * @type Number | 500 * the beginning of the epoch) |
| 501 * @type {number} | |
| 475 */ | 502 */ |
| 476 softExpiration: 0, | 503 softExpiration: 0, |
| 477 | 504 |
| 478 /** | 505 /** |
| 479 * Number of download failures since last success | 506 * Number of download failures since last success |
| 480 * @type Number | 507 * @type {number} |
| 481 */ | 508 */ |
| 482 get errors() | 509 get errors() |
| 483 { | 510 { |
| 484 return this._errors; | 511 return this._errors; |
| 485 }, | 512 }, |
| 486 set errors(value) | 513 set errors(value) |
| 487 { | 514 { |
| 488 if (value != this._errors) | 515 if (value != this._errors) |
| 489 { | 516 { |
| 490 let oldValue = this._errors; | 517 let oldValue = this._errors; |
| 491 this._errors = value; | 518 this._errors = value; |
| 492 FilterNotifier.triggerListeners("subscription.errors", this, value, oldVal ue); | 519 FilterNotifier.triggerListeners("subscription.errors", this, |
| 520 value, oldValue); | |
| 493 } | 521 } |
| 494 return this._errors; | 522 return this._errors; |
| 495 }, | 523 }, |
| 496 | 524 |
| 497 /** | 525 /** |
| 498 * Version of the subscription data retrieved on last successful download | 526 * Version of the subscription data retrieved on last successful download |
| 499 * @type Number | 527 * @type {number} |
| 500 */ | 528 */ |
| 501 version: 0, | 529 version: 0, |
| 502 | 530 |
| 503 /** | 531 /** |
| 504 * Minimal Adblock Plus version required for this subscription | 532 * Minimal Adblock Plus version required for this subscription |
| 505 * @type String | 533 * @type {string} |
| 506 */ | 534 */ |
| 507 requiredVersion: null, | 535 requiredVersion: null, |
| 508 | 536 |
| 509 /** | 537 /** |
| 510 * Number indicating how often the object was downloaded. | 538 * Number indicating how often the object was downloaded. |
| 511 * @type Number | 539 * @type {number} |
| 512 */ | 540 */ |
| 513 downloadCount: 0, | 541 downloadCount: 0, |
| 514 | 542 |
| 515 /** | 543 /** |
| 516 * See Subscription.serialize() | 544 * See Subscription.serialize() |
| 545 * @param {string[]} buffer | |
| 517 */ | 546 */ |
| 518 serialize: function(buffer) | 547 serialize(buffer) |
| 519 { | 548 { |
| 520 RegularSubscription.prototype.serialize.call(this, buffer); | 549 RegularSubscription.prototype.serialize.call(this, buffer); |
| 521 if (this.downloadStatus) | 550 if (this.downloadStatus) |
| 522 buffer.push("downloadStatus=" + this.downloadStatus); | 551 buffer.push("downloadStatus=" + this.downloadStatus); |
| 523 if (this.lastSuccess) | 552 if (this.lastSuccess) |
| 524 buffer.push("lastSuccess=" + this.lastSuccess); | 553 buffer.push("lastSuccess=" + this.lastSuccess); |
| 525 if (this.lastCheck) | 554 if (this.lastCheck) |
| 526 buffer.push("lastCheck=" + this.lastCheck); | 555 buffer.push("lastCheck=" + this.lastCheck); |
| 527 if (this.expires) | 556 if (this.expires) |
| 528 buffer.push("expires=" + this.expires); | 557 buffer.push("expires=" + this.expires); |
| 529 if (this.softExpiration) | 558 if (this.softExpiration) |
| 530 buffer.push("softExpiration=" + this.softExpiration); | 559 buffer.push("softExpiration=" + this.softExpiration); |
| 531 if (this.errors) | 560 if (this.errors) |
| 532 buffer.push("errors=" + this.errors); | 561 buffer.push("errors=" + this.errors); |
| 533 if (this.version) | 562 if (this.version) |
| 534 buffer.push("version=" + this.version); | 563 buffer.push("version=" + this.version); |
| 535 if (this.requiredVersion) | 564 if (this.requiredVersion) |
| 536 buffer.push("requiredVersion=" + this.requiredVersion); | 565 buffer.push("requiredVersion=" + this.requiredVersion); |
| 537 if (this.downloadCount) | 566 if (this.downloadCount) |
| 538 buffer.push("downloadCount=" + this.downloadCount); | 567 buffer.push("downloadCount=" + this.downloadCount); |
| 539 } | 568 } |
| 540 }); | 569 }); |
| OLD | NEW |