| 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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 }, | 456 }, |
| 457 | 457 |
| 458 get dependsOnCharacterData() | 458 get dependsOnCharacterData() |
| 459 { | 459 { |
| 460 // Observe changes to character data only if there's a contains selector in | 460 // Observe changes to character data only if there's a contains selector in |
| 461 // one of the patterns. | 461 // one of the patterns. |
| 462 return getCachedPropertyValue( | 462 return getCachedPropertyValue( |
| 463 this, "_dependsOnCharacterData", | 463 this, "_dependsOnCharacterData", |
| 464 () => this.selectors.some(selector => selector.dependsOnCharacterData) | 464 () => this.selectors.some(selector => selector.dependsOnCharacterData) |
| 465 ); | 465 ); |
| 466 }, |
| 467 |
| 468 matchesMutationTypes(mutationTypes) |
| 469 { |
| 470 let mutationTypeMatchMap = getCachedPropertyValue( |
| 471 this, "_mutationTypeMatchMap", |
| 472 () => new Map([ |
| 473 // All types of DOM-dependent patterns are affected by mutations of |
| 474 // type "childList". |
| 475 ["childList", true], |
| 476 ["attributes", this.maybeDependsOnAttributes], |
| 477 ["characterData", this.dependsOnCharacterData] |
| 478 ]) |
| 479 ); |
| 480 |
| 481 for (let mutationType of mutationTypes) |
| 482 { |
| 483 if (mutationTypeMatchMap.get(mutationType)) |
| 484 return true; |
| 485 } |
| 486 |
| 487 return false; |
| 466 } | 488 } |
| 467 }; | 489 }; |
| 468 | 490 |
| 491 function extractMutationTypes(mutations) |
| 492 { |
| 493 let types = new Set(); |
| 494 |
| 495 for (let mutation of mutations) |
| 496 { |
| 497 types.add(mutation.type); |
| 498 |
| 499 // There are only 3 types of mutations: "attributes", "characterData", and |
| 500 // "childList". |
| 501 if (types.size == 3) |
| 502 break; |
| 503 } |
| 504 |
| 505 return types; |
| 506 } |
| 507 |
| 469 function filterPatterns(patterns, {stylesheets, mutations}) | 508 function filterPatterns(patterns, {stylesheets, mutations}) |
| 470 { | 509 { |
| 471 if (!stylesheets && !mutations) | 510 if (!stylesheets && !mutations) |
| 472 return patterns.slice(); | 511 return patterns.slice(); |
| 473 | 512 |
| 513 let mutationTypes = mutations ? extractMutationTypes(mutations) : null; |
| 514 |
| 474 return patterns.filter( | 515 return patterns.filter( |
| 475 pattern => (stylesheets && pattern.dependsOnStyles) || | 516 pattern => (stylesheets && pattern.dependsOnStyles) || |
| 476 (mutations && pattern.dependsOnDOM) | 517 (mutations && pattern.dependsOnDOM && |
| 518 pattern.matchesMutationTypes(mutationTypes)) |
| 477 ); | 519 ); |
| 478 } | 520 } |
| 479 | 521 |
| 480 function shouldObserveAttributes(patterns) | 522 function shouldObserveAttributes(patterns) |
| 481 { | 523 { |
| 482 return patterns.some(pattern => pattern.maybeDependsOnAttributes); | 524 return patterns.some(pattern => pattern.maybeDependsOnAttributes); |
| 483 } | 525 } |
| 484 | 526 |
| 485 function shouldObserveCharacterData(patterns) | 527 function shouldObserveCharacterData(patterns) |
| 486 { | 528 { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 characterData: shouldObserveCharacterData(this.patterns), | 877 characterData: shouldObserveCharacterData(this.patterns), |
| 836 subtree: true | 878 subtree: true |
| 837 } | 879 } |
| 838 ); | 880 ); |
| 839 this.document.addEventListener("load", this.onLoad.bind(this), true); | 881 this.document.addEventListener("load", this.onLoad.bind(this), true); |
| 840 } | 882 } |
| 841 } | 883 } |
| 842 }; | 884 }; |
| 843 | 885 |
| 844 exports.ElemHideEmulation = ElemHideEmulation; | 886 exports.ElemHideEmulation = ElemHideEmulation; |
| OLD | NEW |