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

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

Issue 29728690: Issue 6504, 6458, 6446 - Update selectors based on DOM mutations (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Encapsulate selector management in CSSSelectorManager class Created March 21, 2018, 2:32 p.m.
Right Patch Set: Add special case check for documents with no extended selectors Created March 21, 2018, 3:28 p.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 | no next file » | 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
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } 475 }
476 476
477 function CSSSelectorManager(root) 477 function CSSSelectorManager(root)
478 { 478 {
479 this._root = root; 479 this._root = root;
480 480
481 this.selectors = []; 481 this.selectors = [];
482 this.filters = []; 482 this.filters = [];
483 483
484 this._lookup = new Set(); 484 this._lookup = new Set();
485
486 this._extended = false;
485 } 487 }
486 488
487 CSSSelectorManager.prototype = { 489 CSSSelectorManager.prototype = {
488 add(selectors, filters) 490 add(selectors, filters)
489 { 491 {
490 for (let i = 0; i < selectors.length; i++) 492 for (let i = 0; i < selectors.length; i++)
491 { 493 {
492 this.selectors.push(selectors[i]); 494 this.selectors.push(selectors[i]);
493 this.filters.push(filters[i]); 495 this.filters.push(filters[i]);
494 496
495 this._lookup.add(selectors[i]); 497 this._lookup.add(selectors[i]);
498
499 if (!this._extended && selectors[i].startsWith(":root > "))
500 this._extended = true;
496 } 501 }
497 }, 502 },
498 503
499 has(selector) 504 has(selector)
500 { 505 {
501 return this._lookup.has(selector); 506 return this._lookup.has(selector);
502 }, 507 },
503 508
504 setAt(index, selector) 509 setAt(index, selector)
505 { 510 {
506 this._lookup.delete(this.selectors[index]); 511 this._lookup.delete(this.selectors[index]);
507 this._lookup.add(selector); 512 this._lookup.add(selector);
508 513
509 this.selectors[index] = selector; 514 this.selectors[index] = selector;
510 }, 515 },
511 516
512 deleteAt(index) 517 deleteAt(index)
513 { 518 {
514 this._lookup.delete(this.selectors[index]); 519 this._lookup.delete(this.selectors[index]);
515 520
516 this.selectors.splice(index, 1); 521 this.selectors.splice(index, 1);
517 this.filters.splice(index, 1); 522 this.filters.splice(index, 1);
518 }, 523 },
519 524
520 update(mutations) 525 update(mutations)
521 { 526 {
527 // If there are no extended CSS selectors (i.e. :-abp-*), there's nothing
528 // to update.
529 if (!this._extended || this.selectors.length == 0)
Manish Jethani 2018/03/21 15:35:26 This is useful. In EasyList the number of sites wi
530 return false;
531
522 let changed = false; 532 let changed = false;
523 533
524 for (let mutation of mutations) 534 for (let mutation of mutations)
525 { 535 {
526 if (this._updateForMutation(mutation)) 536 if (this._updateForMutation(mutation))
527 changed = true; 537 changed = true;
528 } 538 }
529 539
530 return changed; 540 return changed;
531 }, 541 },
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 onLoad(event) 943 onLoad(event)
934 { 944 {
935 let stylesheet = event.target.sheet; 945 let stylesheet = event.target.sheet;
936 if (stylesheet) 946 if (stylesheet)
937 this.queueFiltering([stylesheet]); 947 this.queueFiltering([stylesheet]);
938 }, 948 },
939 949
940 observe(mutations) 950 observe(mutations)
941 { 951 {
942 if (this.css.update(mutations)) 952 if (this.css.update(mutations))
943 this.addSelectorsFunc(this.css.selectors, this.css.filters); 953 this.addSelectorsFunc(this.css.selectors, this.css.filters);
hub 2018/03/23 15:54:25 My concern here is that the intent of queueFilteri
Manish Jethani 2018/03/23 16:55:33 The thing is that I'm trying to avoid running full
944 954
945 this.queueFiltering(null, mutations); 955 this.queueFiltering(null, mutations);
946 }, 956 },
947 957
948 apply(patterns) 958 apply(patterns)
949 { 959 {
950 this.patterns = []; 960 this.patterns = [];
951 for (let pattern of patterns) 961 for (let pattern of patterns)
952 { 962 {
953 let selectors = this.parseSelector(pattern.selector); 963 let selectors = this.parseSelector(pattern.selector);
(...skipping 12 matching lines...) Expand all
966 characterData: shouldObserveCharacterData(this.patterns), 976 characterData: shouldObserveCharacterData(this.patterns),
967 subtree: true 977 subtree: true
968 } 978 }
969 ); 979 );
970 this.document.addEventListener("load", this.onLoad.bind(this), true); 980 this.document.addEventListener("load", this.onLoad.bind(this), true);
971 } 981 }
972 } 982 }
973 }; 983 };
974 984
975 exports.ElemHideEmulation = ElemHideEmulation; 985 exports.ElemHideEmulation = ElemHideEmulation;
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld