Index: lib/subscriptionClasses.js |
=================================================================== |
--- a/lib/subscriptionClasses.js |
+++ b/lib/subscriptionClasses.js |
@@ -14,39 +14,32 @@ |
* You should have received a copy of the GNU General Public License |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
/** |
* @fileOverview Definition of Subscription class and its subclasses. |
*/ |
-Cu.import("resource://gre/modules/Services.jsm"); |
- |
let {ActiveFilter, BlockingFilter, WhitelistFilter, ElemHideBase} = require("filterClasses"); |
let {FilterNotifier} = require("filterNotifier"); |
/** |
* Abstract base class for filter subscriptions |
* |
* @param {String} url download location of the subscription |
* @param {String} [title] title of the filter subscription |
* @constructor |
*/ |
function Subscription(url, title) |
{ |
this.url = url; |
this.filters = []; |
if (title) |
this._title = title; |
- else |
- { |
- let {Utils} = require("utils"); |
- this._title = Utils.getString("newGroup_title"); |
- } |
Subscription.knownSubscriptions[url] = this; |
} |
exports.Subscription = Subscription; |
Subscription.prototype = |
{ |
/** |
* Download location of the subscription |
@@ -124,17 +117,18 @@ Subscription.prototype = |
/** |
* Serializes the subscription to an array of strings for writing out on the disk. |
* @param {string[]} buffer buffer to push the serialization results into |
*/ |
serialize: function(buffer) |
{ |
buffer.push("[Subscription]"); |
buffer.push("url=" + this.url); |
- buffer.push("title=" + this._title); |
+ if (this._title) |
+ buffer.push("title=" + this._title); |
if (this._fixedTitle) |
buffer.push("fixedTitle=true"); |
if (this._disabled) |
buffer.push("disabled=true"); |
}, |
serializeFilters: function(buffer) |
{ |
@@ -161,41 +155,33 @@ Subscription.knownSubscriptions = Object |
* @param {String} url URL of the subscription |
* @return {Subscription} subscription or null if the subscription couldn't be created |
*/ |
Subscription.fromURL = function(url) |
{ |
if (url in Subscription.knownSubscriptions) |
return Subscription.knownSubscriptions[url]; |
- try |
- { |
- // Test URL for validity |
- url = Services.io.newURI(url, null, null).spec; |
+ if (url[0] != "~") |
return new DownloadableSubscription(url, null); |
- } |
- catch (e) |
- { |
+ else |
return new SpecialSubscription(url); |
- } |
}; |
/** |
* Deserializes a subscription |
* |
* @param {Object} obj map of serialized properties and their values |
* @return {Subscription} subscription or null if the subscription couldn't be created |
*/ |
Subscription.fromObject = function(obj) |
{ |
let result; |
- try |
+ if (obj.url[0] != "~") |
{ |
- obj.url = Services.io.newURI(obj.url, null, null).spec; |
- |
// URL is valid - this is a downloadable subscription |
result = new DownloadableSubscription(obj.url, obj.title); |
if ("downloadStatus" in obj) |
result._downloadStatus = obj.downloadStatus; |
if ("lastSuccess" in obj) |
result.lastSuccess = parseInt(obj.lastSuccess, 10) || 0; |
if ("lastCheck" in obj) |
result._lastCheck = parseInt(obj.lastCheck, 10) || 0; |
@@ -203,48 +189,26 @@ Subscription.fromObject = function(obj) |
result.expires = parseInt(obj.expires, 10) || 0; |
if ("softExpiration" in obj) |
result.softExpiration = parseInt(obj.softExpiration, 10) || 0; |
if ("errors" in obj) |
result._errors = parseInt(obj.errors, 10) || 0; |
if ("version" in obj) |
result.version = parseInt(obj.version, 10) || 0; |
if ("requiredVersion" in obj) |
- { |
- let {addonVersion} = require("info"); |
result.requiredVersion = obj.requiredVersion; |
- if (Services.vc.compare(result.requiredVersion, addonVersion) > 0) |
- result.upgradeRequired = true; |
- } |
if ("homepage" in obj) |
result._homepage = obj.homepage; |
if ("lastDownload" in obj) |
result._lastDownload = parseInt(obj.lastDownload, 10) || 0; |
if ("downloadCount" in obj) |
result.downloadCount = parseInt(obj.downloadCount, 10) || 0; |
} |
- catch (e) |
+ else |
{ |
- // Invalid URL - custom filter group |
- if (!("title" in obj)) |
- { |
- // Backwards compatibility - titles and filter types were originally |
- // determined by group identifier. |
- if (obj.url == "~wl~") |
- obj.defaults = "whitelist"; |
- else if (obj.url == "~fl~") |
- obj.defaults = "blocking"; |
- else if (obj.url == "~eh~") |
- obj.defaults = "elemhide"; |
- if ("defaults" in obj) |
- { |
- let {Utils} = require("utils"); |
- obj.title = Utils.getString(obj.defaults + "Group_title"); |
- } |
- } |
result = new SpecialSubscription(obj.url, obj.title); |
if ("defaults" in obj) |
result.defaults = obj.defaults.split(" "); |
} |
if ("fixedTitle" in obj) |
result._fixedTitle = (obj.fixedTitle == "true"); |
if ("disabled" in obj) |
result._disabled = (obj.disabled == "true"); |
@@ -342,19 +306,16 @@ SpecialSubscription.createForFilter = fu |
subscription.filters.push(filter); |
for (let type in SpecialSubscription.defaultsMap) |
{ |
if (filter instanceof SpecialSubscription.defaultsMap[type]) |
subscription.defaults = [type]; |
} |
if (!subscription.defaults) |
subscription.defaults = ["blocking"]; |
- |
- let {Utils} = require("utils"); |
- subscription.title = Utils.getString(subscription.defaults[0] + "Group_title"); |
return subscription; |
}; |
/** |
* Abstract base class for regular filter subscriptions (both internally and externally updated) |
* @param {String} url see Subscription() |
* @param {String} [title] see Subscription() |
* @constructor |
@@ -553,22 +514,16 @@ DownloadableSubscription.prototype = |
/** |
* Minimal Adblock Plus version required for this subscription |
* @type String |
*/ |
requiredVersion: null, |
/** |
- * Should be true if requiredVersion is higher than current Adblock Plus version |
- * @type Boolean |
- */ |
- upgradeRequired: false, |
- |
- /** |
* Number indicating how often the object was downloaded. |
* @type Number |
*/ |
downloadCount: 0, |
/** |
* See Subscription.serialize() |
*/ |