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

Delta Between Two Patch Sets: lib/subscriptionClasses.js

Issue 29375915: Issue 4878 - Start using ESLint for adblockpluscore (Closed)
Left Patch Set: Addressed Sebastian's initial feedback Created Feb. 21, 2017, 6:12 a.m.
Right Patch Set: Removed unused imports Created March 15, 2017, 3:11 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/rsa.js ('k') | lib/synchronizer.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
Sebastian Noack 2017/02/21 09:19:31 If you break after the dot, it looks weird and is
kzar 2017/02/21 10:37:02 Done.
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)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 /**
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld