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

Unified Diff: lib/contentFiltering.js

Issue 29893555: Issue 6997 - Use createStyleSheet implementation from core (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Update dependency to 0a316e60de4e Created Sept. 27, 2018, 5:24 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
« no previous file with comments | « dependencies ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/contentFiltering.js
===================================================================
--- a/lib/contentFiltering.js
+++ b/lib/contentFiltering.js
@@ -15,17 +15,17 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/** @module contentFiltering */
"use strict";
const {RegExpFilter} = require("../adblockpluscore/lib/filterClasses");
-const {ElemHide} = require("../adblockpluscore/lib/elemHide");
+const {ElemHide, createStyleSheet} = require("../adblockpluscore/lib/elemHide");
const {ElemHideEmulation} = require("../adblockpluscore/lib/elemHideEmulation");
const {filterNotifier} = require("../adblockpluscore/lib/filterNotifier");
const {Snippets, compileScript} = require("../adblockpluscore/lib/snippets");
const {checkWhitelisted} = require("./whitelisting");
const {extractHostFromFrame} = require("./url");
const {port} = require("./messaging");
const {HitLogger, logRequest} = require("./hitLogger");
const info = require("info");
@@ -38,44 +38,16 @@
const selectorGroupSize = 1024;
let userStyleSheetsSupported = true;
let snippetsLibrarySource = "";
let executableCode = new Map();
-function* splitSelectors(selectors)
-{
- // Chromium's Blink engine supports only up to 8,192 simple selectors, and
- // even fewer compound selectors, in a rule. The exact number of selectors
- // that would work depends on their sizes (e.g. "#foo .bar" has a size of 2).
- // Since we don't know the sizes of the selectors here, we simply split them
- // into groups of 1,024, based on the reasonable assumption that the average
- // selector won't have a size greater than 8. The alternative would be to
- // calculate the sizes of the selectors and divide them up accordingly, but
- // this approach is more efficient and has worked well in practice. In theory
- // this could still lead to some selectors not working on Chromium, but it is
- // highly unlikely.
- // See issue #6298 and https://crbug.com/804179
- for (let i = 0; i < selectors.length; i += selectorGroupSize)
- yield selectors.slice(i, i + selectorGroupSize);
-}
-
-function* createRules(selectors)
-{
- for (let selectorGroup of splitSelectors(selectors))
- yield selectorGroup.join(", ") + " {display: none !important;}";
-}
-
-function createStyleSheet(selectors)
-{
- return Array.from(createRules(selectors)).join("\n");
-}
-
function addStyleSheet(tabId, frameId, styleSheet)
{
try
{
let promise = browser.tabs.insertCSS(tabId, {
code: styleSheet,
cssOrigin: "user",
frameId,
« no previous file with comments | « dependencies ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld