Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/content/elemHideEmulation.js

Issue 29847558: Issue 6504 - Remove useInlineStyles for now (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Update issue number in comment Created Aug. 10, 2018, 2:27 p.m.
Right Patch Set: Remove one more reference to useInlineStyles Created Aug. 15, 2018, 7:47 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 { 597 {
598 return patterns.some(pattern => pattern.dependsOnCharacterData); 598 return patterns.some(pattern => pattern.dependsOnCharacterData);
599 } 599 }
600 600
601 function ElemHideEmulation(addSelectorsFunc, hideElemsFunc) 601 function ElemHideEmulation(addSelectorsFunc, hideElemsFunc)
602 { 602 {
603 this.document = document; 603 this.document = document;
604 this.addSelectorsFunc = addSelectorsFunc; 604 this.addSelectorsFunc = addSelectorsFunc;
605 this.hideElemsFunc = hideElemsFunc; 605 this.hideElemsFunc = hideElemsFunc;
606 this.observer = new MutationObserver(this.observe.bind(this)); 606 this.observer = new MutationObserver(this.observe.bind(this));
607
608 // This flag is supposed to indicate whether we should prefer setting the
609 // style attribute of the element over using CSS selectors. It is set by the
610 // web extension if the tabs.removeCSS API is available (Firefox 53+). But
611 // because of issues with performance (see #6504), we are ignoring the value
612 // of this flag for now; we always set the style attribute.
613 // https://issues.adblockplus.org/ticket/6504#comment:9
614 this.useInlineStyles = true;
hub 2018/08/10 19:43:16 so if we don't use it, and since the code below ge
Manish Jethani 2018/08/14 16:50:16 I left it there with a comment sorta hoping that s
hub 2018/08/14 17:24:41 Since you remove the code below, I believe it is p
Manish Jethani 2018/08/14 17:46:22 Sounds OK to me. Done.
615 } 607 }
616 608
617 ElemHideEmulation.prototype = { 609 ElemHideEmulation.prototype = {
618 isSameOrigin(stylesheet) 610 isSameOrigin(stylesheet)
619 { 611 {
620 try 612 try
621 { 613 {
622 return new URL(stylesheet.href).origin == this.document.location.origin; 614 return new URL(stylesheet.href).origin == this.document.location.origin;
623 } 615 }
624 catch (e) 616 catch (e)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 715
724 // If neither any style sheets nor any DOM mutations have been specified, 716 // If neither any style sheets nor any DOM mutations have been specified,
725 // do full processing. 717 // do full processing.
726 if (!stylesheets && !mutations) 718 if (!stylesheets && !mutations)
727 stylesheets = this.document.styleSheets; 719 stylesheets = this.document.styleSheets;
728 720
729 // If there are any DOM mutations and any of the patterns depends on both 721 // If there are any DOM mutations and any of the patterns depends on both
730 // style sheets and the DOM (e.g. -abp-has(-abp-properties)), find all the 722 // style sheets and the DOM (e.g. -abp-has(-abp-properties)), find all the
731 // rules in every style sheet in the document, because we need to run 723 // rules in every style sheet in the document, because we need to run
732 // querySelectorAll afterwards. On the other hand, if we only have patterns 724 // querySelectorAll afterwards. On the other hand, if we only have patterns
733 // that depend on either styles or DOM both not both 725 // that depend on either styles or DOM both not both (e.g. -abp-contains),
734 // (e.g. -abp-properties or -abp-contains), we can skip this part. 726 // we can skip this part.
735 if (mutations && patterns.some(pattern => pattern.dependsOnStylesAndDOM)) 727 if (mutations && patterns.some(pattern => pattern.dependsOnStylesAndDOM))
736 stylesheets = this.document.styleSheets; 728 stylesheets = this.document.styleSheets;
737 729
738 for (let stylesheet of stylesheets || []) 730 for (let stylesheet of stylesheets || [])
739 { 731 {
740 // Explicitly ignore third-party stylesheets to ensure consistent behavior 732 // Explicitly ignore third-party stylesheets to ensure consistent behavior
741 // between Firefox and Chrome. 733 // between Firefox and Chrome.
742 if (!this.isSameOrigin(stylesheet)) 734 if (!this.isSameOrigin(stylesheet))
743 continue; 735 continue;
744 736
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 784
793 pattern = patterns.shift(); 785 pattern = patterns.shift();
794 786
795 let evaluationTargets = targets; 787 let evaluationTargets = targets;
796 788
797 // If the pattern appears to contain any sibling combinators, we can't 789 // If the pattern appears to contain any sibling combinators, we can't
798 // easily optimize based on the mutation targets. Since this is a 790 // easily optimize based on the mutation targets. Since this is a
799 // special case, skip the optimization. By setting it to null here we 791 // special case, skip the optimization. By setting it to null here we
800 // make sure we process the entire DOM. 792 // make sure we process the entire DOM.
801 if (pattern.maybeContainsSiblingCombinators) 793 if (pattern.maybeContainsSiblingCombinators)
802 evaluationTargets = null;
803
804 // Ignore mutation targets when using style sheets, because we may have
805 // to update all the CSS selectors.
806 if (!this.useInlineStyles)
807 evaluationTargets = null; 794 evaluationTargets = null;
808 795
809 generator = evaluate(pattern.selectors, 0, "", 796 generator = evaluate(pattern.selectors, 0, "",
810 this.document, cssStyles, evaluationTargets); 797 this.document, cssStyles, evaluationTargets);
811 } 798 }
812 for (let selector of generator) 799 for (let selector of generator)
813 { 800 {
814 if (selector != null) 801 if (selector != null)
815 { 802 {
816 for (let element of this.document.querySelectorAll(selector)) 803 for (let element of this.document.querySelectorAll(selector))
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 characterData: shouldObserveCharacterData(this.patterns), 965 characterData: shouldObserveCharacterData(this.patterns),
979 subtree: true 966 subtree: true
980 } 967 }
981 ); 968 );
982 this.document.addEventListener("load", this.onLoad.bind(this), true); 969 this.document.addEventListener("load", this.onLoad.bind(this), true);
983 } 970 }
984 } 971 }
985 }; 972 };
986 973
987 exports.ElemHideEmulation = ElemHideEmulation; 974 exports.ElemHideEmulation = ElemHideEmulation;
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld