Left: | ||
Right: |
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 |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 ignoreTrailingDot: true, | 393 ignoreTrailingDot: true, |
394 | 394 |
395 /** | 395 /** |
396 * Determines whether domainSource is already upper-case, | 396 * Determines whether domainSource is already upper-case, |
397 * can be overridden by subclasses. | 397 * can be overridden by subclasses. |
398 * @type {boolean} | 398 * @type {boolean} |
399 */ | 399 */ |
400 domainSourceIsUpperCase: false, | 400 domainSourceIsUpperCase: false, |
401 | 401 |
402 /** | 402 /** |
403 * Map containing domains that this filter should match on/not match | 403 * String specifying the domain that this filter should match on, or map |
404 * on or null if the filter should match on all domains | 404 * containing domains that this filter should match on/not match on, or null |
405 * @type {?Map.<string,boolean>} | 405 * if the filter should match on all domains |
406 * @type {?Map.<string,boolean>|string} | |
406 */ | 407 */ |
407 get domains() | 408 get domains() |
408 { | 409 { |
409 // Despite this property being cached, the getter is called | 410 // Despite this property being cached, the getter is called |
410 // several times on Safari, due to WebKit bug 132872 | 411 // several times on Safari, due to WebKit bug 132872 |
411 let prop = Object.getOwnPropertyDescriptor(this, "domains"); | 412 let prop = Object.getOwnPropertyDescriptor(this, "domains"); |
412 if (prop) | 413 if (prop) |
413 return prop.value; | 414 return prop.value; |
414 | 415 |
415 let domains = null; | 416 let domains = null; |
416 | 417 |
417 if (this.domainSource) | 418 if (this.domainSource) |
418 { | 419 { |
419 let source = this.domainSource; | 420 let source = this.domainSource; |
420 if (!this.domainSourceIsUpperCase) | 421 if (!this.domainSourceIsUpperCase) |
421 { | 422 { |
422 // RegExpFilter already have uppercase domains | 423 // RegExpFilter already have uppercase domains |
423 source = source.toUpperCase(); | 424 source = source.toUpperCase(); |
424 } | 425 } |
425 let list = source.split(this.domainSeparator); | 426 let list = source.split(this.domainSeparator); |
426 if (list.length == 1 && list[0][0] != "~") | 427 if (list.length == 1 && list[0][0] != "~") |
427 { | 428 { |
428 // Fast track for the common one-domain scenario | 429 // Fast track for the common one-domain scenario |
429 if (this.ignoreTrailingDot) | 430 if (this.ignoreTrailingDot) |
430 list[0] = list[0].replace(/\.+$/, ""); | 431 list[0] = list[0].replace(/\.+$/, ""); |
431 domains = new Map([["", false], [list[0], true]]); | 432 domains = list[0]; |
432 } | 433 } |
433 else | 434 else |
434 { | 435 { |
435 let hasIncludes = false; | 436 let hasIncludes = false; |
436 for (let i = 0; i < list.length; i++) | 437 for (let i = 0; i < list.length; i++) |
437 { | 438 { |
438 let domain = list[i]; | 439 let domain = list[i]; |
439 if (this.ignoreTrailingDot) | 440 if (this.ignoreTrailingDot) |
440 domain = domain.replace(/\.+$/, ""); | 441 domain = domain.replace(/\.+$/, ""); |
441 if (domain == "") | 442 if (domain == "") |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 return false; | 493 return false; |
493 } | 494 } |
494 | 495 |
495 // If no domains are set the rule matches everywhere | 496 // If no domains are set the rule matches everywhere |
496 if (!this.domains) | 497 if (!this.domains) |
497 return true; | 498 return true; |
498 | 499 |
499 // If the document has no host name, match only if the filter | 500 // If the document has no host name, match only if the filter |
500 // isn't restricted to specific domains | 501 // isn't restricted to specific domains |
501 if (!docDomain) | 502 if (!docDomain) |
502 return this.domains.get(""); | 503 return typeof this.domains != "string" && this.domains.get(""); |
503 | 504 |
504 if (this.ignoreTrailingDot) | 505 if (this.ignoreTrailingDot) |
505 docDomain = docDomain.replace(/\.+$/, ""); | 506 docDomain = docDomain.replace(/\.+$/, ""); |
506 docDomain = docDomain.toUpperCase(); | 507 docDomain = docDomain.toUpperCase(); |
507 | 508 |
509 if (typeof this.domains == "string") | |
510 { | |
511 return docDomain == this.domains || | |
512 docDomain.endsWith("." + this.domains); | |
513 } | |
514 | |
508 while (true) | 515 while (true) |
509 { | 516 { |
510 let isDomainIncluded = this.domains.get(docDomain); | 517 let isDomainIncluded = this.domains.get(docDomain); |
511 if (typeof isDomainIncluded != "undefined") | 518 if (typeof isDomainIncluded != "undefined") |
512 return isDomainIncluded; | 519 return isDomainIncluded; |
513 | 520 |
514 let nextDot = docDomain.indexOf("."); | 521 let nextDot = docDomain.indexOf("."); |
515 if (nextDot < 0) | 522 if (nextDot < 0) |
516 break; | 523 break; |
517 docDomain = docDomain.substr(nextDot + 1); | 524 docDomain = docDomain.substr(nextDot + 1); |
518 } | 525 } |
519 return this.domains.get(""); | 526 return this.domains.get(""); |
520 }, | 527 }, |
521 | 528 |
522 /** | 529 /** |
523 * Checks whether this filter is active only on a domain and its subdomains. | 530 * Checks whether this filter is active only on a domain and its subdomains. |
524 * @param {string} docDomain | 531 * @param {string} docDomain |
525 * @return {boolean} | 532 * @return {boolean} |
526 */ | 533 */ |
527 isActiveOnlyOnDomain(docDomain) | 534 isActiveOnlyOnDomain(docDomain) |
528 { | 535 { |
529 if (!docDomain || !this.domains || this.domains.get("")) | 536 if (!docDomain || !this.domains || |
537 typeof this.domains != "string" && this.domains.get("")) | |
sergei
2018/05/28 09:22:07
IMO, perhaps it would be safer to rather check tha
kzar
2018/06/05 16:51:30
Disagree on this one, people that don't understand
Manish Jethani
2018/06/06 11:16:31
This is one of those things that can lead to an en
Manish Jethani
2018/06/06 12:31:18
typeof is typically faster than instanceof, so whe
| |
538 { | |
530 return false; | 539 return false; |
540 } | |
531 | 541 |
532 if (this.ignoreTrailingDot) | 542 if (this.ignoreTrailingDot) |
533 docDomain = docDomain.replace(/\.+$/, ""); | 543 docDomain = docDomain.replace(/\.+$/, ""); |
534 docDomain = docDomain.toUpperCase(); | 544 docDomain = docDomain.toUpperCase(); |
535 | 545 |
546 if (typeof this.domains == "string") | |
547 { | |
548 return docDomain == this.domains || | |
549 this.domains.endsWith("." + docDomain); | |
550 } | |
551 | |
536 for (let [domain, isIncluded] of this.domains) | 552 for (let [domain, isIncluded] of this.domains) |
537 { | 553 { |
538 if (isIncluded && domain != docDomain) | 554 if (isIncluded && domain != docDomain) |
539 { | 555 { |
540 if (domain.length <= docDomain.length) | 556 if (domain.length <= docDomain.length) |
541 return false; | 557 return false; |
542 | 558 |
543 if (!domain.endsWith("." + docDomain)) | 559 if (!domain.endsWith("." + docDomain)) |
544 return false; | 560 return false; |
545 } | 561 } |
546 } | 562 } |
547 | 563 |
548 return true; | 564 return true; |
549 }, | 565 }, |
550 | 566 |
551 /** | 567 /** |
552 * Checks whether this filter is generic or specific | 568 * Checks whether this filter is generic or specific |
553 * @return {boolean} | 569 * @return {boolean} |
554 */ | 570 */ |
555 isGeneric() | 571 isGeneric() |
556 { | 572 { |
557 return !(this.sitekeys && this.sitekeys.length) && | 573 return !(this.sitekeys && this.sitekeys.length) && |
558 (!this.domains || this.domains.get("")); | 574 (!this.domains || |
575 typeof this.domains != "string" && this.domains.get("")); | |
559 }, | 576 }, |
560 | 577 |
561 /** | 578 /** |
562 * See Filter.serialize() | 579 * See Filter.serialize() |
563 * @inheritdoc | 580 * @inheritdoc |
564 */ | 581 */ |
565 serialize(buffer) | 582 serialize(buffer) |
566 { | 583 { |
567 if (this._disabled || this._hitCount || this._lastHit) | 584 if (this._disabled || this._hitCount || this._lastHit) |
568 { | 585 { |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1114 */ | 1131 */ |
1115 function ElemHideEmulationFilter(text, domains, selector) | 1132 function ElemHideEmulationFilter(text, domains, selector) |
1116 { | 1133 { |
1117 ElemHideBase.call(this, text, domains, selector); | 1134 ElemHideBase.call(this, text, domains, selector); |
1118 } | 1135 } |
1119 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; | 1136 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
1120 | 1137 |
1121 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { | 1138 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
1122 type: "elemhideemulation" | 1139 type: "elemhideemulation" |
1123 }); | 1140 }); |
OLD | NEW |