Index: lib/content/elemHideEmulation.js |
=================================================================== |
--- a/lib/content/elemHideEmulation.js |
+++ b/lib/content/elemHideEmulation.js |
@@ -448,27 +448,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([ |
Manish Jethani
2018/03/20 09:41:33
This is a cached property also so the map gets cre
|
+ // 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); |
} |