Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: assets/js/SubscriptionClasses.jsm

Issue 8482109: ABP/Android JavaScript code (Closed)
Patch Set: Created Oct. 5, 2012, 9:23 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/.
5 */
6
7 //
8 // This file has been generated automatically from Adblock Plus source code
9 //
10
11 (function (_patchFunc2) {
12 function Subscription(url, title) {
13 this.url = url;
14 this.filters = [];
15 this._title = title || Utils.getString("newGroup_title");
16 Subscription.knownSubscriptions[url] = this;
17 }
18 Subscription.prototype = {
19 url: null,
20 filters: null,
21 _title: null,
22 _disabled: false,
23 get title() {
24 return this._title;
25 },
26 set title(value) {
27 if (value != this._title) {
28 var oldValue = this._title;
29 this._title = value;
30 FilterNotifier.triggerListeners("subscription.title", this, value, oldVa lue);
31 }
32 return this._title;
33 }
34 ,
35 get disabled() {
36 return this._disabled;
37 },
38 set disabled(value) {
39 if (value != this._disabled) {
40 var oldValue = this._disabled;
41 this._disabled = value;
42 FilterNotifier.triggerListeners("subscription.disabled", this, value, ol dValue);
43 }
44 return this._disabled;
45 }
46 ,
47 serialize: function (buffer) {
48 buffer.push("[Subscription]");
49 buffer.push("url=" + this.url);
50 buffer.push("title=" + this._title);
51 if (this._disabled)
52 buffer.push("disabled=true");
53 }
54 ,
55 serializeFilters: function (buffer) {
56 for (var _loopIndex0 = 0;
57 _loopIndex0 < this.filters.length; ++ _loopIndex0) {
58 var filter = this.filters[_loopIndex0];
59 buffer.push(filter.text.replace(/\[/g, "\\["));
60 }
61 }
62 ,
63 toString: function () {
64 var buffer = [];
65 this.serialize(buffer);
66 return buffer.join("\n");
67 }
68
69 };
70 Subscription.knownSubscriptions = {
71 __proto__: null
72 };
73 Subscription.fromURL = (function (url) {
74 if (url in Subscription.knownSubscriptions)
75 return Subscription.knownSubscriptions[url];
76 try {
77 url = Utils.ioService.newURI(url, null, null).spec;
78 return new DownloadableSubscription(url, null);
79 }
80 catch (e){
81 return new SpecialSubscription(url);
82 }
83 }
84 );
85 Subscription.fromObject = (function (obj) {
86 var result;
87 try {
88 obj.url = Utils.ioService.newURI(obj.url, null, null).spec;
89 result = new DownloadableSubscription(obj.url, obj.title);
90 if ("nextURL" in obj)
91 result.nextURL = obj.nextURL;
92 if ("downloadStatus" in obj)
93 result._downloadStatus = obj.downloadStatus;
94 if ("lastModified" in obj)
95 result.lastModified = obj.lastModified;
96 if ("lastSuccess" in obj)
97 result.lastSuccess = parseInt(obj.lastSuccess) || 0;
98 if ("lastCheck" in obj)
99 result._lastCheck = parseInt(obj.lastCheck) || 0;
100 if ("expires" in obj)
101 result.expires = parseInt(obj.expires) || 0;
102 if ("softExpiration" in obj)
103 result.softExpiration = parseInt(obj.softExpiration) || 0;
104 if ("errors" in obj)
105 result._errors = parseInt(obj.errors) || 0;
106 if ("requiredVersion" in obj) {
107 result.requiredVersion = obj.requiredVersion;
108 if (Utils.versionComparator.compare(result.requiredVersion, Utils.addonV ersion) > 0)
109 result.upgradeRequired = true;
110 }
111 if ("alternativeLocations" in obj)
112 result.alternativeLocations = obj.alternativeLocations;
113 if ("homepage" in obj)
114 result._homepage = obj.homepage;
115 if ("lastDownload" in obj)
116 result._lastDownload = parseInt(obj.lastDownload) || 0;
117 }
118 catch (e){
119 if (!("title" in obj)) {
120 if (obj.url == "~wl~")
121 obj.defaults = "whitelist";
122 else
123 if (obj.url == "~fl~")
124 obj.defaults = "blocking";
125 else
126 if (obj.url == "~eh~")
127 obj.defaults = "elemhide";
128 if ("defaults" in obj)
129 obj.title = Utils.getString(obj.defaults + "Group_title");
130 }
131 result = new SpecialSubscription(obj.url, obj.title);
132 if ("defaults" in obj)
133 result.defaults = obj.defaults.split(" ");
134 }
135 if ("disabled" in obj)
136 result._disabled = (obj.disabled == "true");
137 return result;
138 }
139 );
140 function SpecialSubscription(url, title) {
141 Subscription.call(this, url, title);
142 }
143 SpecialSubscription.prototype = {
144 __proto__: Subscription.prototype,
145 defaults: null,
146 isDefaultFor: function (filter) {
147 if (this.defaults && this.defaults.length) {
148 for (var _loopIndex1 = 0;
149 _loopIndex1 < this.defaults.length; ++ _loopIndex1) {
150 var type = this.defaults[_loopIndex1];
151 if (filter instanceof SpecialSubscription.defaultsMap[type])
152 return true;
153 if (!(filter instanceof ActiveFilter) && type == "blacklist")
154 return true;
155 }
156 }
157 return false;
158 }
159 ,
160 serialize: function (buffer) {
161 Subscription.prototype.serialize.call(this, buffer);
162 if (this.defaults && this.defaults.length)
163 buffer.push("defaults=" + this.defaults.filter(function (type) {
164 return type in SpecialSubscription.defaultsMap;
165 }).join(" "));
166 if (this._lastDownload)
167 buffer.push("lastDownload=" + this._lastDownload);
168 }
169
170 };
171 SpecialSubscription.defaultsMap = {
172 __proto__: null,
173 "whitelist": WhitelistFilter,
174 "blocking": BlockingFilter,
175 "elemhide": ElemHideFilter
176 };
177 SpecialSubscription.create = (function (title) {
178 var url;
179 do {
180 url = "~user~" + Math.round(Math.random() * 1000000);
181 }
182 while (url in Subscription.knownSubscriptions);
183 return new SpecialSubscription(url, title);
184 }
185 );
186 SpecialSubscription.createForFilter = (function (filter) {
187 var subscription = SpecialSubscription.create();
188 subscription.filters.push(filter);
189 for (var type in SpecialSubscription.defaultsMap) {
190 if (filter instanceof SpecialSubscription.defaultsMap[type])
191 subscription.defaults = [type];
192 }
193 if (!subscription.defaults)
194 subscription.defaults = ["blocking"];
195 subscription.title = Utils.getString(subscription.defaults[0] + "Group_title ");
196 return subscription;
197 }
198 );
199 function RegularSubscription(url, title) {
200 Subscription.call(this, url, title || url);
201 }
202 RegularSubscription.prototype = {
203 __proto__: Subscription.prototype,
204 _homepage: null,
205 _lastDownload: 0,
206 get homepage() {
207 return this._homepage;
208 },
209 set homepage(value) {
210 if (value != this._homepage) {
211 var oldValue = this._homepage;
212 this._homepage = value;
213 FilterNotifier.triggerListeners("subscription.homepage", this, value, ol dValue);
214 }
215 return this._homepage;
216 }
217 ,
218 get lastDownload() {
219 return this._lastDownload;
220 },
221 set lastDownload(value) {
222 if (value != this._lastDownload) {
223 var oldValue = this._lastDownload;
224 this._lastDownload = value;
225 FilterNotifier.triggerListeners("subscription.lastDownload", this, value , oldValue);
226 }
227 return this._lastDownload;
228 }
229 ,
230 serialize: function (buffer) {
231 Subscription.prototype.serialize.call(this, buffer);
232 if (this._homepage)
233 buffer.push("homepage=" + this._homepage);
234 if (this._lastDownload)
235 buffer.push("lastDownload=" + this._lastDownload);
236 }
237
238 };
239 function ExternalSubscription(url, title) {
240 RegularSubscription.call(this, url, title);
241 }
242 ExternalSubscription.prototype = {
243 __proto__: RegularSubscription.prototype,
244 serialize: function (buffer) {
245 throw new Error("Unexpected call, external subscriptions should not be ser ialized");
246 }
247
248 };
249 function DownloadableSubscription(url, title) {
250 RegularSubscription.call(this, url, title);
251 }
252 DownloadableSubscription.prototype = {
253 __proto__: RegularSubscription.prototype,
254 _downloadStatus: null,
255 _lastCheck: 0,
256 _errors: 0,
257 nextURL: null,
258 get downloadStatus() {
259 return this._downloadStatus;
260 },
261 set downloadStatus(value) {
262 var oldValue = this._downloadStatus;
263 this._downloadStatus = value;
264 FilterNotifier.triggerListeners("subscription.downloadStatus", this, value , oldValue);
265 return this._downloadStatus;
266 }
267 ,
268 lastModified: null,
269 lastSuccess: 0,
270 get lastCheck() {
271 return this._lastCheck;
272 },
273 set lastCheck(value) {
274 if (value != this._lastCheck) {
275 var oldValue = this._lastCheck;
276 this._lastCheck = value;
277 FilterNotifier.triggerListeners("subscription.lastCheck", this, value, o ldValue);
278 }
279 return this._lastCheck;
280 }
281 ,
282 expires: 0,
283 softExpiration: 0,
284 get errors() {
285 return this._errors;
286 },
287 set errors(value) {
288 if (value != this._errors) {
289 var oldValue = this._errors;
290 this._errors = value;
291 FilterNotifier.triggerListeners("subscription.errors", this, value, oldV alue);
292 }
293 return this._errors;
294 }
295 ,
296 requiredVersion: null,
297 upgradeRequired: false,
298 alternativeLocations: null,
299 serialize: function (buffer) {
300 RegularSubscription.prototype.serialize.call(this, buffer);
301 if (this.nextURL)
302 buffer.push("nextURL=" + this.nextURL);
303 if (this.downloadStatus)
304 buffer.push("downloadStatus=" + this.downloadStatus);
305 if (this.lastModified)
306 buffer.push("lastModified=" + this.lastModified);
307 if (this.lastSuccess)
308 buffer.push("lastSuccess=" + this.lastSuccess);
309 if (this.lastCheck)
310 buffer.push("lastCheck=" + this.lastCheck);
311 if (this.expires)
312 buffer.push("expires=" + this.expires);
313 if (this.softExpiration)
314 buffer.push("softExpiration=" + this.softExpiration);
315 if (this.errors)
316 buffer.push("errors=" + this.errors);
317 if (this.requiredVersion)
318 buffer.push("requiredVersion=" + this.requiredVersion);
319 if (this.alternativeLocations)
320 buffer.push("alternativeLocations=" + this.alternativeLocations);
321 }
322
323 };
324 if (typeof _patchFunc2 != "undefined")
325 eval("(" + _patchFunc2.toString() + ")()");
326 window.Subscription = Subscription;
327 window.SpecialSubscription = SpecialSubscription;
328 window.RegularSubscription = RegularSubscription;
329 window.ExternalSubscription = ExternalSubscription;
330 window.DownloadableSubscription = DownloadableSubscription;
331 }
332 )(window.SubscriptionClassesPatch);
OLDNEW
« no previous file with comments | « assets/js/Matcher.jsm ('k') | assets/js/Synchronizer.jsm » ('j') | assets/js/XMLHttpRequest.jsm » ('J')

Powered by Google App Engine
This is Rietveld