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: Use generator functions Created Jan. 30, 2018, 7:04 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 | 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 selectors; more
434 // therefore chunk the inserted selectors into groups of 200 to be safe. 434 // specifically, it ignores any selectors that start at index 8192 or
435 // (Chrome also has a limit, larger... but we're not certain exactly what it 435 // beyond in the list of plain selectors. In order to avoid spilling
436 // is! Edge apparently has no such limit.) 436 // outside of this range, we simply add multiple rules in groups of up to
437 // [1] - https://github.com/WebKit/webkit/blob/1cb2227f6b2a1035f7bdc46e5ab69 debb75fc1de/Source/WebCore/css/RuleSet.h#L68 437 // 1,024 selectors each.
438 // See issue #6298 and https://crbug.com/804179
438 for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize) 439 for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize)
439 { 440 {
440 let selector = preparedSelectors.slice( 441 let selector = preparedSelectors.slice(
441 i, i + this.selectorGroupSize 442 i, i + this.selectorGroupSize
442 ).join(", "); 443 ).join(", ");
443 this.style.sheet.insertRule(selector + "{display: none !important;}", 444 this.style.sheet.insertRule(selector + "{display: none !important;}",
444 this.style.sheet.cssRules.length); 445 this.style.sheet.cssRules.length);
445 } 446 }
446 }, 447 },
447 448
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 let element = event.target; 530 let element = event.target;
530 if (/^i?frame$/.test(element.localName)) 531 if (/^i?frame$/.test(element.localName))
531 checkCollapse(element); 532 checkCollapse(element);
532 }, true); 533 }, true);
533 } 534 }
534 535
535 window.checkCollapse = checkCollapse; 536 window.checkCollapse = checkCollapse;
536 window.elemhide = elemhide; 537 window.elemhide = elemhide;
537 window.typeMap = typeMap; 538 window.typeMap = typeMap;
538 window.getURLsFromElement = getURLsFromElement; 539 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