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

Side by Side 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: Rebase Created March 20, 2018, 9:33 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 }, 446 },
447 447
448 get dependsOnCharacterData() 448 get dependsOnCharacterData()
449 { 449 {
450 // Observe changes to character data only if there's a contains selector in 450 // Observe changes to character data only if there's a contains selector in
451 // one of the patterns. 451 // one of the patterns.
452 return getCachedPropertyValue( 452 return getCachedPropertyValue(
453 this, "_dependsOnCharacterData", 453 this, "_dependsOnCharacterData",
454 () => this.selectors.some(selector => selector.dependsOnCharacterData) 454 () => this.selectors.some(selector => selector.dependsOnCharacterData)
455 ); 455 );
456 },
457
458 matchesMutationTypes(mutationTypes)
459 {
460 let mutationTypeMatchMap = getCachedPropertyValue(
461 this, "_mutationTypeMatchMap",
462 () => new Map([
Manish Jethani 2018/03/20 09:41:33 This is a cached property also so the map gets cre
463 // All types of DOM-dependent patterns are affected by mutations of
464 // type "childList".
465 ["childList", true],
466 ["attributes", this.maybeDependsOnAttributes],
467 ["characterData", this.dependsOnCharacterData]
468 ])
469 );
470
471 for (let mutationType of mutationTypes)
472 {
473 if (mutationTypeMatchMap.get(mutationType))
474 return true;
475 }
476
477 return false;
456 } 478 }
457 }; 479 };
458 480
481 function extractMutationTypes(mutations)
482 {
483 let types = new Set();
484
485 for (let mutation of mutations)
486 {
487 types.add(mutation.type);
488
489 // There are only 3 types of mutations: "attributes", "characterData", and
490 // "childList".
491 if (types.size == 3)
492 break;
493 }
494
495 return types;
496 }
497
459 function filterPatterns(patterns, {stylesheets, mutations}) 498 function filterPatterns(patterns, {stylesheets, mutations})
460 { 499 {
461 if (!stylesheets && !mutations) 500 if (!stylesheets && !mutations)
462 return patterns.slice(); 501 return patterns.slice();
463 502
503 let mutationTypes = mutations ? extractMutationTypes(mutations) : null;
504
464 return patterns.filter( 505 return patterns.filter(
465 pattern => (stylesheets && pattern.dependsOnStyles) || 506 pattern => (stylesheets && pattern.dependsOnStyles) ||
466 (mutations && pattern.dependsOnDOM) 507 (mutations && pattern.dependsOnDOM &&
508 pattern.matchesMutationTypes(mutationTypes))
467 ); 509 );
468 } 510 }
469 511
470 function shouldObserveAttributes(patterns) 512 function shouldObserveAttributes(patterns)
471 { 513 {
472 return patterns.some(pattern => pattern.maybeDependsOnAttributes); 514 return patterns.some(pattern => pattern.maybeDependsOnAttributes);
473 } 515 }
474 516
475 function shouldObserveCharacterData(patterns) 517 function shouldObserveCharacterData(patterns)
476 { 518 {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 characterData: shouldObserveCharacterData(this.patterns), 851 characterData: shouldObserveCharacterData(this.patterns),
810 subtree: true 852 subtree: true
811 } 853 }
812 ); 854 );
813 this.document.addEventListener("load", this.onLoad.bind(this), true); 855 this.document.addEventListener("load", this.onLoad.bind(this), true);
814 } 856 }
815 } 857 }
816 }; 858 };
817 859
818 exports.ElemHideEmulation = ElemHideEmulation; 860 exports.ElemHideEmulation = ElemHideEmulation;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld