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 |
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 Filter class and its subclasses. | 21 * @fileOverview Definition of Filter class and its subclasses. |
22 */ | 22 */ |
23 | 23 |
24 const {FilterNotifier} = require("./filterNotifier"); | 24 const {FilterNotifier} = require("./filterNotifier"); |
25 const {extend} = require("./coreUtils"); | 25 const {extend} = require("./coreUtils"); |
26 const {filterToRegExp} = require("./common"); | 26 const {filterToRegExp} = require("./common"); |
27 | 27 |
28 /** | 28 /** |
| 29 * All known unique domain sources mapped to their parsed values. |
| 30 * @type {Map.<string,Map.<string,boolean>>} |
| 31 */ |
| 32 let knownDomainMaps = new Map(); |
| 33 |
| 34 /** |
29 * Abstract base class for filters | 35 * Abstract base class for filters |
30 * | 36 * |
31 * @param {string} text string representation of the filter | 37 * @param {string} text string representation of the filter |
32 * @constructor | 38 * @constructor |
33 */ | 39 */ |
34 function Filter(text) | 40 function Filter(text) |
35 { | 41 { |
36 this.text = text; | 42 this.text = text; |
37 this.subscriptions = []; | 43 this.subscriptions = []; |
38 } | 44 } |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 */ | 397 */ |
392 domainSourceIsLowerCase: false, | 398 domainSourceIsLowerCase: false, |
393 | 399 |
394 /** | 400 /** |
395 * Map containing domains that this filter should match on/not match | 401 * Map containing domains that this filter should match on/not match |
396 * on or null if the filter should match on all domains | 402 * on or null if the filter should match on all domains |
397 * @type {?Map.<string,boolean>} | 403 * @type {?Map.<string,boolean>} |
398 */ | 404 */ |
399 get domains() | 405 get domains() |
400 { | 406 { |
401 let prop = Object.getOwnPropertyDescriptor(this, "_domains"); | |
402 if (prop) | |
403 { | |
404 let {value} = prop; | |
405 return typeof value == "string" ? | |
406 new Map([[value, true], ["", false]]) : value; | |
407 } | |
408 | |
409 let domains = null; | 407 let domains = null; |
410 | 408 |
411 if (this.domainSource) | 409 if (this.domainSource) |
412 { | 410 { |
413 let source = this.domainSource; | 411 let source = this.domainSource; |
414 if (!this.domainSourceIsLowerCase) | 412 if (!this.domainSourceIsLowerCase) |
415 { | 413 { |
416 // RegExpFilter already have lowercase domains | 414 // RegExpFilter already have lowercase domains |
417 source = source.toLowerCase(); | 415 source = source.toLowerCase(); |
418 } | 416 } |
419 let list = source.split(this.domainSeparator); | 417 |
420 if (list.length == 1 && list[0][0] != "~") | 418 let knownMap = knownDomainMaps.get(source); |
| 419 if (knownMap) |
421 { | 420 { |
422 // Fast track for the common one-domain scenario | 421 domains = knownMap; |
423 domains = list[0]; | |
424 } | 422 } |
425 else | 423 else |
426 { | 424 { |
427 let hasIncludes = false; | 425 let list = source.split(this.domainSeparator); |
428 for (let i = 0; i < list.length; i++) | 426 if (list.length == 1 && list[0][0] != "~") |
429 { | 427 { |
430 let domain = list[i]; | 428 // Fast track for the common one-domain scenario |
431 if (domain == "") | 429 domains = new Map([[list[0], true], ["", false]]); |
432 continue; | 430 } |
| 431 else |
| 432 { |
| 433 let hasIncludes = false; |
| 434 for (let i = 0; i < list.length; i++) |
| 435 { |
| 436 let domain = list[i]; |
| 437 if (domain == "") |
| 438 continue; |
433 | 439 |
434 let include; | 440 let include; |
435 if (domain[0] == "~") | 441 if (domain[0] == "~") |
436 { | 442 { |
437 include = false; | 443 include = false; |
438 domain = domain.substr(1); | 444 domain = domain.substr(1); |
439 } | 445 } |
440 else | 446 else |
441 { | 447 { |
442 include = true; | 448 include = true; |
443 hasIncludes = true; | 449 hasIncludes = true; |
| 450 } |
| 451 |
| 452 if (!domains) |
| 453 domains = new Map(); |
| 454 |
| 455 domains.set(domain, include); |
444 } | 456 } |
445 | 457 |
446 if (!domains) | 458 if (domains) |
447 domains = new Map(); | 459 domains.set("", !hasIncludes); |
| 460 } |
448 | 461 |
449 domains.set(domain, include); | |
450 } | |
451 if (domains) | 462 if (domains) |
452 domains.set("", !hasIncludes); | 463 knownDomainMaps.set(source, domains); |
453 } | 464 } |
454 | 465 |
455 this.domainSource = null; | 466 this.domainSource = null; |
456 } | 467 } |
457 | 468 |
458 Object.defineProperty(this, "_domains", {value: domains}); | 469 Object.defineProperty(this, "domains", {value: domains}); |
459 return this.domains; | 470 return this.domains; |
460 }, | 471 }, |
461 | 472 |
462 /** | 473 /** |
463 * Array containing public keys of websites that this filter should apply to | 474 * Array containing public keys of websites that this filter should apply to |
464 * @type {?string[]} | 475 * @type {?string[]} |
465 */ | 476 */ |
466 sitekeys: null, | 477 sitekeys: null, |
467 | 478 |
468 /** | 479 /** |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 | 1183 |
1173 /** | 1184 /** |
1174 * Script that should be executed | 1185 * Script that should be executed |
1175 * @type {string} | 1186 * @type {string} |
1176 */ | 1187 */ |
1177 get script() | 1188 get script() |
1178 { | 1189 { |
1179 return this.body; | 1190 return this.body; |
1180 } | 1191 } |
1181 }); | 1192 }); |
OLD | NEW |