OLD | NEW |
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 Loading... |
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) |
| 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 Loading... |
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, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
OLD | NEW |