LEFT | RIGHT |
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 |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 domainSeparator: null, | 386 domainSeparator: null, |
387 | 387 |
388 /** | 388 /** |
389 * Determines whether domainSource is already upper-case, | 389 * Determines whether domainSource is already upper-case, |
390 * can be overridden by subclasses. | 390 * can be overridden by subclasses. |
391 * @type {boolean} | 391 * @type {boolean} |
392 */ | 392 */ |
393 domainSourceIsUpperCase: false, | 393 domainSourceIsUpperCase: false, |
394 | 394 |
395 /** | 395 /** |
396 * String specifying the domain that this filter should match on, or map | 396 * Map containing domains that this filter should match on/not match |
397 * containing domains that this filter should match on/not match on, or null | 397 * on or null if the filter should match on all domains |
398 * if the filter should match on all domains | 398 * @type {?Map.<string,boolean>} |
399 * @type {?Map.<string,boolean>|string} | |
400 */ | 399 */ |
401 get domains() | 400 get domains() |
402 { | 401 { |
403 // Despite this property being cached, the getter is called | 402 // Despite this property being cached, the getter is called |
404 // several times on Safari, due to WebKit bug 132872 | 403 // several times on Safari, due to WebKit bug 132872 |
405 let prop = Object.getOwnPropertyDescriptor(this, "domains"); | 404 let prop = Object.getOwnPropertyDescriptor(this, "_domains"); |
406 if (prop) | 405 if (prop) |
407 return prop.value; | 406 { |
| 407 let {value} = prop; |
| 408 return typeof value == "string" ? |
| 409 new Map([[value, true], ["", false]]) : value; |
| 410 } |
408 | 411 |
409 let domains = null; | 412 let domains = null; |
410 | 413 |
411 if (this.domainSource) | 414 if (this.domainSource) |
412 { | 415 { |
413 let source = this.domainSource; | 416 let source = this.domainSource; |
414 if (!this.domainSourceIsUpperCase) | 417 if (!this.domainSourceIsUpperCase) |
415 { | 418 { |
416 // RegExpFilter already have uppercase domains | 419 // RegExpFilter already have uppercase domains |
417 source = source.toUpperCase(); | 420 source = source.toUpperCase(); |
(...skipping 30 matching lines...) Expand all Loading... |
448 | 451 |
449 domains.set(domain, include); | 452 domains.set(domain, include); |
450 } | 453 } |
451 if (domains) | 454 if (domains) |
452 domains.set("", !hasIncludes); | 455 domains.set("", !hasIncludes); |
453 } | 456 } |
454 | 457 |
455 this.domainSource = null; | 458 this.domainSource = null; |
456 } | 459 } |
457 | 460 |
458 Object.defineProperty(this, "domains", {value: domains, enumerable: true}); | 461 Object.defineProperty(this, "_domains", {value: domains}); |
459 return this.domains; | 462 return this.domains; |
460 }, | 463 }, |
461 | 464 |
462 /** | 465 /** |
463 * Array containing public keys of websites that this filter should apply to | 466 * Array containing public keys of websites that this filter should apply to |
464 * @type {?string[]} | 467 * @type {?string[]} |
465 */ | 468 */ |
466 sitekeys: null, | 469 sitekeys: null, |
467 | 470 |
468 /** | 471 /** |
(...skipping 13 matching lines...) Expand all Loading... |
482 return false; | 485 return false; |
483 } | 486 } |
484 | 487 |
485 // If no domains are set the rule matches everywhere | 488 // If no domains are set the rule matches everywhere |
486 if (!this.domains) | 489 if (!this.domains) |
487 return true; | 490 return true; |
488 | 491 |
489 // If the document has no host name, match only if the filter | 492 // If the document has no host name, match only if the filter |
490 // isn't restricted to specific domains | 493 // isn't restricted to specific domains |
491 if (!docDomain) | 494 if (!docDomain) |
492 return typeof this.domains != "string" && this.domains.get(""); | 495 return this.domains.get(""); |
493 | 496 |
494 docDomain = docDomain.replace(/\.+$/, "").toUpperCase(); | 497 docDomain = docDomain.replace(/\.+$/, "").toUpperCase(); |
495 | |
496 if (typeof this.domains == "string") | |
497 { | |
498 return docDomain == this.domains || | |
499 docDomain.endsWith("." + this.domains); | |
500 } | |
501 | 498 |
502 while (true) | 499 while (true) |
503 { | 500 { |
504 let isDomainIncluded = this.domains.get(docDomain); | 501 let isDomainIncluded = this.domains.get(docDomain); |
505 if (typeof isDomainIncluded != "undefined") | 502 if (typeof isDomainIncluded != "undefined") |
506 return isDomainIncluded; | 503 return isDomainIncluded; |
507 | 504 |
508 let nextDot = docDomain.indexOf("."); | 505 let nextDot = docDomain.indexOf("."); |
509 if (nextDot < 0) | 506 if (nextDot < 0) |
510 break; | 507 break; |
511 docDomain = docDomain.substr(nextDot + 1); | 508 docDomain = docDomain.substr(nextDot + 1); |
512 } | 509 } |
513 return this.domains.get(""); | 510 return this.domains.get(""); |
514 }, | 511 }, |
515 | 512 |
516 /** | 513 /** |
517 * Checks whether this filter is active only on a domain and its subdomains. | 514 * Checks whether this filter is active only on a domain and its subdomains. |
518 * @param {string} docDomain | 515 * @param {string} docDomain |
519 * @return {boolean} | 516 * @return {boolean} |
520 */ | 517 */ |
521 isActiveOnlyOnDomain(docDomain) | 518 isActiveOnlyOnDomain(docDomain) |
522 { | 519 { |
523 if (!docDomain || !this.domains || | 520 if (!docDomain || !this.domains || this.domains.get("")) |
524 typeof this.domains != "string" && this.domains.get("")) | |
525 { | |
526 return false; | 521 return false; |
527 } | |
528 | 522 |
529 docDomain = docDomain.replace(/\.+$/, "").toUpperCase(); | 523 docDomain = docDomain.replace(/\.+$/, "").toUpperCase(); |
530 | |
531 if (typeof this.domains == "string") | |
532 { | |
533 return docDomain == this.domains || | |
534 this.domains.endsWith("." + docDomain); | |
535 } | |
536 | 524 |
537 for (let [domain, isIncluded] of this.domains) | 525 for (let [domain, isIncluded] of this.domains) |
538 { | 526 { |
539 if (isIncluded && domain != docDomain) | 527 if (isIncluded && domain != docDomain) |
540 { | 528 { |
541 if (domain.length <= docDomain.length) | 529 if (domain.length <= docDomain.length) |
542 return false; | 530 return false; |
543 | 531 |
544 if (!domain.endsWith("." + docDomain)) | 532 if (!domain.endsWith("." + docDomain)) |
545 return false; | 533 return false; |
546 } | 534 } |
547 } | 535 } |
548 | 536 |
549 return true; | 537 return true; |
550 }, | 538 }, |
551 | 539 |
552 /** | 540 /** |
553 * Checks whether this filter is generic or specific | 541 * Checks whether this filter is generic or specific |
554 * @return {boolean} | 542 * @return {boolean} |
555 */ | 543 */ |
556 isGeneric() | 544 isGeneric() |
557 { | 545 { |
558 return !(this.sitekeys && this.sitekeys.length) && | 546 return !(this.sitekeys && this.sitekeys.length) && |
559 (!this.domains || | 547 (!this.domains || this.domains.get("")); |
560 typeof this.domains != "string" && this.domains.get("")); | |
561 }, | 548 }, |
562 | 549 |
563 /** | 550 /** |
564 * See Filter.serialize() | 551 * See Filter.serialize() |
565 * @inheritdoc | 552 * @inheritdoc |
566 */ | 553 */ |
567 serialize(buffer) | 554 serialize(buffer) |
568 { | 555 { |
569 if (this._disabled || this._hitCount || this._lastHit) | 556 if (this._disabled || this._hitCount || this._lastHit) |
570 { | 557 { |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 */ | 1103 */ |
1117 function ElemHideEmulationFilter(text, domains, selector) | 1104 function ElemHideEmulationFilter(text, domains, selector) |
1118 { | 1105 { |
1119 ElemHideBase.call(this, text, domains, selector); | 1106 ElemHideBase.call(this, text, domains, selector); |
1120 } | 1107 } |
1121 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; | 1108 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
1122 | 1109 |
1123 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { | 1110 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
1124 type: "elemhideemulation" | 1111 type: "elemhideemulation" |
1125 }); | 1112 }); |
LEFT | RIGHT |