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

Unified Diff: lib/cssInjection.js

Issue 29545645: Issue 5695 - Use tabs.insertCSS if extensionTypes.CSSOrigin exists (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Sept. 15, 2017, 12:58 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 | « no previous file | 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,43 +21,30 @@
const {RegExpFilter} = require("filterClasses");
const {ElemHide} = require("elemHide");
const {checkWhitelisted} = require("whitelisting");
const {extractHostFromFrame} = require("url");
const {port} = require("messaging");
const devtools = require("devtools");
-let userStylesheetsSupported = true;
+let userStyleSheetsSupported = "extensionTypes" in chrome &&
Manish Jethani 2017/09/15 13:02:42 Note: "style sheet" is actually two words, I've ch
Sebastian Noack 2017/09/15 18:46:37 In which case, does chrome.extensionTypes does not
Manish Jethani 2017/09/15 21:26:08 It doesn't exist on Chrome.
Sebastian Noack 2017/09/15 22:52:44 Indeed. The MDN compatibility information are misl
+ "CSSOrigin" in chrome.extensionTypes;
function hideElements(tabId, frameId, selectors)
{
- let code = selectors.join(", ") + "{display: none !important;}";
-
- try
- {
- chrome.tabs.insertCSS(tabId,
- {
- code,
- cssOrigin: "user",
- frameId,
- matchAboutBlank: true,
- runAt: "document_start"
- }
- );
- return true;
- }
- catch (error)
- {
- if (/\bError processing cssOrigin\b/.test(error.message) == -1)
- throw error;
-
- userStylesheetsSupported = false;
- return false;
- }
+ chrome.tabs.insertCSS(tabId,
Sebastian Noack 2017/09/15 18:46:37 Nit: The additional indentation (and one additiona
Manish Jethani 2017/09/15 21:26:09 Done.
+ {
+ code: selectors.join(", ") + "{display: none !important;}",
+ cssOrigin: "user",
+ frameId,
+ matchAboutBlank: true,
+ runAt: "document_start"
+ }
+ );
}
port.on("elemhide.getSelectors", (msg, sender) =>
{
let selectors;
let trace = devtools && devtools.hasPanel(sender.page);
if (!checkWhitelisted(sender.page, sender.frame,
@@ -71,24 +58,27 @@
specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING
);
}
else
{
selectors = [];
}
- if (selectors.length == 0 || userStylesheetsSupported &&
- hideElements(sender.page.id, sender.frame.id, selectors))
+ if (selectors.length == 0 || userStyleSheetsSupported)
Sebastian Noack 2017/09/15 18:46:37 I had a go before. But you were quicker, getting y
Manish Jethani 2017/09/15 21:26:08 I've incorporated the simplifications and made som
{
+ if (userStyleSheetsSupported && selectors.length > 0)
+ hideElements(sender.page.id, sender.frame.id, selectors);
Manish Jethani 2017/09/15 13:02:42 If userStyleSheetsSupported is true then a call to
+
if (trace)
return {selectors, trace: true, inject: false};
return {trace: false, inject: false};
}
return {selectors, trace, inject: true};
});
port.on("elemhide.injectSelectors", (msg, sender) =>
{
- return hideElements(sender.page.id, sender.frame.id, msg.selectors);
+ if (userStyleSheetsSupported)
Manish Jethani 2017/09/15 13:02:42 Since there's no try...catch in hideElements now,
Sebastian Noack 2017/09/15 18:46:37 It seems no message of this type is send by the co
Manish Jethani 2017/09/15 21:26:09 Done.
+ hideElements(sender.page.id, sender.frame.id, msg.selectors);
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld