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

Delta Between Two Patch Sets: lib/content/elemHideEmulation.js

Issue 29714601: Issue 6437 - Skip elements not affected by DOM mutations (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Ignore mutation targets when using style sheets Created May 13, 2018, 2:49 p.m.
Right Patch Set: Rename debug mode to test mode Created May 18, 2018, 3:41 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | test/browser/elemHideEmulation.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 testInfo = null;
28
29 function setTestMode()
30 {
31 testInfo = {
32 lastProcessedElements: new Set()
33 };
34 }
35
36 exports.setTestMode = setTestMode;
37
38 function getTestInfo()
39 {
40 return testInfo;
41 }
42
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
27 function getCachedPropertyValue(object, name, defaultValueFunc = () => {}) 45 function getCachedPropertyValue(object, name, defaultValueFunc = () => {})
28 { 46 {
29 let value = object[name]; 47 let value = object[name];
30 if (typeof value == "undefined") 48 if (typeof value == "undefined")
31 Object.defineProperty(object, name, {value: value = defaultValueFunc()}); 49 Object.defineProperty(object, name, {value: value = defaultValueFunc()});
32 return value; 50 return value;
33 } 51 }
34 52
35 /** Return position of node from parent. 53 /** Return position of node from parent.
36 * @param {Node} node the node to find the position of. 54 * @param {Node} node the node to find the position of.
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 let iter = evaluate(this._innerSelectors, 0, "", element, styles, 324 let iter = evaluate(this._innerSelectors, 0, "", element, styles,
307 targets); 325 targets);
308 for (let selector of iter) 326 for (let selector of iter)
309 { 327 {
310 if (selector == null) 328 if (selector == null)
311 yield null; 329 yield null;
312 else if (scopedQuerySelector(element, selector)) 330 else if (scopedQuerySelector(element, selector))
313 yield element; 331 yield element;
314 } 332 }
315 yield null; 333 yield null;
334
335 if (testInfo)
336 testInfo.lastProcessedElements.add(element);
316 } 337 }
317 } 338 }
318 } 339 }
319 }; 340 };
320 341
321 function ContainsSelector(textContent) 342 function ContainsSelector(textContent)
322 { 343 {
323 this._regexp = makeRegExpParameter(textContent); 344 this._regexp = makeRegExpParameter(textContent);
324 } 345 }
325 346
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 target.contains(element))) 381 target.contains(element)))
361 { 382 {
362 yield null; 383 yield null;
363 continue; 384 continue;
364 } 385 }
365 386
366 if (this._regexp && this._regexp.test(element.textContent)) 387 if (this._regexp && this._regexp.test(element.textContent))
367 yield element; 388 yield element;
368 else 389 else
369 yield null; 390 yield null;
391
392 if (testInfo)
393 testInfo.lastProcessedElements.add(element);
370 } 394 }
371 } 395 }
372 } 396 }
373 }; 397 };
374 398
375 function PropsSelector(propertyExpression) 399 function PropsSelector(propertyExpression)
376 { 400 {
377 let regexpString; 401 let regexpString;
378 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && 402 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" &&
379 propertyExpression[propertyExpression.length - 1] == "/") 403 propertyExpression[propertyExpression.length - 1] == "/")
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 * @param {MutationRecord[]} [mutations] 692 * @param {MutationRecord[]} [mutations]
669 * 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
670 * made reprocessing necessary. This parameter shouldn't be passed in for 694 * made reprocessing necessary. This parameter shouldn't be passed in for
671 * the initial processing, the entire document will be considered 695 * the initial processing, the entire document will be considered
672 * 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.
673 * @param {function} [done] 697 * @param {function} [done]
674 * Callback to call when done. 698 * Callback to call when done.
675 */ 699 */
676 _addSelectors(stylesheets, mutations, done) 700 _addSelectors(stylesheets, mutations, done)
677 { 701 {
702 if (testInfo)
703 testInfo.lastProcessedElements.clear();
704
678 let patterns = filterPatterns(this.patterns, {stylesheets, mutations}); 705 let patterns = filterPatterns(this.patterns, {stylesheets, mutations});
679 706
680 let selectors = []; 707 let selectors = [];
681 let selectorFilters = []; 708 let selectorFilters = [];
682 709
683 let elements = []; 710 let elements = [];
684 let elementFilters = []; 711 let elementFilters = [];
685 712
686 let cssStyles = []; 713 let cssStyles = [];
687 714
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 931
905 onLoad(event) 932 onLoad(event)
906 { 933 {
907 let stylesheet = event.target.sheet; 934 let stylesheet = event.target.sheet;
908 if (stylesheet) 935 if (stylesheet)
909 this.queueFiltering([stylesheet]); 936 this.queueFiltering([stylesheet]);
910 }, 937 },
911 938
912 observe(mutations) 939 observe(mutations)
913 { 940 {
941 if (testInfo)
942 {
943 // In test mode, filter out any mutations likely done by us
944 // (i.e. style="display: none !important"). This makes it easier to
945 // observe how the code responds to DOM mutations.
946 mutations = mutations.filter(
947 ({type, attributeName, target: {style: newValue}, oldValue}) =>
948 !(type == "attributes" && attributeName == "style" &&
949 newValue.display == "none" && oldValue.display != "none")
950 );
951
952 if (mutations.length == 0)
953 return;
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
955
914 this.queueFiltering(null, mutations); 956 this.queueFiltering(null, mutations);
915 }, 957 },
916 958
917 apply(patterns) 959 apply(patterns)
918 { 960 {
919 this.patterns = []; 961 this.patterns = [];
920 for (let pattern of patterns) 962 for (let pattern of patterns)
921 { 963 {
922 let selectors = this.parseSelector(pattern.selector); 964 let selectors = this.parseSelector(pattern.selector);
923 if (selectors != null && selectors.length > 0) 965 if (selectors != null && selectors.length > 0)
(...skipping 11 matching lines...) Expand all
935 characterData: shouldObserveCharacterData(this.patterns), 977 characterData: shouldObserveCharacterData(this.patterns),
936 subtree: true 978 subtree: true
937 } 979 }
938 ); 980 );
939 this.document.addEventListener("load", this.onLoad.bind(this), true); 981 this.document.addEventListener("load", this.onLoad.bind(this), true);
940 } 982 }
941 } 983 }
942 }; 984 };
943 985
944 exports.ElemHideEmulation = ElemHideEmulation; 986 exports.ElemHideEmulation = ElemHideEmulation;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld