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

Side by Side Diff: include.preload.js

Issue 29714638: Issue 6446 - Ignore emulated selectors if unchanged (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Make emulatedSelectors member of ElemHide Created March 7, 2018, 6:21 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 ["input", "IMAGE"], 28 ["input", "IMAGE"],
29 ["picture", "IMAGE"], 29 ["picture", "IMAGE"],
30 ["audio", "MEDIA"], 30 ["audio", "MEDIA"],
31 ["video", "MEDIA"], 31 ["video", "MEDIA"],
32 ["frame", "SUBDOCUMENT"], 32 ["frame", "SUBDOCUMENT"],
33 ["iframe", "SUBDOCUMENT"], 33 ["iframe", "SUBDOCUMENT"],
34 ["object", "OBJECT"], 34 ["object", "OBJECT"],
35 ["embed", "OBJECT"] 35 ["embed", "OBJECT"]
36 ]); 36 ]);
37 37
38 function haveSelectorsChanged(selectors, oldSelectors)
39 {
40 if (selectors.length != oldSelectors.length)
41 return true;
42
43 return !selectors.every((selector, index) => selector == oldSelectors[index]);
44 }
45
38 function getURLsFromObjectElement(element) 46 function getURLsFromObjectElement(element)
39 { 47 {
40 let url = element.getAttribute("data"); 48 let url = element.getAttribute("data");
41 if (url) 49 if (url)
42 return [url]; 50 return [url];
43 51
44 for (let child of element.children) 52 for (let child of element.children)
45 { 53 {
46 if (child.localName != "param") 54 if (child.localName != "param")
47 continue; 55 continue;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 }; 348 };
341 349
342 function ElemHide() 350 function ElemHide()
343 { 351 {
344 this.shadow = this.createShadowTree(); 352 this.shadow = this.createShadowTree();
345 this.styles = new Map(); 353 this.styles = new Map();
346 this.tracer = null; 354 this.tracer = null;
347 this.inline = true; 355 this.inline = true;
348 this.inlineEmulated = true; 356 this.inlineEmulated = true;
349 this.emulatedPatterns = null; 357 this.emulatedPatterns = null;
358 this.emulatedSelectors = [];
350 359
351 this.elemHideEmulation = new ElemHideEmulation( 360 this.elemHideEmulation = new ElemHideEmulation(
352 this.addSelectors.bind(this), 361 this.addSelectors.bind(this),
353 this.hideElements.bind(this) 362 this.hideElements.bind(this)
354 ); 363 );
355 } 364 }
356 ElemHide.prototype = { 365 ElemHide.prototype = {
357 selectorGroupSize: 1024, 366 selectorGroupSize: 1024,
358 367
359 createShadowTree() 368 createShadowTree()
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 let selector = preparedSelectors.slice( 456 let selector = preparedSelectors.slice(
448 i, i + this.selectorGroupSize 457 i, i + this.selectorGroupSize
449 ).join(", "); 458 ).join(", ");
450 style.sheet.insertRule(selector + "{display: none !important;}", 459 style.sheet.insertRule(selector + "{display: none !important;}",
451 style.sheet.cssRules.length); 460 style.sheet.cssRules.length);
452 } 461 }
453 }, 462 },
454 463
455 addSelectors(selectors, filters) 464 addSelectors(selectors, filters)
456 { 465 {
466 if (!haveSelectorsChanged(selectors, this.emulatedSelectors))
467 return;
468
469 this.emulatedSelectors = selectors;
470
457 if (this.inline || this.inlineEmulated) 471 if (this.inline || this.inlineEmulated)
458 { 472 {
459 // Insert the style rules inline if we have been instructed by the 473 // Insert the style rules inline if we have been instructed by the
460 // background page to do so. This is usually the case, except on platforms 474 // background page to do so. This is usually the case, except on platforms
461 // that do support user stylesheets via the browser.tabs.insertCSS API 475 // that do support user stylesheets via the browser.tabs.insertCSS API
462 // (Firefox 53 onwards for now and possibly Chrome in the near future). 476 // (Firefox 53 onwards for now and possibly Chrome in the near future).
463 // Once all supported platforms have implemented this API, we can remove 477 // Once all supported platforms have implemented this API, we can remove
464 // the code below. See issue #5090. 478 // the code below. See issue #5090.
465 // Related Chrome and Firefox issues: 479 // Related Chrome and Firefox issues:
466 // https://bugs.chromium.org/p/chromium/issues/detail?id=632009 480 // https://bugs.chromium.org/p/chromium/issues/detail?id=632009
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 let element = event.target; 551 let element = event.target;
538 if (/^i?frame$/.test(element.localName)) 552 if (/^i?frame$/.test(element.localName))
539 checkCollapse(element); 553 checkCollapse(element);
540 }, true); 554 }, true);
541 } 555 }
542 556
543 window.checkCollapse = checkCollapse; 557 window.checkCollapse = checkCollapse;
544 window.elemhide = elemhide; 558 window.elemhide = elemhide;
545 window.typeMap = typeMap; 559 window.typeMap = typeMap;
546 window.getURLsFromElement = getURLsFromElement; 560 window.getURLsFromElement = getURLsFromElement;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld