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

Delta Between Two Patch Sets: 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/
Left Patch Set: Use generator functions Created Jan. 30, 2018, 7:04 a.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/cssInjection.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
(...skipping 412 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 // Chromium's Blink engine supports only up to 8,192 selectors; more 433 // Chromium's Blink engine supports only up to 8,192 simple selectors, and
434 // specifically, it ignores any selectors that start at index 8192 or 434 // even fewer compound selectors, in a rule. The exact number of selectors
435 // beyond in the list of plain selectors. In order to avoid spilling 435 // that would work depends on their sizes (e.g. "#foo .bar" has a
436 // outside of this range, we simply add multiple rules in groups of up to 436 // size of 2). Since we don't know the sizes of the selectors here, we
437 // 1,024 selectors each. 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.
438 // See issue #6298 and https://crbug.com/804179 443 // See issue #6298 and https://crbug.com/804179
439 for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize) 444 for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize)
440 { 445 {
441 let selector = preparedSelectors.slice( 446 let selector = preparedSelectors.slice(
442 i, i + this.selectorGroupSize 447 i, i + this.selectorGroupSize
443 ).join(", "); 448 ).join(", ");
444 this.style.sheet.insertRule(selector + "{display: none !important;}", 449 this.style.sheet.insertRule(selector + "{display: none !important;}",
445 this.style.sheet.cssRules.length); 450 this.style.sheet.cssRules.length);
446 } 451 }
447 }, 452 },
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 let element = event.target; 535 let element = event.target;
531 if (/^i?frame$/.test(element.localName)) 536 if (/^i?frame$/.test(element.localName))
532 checkCollapse(element); 537 checkCollapse(element);
533 }, true); 538 }, true);
534 } 539 }
535 540
536 window.checkCollapse = checkCollapse; 541 window.checkCollapse = checkCollapse;
537 window.elemhide = elemhide; 542 window.elemhide = elemhide;
538 window.typeMap = typeMap; 543 window.typeMap = typeMap;
539 window.getURLsFromElement = getURLsFromElement; 544 window.getURLsFromElement = getURLsFromElement;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld