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

Side by Side Diff: include.preload.js

Issue 29679796: Issue 6298 - Split injected CSS hiding rule into groups of 1,024 selectors (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Update comment explaining why we split the selectors into groups of 1,024 Created Jan. 30, 2018, 1:39 p.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 | lib/cssInjection.js » ('j') | 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 this.tracer = null; 346 this.tracer = null;
347 this.inline = true; 347 this.inline = true;
348 this.emulatedPatterns = null; 348 this.emulatedPatterns = null;
349 349
350 this.elemHideEmulation = new ElemHideEmulation( 350 this.elemHideEmulation = new ElemHideEmulation(
351 this.addSelectors.bind(this), 351 this.addSelectors.bind(this),
352 this.hideElements.bind(this) 352 this.hideElements.bind(this)
353 ); 353 );
354 } 354 }
355 ElemHide.prototype = { 355 ElemHide.prototype = {
356 selectorGroupSize: 200, 356 selectorGroupSize: 1024,
357 357
358 createShadowTree() 358 createShadowTree()
359 { 359 {
360 // Use Shadow DOM if available as to not mess with with web pages that 360 // Use Shadow DOM if available as to not mess with with web pages that
361 // rely on the order of their own <style> tags (#309). However, creating 361 // rely on the order of their own <style> tags (#309). However, creating
362 // a shadow root breaks running CSS transitions. So we have to create 362 // a shadow root breaks running CSS transitions. So we have to create
363 // the shadow root before transistions might start (#452). 363 // the shadow root before transistions might start (#452).
364 if (!("createShadowRoot" in document.documentElement)) 364 if (!("createShadowRoot" in document.documentElement))
365 return null; 365 return null;
366 366
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 let subSelectors = splitSelector(selector); 423 let subSelectors = splitSelector(selector);
424 for (let subSelector of subSelectors) 424 for (let subSelector of subSelectors)
425 preparedSelectors.push("::content " + subSelector); 425 preparedSelectors.push("::content " + subSelector);
426 } 426 }
427 } 427 }
428 else 428 else
429 { 429 {
430 preparedSelectors = selectors; 430 preparedSelectors = selectors;
431 } 431 }
432 432
433 // Safari only allows 8192 primitive selectors to be injected at once[1], we 433 // Chromium's Blink engine supports only up to 8,192 simple selectors, and
434 // therefore chunk the inserted selectors into groups of 200 to be safe. 434 // even fewer compound selectors, in a rule. The exact number of selectors
435 // (Chrome also has a limit, larger... but we're not certain exactly what it 435 // that would work depends on their sizes (e.g. "#foo .bar" has a
436 // is! Edge apparently has no such limit.) 436 // size of 2). Since we don't know the sizes of the selectors here, we
437 // [1] - https://github.com/WebKit/webkit/blob/1cb2227f6b2a1035f7bdc46e5ab69 debb75fc1de/Source/WebCore/css/RuleSet.h#L68 437 // simply split them into groups of 1,024, based on the reasonable
438 // assumption that the average selector won't have a size greater than 8.
439 // The alternative would be to calculate the sizes of the selectors and
440 // divide them up accordingly, but this approach is more efficient and has
441 // worked well in practice. In theory this could still lead to some
442 // selectors not working on Chromium, but it is highly unlikely.
443 // See issue #6298 and https://crbug.com/804179
438 for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize) 444 for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize)
439 { 445 {
440 let selector = preparedSelectors.slice( 446 let selector = preparedSelectors.slice(
441 i, i + this.selectorGroupSize 447 i, i + this.selectorGroupSize
442 ).join(", "); 448 ).join(", ");
443 this.style.sheet.insertRule(selector + "{display: none !important;}", 449 this.style.sheet.insertRule(selector + "{display: none !important;}",
444 this.style.sheet.cssRules.length); 450 this.style.sheet.cssRules.length);
445 } 451 }
446 }, 452 },
447 453
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 let element = event.target; 535 let element = event.target;
530 if (/^i?frame$/.test(element.localName)) 536 if (/^i?frame$/.test(element.localName))
531 checkCollapse(element); 537 checkCollapse(element);
532 }, true); 538 }, true);
533 } 539 }
534 540
535 window.checkCollapse = checkCollapse; 541 window.checkCollapse = checkCollapse;
536 window.elemhide = elemhide; 542 window.elemhide = elemhide;
537 window.typeMap = typeMap; 543 window.typeMap = typeMap;
538 window.getURLsFromElement = getURLsFromElement; 544 window.getURLsFromElement = getURLsFromElement;
OLDNEW
« no previous file with comments | « no previous file | lib/cssInjection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld