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

Unified Diff: lib/content/elemHideEmulation.js

Issue 29713565: Issue 6437 - Filter out patterns that do not match DOM mutations (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add tests Created April 24, 2018, 12:39 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 | test/browser/elemHideEmulation.js » ('j') | test/browser/elemHideEmulation.js » ('J')
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
@@ -222,16 +222,18 @@
function PlainSelector(selector)
{
this._selector = selector;
this.maybeDependsOnAttributes = /[#.]|\[.+\]/.test(selector);
}
PlainSelector.prototype = {
+ preferHideWithSelector: true,
Manish Jethani 2018/04/24 12:43:01 This is a bug. If there's only the filter "example
+
/**
* Generator function returning a pair of selector
* string and subtree.
* @param {string} prefix the prefix for the selector.
* @param {Node} subtree the subtree we work on.
* @param {StringifiedStyle[]} styles the stringified style objects.
*/
*getSelectors(prefix, subtree, styles)
@@ -458,27 +460,69 @@
get dependsOnCharacterData()
{
// Observe changes to character data only if there's a contains selector in
// one of the patterns.
return getCachedPropertyValue(
this, "_dependsOnCharacterData",
() => this.selectors.some(selector => selector.dependsOnCharacterData)
);
+ },
+
+ matchesMutationTypes(mutationTypes)
+ {
+ let mutationTypeMatchMap = getCachedPropertyValue(
+ this, "_mutationTypeMatchMap",
+ () => new Map([
+ // All types of DOM-dependent patterns are affected by mutations of
+ // type "childList".
+ ["childList", true],
+ ["attributes", this.maybeDependsOnAttributes],
+ ["characterData", this.dependsOnCharacterData]
+ ])
+ );
+
+ for (let mutationType of mutationTypes)
+ {
+ if (mutationTypeMatchMap.get(mutationType))
+ return true;
+ }
+
+ return false;
}
};
+function extractMutationTypes(mutations)
+{
+ let types = new Set();
+
+ for (let mutation of mutations)
+ {
+ types.add(mutation.type);
+
+ // There are only 3 types of mutations: "attributes", "characterData", and
+ // "childList".
+ if (types.size == 3)
+ break;
+ }
+
+ return types;
+}
+
function filterPatterns(patterns, {stylesheets, mutations})
{
if (!stylesheets && !mutations)
return patterns.slice();
+ let mutationTypes = mutations ? extractMutationTypes(mutations) : null;
+
return patterns.filter(
pattern => (stylesheets && pattern.dependsOnStyles) ||
- (mutations && pattern.dependsOnDOM)
+ (mutations && pattern.dependsOnDOM &&
+ pattern.matchesMutationTypes(mutationTypes))
);
}
function shouldObserveAttributes(patterns)
{
return patterns.some(pattern => pattern.maybeDependsOnAttributes);
}
« no previous file with comments | « no previous file | test/browser/elemHideEmulation.js » ('j') | test/browser/elemHideEmulation.js » ('J')

Powered by Google App Engine
This is Rietveld