| 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-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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 if (value != this._disabled) | 118 if (value != this._disabled) |
| 119 { | 119 { |
| 120 let oldValue = this._disabled; | 120 let oldValue = this._disabled; |
| 121 this._disabled = value; | 121 this._disabled = value; |
| 122 filterNotifier.emit("subscription.disabled", this, value, oldValue); | 122 filterNotifier.emit("subscription.disabled", this, value, oldValue); |
| 123 } | 123 } |
| 124 return this._disabled; | 124 return this._disabled; |
| 125 }, | 125 }, |
| 126 | 126 |
| 127 /** | 127 /** |
| 128 * Serializes the subscription to an array of strings for writing | 128 * Serializes the subscription for writing |
|
Manish Jethani
2018/10/22 20:18:01
Nit: We could wrap this.
Jon Sonesen
2018/10/22 22:59:36
Acknowledged.
| |
| 129 * out on the disk. | 129 * out on the disk. |
| 130 * @param {string[]} buffer buffer to push the serialization results into | 130 * @yields {string} |
| 131 */ | 131 */ |
| 132 serialize(buffer) | 132 *serialize() |
| 133 { | 133 { |
| 134 buffer.push("[Subscription]"); | 134 let {url, type, _title, _fixedTitle, _disabled} = this; |
| 135 buffer.push("url=" + this.url); | 135 |
| 136 if (this.type) | 136 yield "[Subscription]"; |
| 137 buffer.push("type=" + this.type); | 137 yield "url=" + url; |
| 138 if (this._title) | 138 |
| 139 buffer.push("title=" + this._title); | 139 if (type) |
| 140 if (this._fixedTitle) | 140 yield "type=" + type; |
| 141 buffer.push("fixedTitle=true"); | 141 if (_title) |
| 142 if (this._disabled) | 142 yield "title=" + _title; |
| 143 buffer.push("disabled=true"); | 143 if (_fixedTitle) |
| 144 yield "fixedTitle=true"; | |
| 145 if (_disabled) | |
| 146 yield "disabled=true"; | |
| 144 }, | 147 }, |
| 145 | 148 |
| 146 serializeFilters(buffer) | 149 *serializeFilters() |
| 147 { | 150 { |
| 148 for (let filter of this.filters) | 151 let {filters} = this; |
| 149 buffer.push(filter.text.replace(/\[/g, "\\[")); | 152 |
| 153 yield "[Subscription filters]"; | |
| 154 for (let filter of filters) | |
| 155 yield filter.text.replace(/\[/g, "\\["); | |
| 150 }, | 156 }, |
| 151 | 157 |
| 152 toString() | 158 toString() |
| 153 { | 159 { |
| 154 let buffer = []; | 160 return [...this.serialize()].join("\n"); |
|
Jon Sonesen
2018/10/22 22:59:36
This may be unrelated, but I was reading about how
Manish Jethani
2018/10/22 23:01:29
I don't know (where is this method called?), but I
Jon Sonesen
2018/10/23 02:04:24
Acknowledged.
| |
| 155 this.serialize(buffer); | |
| 156 return buffer.join("\n"); | |
| 157 } | 161 } |
| 158 }; | 162 }; |
| 159 | 163 |
| 160 /** | 164 /** |
| 161 * Cache for known filter subscriptions, maps URL to subscription objects. | 165 * Cache for known filter subscriptions, maps URL to subscription objects. |
| 162 * @type {Map.<string,Subscription>} | 166 * @type {Map.<string,Subscription>} |
| 163 */ | 167 */ |
| 164 Subscription.knownSubscriptions = new Map(); | 168 Subscription.knownSubscriptions = new Map(); |
| 165 | 169 |
| 166 /** | 170 /** |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 } | 278 } |
| 275 } | 279 } |
| 276 | 280 |
| 277 return false; | 281 return false; |
| 278 }, | 282 }, |
| 279 | 283 |
| 280 /** | 284 /** |
| 281 * See Subscription.serialize() | 285 * See Subscription.serialize() |
| 282 * @inheritdoc | 286 * @inheritdoc |
| 283 */ | 287 */ |
| 284 serialize(buffer) | 288 *serialize() |
| 285 { | 289 { |
| 286 Subscription.prototype.serialize.call(this, buffer); | 290 let {defaults, _lastDownload} = this; |
| 287 if (this.defaults && this.defaults.length) | 291 |
| 292 yield* Subscription.prototype.serialize.call(this); | |
| 293 | |
| 294 if (defaults && defaults.length) | |
| 288 { | 295 { |
| 289 buffer.push("defaults=" + | 296 yield "defaults=" + |
| 290 this.defaults.filter( | 297 defaults.filter( |
| 291 type => SpecialSubscription.defaultsMap.has(type) | 298 type => SpecialSubscription.defaultsMap.has(type) |
| 292 ).join(" ") | 299 ).join(" "); |
| 293 ); | |
| 294 } | 300 } |
| 295 if (this._lastDownload) | 301 if (_lastDownload) |
| 296 buffer.push("lastDownload=" + this._lastDownload); | 302 yield "lastDownload=" + _lastDownload; |
| 297 } | 303 } |
| 298 }); | 304 }); |
| 299 | 305 |
| 300 SpecialSubscription.defaultsMap = new Map([ | 306 SpecialSubscription.defaultsMap = new Map([ |
| 301 ["whitelist", WhitelistFilter], | 307 ["whitelist", WhitelistFilter], |
| 302 ["blocking", BlockingFilter], | 308 ["blocking", BlockingFilter], |
| 303 ["elemhide", ElemHideBase] | 309 ["elemhide", ElemHideBase] |
| 304 ]); | 310 ]); |
| 305 | 311 |
| 306 /** | 312 /** |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 this._lastDownload = value; | 398 this._lastDownload = value; |
| 393 filterNotifier.emit("subscription.lastDownload", this, value, oldValue); | 399 filterNotifier.emit("subscription.lastDownload", this, value, oldValue); |
| 394 } | 400 } |
| 395 return this._lastDownload; | 401 return this._lastDownload; |
| 396 }, | 402 }, |
| 397 | 403 |
| 398 /** | 404 /** |
| 399 * See Subscription.serialize() | 405 * See Subscription.serialize() |
| 400 * @inheritdoc | 406 * @inheritdoc |
| 401 */ | 407 */ |
| 402 serialize(buffer) | 408 *serialize() |
| 403 { | 409 { |
| 404 Subscription.prototype.serialize.call(this, buffer); | 410 let {_homepage, _lastDownload} = this; |
| 405 if (this._homepage) | 411 |
| 406 buffer.push("homepage=" + this._homepage); | 412 yield* Subscription.prototype.serialize.call(this); |
| 407 if (this._lastDownload) | 413 |
| 408 buffer.push("lastDownload=" + this._lastDownload); | 414 if (_homepage) |
| 415 yield "homepage=" + _homepage; | |
| 416 if (_lastDownload) | |
| 417 yield "lastDownload=" + _lastDownload; | |
| 409 } | 418 } |
| 410 }); | 419 }); |
| 411 | 420 |
| 412 /** | 421 /** |
| 413 * Class for filter subscriptions updated externally (by other extension) | 422 * Class for filter subscriptions updated externally (by other extension) |
| 414 * @param {string} url see {@link Subscription Subscription()} | 423 * @param {string} url see {@link Subscription Subscription()} |
| 415 * @param {string} [title] see {@link Subscription Subscription()} | 424 * @param {string} [title] see {@link Subscription Subscription()} |
| 416 * @constructor | 425 * @constructor |
| 417 * @augments RegularSubscription | 426 * @augments RegularSubscription |
| 418 */ | 427 */ |
| 419 function ExternalSubscription(url, title) | 428 function ExternalSubscription(url, title) |
| 420 { | 429 { |
| 421 RegularSubscription.call(this, url, title); | 430 RegularSubscription.call(this, url, title); |
| 422 } | 431 } |
| 423 exports.ExternalSubscription = ExternalSubscription; | 432 exports.ExternalSubscription = ExternalSubscription; |
| 424 | 433 |
| 425 ExternalSubscription.prototype = extend(RegularSubscription, { | 434 ExternalSubscription.prototype = extend(RegularSubscription, { |
| 426 /** | 435 /** |
| 427 * See Subscription.serialize() | 436 * See Subscription.serialize() |
| 428 * @inheritdoc | 437 * @inheritdoc |
| 429 */ | 438 */ |
| 430 serialize(buffer) | 439 *serialize() // eslint-disable-line require-yield |
| 431 { | 440 { |
| 432 throw new Error( | 441 throw new Error( |
| 433 "Unexpected call, external subscriptions should not be serialized" | 442 "Unexpected call, external subscriptions should not be serialized" |
| 434 ); | 443 ); |
| 435 } | 444 } |
| 436 }); | 445 }); |
| 437 | 446 |
| 438 /** | 447 /** |
| 439 * Class for filter subscriptions updated externally (by other extension) | 448 * Class for filter subscriptions updated externally (by other extension) |
| 440 * @param {string} url see {@link Subscription Subscription()} | 449 * @param {string} url see {@link Subscription Subscription()} |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 /** | 554 /** |
| 546 * Number indicating how often the object was downloaded. | 555 * Number indicating how often the object was downloaded. |
| 547 * @type {number} | 556 * @type {number} |
| 548 */ | 557 */ |
| 549 downloadCount: 0, | 558 downloadCount: 0, |
| 550 | 559 |
| 551 /** | 560 /** |
| 552 * See Subscription.serialize() | 561 * See Subscription.serialize() |
| 553 * @inheritdoc | 562 * @inheritdoc |
| 554 */ | 563 */ |
| 555 serialize(buffer) | 564 *serialize() |
| 556 { | 565 { |
| 557 RegularSubscription.prototype.serialize.call(this, buffer); | 566 let {downloadStatus, lastSuccess, lastCheck, expires, |
| 558 if (this.downloadStatus) | 567 softExpiration, errors, version, requiredVersion, |
| 559 buffer.push("downloadStatus=" + this.downloadStatus); | 568 downloadCount} = this; |
| 560 if (this.lastSuccess) | 569 |
| 561 buffer.push("lastSuccess=" + this.lastSuccess); | 570 yield* RegularSubscription.prototype.serialize.call(this); |
| 562 if (this.lastCheck) | 571 |
| 563 buffer.push("lastCheck=" + this.lastCheck); | 572 if (downloadStatus) |
| 564 if (this.expires) | 573 yield "downloadStatus=" + downloadStatus; |
| 565 buffer.push("expires=" + this.expires); | 574 if (lastSuccess) |
| 566 if (this.softExpiration) | 575 yield "lastSuccess=" + lastSuccess; |
| 567 buffer.push("softExpiration=" + this.softExpiration); | 576 if (lastCheck) |
| 568 if (this.errors) | 577 yield "lastCheck=" + lastCheck; |
| 569 buffer.push("errors=" + this.errors); | 578 if (expires) |
| 570 if (this.version) | 579 yield "expires=" + expires; |
| 571 buffer.push("version=" + this.version); | 580 if (softExpiration) |
| 572 if (this.requiredVersion) | 581 yield "softExpiration=" + softExpiration; |
| 573 buffer.push("requiredVersion=" + this.requiredVersion); | 582 if (errors) |
| 574 if (this.downloadCount) | 583 yield "errors=" + errors; |
| 575 buffer.push("downloadCount=" + this.downloadCount); | 584 if (version) |
| 585 yield "version=" + version; | |
| 586 if (requiredVersion) | |
| 587 yield "requiredVersion=" + requiredVersion; | |
| 588 if (downloadCount) | |
| 589 yield "downloadCount=" + downloadCount; | |
| 576 } | 590 } |
| 577 }); | 591 }); |
| OLD | NEW |