| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 const {textToRegExp, filterToRegExp, splitSelector} = require("../common"); | 20 const {textToRegExp, filterToRegExp, splitSelector} = require("../common"); |
| 21 const {indexOf} = require("../coreUtils"); | 21 const {indexOf} = require("../coreUtils"); |
| 22 | 22 |
| 23 let MIN_INVOCATION_INTERVAL = 3000; | 23 let MIN_INVOCATION_INTERVAL = 3000; |
| 24 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50; | 24 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50; |
| 25 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; | 25 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; |
| 26 | 26 |
| 27 let debugInfo = null; | 27 let testInfo = null; |
| 28 | 28 |
| 29 function setDebugMode() | 29 function setTestMode() |
| 30 { | 30 { |
| 31 debugInfo = { | 31 testInfo = { |
| 32 lastProcessedElements: new Set() | 32 lastProcessedElements: new Set() |
| 33 }; | 33 }; |
| 34 } | 34 } |
| 35 | 35 |
| 36 exports.setDebugMode = setDebugMode; | 36 exports.setTestMode = setTestMode; |
| 37 | 37 |
| 38 function getDebugInfo() | 38 function getTestInfo() |
| 39 { | 39 { |
| 40 return debugInfo; | 40 return testInfo; |
| 41 } | 41 } |
| 42 | 42 |
| 43 exports.getDebugInfo = getDebugInfo; | 43 exports.getTestInfo = getTestInfo; |
|
hub
2018/05/24 19:19:09
I'm a bit skeptical with that way or test, includi
Manish Jethani
2018/05/25 07:21:25
We can work on improving our test framework, but f
| |
| 44 | 44 |
| 45 function getCachedPropertyValue(object, name, defaultValueFunc = () => {}) | 45 function getCachedPropertyValue(object, name, defaultValueFunc = () => {}) |
| 46 { | 46 { |
| 47 let value = object[name]; | 47 let value = object[name]; |
| 48 if (typeof value == "undefined") | 48 if (typeof value == "undefined") |
| 49 Object.defineProperty(object, name, {value: value = defaultValueFunc()}); | 49 Object.defineProperty(object, name, {value: value = defaultValueFunc()}); |
| 50 return value; | 50 return value; |
| 51 } | 51 } |
| 52 | 52 |
| 53 /** Return position of node from parent. | 53 /** Return position of node from parent. |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 targets); | 325 targets); |
| 326 for (let selector of iter) | 326 for (let selector of iter) |
| 327 { | 327 { |
| 328 if (selector == null) | 328 if (selector == null) |
| 329 yield null; | 329 yield null; |
| 330 else if (scopedQuerySelector(element, selector)) | 330 else if (scopedQuerySelector(element, selector)) |
| 331 yield element; | 331 yield element; |
| 332 } | 332 } |
| 333 yield null; | 333 yield null; |
| 334 | 334 |
| 335 if (debugInfo) | 335 if (testInfo) |
| 336 debugInfo.lastProcessedElements.add(element); | 336 testInfo.lastProcessedElements.add(element); |
| 337 } | 337 } |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 }; | 340 }; |
| 341 | 341 |
| 342 function ContainsSelector(textContent) | 342 function ContainsSelector(textContent) |
| 343 { | 343 { |
| 344 this._regexp = makeRegExpParameter(textContent); | 344 this._regexp = makeRegExpParameter(textContent); |
| 345 } | 345 } |
| 346 | 346 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 { | 382 { |
| 383 yield null; | 383 yield null; |
| 384 continue; | 384 continue; |
| 385 } | 385 } |
| 386 | 386 |
| 387 if (this._regexp && this._regexp.test(element.textContent)) | 387 if (this._regexp && this._regexp.test(element.textContent)) |
| 388 yield element; | 388 yield element; |
| 389 else | 389 else |
| 390 yield null; | 390 yield null; |
| 391 | 391 |
| 392 if (debugInfo) | 392 if (testInfo) |
| 393 debugInfo.lastProcessedElements.add(element); | 393 testInfo.lastProcessedElements.add(element); |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 } | 396 } |
| 397 }; | 397 }; |
| 398 | 398 |
| 399 function PropsSelector(propertyExpression) | 399 function PropsSelector(propertyExpression) |
| 400 { | 400 { |
| 401 let regexpString; | 401 let regexpString; |
| 402 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && | 402 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && |
| 403 propertyExpression[propertyExpression.length - 1] == "/") | 403 propertyExpression[propertyExpression.length - 1] == "/") |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 * @param {MutationRecord[]} [mutations] | 692 * @param {MutationRecord[]} [mutations] |
| 693 * The list of DOM mutations that have been applied to the document and | 693 * The list of DOM mutations that have been applied to the document and |
| 694 * made reprocessing necessary. This parameter shouldn't be passed in for | 694 * made reprocessing necessary. This parameter shouldn't be passed in for |
| 695 * the initial processing, the entire document will be considered | 695 * the initial processing, the entire document will be considered |
| 696 * then and all rules, including the ones not dependent on the DOM. | 696 * then and all rules, including the ones not dependent on the DOM. |
| 697 * @param {function} [done] | 697 * @param {function} [done] |
| 698 * Callback to call when done. | 698 * Callback to call when done. |
| 699 */ | 699 */ |
| 700 _addSelectors(stylesheets, mutations, done) | 700 _addSelectors(stylesheets, mutations, done) |
| 701 { | 701 { |
| 702 if (debugInfo) | 702 if (testInfo) |
| 703 debugInfo.lastProcessedElements.clear(); | 703 testInfo.lastProcessedElements.clear(); |
| 704 | 704 |
| 705 let patterns = filterPatterns(this.patterns, {stylesheets, mutations}); | 705 let patterns = filterPatterns(this.patterns, {stylesheets, mutations}); |
| 706 | 706 |
| 707 let selectors = []; | 707 let selectors = []; |
| 708 let selectorFilters = []; | 708 let selectorFilters = []; |
| 709 | 709 |
| 710 let elements = []; | 710 let elements = []; |
| 711 let elementFilters = []; | 711 let elementFilters = []; |
| 712 | 712 |
| 713 let cssStyles = []; | 713 let cssStyles = []; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 931 | 931 |
| 932 onLoad(event) | 932 onLoad(event) |
| 933 { | 933 { |
| 934 let stylesheet = event.target.sheet; | 934 let stylesheet = event.target.sheet; |
| 935 if (stylesheet) | 935 if (stylesheet) |
| 936 this.queueFiltering([stylesheet]); | 936 this.queueFiltering([stylesheet]); |
| 937 }, | 937 }, |
| 938 | 938 |
| 939 observe(mutations) | 939 observe(mutations) |
| 940 { | 940 { |
| 941 if (debugInfo) | 941 if (testInfo) |
| 942 { | 942 { |
| 943 // In debug mode, filter out any mutations likely done by us | 943 // In test mode, filter out any mutations likely done by us |
| 944 // (i.e. style="display: none !important"). This makes it easier to | 944 // (i.e. style="display: none !important"). This makes it easier to |
| 945 // observe how the code responds to DOM mutations. | 945 // observe how the code responds to DOM mutations. |
| 946 // | |
| 947 // Note: This also creates the potential for "heisenbugs", but as long as | |
| 948 // this is the only instance it should be manageable. | |
| 949 mutations = mutations.filter( | 946 mutations = mutations.filter( |
| 950 ({type, attributeName, target: {style: newValue}, oldValue}) => | 947 ({type, attributeName, target: {style: newValue}, oldValue}) => |
| 951 !(type == "attributes" && attributeName == "style" && | 948 !(type == "attributes" && attributeName == "style" && |
| 952 newValue.display == "none" && oldValue.display != "none") | 949 newValue.display == "none" && oldValue.display != "none") |
| 953 ); | 950 ); |
| 954 | 951 |
| 955 if (mutations.length == 0) | 952 if (mutations.length == 0) |
| 956 return; | 953 return; |
| 957 } | 954 } |
|
hub
2018/05/24 19:19:09
... and this :-/
There should be a better way to
Manish Jethani
2018/05/25 07:21:25
OK, do you have any suggestions? This is only done
| |
| 958 | 955 |
| 959 this.queueFiltering(null, mutations); | 956 this.queueFiltering(null, mutations); |
| 960 }, | 957 }, |
| 961 | 958 |
| 962 apply(patterns) | 959 apply(patterns) |
| 963 { | 960 { |
| 964 this.patterns = []; | 961 this.patterns = []; |
| 965 for (let pattern of patterns) | 962 for (let pattern of patterns) |
| 966 { | 963 { |
| 967 let selectors = this.parseSelector(pattern.selector); | 964 let selectors = this.parseSelector(pattern.selector); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 980 characterData: shouldObserveCharacterData(this.patterns), | 977 characterData: shouldObserveCharacterData(this.patterns), |
| 981 subtree: true | 978 subtree: true |
| 982 } | 979 } |
| 983 ); | 980 ); |
| 984 this.document.addEventListener("load", this.onLoad.bind(this), true); | 981 this.document.addEventListener("load", this.onLoad.bind(this), true); |
| 985 } | 982 } |
| 986 } | 983 } |
| 987 }; | 984 }; |
| 988 | 985 |
| 989 exports.ElemHideEmulation = ElemHideEmulation; | 986 exports.ElemHideEmulation = ElemHideEmulation; |
| LEFT | RIGHT |