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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 return filter; | 461 return filter; |
462 } | 462 } |
463 } | 463 } |
464 } | 464 } |
465 } | 465 } |
466 | 466 |
467 return null; | 467 return null; |
468 } | 468 } |
469 | 469 |
470 _checkEntryMatchSimple(keyword, location, typeMask, docDomain, thirdParty, | 470 _checkEntryMatchSimple(keyword, location, typeMask, docDomain, thirdParty, |
471 sitekey, specificOnly, collection) | 471 sitekey, collection) |
472 { | 472 { |
473 let filters = this._simpleFiltersByKeyword.get(keyword); | 473 let filters = this._simpleFiltersByKeyword.get(keyword); |
474 if (filters) | 474 if (filters) |
475 { | 475 { |
476 let lowerCaseLocation = location.toLowerCase(); | 476 let lowerCaseLocation = location.toLowerCase(); |
477 | 477 |
478 for (let filter of filters) | 478 for (let filter of filters) |
479 { | 479 { |
480 if (specificOnly && !(filter instanceof WhitelistFilter)) | |
481 continue; | |
482 | |
483 if (filter.matchesLocation(location, lowerCaseLocation)) | 480 if (filter.matchesLocation(location, lowerCaseLocation)) |
484 { | 481 { |
485 if (!collection) | 482 if (!collection) |
486 return filter; | 483 return filter; |
487 | 484 |
488 collection.push(filter); | 485 collection.push(filter); |
489 } | 486 } |
490 } | 487 } |
491 } | 488 } |
492 | 489 |
493 return null; | 490 return null; |
494 } | 491 } |
495 | 492 |
496 _checkEntryMatchForType(keyword, location, typeMask, docDomain, thirdParty, | 493 _checkEntryMatchForType(keyword, location, typeMask, docDomain, thirdParty, |
497 sitekey, specificOnly, collection) | 494 sitekey, specificOnly, collection) |
498 { | 495 { |
499 let filtersForType = this._filterMapsByType.get(typeMask); | 496 let filtersForType = this._filterMapsByType.get(typeMask); |
500 if (filtersForType) | 497 if (filtersForType) |
501 { | 498 { |
502 let filters = filtersForType.get(keyword); | 499 let filters = filtersForType.get(keyword); |
503 if (filters) | 500 if (filters) |
504 { | 501 { |
505 for (let filter of filters) | 502 for (let filter of filters) |
506 { | 503 { |
507 if (specificOnly && filter.isGeneric() && | 504 if (specificOnly && filter.isGeneric()) |
508 !(filter instanceof WhitelistFilter)) | |
509 continue; | 505 continue; |
510 | 506 |
511 if (filter.matches(location, typeMask, docDomain, thirdParty, | 507 if (filter.matches(location, typeMask, docDomain, thirdParty, |
512 sitekey)) | 508 sitekey)) |
513 { | 509 { |
514 if (!collection) | 510 if (!collection) |
515 return filter; | 511 return filter; |
516 | 512 |
517 collection.push(filter); | 513 collection.push(filter); |
518 } | 514 } |
(...skipping 12 matching lines...) Expand all Loading... |
531 { | 527 { |
532 if (filtersByDomain instanceof Map) | 528 if (filtersByDomain instanceof Map) |
533 { | 529 { |
534 return this._matchFiltersByDomain(filtersByDomain, location, typeMask, | 530 return this._matchFiltersByDomain(filtersByDomain, location, typeMask, |
535 docDomain, thirdParty, sitekey, | 531 docDomain, thirdParty, sitekey, |
536 specificOnly, collection); | 532 specificOnly, collection); |
537 } | 533 } |
538 | 534 |
539 // Because of the memory optimization in the add function, most of the | 535 // Because of the memory optimization in the add function, most of the |
540 // time this will be a filter rather than a map. | 536 // time this will be a filter rather than a map. |
541 return this._matchFilterWithoutDomain(filtersByDomain, location, | 537 |
542 typeMask, thirdParty, sitekey, | 538 // Also see #7312: If it's a single filter, it's always the equivalent of |
543 collection); | 539 // Map { "" => Map { filter => true } } (i.e. applies to any domain). If |
| 540 // the specific-only flag is set, we skip it. |
| 541 if (!specificOnly) |
| 542 { |
| 543 return this._matchFilterWithoutDomain(filtersByDomain, location, |
| 544 typeMask, thirdParty, sitekey, |
| 545 collection); |
| 546 } |
544 } | 547 } |
545 | 548 |
546 return null; | 549 return null; |
547 } | 550 } |
548 | 551 |
549 /** | 552 /** |
550 * Checks whether the entries for a particular keyword match a URL | 553 * Checks whether the entries for a particular keyword match a URL |
551 * @param {string} keyword | 554 * @param {string} keyword |
552 * @param {string} location | 555 * @param {string} location |
553 * @param {number} typeMask | 556 * @param {number} typeMask |
(...skipping 10 matching lines...) Expand all Loading... |
564 */ | 567 */ |
565 checkEntryMatch(keyword, location, typeMask, docDomain, thirdParty, sitekey, | 568 checkEntryMatch(keyword, location, typeMask, docDomain, thirdParty, sitekey, |
566 specificOnly, collection) | 569 specificOnly, collection) |
567 { | 570 { |
568 // We need to skip the simple (location-only) filters if the type mask does | 571 // We need to skip the simple (location-only) filters if the type mask does |
569 // not contain any default content types. | 572 // not contain any default content types. |
570 if (!specificOnly && (typeMask & DEFAULT_TYPES) != 0) | 573 if (!specificOnly && (typeMask & DEFAULT_TYPES) != 0) |
571 { | 574 { |
572 let filter = this._checkEntryMatchSimple(keyword, location, typeMask, | 575 let filter = this._checkEntryMatchSimple(keyword, location, typeMask, |
573 docDomain, thirdParty, sitekey, | 576 docDomain, thirdParty, sitekey, |
574 specificOnly, collection); | 577 collection); |
575 if (filter) | 578 if (filter) |
576 return filter; | 579 return filter; |
577 } | 580 } |
578 | 581 |
579 // If the type mask contains a non-default type (first condition) and it is | 582 // If the type mask contains a non-default type (first condition) and it is |
580 // the only type in the mask (second condition), we can use the | 583 // the only type in the mask (second condition), we can use the |
581 // type-specific map, which typically contains a lot fewer filters. This | 584 // type-specific map, which typically contains a lot fewer filters. This |
582 // enables faster lookups for whitelisting types like $document, $elemhide, | 585 // enables faster lookups for whitelisting types like $document, $elemhide, |
583 // and so on, as well as other special types like $csp. | 586 // and so on, as well as other special types like $csp. |
584 if ((typeMask & NON_DEFAULT_TYPES) != 0 && (typeMask & typeMask - 1) == 0) | 587 if ((typeMask & NON_DEFAULT_TYPES) != 0 && (typeMask & typeMask - 1) == 0) |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 | 893 |
891 exports.CombinedMatcher = CombinedMatcher; | 894 exports.CombinedMatcher = CombinedMatcher; |
892 | 895 |
893 /** | 896 /** |
894 * Shared {@link CombinedMatcher} instance that should usually be used. | 897 * Shared {@link CombinedMatcher} instance that should usually be used. |
895 * @type {CombinedMatcher} | 898 * @type {CombinedMatcher} |
896 */ | 899 */ |
897 let defaultMatcher = new CombinedMatcher(); | 900 let defaultMatcher = new CombinedMatcher(); |
898 | 901 |
899 exports.defaultMatcher = defaultMatcher; | 902 exports.defaultMatcher = defaultMatcher; |
OLD | NEW |