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

Unified Diff: lib/cssInjection.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: Created Jan. 25, 2018, 5:12 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include.preload.js ('K') | « include.preload.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/cssInjection.js
===================================================================
--- a/lib/cssInjection.js
+++ b/lib/cssInjection.js
@@ -24,16 +24,35 @@
const {ElemHideEmulation} = require("elemHideEmulation");
const {checkWhitelisted} = require("whitelisting");
const {extractHostFromFrame} = require("url");
const {port} = require("messaging");
const devtools = require("devtools");
const userStyleSheetsSupported = "extensionTypes" in browser &&
"CSSOrigin" in browser.extensionTypes;
+const selectorGroupSize = 200;
+
+function createStyleSheet(selectors)
+{
+ let styleSheet = "";
+
+ // Chromium's Blink engine supports only up to 8,192 selectors; more
kzar 2018/01/25 17:46:47 If we're limited to 8192 why do we go with 200?
Manish Jethani 2018/01/25 18:42:41 It's "up to 8,192" selectors. If you have 8,192 s
Manish Jethani 2018/01/25 18:44:28 This was not technically true by the way but now [
Manish Jethani 2018/01/30 06:19:43 Now that I think about it, maybe we should increas
kzar1 2018/01/30 11:39:59 Sounds good to me, but let's rewrite the comment t
Manish Jethani 2018/01/30 13:15:43 Unfortunately this comment is confusing and techni
+ // specifically, it ignores any selectors that start at index 8192 or beyond
+ // in the list of plain selectors. In order to avoid spilling outside of this
+ // range, we simply add multiple rules in groups of up to 200 selectors each.
+ // See issue #6298 and https://crbug.com/804179
+ for (let i = 0; i < selectors.length; i += selectorGroupSize)
+ {
+ styleSheet += selectors.slice(i, i + selectorGroupSize).join(", ") +
+ " {display: none !important;}\n";
+ }
+
+ return styleSheet;
+}
function addStyleSheet(tabId, frameId, styleSheet)
{
browser.tabs.insertCSS(tabId, {
code: styleSheet,
cssOrigin: "user",
frameId,
matchAboutBlank: true,
@@ -50,17 +69,17 @@
matchAboutBlank: true
});
}
function updateFrameStyles(tabId, frameId, selectors, groupName)
{
let styleSheet = null;
if (selectors.length > 0)
- styleSheet = selectors.join(", ") + "{display: none !important;}";
+ styleSheet = createStyleSheet(selectors);
let frame = ext.getFrame(tabId, frameId);
if (!frame.injectedStyleSheets)
frame.injectedStyleSheets = new Map();
let oldStyleSheet = frame.injectedStyleSheets.get(groupName);
// Ideally we would compare the old and new style sheets and skip this code
« include.preload.js ('K') | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld