| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 */ | 177 */ |
| 178 Subscription.fromObject = function(obj) | 178 Subscription.fromObject = function(obj) |
| 179 { | 179 { |
| 180 let result; | 180 let result; |
| 181 try | 181 try |
| 182 { | 182 { |
| 183 obj.url = Services.io.newURI(obj.url, null, null).spec; | 183 obj.url = Services.io.newURI(obj.url, null, null).spec; |
| 184 | 184 |
| 185 // URL is valid - this is a downloadable subscription | 185 // URL is valid - this is a downloadable subscription |
| 186 result = new DownloadableSubscription(obj.url, obj.title); | 186 result = new DownloadableSubscription(obj.url, obj.title); |
| 187 if ("nextURL" in obj) | |
| 188 result.nextURL = obj.nextURL; | |
| 189 if ("downloadStatus" in obj) | 187 if ("downloadStatus" in obj) |
| 190 result._downloadStatus = obj.downloadStatus; | 188 result._downloadStatus = obj.downloadStatus; |
| 191 if ("lastModified" in obj) | |
| 192 result.lastModified = obj.lastModified; | |
| 193 if ("lastSuccess" in obj) | 189 if ("lastSuccess" in obj) |
| 194 result.lastSuccess = parseInt(obj.lastSuccess) || 0; | 190 result.lastSuccess = parseInt(obj.lastSuccess) || 0; |
| 195 if ("lastCheck" in obj) | 191 if ("lastCheck" in obj) |
| 196 result._lastCheck = parseInt(obj.lastCheck) || 0; | 192 result._lastCheck = parseInt(obj.lastCheck) || 0; |
| 197 if ("expires" in obj) | 193 if ("expires" in obj) |
| 198 result.expires = parseInt(obj.expires) || 0; | 194 result.expires = parseInt(obj.expires) || 0; |
| 199 if ("softExpiration" in obj) | 195 if ("softExpiration" in obj) |
| 200 result.softExpiration = parseInt(obj.softExpiration) || 0; | 196 result.softExpiration = parseInt(obj.softExpiration) || 0; |
| 201 if ("errors" in obj) | 197 if ("errors" in obj) |
| 202 result._errors = parseInt(obj.errors) || 0; | 198 result._errors = parseInt(obj.errors) || 0; |
| 199 if ("version" in obj) |
| 200 result.version = parseInt(obj.version) || 0; |
| 203 if ("requiredVersion" in obj) | 201 if ("requiredVersion" in obj) |
| 204 { | 202 { |
| 205 let {addonVersion} = require("info"); | 203 let {addonVersion} = require("info"); |
| 206 result.requiredVersion = obj.requiredVersion; | 204 result.requiredVersion = obj.requiredVersion; |
| 207 if (Services.vc.compare(result.requiredVersion, addonVersion) > 0) | 205 if (Services.vc.compare(result.requiredVersion, addonVersion) > 0) |
| 208 result.upgradeRequired = true; | 206 result.upgradeRequired = true; |
| 209 } | 207 } |
| 210 if ("alternativeLocations" in obj) | |
| 211 result.alternativeLocations = obj.alternativeLocations; | |
| 212 if ("homepage" in obj) | 208 if ("homepage" in obj) |
| 213 result._homepage = obj.homepage; | 209 result._homepage = obj.homepage; |
| 214 if ("lastDownload" in obj) | 210 if ("lastDownload" in obj) |
| 215 result._lastDownload = parseInt(obj.lastDownload) || 0; | 211 result._lastDownload = parseInt(obj.lastDownload) || 0; |
| 216 } | 212 } |
| 217 catch (e) | 213 catch (e) |
| 218 { | 214 { |
| 219 // Invalid URL - custom filter group | 215 // Invalid URL - custom filter group |
| 220 if (!("title" in obj)) | 216 if (!("title" in obj)) |
| 221 { | 217 { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 448 |
| 453 DownloadableSubscription.prototype = | 449 DownloadableSubscription.prototype = |
| 454 { | 450 { |
| 455 __proto__: RegularSubscription.prototype, | 451 __proto__: RegularSubscription.prototype, |
| 456 | 452 |
| 457 _downloadStatus: null, | 453 _downloadStatus: null, |
| 458 _lastCheck: 0, | 454 _lastCheck: 0, |
| 459 _errors: 0, | 455 _errors: 0, |
| 460 | 456 |
| 461 /** | 457 /** |
| 462 * Next URL the downloaded should be attempted from (in case of redirects) | |
| 463 * @type String | |
| 464 */ | |
| 465 nextURL: null, | |
| 466 | |
| 467 /** | |
| 468 * Status of the last download (ID of a string) | 458 * Status of the last download (ID of a string) |
| 469 * @type String | 459 * @type String |
| 470 */ | 460 */ |
| 471 get downloadStatus() this._downloadStatus, | 461 get downloadStatus() this._downloadStatus, |
| 472 set downloadStatus(value) | 462 set downloadStatus(value) |
| 473 { | 463 { |
| 474 let oldValue = this._downloadStatus; | 464 let oldValue = this._downloadStatus; |
| 475 this._downloadStatus = value; | 465 this._downloadStatus = value; |
| 476 FilterNotifier.triggerListeners("subscription.downloadStatus", this, value,
oldValue); | 466 FilterNotifier.triggerListeners("subscription.downloadStatus", this, value,
oldValue); |
| 477 return this._downloadStatus; | 467 return this._downloadStatus; |
| 478 }, | 468 }, |
| 479 | 469 |
| 480 /** | 470 /** |
| 481 * Value of the Last-Modified header returned by the server on last download | |
| 482 * @type String | |
| 483 */ | |
| 484 lastModified: null, | |
| 485 | |
| 486 /** | |
| 487 * Time of the last successful download (in seconds since the beginning of the | 471 * Time of the last successful download (in seconds since the beginning of the |
| 488 * epoch). | 472 * epoch). |
| 489 */ | 473 */ |
| 490 lastSuccess: 0, | 474 lastSuccess: 0, |
| 491 | 475 |
| 492 /** | 476 /** |
| 493 * Time when the subscription was considered for an update last time (in secon
ds | 477 * Time when the subscription was considered for an update last time (in secon
ds |
| 494 * since the beginning of the epoch). This will be used to increase softExpira
tion | 478 * since the beginning of the epoch). This will be used to increase softExpira
tion |
| 495 * if the user doesn't use Adblock Plus for some time. | 479 * if the user doesn't use Adblock Plus for some time. |
| 496 * @type Number | 480 * @type Number |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 if (value != this._errors) | 513 if (value != this._errors) |
| 530 { | 514 { |
| 531 let oldValue = this._errors; | 515 let oldValue = this._errors; |
| 532 this._errors = value; | 516 this._errors = value; |
| 533 FilterNotifier.triggerListeners("subscription.errors", this, value, oldVal
ue); | 517 FilterNotifier.triggerListeners("subscription.errors", this, value, oldVal
ue); |
| 534 } | 518 } |
| 535 return this._errors; | 519 return this._errors; |
| 536 }, | 520 }, |
| 537 | 521 |
| 538 /** | 522 /** |
| 523 * Version of the subscription data retrieved on last successful download |
| 524 * @type Number |
| 525 */ |
| 526 version: 0, |
| 527 |
| 528 /** |
| 539 * Minimal Adblock Plus version required for this subscription | 529 * Minimal Adblock Plus version required for this subscription |
| 540 * @type String | 530 * @type String |
| 541 */ | 531 */ |
| 542 requiredVersion: null, | 532 requiredVersion: null, |
| 543 | 533 |
| 544 /** | 534 /** |
| 545 * Should be true if requiredVersion is higher than current Adblock Plus versi
on | 535 * Should be true if requiredVersion is higher than current Adblock Plus versi
on |
| 546 * @type Boolean | 536 * @type Boolean |
| 547 */ | 537 */ |
| 548 upgradeRequired: false, | 538 upgradeRequired: false, |
| 549 | 539 |
| 550 /** | 540 /** |
| 551 * Value of the X-Alternative-Locations header: comma-separated list of URLs | |
| 552 * with their weighting factors, e.g.: http://foo.example.com/;q=0.5,http://ba
r.example.com/;q=2 | |
| 553 * @type String | |
| 554 */ | |
| 555 alternativeLocations: null, | |
| 556 | |
| 557 /** | |
| 558 * See Subscription.serialize() | 541 * See Subscription.serialize() |
| 559 */ | 542 */ |
| 560 serialize: function(buffer) | 543 serialize: function(buffer) |
| 561 { | 544 { |
| 562 RegularSubscription.prototype.serialize.call(this, buffer); | 545 RegularSubscription.prototype.serialize.call(this, buffer); |
| 563 if (this.nextURL) | |
| 564 buffer.push("nextURL=" + this.nextURL); | |
| 565 if (this.downloadStatus) | 546 if (this.downloadStatus) |
| 566 buffer.push("downloadStatus=" + this.downloadStatus); | 547 buffer.push("downloadStatus=" + this.downloadStatus); |
| 567 if (this.lastModified) | |
| 568 buffer.push("lastModified=" + this.lastModified); | |
| 569 if (this.lastSuccess) | 548 if (this.lastSuccess) |
| 570 buffer.push("lastSuccess=" + this.lastSuccess); | 549 buffer.push("lastSuccess=" + this.lastSuccess); |
| 571 if (this.lastCheck) | 550 if (this.lastCheck) |
| 572 buffer.push("lastCheck=" + this.lastCheck); | 551 buffer.push("lastCheck=" + this.lastCheck); |
| 573 if (this.expires) | 552 if (this.expires) |
| 574 buffer.push("expires=" + this.expires); | 553 buffer.push("expires=" + this.expires); |
| 575 if (this.softExpiration) | 554 if (this.softExpiration) |
| 576 buffer.push("softExpiration=" + this.softExpiration); | 555 buffer.push("softExpiration=" + this.softExpiration); |
| 577 if (this.errors) | 556 if (this.errors) |
| 578 buffer.push("errors=" + this.errors); | 557 buffer.push("errors=" + this.errors); |
| 558 if (this.version) |
| 559 buffer.push("version=" + this.version); |
| 579 if (this.requiredVersion) | 560 if (this.requiredVersion) |
| 580 buffer.push("requiredVersion=" + this.requiredVersion); | 561 buffer.push("requiredVersion=" + this.requiredVersion); |
| 581 if (this.alternativeLocations) | |
| 582 buffer.push("alternativeLocations=" + this.alternativeLocations); | |
| 583 } | 562 } |
| 584 }; | 563 }; |
| OLD | NEW |