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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 | 600 |
601 function shouldObserveCharacterData(patterns) | 601 function shouldObserveCharacterData(patterns) |
602 { | 602 { |
603 return patterns.some(pattern => pattern.dependsOnCharacterData); | 603 return patterns.some(pattern => pattern.dependsOnCharacterData); |
604 } | 604 } |
605 | 605 |
606 class ElemHideEmulation | 606 class ElemHideEmulation |
607 { | 607 { |
608 constructor(addSelectorsFunc, hideElemsFunc) | 608 constructor(addSelectorsFunc, hideElemsFunc) |
609 { | 609 { |
| 610 // Note: The first parameter to this constructor was previously used for |
| 611 // injecting style sheets into the document for :-abp-properties() but this |
| 612 // code has since moved on to use inline styles for all types of emulation |
| 613 // filters (#6610). Nevertheless, there is a plan to go back to using style |
| 614 // sheets on platforms that support the tabs.removeCSS API (#6504); hence |
| 615 // this first parameter remains for now. |
| 616 |
610 this._filteringInProgress = false; | 617 this._filteringInProgress = false; |
611 this._lastInvocation = -MIN_INVOCATION_INTERVAL; | 618 this._lastInvocation = -MIN_INVOCATION_INTERVAL; |
612 this._scheduledProcessing = null; | 619 this._scheduledProcessing = null; |
613 | 620 |
614 this.document = document; | 621 this.document = document; |
615 this.addSelectorsFunc = addSelectorsFunc; | |
616 this.hideElemsFunc = hideElemsFunc; | 622 this.hideElemsFunc = hideElemsFunc; |
617 this.observer = new MutationObserver(this.observe.bind(this)); | 623 this.observer = new MutationObserver(this.observe.bind(this)); |
618 } | 624 } |
619 | 625 |
620 isSameOrigin(stylesheet) | 626 isSameOrigin(stylesheet) |
621 { | 627 { |
622 try | 628 try |
623 { | 629 { |
624 return new URL(stylesheet.href).origin == this.document.location.origin; | 630 return new URL(stylesheet.href).origin == this.document.location.origin; |
625 } | 631 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 * @param {function} [done] | 714 * @param {function} [done] |
709 * Callback to call when done. | 715 * Callback to call when done. |
710 */ | 716 */ |
711 _addSelectors(stylesheets, mutations, done) | 717 _addSelectors(stylesheets, mutations, done) |
712 { | 718 { |
713 if (testInfo) | 719 if (testInfo) |
714 testInfo.lastProcessedElements.clear(); | 720 testInfo.lastProcessedElements.clear(); |
715 | 721 |
716 let patterns = filterPatterns(this.patterns, {stylesheets, mutations}); | 722 let patterns = filterPatterns(this.patterns, {stylesheets, mutations}); |
717 | 723 |
718 let selectors = []; | |
719 let selectorFilters = []; | |
720 | |
721 let elements = []; | 724 let elements = []; |
722 let elementFilters = []; | 725 let elementFilters = []; |
723 | 726 |
724 let cssStyles = []; | 727 let cssStyles = []; |
725 | 728 |
726 // If neither any style sheets nor any DOM mutations have been specified, | 729 // If neither any style sheets nor any DOM mutations have been specified, |
727 // do full processing. | 730 // do full processing. |
728 if (!stylesheets && !mutations) | 731 if (!stylesheets && !mutations) |
729 stylesheets = this.document.styleSheets; | 732 stylesheets = this.document.styleSheets; |
730 | 733 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 let generator = null; | 779 let generator = null; |
777 | 780 |
778 let processPatterns = () => | 781 let processPatterns = () => |
779 { | 782 { |
780 let cycleStart = performance.now(); | 783 let cycleStart = performance.now(); |
781 | 784 |
782 if (!pattern) | 785 if (!pattern) |
783 { | 786 { |
784 if (!patterns.length) | 787 if (!patterns.length) |
785 { | 788 { |
786 if (selectors.length > 0) | |
787 this.addSelectorsFunc(selectors, selectorFilters); | |
788 if (elements.length > 0) | 789 if (elements.length > 0) |
789 this.hideElemsFunc(elements, elementFilters); | 790 this.hideElemsFunc(elements, elementFilters); |
790 if (typeof done == "function") | 791 if (typeof done == "function") |
791 done(); | 792 done(); |
792 return; | 793 return; |
793 } | 794 } |
794 | 795 |
795 pattern = patterns.shift(); | 796 pattern = patterns.shift(); |
796 | 797 |
797 let evaluationTargets = targets; | 798 let evaluationTargets = targets; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 characterData: shouldObserveCharacterData(this.patterns), | 972 characterData: shouldObserveCharacterData(this.patterns), |
972 subtree: true | 973 subtree: true |
973 } | 974 } |
974 ); | 975 ); |
975 this.document.addEventListener("load", this.onLoad.bind(this), true); | 976 this.document.addEventListener("load", this.onLoad.bind(this), true); |
976 } | 977 } |
977 } | 978 } |
978 } | 979 } |
979 | 980 |
980 exports.ElemHideEmulation = ElemHideEmulation; | 981 exports.ElemHideEmulation = ElemHideEmulation; |
OLD | NEW |