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

Unified Diff: lib/cssInjection.js

Issue 29564767: Issue 242 - Use user style sheets on Chromium (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Rewrite Created Jan. 31, 2018, 8:19 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
« 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
@@ -21,19 +21,25 @@
const {RegExpFilter} = require("filterClasses");
const {ElemHide} = require("elemHide");
const {ElemHideEmulation} = require("elemHideEmulation");
const {checkWhitelisted} = require("whitelisting");
const {extractHostFromFrame} = require("url");
const {port} = require("messaging");
const devtools = require("devtools");
+const info = require("info");
-const userStyleSheetsSupported = "extensionTypes" in browser &&
- "CSSOrigin" in browser.extensionTypes;
+const userStyleSheetsSupported = ("extensionTypes" in browser &&
+ "CSSOrigin" in browser.extensionTypes) ||
+ (info.platform == "chromium" &&
+ parseInt(info.platformVersion, 10) >= 66);
Sebastian Noack 2018/01/31 11:23:37 Perhaps, we should consider going back to the try-
Manish Jethani 2018/01/31 12:36:27 What if Edge adds support for cssOrigin but behave
+const styleSheetRemovalSupported = "removeCSS" in browser.tabs &&
+ info.platform != "chromium";
kzar 2018/01/31 11:11:32 IMO we only know removeCSS works on Gecko and so w
Sebastian Noack 2018/01/31 11:23:37 Why not just checking for presence of "removeCSS"?
kzar 2018/01/31 11:25:29 Well as we discussed in IRC don't we agree it woul
Sebastian Noack 2018/01/31 11:54:44 Well, we were talking about cssOrigin, which is no
kzar 2018/01/31 11:57:56 Fair enough, if you both agree to do it that way I
Manish Jethani 2018/01/31 12:36:27 Makes sense. Done.
Manish Jethani 2018/01/31 12:36:27 With tabs.removeCSS specifically we're thinking of
Manish Jethani 2018/01/31 12:36:27 See my other comment. In the case of tabs.removeCS
+
const selectorGroupSize = 1024;
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
@@ -67,16 +73,23 @@
frameId,
matchAboutBlank: true,
runAt: "document_start"
});
}
function removeStyleSheet(tabId, frameId, styleSheet)
{
+ // Chromium's support for tabs.removeCSS is still a work in progress and the
kzar 2018/01/31 11:11:32 IMO this comment should go by the styleSheetRemova
Manish Jethani 2018/01/31 12:36:27 Done.
+ // API is likely to be different from Firefox's; for now we just don't use it
+ // at all, even if it's available.
+ // See https://crbug.com/608854
+ if (!styleSheetRemovalSupported)
+ return;
+
browser.tabs.removeCSS(tabId, {
code: styleSheet,
cssOrigin: "user",
frameId,
matchAboutBlank: true
});
}
@@ -137,16 +150,23 @@
if (!inline)
updateFrameStyles(sender.page.id, sender.frame.id, selectors);
let response = {trace, inline, emulatedPatterns};
if (trace || inline)
response.selectors = selectors;
+ // If we can't remove user style sheets using tabs.removeCSS, we'll only keep
+ // adding them, which could cause problems with emulated filters as described
+ // in issue #5864. Instead, we can just ask the content script to add styles
+ // for emulated filters inline.
+ if (!styleSheetRemovalSupported)
+ response.inlineEmulated = true;
+
return response;
});
port.on("elemhide.injectSelectors", (message, sender) =>
{
updateFrameStyles(sender.page.id, sender.frame.id, message.selectors,
message.groupName);
});
« include.preload.js ('K') | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld