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

Side by Side 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.
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 // Observe changes to character data only if there's a contains selector in 447 // Observe changes to character data only if there's a contains selector in
448 // one of the patterns. 448 // one of the patterns.
449 return getCachedPropertyValue( 449 return getCachedPropertyValue(
450 this, "_dependsOnCharacterData", 450 this, "_dependsOnCharacterData",
451 () => this.selectors.some(selector => selector.dependsOnCharacterData) 451 () => this.selectors.some(selector => selector.dependsOnCharacterData)
452 ); 452 );
453 } 453 }
454 }; 454 };
455 455
456 function filterPatterns(patterns, {stylesheets, mutations}) 456 function filterPatterns(patterns, {stylesheets, mutations}, document)
457 { 457 {
458 if (!stylesheets && !mutations) 458 if (!stylesheets && !mutations)
459 {
460 // On initial load, skip DOM-only patterns if it's the top frame, because
461 // there's usually nothing interesting to see and we can respond to any
462 // mutations later.
463 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
464 return patterns.filter(pattern => pattern.dependsOnStyles);
465
459 return patterns.slice(); 466 return patterns.slice();
467 }
460 468
461 return patterns.filter( 469 return patterns.filter(
462 pattern => (stylesheets && pattern.dependsOnStyles) || 470 pattern => (stylesheets && pattern.dependsOnStyles) ||
463 (mutations && pattern.dependsOnDOM) 471 (mutations && pattern.dependsOnDOM)
464 ); 472 );
465 } 473 }
466 474
467 function shouldObserveAttributes(patterns) 475 function shouldObserveAttributes(patterns)
468 { 476 {
469 return patterns.some(pattern => pattern.maybeDependsOnAttributes); 477 return patterns.some(pattern => pattern.maybeDependsOnAttributes);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 * @param {MutationRecord[]} [mutations] 578 * @param {MutationRecord[]} [mutations]
571 * The list of DOM mutations that have been applied to the document and 579 * The list of DOM mutations that have been applied to the document and
572 * made reprocessing necessary. This parameter shouldn't be passed in for 580 * made reprocessing necessary. This parameter shouldn't be passed in for
573 * the initial processing, the entire document will be considered 581 * the initial processing, the entire document will be considered
574 * then and all rules, including the ones not dependent on the DOM. 582 * then and all rules, including the ones not dependent on the DOM.
575 * @param {function} [done] 583 * @param {function} [done]
576 * Callback to call when done. 584 * Callback to call when done.
577 */ 585 */
578 _addSelectors(stylesheets, mutations, done) 586 _addSelectors(stylesheets, mutations, done)
579 { 587 {
580 let patterns = filterPatterns(this.patterns, {stylesheets, mutations}); 588 let patterns = filterPatterns(this.patterns, {stylesheets, mutations},
589 this.document);
581 590
582 let selectors = []; 591 let selectors = [];
583 let selectorFilters = []; 592 let selectorFilters = [];
584 593
585 let elements = []; 594 let elements = [];
586 let elementFilters = []; 595 let elementFilters = [];
587 596
588 let cssStyles = []; 597 let cssStyles = [];
589 598
590 // If neither any style sheets nor any DOM mutations have been specified, 599 // If neither any style sheets nor any DOM mutations have been specified,
591 // do full processing. 600 // do full processing.
592 if (!stylesheets && !mutations) 601 if (!stylesheets && !mutations)
593 stylesheets = this.document.styleSheets; 602 stylesheets = this.document.styleSheets;
594 603
595 // If there are any DOM mutations and any of the patterns depends on both 604 // If there are any DOM mutations and any of the patterns depends on both
596 // style sheets and the DOM (e.g. -abp-has(-abp-properties)), find all the 605 // style sheets and the DOM (e.g. -abp-has(-abp-properties)), find all the
597 // rules in every style sheet in the document, because we need to run 606 // rules in every style sheet in the document, because we need to run
598 // querySelectorAll afterwards. On the other hand, if we only have patterns 607 // querySelectorAll afterwards. On the other hand, if we only have patterns
599 // that depend on either styles or DOM both not both 608 // that depend on either styles or DOM but not both
600 // (e.g. -abp-properties or -abp-contains), we can skip this part. 609 // (e.g. -abp-properties or -abp-contains), we can skip this part.
601 if (mutations && patterns.some(pattern => pattern.dependsOnStylesAndDOM)) 610 if (mutations && patterns.some(pattern => pattern.dependsOnStylesAndDOM))
602 stylesheets = this.document.styleSheets; 611 stylesheets = this.document.styleSheets;
603 612
604 for (let stylesheet of stylesheets || []) 613 for (let stylesheet of stylesheets || [])
605 { 614 {
606 // Explicitly ignore third-party stylesheets to ensure consistent behavior 615 // Explicitly ignore third-party stylesheets to ensure consistent behavior
607 // between Firefox and Chrome. 616 // between Firefox and Chrome.
608 if (!this.isSameOrigin(stylesheet)) 617 if (!this.isSameOrigin(stylesheet))
609 continue; 618 continue;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 characterData: shouldObserveCharacterData(this.patterns), 817 characterData: shouldObserveCharacterData(this.patterns),
809 subtree: true 818 subtree: true
810 } 819 }
811 ); 820 );
812 this.document.addEventListener("load", this.onLoad.bind(this), true); 821 this.document.addEventListener("load", this.onLoad.bind(this), true);
813 } 822 }
814 } 823 }
815 }; 824 };
816 825
817 exports.ElemHideEmulation = ElemHideEmulation; 826 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