| 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-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"; | 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 let {ActiveFilter, BlockingFilter, | 24 const {ActiveFilter, BlockingFilter, |
| 25 WhitelistFilter, ElemHideBase} = require("filterClasses"); | 25 WhitelistFilter, ElemHideBase} = require("filterClasses"); |
| 26 let {FilterNotifier} = require("filterNotifier"); | 26 const {FilterNotifier} = require("filterNotifier"); |
| 27 let {desc, extend} = require("coreUtils"); | 27 const {desc, 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 { |
| 38 this.url = url; | 38 this.url = url; |
| 39 this.filters = []; | 39 this.filters = []; |
| 40 if (title) | 40 if (title) |
| 41 this._title = title; | 41 this._title = title; |
| 42 Subscription.knownSubscriptions[url] = this; | 42 Subscription.knownSubscriptions[url] = this; |
| 43 } | 43 } |
| 44 exports.Subscription = Subscription; | 44 exports.Subscription = Subscription; |
| 45 | 45 |
| 46 Subscription.prototype = | 46 Subscription.prototype = |
| 47 { | 47 { |
| 48 /** | 48 /** |
| 49 * Download location of the subscription | 49 * Download location of the subscription |
| 50 * @type {String} | 50 * @type {string} |
| 51 */ | 51 */ |
| 52 url: null, | 52 url: null, |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * Filters contained in the filter subscription | 55 * Filters contained in the filter subscription |
| 56 * @type {Filter[]} | 56 * @type {Filter[]} |
| 57 */ | 57 */ |
| 58 filters: null, | 58 filters: null, |
| 59 | 59 |
| 60 _title: null, | 60 _title: null, |
| 61 _fixedTitle: false, | 61 _fixedTitle: false, |
| 62 _disabled: false, | 62 _disabled: false, |
| 63 | 63 |
| 64 /** | 64 /** |
| 65 * Title of the filter subscription | 65 * Title of the filter subscription |
| 66 * @type {String} | 66 * @type {string} |
| 67 */ | 67 */ |
| 68 get title() | 68 get title() |
| 69 { | 69 { |
| 70 return this._title; | 70 return this._title; |
| 71 }, | 71 }, |
| 72 set title(value) | 72 set title(value) |
| 73 { | 73 { |
| 74 if (value != this._title) | 74 if (value != this._title) |
| 75 { | 75 { |
| 76 let oldValue = this._title; | 76 let oldValue = this._title; |
| 77 this._title = value; | 77 this._title = value; |
| 78 FilterNotifier.triggerListeners("subscription.title", | 78 FilterNotifier.triggerListeners("subscription.title", |
| 79 this, value, oldValue); | 79 this, value, oldValue); |
| 80 } | 80 } |
| 81 return this._title; | 81 return this._title; |
| 82 }, | 82 }, |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * Determines whether the title should be editable | 85 * Determines whether the title should be editable |
| 86 * @type {Boolean} | 86 * @type {boolean} |
| 87 */ | 87 */ |
| 88 get fixedTitle() | 88 get fixedTitle() |
| 89 { | 89 { |
| 90 return this._fixedTitle; | 90 return this._fixedTitle; |
| 91 }, | 91 }, |
| 92 set fixedTitle(value) | 92 set fixedTitle(value) |
| 93 { | 93 { |
| 94 if (value != this._fixedTitle) | 94 if (value != this._fixedTitle) |
| 95 { | 95 { |
| 96 let oldValue = this._fixedTitle; | 96 let oldValue = this._fixedTitle; |
| 97 this._fixedTitle = value; | 97 this._fixedTitle = value; |
| 98 FilterNotifier.triggerListeners("subscription.fixedTitle", | 98 FilterNotifier.triggerListeners("subscription.fixedTitle", |
| 99 this, value, oldValue); | 99 this, value, oldValue); |
| 100 } | 100 } |
| 101 return this._fixedTitle; | 101 return this._fixedTitle; |
| 102 }, | 102 }, |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * Defines whether the filters in the subscription should be disabled | 105 * Defines whether the filters in the subscription should be disabled |
| 106 * @type {Boolean} | 106 * @type {boolean} |
| 107 */ | 107 */ |
| 108 get disabled() | 108 get disabled() |
| 109 { | 109 { |
| 110 return this._disabled; | 110 return this._disabled; |
| 111 }, | 111 }, |
| 112 set disabled(value) | 112 set disabled(value) |
| 113 { | 113 { |
| 114 if (value != this._disabled) | 114 if (value != this._disabled) |
| 115 { | 115 { |
| 116 let oldValue = this._disabled; | 116 let oldValue = this._disabled; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 /** | 155 /** |
| 156 * Cache for known filter subscriptions, maps URL to subscription objects. | 156 * Cache for known filter subscriptions, maps URL to subscription objects. |
| 157 * @type {Object} | 157 * @type {Object} |
| 158 */ | 158 */ |
| 159 Subscription.knownSubscriptions = Object.create(null); | 159 Subscription.knownSubscriptions = Object.create(null); |
| 160 | 160 |
| 161 /** | 161 /** |
| 162 * 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. |
| 163 * @param {String} url URL of the subscription | 163 * @param {string} url |
| 164 * @return {Subscription} subscription or null if the subscription couldn't be | 164 * URL of the subscription |
| 165 * created | 165 * @return {Subscription} |
| 166 * subscription or null if the subscription couldn't be created |
| 166 */ | 167 */ |
| 167 Subscription.fromURL = function(url) | 168 Subscription.fromURL = function(url) |
| 168 { | 169 { |
| 169 if (url in Subscription.knownSubscriptions) | 170 if (url in Subscription.knownSubscriptions) |
| 170 return Subscription.knownSubscriptions[url]; | 171 return Subscription.knownSubscriptions[url]; |
| 171 | 172 |
| 172 if (url[0] != "~") | 173 if (url[0] != "~") |
| 173 return new DownloadableSubscription(url, null); | 174 return new DownloadableSubscription(url, null); |
| 174 return new SpecialSubscription(url); | 175 return new SpecialSubscription(url); |
| 175 }; | 176 }; |
| 176 | 177 |
| 177 /** | 178 /** |
| 178 * Deserializes a subscription | 179 * Deserializes a subscription |
| 179 * | 180 * |
| 180 * @param {Object} obj map of serialized properties and their values | 181 * @param {Object} obj |
| 181 * @return {Subscription} subscription or null if the subscription couldn't be | 182 * map of serialized properties and their values |
| 182 * created | 183 * @return {Subscription} |
| 184 * subscription or null if the subscription couldn't be created |
| 183 */ | 185 */ |
| 184 Subscription.fromObject = function(obj) | 186 Subscription.fromObject = function(obj) |
| 185 { | 187 { |
| 186 let result; | 188 let result; |
| 187 if (obj.url[0] != "~") | 189 if (obj.url[0] != "~") |
| 188 { | 190 { |
| 189 // URL is valid - this is a downloadable subscription | 191 // URL is valid - this is a downloadable subscription |
| 190 result = new DownloadableSubscription(obj.url, obj.title); | 192 result = new DownloadableSubscription(obj.url, obj.title); |
| 191 if ("downloadStatus" in obj) | 193 if ("downloadStatus" in obj) |
| 192 result._downloadStatus = obj.downloadStatus; | 194 result._downloadStatus = obj.downloadStatus; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 220 if ("fixedTitle" in obj) | 222 if ("fixedTitle" in obj) |
| 221 result._fixedTitle = (obj.fixedTitle == "true"); | 223 result._fixedTitle = (obj.fixedTitle == "true"); |
| 222 if ("disabled" in obj) | 224 if ("disabled" in obj) |
| 223 result._disabled = (obj.disabled == "true"); | 225 result._disabled = (obj.disabled == "true"); |
| 224 | 226 |
| 225 return result; | 227 return result; |
| 226 }; | 228 }; |
| 227 | 229 |
| 228 /** | 230 /** |
| 229 * Class for special filter subscriptions (user's filters) | 231 * Class for special filter subscriptions (user's filters) |
| 230 * @param {String} url see Subscription() | 232 * @param {string} url see Subscription() |
| 231 * @param {String} [title] see Subscription() | 233 * @param {string} [title] see Subscription() |
| 232 * @constructor | 234 * @constructor |
| 233 * @augments Subscription | 235 * @augments Subscription |
| 234 */ | 236 */ |
| 235 function SpecialSubscription(url, title) | 237 function SpecialSubscription(url, title) |
| 236 { | 238 { |
| 237 Subscription.call(this, url, title); | 239 Subscription.call(this, url, title); |
| 238 } | 240 } |
| 239 exports.SpecialSubscription = SpecialSubscription; | 241 exports.SpecialSubscription = SpecialSubscription; |
| 240 | 242 |
| 241 SpecialSubscription.prototype = extend(Subscription, { | 243 SpecialSubscription.prototype = extend(Subscription, { |
| 242 /** | 244 /** |
| 243 * Filter types that should be added to this subscription by default | 245 * Filter types that should be added to this subscription by default |
| 244 * (entries should correspond to keys in SpecialSubscription.defaultsMap). | 246 * (entries should correspond to keys in SpecialSubscription.defaultsMap). |
| 245 * @type {string[]} | 247 * @type {string[]} |
| 246 */ | 248 */ |
| 247 defaults: null, | 249 defaults: null, |
| 248 | 250 |
| 249 /** | 251 /** |
| 250 * Tests whether a filter should be added to this group by default | 252 * Tests whether a filter should be added to this group by default |
| 251 * @param {Filter} filter filter to be tested | 253 * @param {Filter} filter filter to be tested |
| 252 * @return {Boolean} | 254 * @return {boolean} |
| 253 */ | 255 */ |
| 254 isDefaultFor(filter) | 256 isDefaultFor(filter) |
| 255 { | 257 { |
| 256 if (this.defaults && this.defaults.length) | 258 if (this.defaults && this.defaults.length) |
| 257 { | 259 { |
| 258 for (let type of this.defaults) | 260 for (let type of this.defaults) |
| 259 { | 261 { |
| 260 if (filter instanceof SpecialSubscription.defaultsMap[type]) | 262 if (filter instanceof SpecialSubscription.defaultsMap[type]) |
| 261 return true; | 263 return true; |
| 262 if (!(filter instanceof ActiveFilter) && type == "blacklist") | 264 if (!(filter instanceof ActiveFilter) && type == "blacklist") |
| 263 return true; | 265 return true; |
| 264 } | 266 } |
| 265 } | 267 } |
| 266 | 268 |
| 267 return false; | 269 return false; |
| 268 }, | 270 }, |
| 269 | 271 |
| 270 /** | 272 /** |
| 271 * See Subscription.serialize() | 273 * See Subscription.serialize() |
| 272 * @param {string[]} buffer buffer to push the serialization results into | 274 * @inheritdoc |
| 273 */ | 275 */ |
| 274 serialize(buffer) | 276 serialize(buffer) |
| 275 { | 277 { |
| 276 Subscription.prototype.serialize.call(this, buffer); | 278 Subscription.prototype.serialize.call(this, buffer); |
| 277 if (this.defaults && this.defaults.length) | 279 if (this.defaults && this.defaults.length) |
| 278 { | 280 { |
| 279 buffer.push("defaults=" + this.defaults. | 281 buffer.push("defaults=" + |
| 280 filter((type) => type in SpecialSubscription.defaultsMap).join(" ")); | 282 this.defaults.filter( |
| 283 type => type in SpecialSubscription.defaultsMap |
| 284 ).join(" ") |
| 285 ); |
| 281 } | 286 } |
| 282 if (this._lastDownload) | 287 if (this._lastDownload) |
| 283 buffer.push("lastDownload=" + this._lastDownload); | 288 buffer.push("lastDownload=" + this._lastDownload); |
| 284 } | 289 } |
| 285 }); | 290 }); |
| 286 | 291 |
| 287 SpecialSubscription.defaultsMap = Object.create(null, desc({ | 292 SpecialSubscription.defaultsMap = Object.create(null, desc({ |
| 288 whitelist: WhitelistFilter, | 293 whitelist: WhitelistFilter, |
| 289 blocking: BlockingFilter, | 294 blocking: BlockingFilter, |
| 290 elemhide: ElemHideBase | 295 elemhide: ElemHideBase |
| 291 })); | 296 })); |
| 292 | 297 |
| 293 /** | 298 /** |
| 294 * Creates a new user-defined filter group. | 299 * Creates a new user-defined filter group. |
| 295 * @param {String} [title] title of the new filter group | 300 * @param {string} [title] title of the new filter group |
| 296 * @return {SpecialSubscription} | 301 * @return {SpecialSubscription} |
| 297 */ | 302 */ |
| 298 SpecialSubscription.create = function(title) | 303 SpecialSubscription.create = function(title) |
| 299 { | 304 { |
| 300 let url; | 305 let url; |
| 301 do | 306 do |
| 307 { |
| 302 url = "~user~" + Math.round(Math.random() * 1000000); | 308 url = "~user~" + Math.round(Math.random() * 1000000); |
| 303 while (url in Subscription.knownSubscriptions); | 309 } while (url in Subscription.knownSubscriptions); |
| 304 return new SpecialSubscription(url, title); | 310 return new SpecialSubscription(url, title); |
| 305 }; | 311 }; |
| 306 | 312 |
| 307 /** | 313 /** |
| 308 * Creates a new user-defined filter group and adds the given filter to it. | 314 * Creates a new user-defined filter group and adds the given filter to it. |
| 309 * This group will act as the default group for this filter type. | 315 * This group will act as the default group for this filter type. |
| 310 * @param {Filter} filter | 316 * @param {Filter} filter |
| 311 * @return {SpecialSubscription} | 317 * @return {SpecialSubscription} |
| 312 */ | 318 */ |
| 313 SpecialSubscription.createForFilter = function(filter) | 319 SpecialSubscription.createForFilter = function(filter) |
| 314 { | 320 { |
| 315 let subscription = SpecialSubscription.create(); | 321 let subscription = SpecialSubscription.create(); |
| 316 subscription.filters.push(filter); | 322 subscription.filters.push(filter); |
| 317 for (let type in SpecialSubscription.defaultsMap) | 323 for (let type in SpecialSubscription.defaultsMap) |
| 318 { | 324 { |
| 319 if (filter instanceof SpecialSubscription.defaultsMap[type]) | 325 if (filter instanceof SpecialSubscription.defaultsMap[type]) |
| 320 subscription.defaults = [type]; | 326 subscription.defaults = [type]; |
| 321 } | 327 } |
| 322 if (!subscription.defaults) | 328 if (!subscription.defaults) |
| 323 subscription.defaults = ["blocking"]; | 329 subscription.defaults = ["blocking"]; |
| 324 return subscription; | 330 return subscription; |
| 325 }; | 331 }; |
| 326 | 332 |
| 327 /** | 333 /** |
| 328 * Abstract base class for regular filter subscriptions (both | 334 * Abstract base class for regular filter subscriptions (both |
| 329 * internally and externally updated) | 335 * internally and externally updated) |
| 330 * @param {String} url see Subscription() | 336 * @param {string} url see Subscription() |
| 331 * @param {String} [title] see Subscription() | 337 * @param {string} [title] see Subscription() |
| 332 * @constructor | 338 * @constructor |
| 333 * @augments Subscription | 339 * @augments Subscription |
| 334 */ | 340 */ |
| 335 function RegularSubscription(url, title) | 341 function RegularSubscription(url, title) |
| 336 { | 342 { |
| 337 Subscription.call(this, url, title || url); | 343 Subscription.call(this, url, title || url); |
| 338 } | 344 } |
| 339 exports.RegularSubscription = RegularSubscription; | 345 exports.RegularSubscription = RegularSubscription; |
| 340 | 346 |
| 341 RegularSubscription.prototype = extend(Subscription, { | 347 RegularSubscription.prototype = extend(Subscription, { |
| 342 _homepage: null, | 348 _homepage: null, |
| 343 _lastDownload: 0, | 349 _lastDownload: 0, |
| 344 | 350 |
| 345 /** | 351 /** |
| 346 * Filter subscription homepage if known | 352 * Filter subscription homepage if known |
| 347 * @type {String} | 353 * @type {string} |
| 348 */ | 354 */ |
| 349 get homepage() | 355 get homepage() |
| 350 { | 356 { |
| 351 return this._homepage; | 357 return this._homepage; |
| 352 }, | 358 }, |
| 353 set homepage(value) | 359 set homepage(value) |
| 354 { | 360 { |
| 355 if (value != this._homepage) | 361 if (value != this._homepage) |
| 356 { | 362 { |
| 357 let oldValue = this._homepage; | 363 let oldValue = this._homepage; |
| 358 this._homepage = value; | 364 this._homepage = value; |
| 359 FilterNotifier.triggerListeners("subscription.homepage", | 365 FilterNotifier.triggerListeners("subscription.homepage", |
| 360 this, value, oldValue); | 366 this, value, oldValue); |
| 361 } | 367 } |
| 362 return this._homepage; | 368 return this._homepage; |
| 363 }, | 369 }, |
| 364 | 370 |
| 365 /** | 371 /** |
| 366 * Time of the last subscription download (in seconds since the | 372 * Time of the last subscription download (in seconds since the |
| 367 * beginning of the epoch) | 373 * beginning of the epoch) |
| 368 * @type {Number} | 374 * @type {number} |
| 369 */ | 375 */ |
| 370 get lastDownload() | 376 get lastDownload() |
| 371 { | 377 { |
| 372 return this._lastDownload; | 378 return this._lastDownload; |
| 373 }, | 379 }, |
| 374 set lastDownload(value) | 380 set lastDownload(value) |
| 375 { | 381 { |
| 376 if (value != this._lastDownload) | 382 if (value != this._lastDownload) |
| 377 { | 383 { |
| 378 let oldValue = this._lastDownload; | 384 let oldValue = this._lastDownload; |
| 379 this._lastDownload = value; | 385 this._lastDownload = value; |
| 380 FilterNotifier.triggerListeners("subscription.lastDownload", | 386 FilterNotifier.triggerListeners("subscription.lastDownload", |
| 381 this, value, oldValue); | 387 this, value, oldValue); |
| 382 } | 388 } |
| 383 return this._lastDownload; | 389 return this._lastDownload; |
| 384 }, | 390 }, |
| 385 | 391 |
| 386 /** | 392 /** |
| 387 * See Subscription.serialize() | 393 * See Subscription.serialize() |
| 388 * @param {string[]} buffer | 394 * @inheritdoc |
| 389 */ | 395 */ |
| 390 serialize(buffer) | 396 serialize(buffer) |
| 391 { | 397 { |
| 392 Subscription.prototype.serialize.call(this, buffer); | 398 Subscription.prototype.serialize.call(this, buffer); |
| 393 if (this._homepage) | 399 if (this._homepage) |
| 394 buffer.push("homepage=" + this._homepage); | 400 buffer.push("homepage=" + this._homepage); |
| 395 if (this._lastDownload) | 401 if (this._lastDownload) |
| 396 buffer.push("lastDownload=" + this._lastDownload); | 402 buffer.push("lastDownload=" + this._lastDownload); |
| 397 } | 403 } |
| 398 }); | 404 }); |
| 399 | 405 |
| 400 /** | 406 /** |
| 401 * Class for filter subscriptions updated externally (by other extension) | 407 * Class for filter subscriptions updated externally (by other extension) |
| 402 * @param {String} url see Subscription() | 408 * @param {string} url see Subscription() |
| 403 * @param {String} [title] see Subscription() | 409 * @param {string} [title] see Subscription() |
| 404 * @constructor | 410 * @constructor |
| 405 * @augments RegularSubscription | 411 * @augments RegularSubscription |
| 406 */ | 412 */ |
| 407 function ExternalSubscription(url, title) | 413 function ExternalSubscription(url, title) |
| 408 { | 414 { |
| 409 RegularSubscription.call(this, url, title); | 415 RegularSubscription.call(this, url, title); |
| 410 } | 416 } |
| 411 exports.ExternalSubscription = ExternalSubscription; | 417 exports.ExternalSubscription = ExternalSubscription; |
| 412 | 418 |
| 413 ExternalSubscription.prototype = extend(RegularSubscription, { | 419 ExternalSubscription.prototype = extend(RegularSubscription, { |
| 414 /** | 420 /** |
| 415 * See Subscription.serialize() | 421 * See Subscription.serialize() |
| 416 * @param {string[]} buffer | 422 * @inheritdoc |
| 417 */ | 423 */ |
| 418 serialize(buffer) | 424 serialize(buffer) |
| 419 { | 425 { |
| 420 throw new Error( | 426 throw new Error( |
| 421 "Unexpected call, external subscriptions should not be serialized" | 427 "Unexpected call, external subscriptions should not be serialized" |
| 422 ); | 428 ); |
| 423 } | 429 } |
| 424 }); | 430 }); |
| 425 | 431 |
| 426 /** | 432 /** |
| 427 * Class for filter subscriptions updated externally (by other extension) | 433 * Class for filter subscriptions updated externally (by other extension) |
| 428 * @param {String} url see Subscription() | 434 * @param {string} url see Subscription() |
| 429 * @param {String} [title] see Subscription() | 435 * @param {string} [title] see Subscription() |
| 430 * @constructor | 436 * @constructor |
| 431 * @augments RegularSubscription | 437 * @augments RegularSubscription |
| 432 */ | 438 */ |
| 433 function DownloadableSubscription(url, title) | 439 function DownloadableSubscription(url, title) |
| 434 { | 440 { |
| 435 RegularSubscription.call(this, url, title); | 441 RegularSubscription.call(this, url, title); |
| 436 } | 442 } |
| 437 exports.DownloadableSubscription = DownloadableSubscription; | 443 exports.DownloadableSubscription = DownloadableSubscription; |
| 438 | 444 |
| 439 DownloadableSubscription.prototype = extend(RegularSubscription, { | 445 DownloadableSubscription.prototype = extend(RegularSubscription, { |
| 440 _downloadStatus: null, | 446 _downloadStatus: null, |
| 441 _lastCheck: 0, | 447 _lastCheck: 0, |
| 442 _errors: 0, | 448 _errors: 0, |
| 443 | 449 |
| 444 /** | 450 /** |
| 445 * Status of the last download (ID of a string) | 451 * Status of the last download (ID of a string) |
| 446 * @type {String} | 452 * @type {string} |
| 447 */ | 453 */ |
| 448 get downloadStatus() | 454 get downloadStatus() |
| 449 { | 455 { |
| 450 return this._downloadStatus; | 456 return this._downloadStatus; |
| 451 }, | 457 }, |
| 452 set downloadStatus(value) | 458 set downloadStatus(value) |
| 453 { | 459 { |
| 454 let oldValue = this._downloadStatus; | 460 let oldValue = this._downloadStatus; |
| 455 this._downloadStatus = value; | 461 this._downloadStatus = value; |
| 456 FilterNotifier.triggerListeners("subscription.downloadStatus", | 462 FilterNotifier.triggerListeners("subscription.downloadStatus", |
| 457 this, value, oldValue); | 463 this, value, oldValue); |
| 458 return this._downloadStatus; | 464 return this._downloadStatus; |
| 459 }, | 465 }, |
| 460 | 466 |
| 461 /** | 467 /** |
| 462 * Time of the last successful download (in seconds since the beginning of the | 468 * Time of the last successful download (in seconds since the beginning of the |
| 463 * epoch). | 469 * epoch). |
| 464 */ | 470 */ |
| 465 lastSuccess: 0, | 471 lastSuccess: 0, |
| 466 | 472 |
| 467 /** | 473 /** |
| 468 * Time when the subscription was considered for an update last time | 474 * Time when the subscription was considered for an update last time |
| 469 * (in seconds since the beginning of the epoch). This will be used | 475 * (in seconds since the beginning of the epoch). This will be used |
| 470 * to increase softExpiration if the user doesn't use Adblock Plus | 476 * to increase softExpiration if the user doesn't use Adblock Plus |
| 471 * for some time. | 477 * for some time. |
| 472 * @type {Number} | 478 * @type {number} |
| 473 */ | 479 */ |
| 474 get lastCheck() | 480 get lastCheck() |
| 475 { | 481 { |
| 476 return this._lastCheck; | 482 return this._lastCheck; |
| 477 }, | 483 }, |
| 478 set lastCheck(value) | 484 set lastCheck(value) |
| 479 { | 485 { |
| 480 if (value != this._lastCheck) | 486 if (value != this._lastCheck) |
| 481 { | 487 { |
| 482 let oldValue = this._lastCheck; | 488 let oldValue = this._lastCheck; |
| 483 this._lastCheck = value; | 489 this._lastCheck = value; |
| 484 FilterNotifier.triggerListeners("subscription.lastCheck", | 490 FilterNotifier.triggerListeners("subscription.lastCheck", |
| 485 this, value, oldValue); | 491 this, value, oldValue); |
| 486 } | 492 } |
| 487 return this._lastCheck; | 493 return this._lastCheck; |
| 488 }, | 494 }, |
| 489 | 495 |
| 490 /** | 496 /** |
| 491 * Hard expiration time of the filter subscription (in seconds since | 497 * Hard expiration time of the filter subscription (in seconds since |
| 492 * the beginning of the epoch) | 498 * the beginning of the epoch) |
| 493 * @type {Number} | 499 * @type {number} |
| 494 */ | 500 */ |
| 495 expires: 0, | 501 expires: 0, |
| 496 | 502 |
| 497 /** | 503 /** |
| 498 * Soft expiration time of the filter subscription (in seconds since | 504 * Soft expiration time of the filter subscription (in seconds since |
| 499 * the beginning of the epoch) | 505 * the beginning of the epoch) |
| 500 * @type {Number} | 506 * @type {number} |
| 501 */ | 507 */ |
| 502 softExpiration: 0, | 508 softExpiration: 0, |
| 503 | 509 |
| 504 /** | 510 /** |
| 505 * Number of download failures since last success | 511 * Number of download failures since last success |
| 506 * @type {Number} | 512 * @type {number} |
| 507 */ | 513 */ |
| 508 get errors() | 514 get errors() |
| 509 { | 515 { |
| 510 return this._errors; | 516 return this._errors; |
| 511 }, | 517 }, |
| 512 set errors(value) | 518 set errors(value) |
| 513 { | 519 { |
| 514 if (value != this._errors) | 520 if (value != this._errors) |
| 515 { | 521 { |
| 516 let oldValue = this._errors; | 522 let oldValue = this._errors; |
| 517 this._errors = value; | 523 this._errors = value; |
| 518 FilterNotifier.triggerListeners("subscription.errors", this, | 524 FilterNotifier.triggerListeners("subscription.errors", this, |
| 519 value, oldValue); | 525 value, oldValue); |
| 520 } | 526 } |
| 521 return this._errors; | 527 return this._errors; |
| 522 }, | 528 }, |
| 523 | 529 |
| 524 /** | 530 /** |
| 525 * Version of the subscription data retrieved on last successful download | 531 * Version of the subscription data retrieved on last successful download |
| 526 * @type {Number} | 532 * @type {number} |
| 527 */ | 533 */ |
| 528 version: 0, | 534 version: 0, |
| 529 | 535 |
| 530 /** | 536 /** |
| 531 * Minimal Adblock Plus version required for this subscription | 537 * Minimal Adblock Plus version required for this subscription |
| 532 * @type {String} | 538 * @type {string} |
| 533 */ | 539 */ |
| 534 requiredVersion: null, | 540 requiredVersion: null, |
| 535 | 541 |
| 536 /** | 542 /** |
| 537 * Number indicating how often the object was downloaded. | 543 * Number indicating how often the object was downloaded. |
| 538 * @type {Number} | 544 * @type {number} |
| 539 */ | 545 */ |
| 540 downloadCount: 0, | 546 downloadCount: 0, |
| 541 | 547 |
| 542 /** | 548 /** |
| 543 * See Subscription.serialize() | 549 * See Subscription.serialize() |
| 544 * @param {string[]} buffer | 550 * @inheritdoc |
| 545 */ | 551 */ |
| 546 serialize(buffer) | 552 serialize(buffer) |
| 547 { | 553 { |
| 548 RegularSubscription.prototype.serialize.call(this, buffer); | 554 RegularSubscription.prototype.serialize.call(this, buffer); |
| 549 if (this.downloadStatus) | 555 if (this.downloadStatus) |
| 550 buffer.push("downloadStatus=" + this.downloadStatus); | 556 buffer.push("downloadStatus=" + this.downloadStatus); |
| 551 if (this.lastSuccess) | 557 if (this.lastSuccess) |
| 552 buffer.push("lastSuccess=" + this.lastSuccess); | 558 buffer.push("lastSuccess=" + this.lastSuccess); |
| 553 if (this.lastCheck) | 559 if (this.lastCheck) |
| 554 buffer.push("lastCheck=" + this.lastCheck); | 560 buffer.push("lastCheck=" + this.lastCheck); |
| 555 if (this.expires) | 561 if (this.expires) |
| 556 buffer.push("expires=" + this.expires); | 562 buffer.push("expires=" + this.expires); |
| 557 if (this.softExpiration) | 563 if (this.softExpiration) |
| 558 buffer.push("softExpiration=" + this.softExpiration); | 564 buffer.push("softExpiration=" + this.softExpiration); |
| 559 if (this.errors) | 565 if (this.errors) |
| 560 buffer.push("errors=" + this.errors); | 566 buffer.push("errors=" + this.errors); |
| 561 if (this.version) | 567 if (this.version) |
| 562 buffer.push("version=" + this.version); | 568 buffer.push("version=" + this.version); |
| 563 if (this.requiredVersion) | 569 if (this.requiredVersion) |
| 564 buffer.push("requiredVersion=" + this.requiredVersion); | 570 buffer.push("requiredVersion=" + this.requiredVersion); |
| 565 if (this.downloadCount) | 571 if (this.downloadCount) |
| 566 buffer.push("downloadCount=" + this.downloadCount); | 572 buffer.push("downloadCount=" + this.downloadCount); |
| 567 } | 573 } |
| 568 }); | 574 }); |
| LEFT | RIGHT |