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: Increase group size to 1,024 Created Jan. 30, 2018, 6:30 a.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
« no previous file with comments | « 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,36 @@
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 = 1024;
+
+function createStyleSheet(selectors)
+{
+ let styleSheet = "";
+
+ // Chromium's Blink engine supports only up to 8,192 selectors; more
+ // 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 1,024 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 +70,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
« no previous file with comments | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld