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

Unified Diff: lib/content/elemHideEmulation.js

Issue 29730630: Issue 6437 - Skip DOM-only patterns on initial load (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Fix unrelated typo in comments Created March 22, 2018, 4:30 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/content/elemHideEmulation.js
===================================================================
--- a/lib/content/elemHideEmulation.js
+++ b/lib/content/elemHideEmulation.js
@@ -448,20 +448,28 @@
// one of the patterns.
return getCachedPropertyValue(
this, "_dependsOnCharacterData",
() => this.selectors.some(selector => selector.dependsOnCharacterData)
);
}
};
-function filterPatterns(patterns, {stylesheets, mutations})
+function filterPatterns(patterns, {stylesheets, mutations}, document)
{
if (!stylesheets && !mutations)
+ {
+ // On initial load, skip DOM-only patterns if it's the top frame, because
+ // there's usually nothing interesting to see and we can respond to any
+ // mutations later.
+ if (typeof top != "undefined" && document.defaultView == top)
hub 2018/03/23 14:58:59 Maybe I'm missing something, but where does that `
Manish Jethani 2018/03/23 16:56:46 That's a reference to the global variable window.t
hub 2018/03/24 01:02:14 I think it would be better, yes, both for clarity
+ return patterns.filter(pattern => pattern.dependsOnStyles);
+
return patterns.slice();
+ }
return patterns.filter(
pattern => (stylesheets && pattern.dependsOnStyles) ||
(mutations && pattern.dependsOnDOM)
);
}
function shouldObserveAttributes(patterns)
@@ -572,17 +580,18 @@
* made reprocessing necessary. This parameter shouldn't be passed in for
* the initial processing, the entire document will be considered
* then and all rules, including the ones not dependent on the DOM.
* @param {function} [done]
* Callback to call when done.
*/
_addSelectors(stylesheets, mutations, done)
{
- let patterns = filterPatterns(this.patterns, {stylesheets, mutations});
+ let patterns = filterPatterns(this.patterns, {stylesheets, mutations},
+ this.document);
let selectors = [];
let selectorFilters = [];
let elements = [];
let elementFilters = [];
let cssStyles = [];
@@ -591,17 +600,17 @@
// do full processing.
if (!stylesheets && !mutations)
stylesheets = this.document.styleSheets;
// If there are any DOM mutations and any of the patterns depends on both
// style sheets and the DOM (e.g. -abp-has(-abp-properties)), find all the
// rules in every style sheet in the document, because we need to run
// querySelectorAll afterwards. On the other hand, if we only have patterns
- // that depend on either styles or DOM both not both
+ // that depend on either styles or DOM but not both
// (e.g. -abp-properties or -abp-contains), we can skip this part.
if (mutations && patterns.some(pattern => pattern.dependsOnStylesAndDOM))
stylesheets = this.document.styleSheets;
for (let stylesheet of stylesheets || [])
{
// Explicitly ignore third-party stylesheets to ensure consistent behavior
// between Firefox and Chrome.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld