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

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

Issue 29494577: Issue 5438 - Observer DOM changes to reapply filters. (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: And now the test, with issues Created Aug. 23, 2017, 12:57 a.m.
Right Patch Set: Addressed comments Created Aug. 26, 2017, 1:44 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 {filterToRegExp, splitSelector} = require("common"); 20 const {filterToRegExp, splitSelector} = require("common");
21 21
22 const MIN_INVOCATION_INTERVAL = 3000; 22 let MIN_INVOCATION_INTERVAL = 3000;
23 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50; 23 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50;
24 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; 24 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i;
25 25
26 /** Return position of node from parent. 26 /** Return position of node from parent.
27 * @param {Node} node the node to find the position of. 27 * @param {Node} node the node to find the position of.
28 * @return {number} One-based index like for :nth-child(), or 0 on error. 28 * @return {number} One-based index like for :nth-child(), or 0 on error.
29 */ 29 */
30 function positionInParent(node) 30 function positionInParent(node)
31 { 31 {
32 let {children} = node.parentNode; 32 let {children} = node.parentNode;
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 return; 495 return;
496 } 496 }
497 } 497 }
498 pattern = null; 498 pattern = null;
499 return processPatterns(); 499 return processPatterns();
500 }; 500 };
501 501
502 processPatterns(); 502 processPatterns();
503 }, 503 },
504 504
505 // This property is only used in the tests
506 // to shorten the invocation interval
507 get MIN_INVOCATION_INTERVAL()
508 {
509 return MIN_INVOCATION_INTERVAL;
510 },
511
512 set MIN_INVOCATION_INTERVAL(interval)
513 {
514 MIN_INVOCATION_INTERVAL = interval;
515 },
516
505 _filteringInProgress: false, 517 _filteringInProgress: false,
506 _lastInvocation: -MIN_INVOCATION_INTERVAL, 518 _lastInvocation: -MIN_INVOCATION_INTERVAL,
507 _scheduledProcessing: null, 519 _scheduledProcessing: null,
508 520
509 /** 521 /**
510 * Re-run filtering either immediately or queued. 522 * Re-run filtering either immediately or queued.
511 * @param {CSSStyleSheet[]} [stylesheets] 523 * @param {CSSStyleSheet[]} [stylesheets]
512 * new stylesheets to be processed. This parameter should be omitted 524 * new stylesheets to be processed. This parameter should be omitted
513 * for DOM modification (full reprocessing required). 525 * for DOM modification (full reprocessing required).
514 */ 526 */
(...skipping 16 matching lines...) Expand all
531 if (!stylesheets) 543 if (!stylesheets)
532 this._scheduledProcessing.stylesheets = null; 544 this._scheduledProcessing.stylesheets = null;
533 else if (this._scheduledProcessing.stylesheets) 545 else if (this._scheduledProcessing.stylesheets)
534 this._scheduledProcessing.stylesheets.push(...stylesheets); 546 this._scheduledProcessing.stylesheets.push(...stylesheets);
535 } 547 }
536 else if (this._filteringInProgress) 548 else if (this._filteringInProgress)
537 { 549 {
538 this._scheduledProcessing = {stylesheets}; 550 this._scheduledProcessing = {stylesheets};
539 } 551 }
540 else if (this.window.performance.now() - 552 else if (this.window.performance.now() -
541 this._lastInvocation < MIN_INVOCATION_INTERVAL) 553 this._lastInvocation < MIN_INVOCATION_INTERVAL)
542 { 554 {
543 this._scheduledProcessing = {stylesheets}; 555 this._scheduledProcessing = {stylesheets};
544 this.window.setTimeout(() => 556 this.window.setTimeout(() =>
545 { 557 {
546 let newStylesheets = this._scheduledProcessing.stylesheets; 558 let newStylesheets = this._scheduledProcessing.stylesheets;
547 this._filteringInProgress = true; 559 this._filteringInProgress = true;
548 this._scheduledProcessing = null; 560 this._scheduledProcessing = null;
549 this._addSelectors(newStylesheets, completion); 561 this._addSelectors(newStylesheets, completion);
550 }, 562 },
551 MIN_INVOCATION_INTERVAL - 563 MIN_INVOCATION_INTERVAL -
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 subtree: true 607 subtree: true
596 } 608 }
597 ); 609 );
598 document.addEventListener("load", this.onLoad.bind(this), true); 610 document.addEventListener("load", this.onLoad.bind(this), true);
599 } 611 }
600 }); 612 });
601 } 613 }
602 }; 614 };
603 615
604 exports.ElemHideEmulation = ElemHideEmulation; 616 exports.ElemHideEmulation = ElemHideEmulation;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld