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: Skip false properties Created Sept. 15, 2017, 9:23 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
@@ -21,74 +21,57 @@
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 &&
Sebastian Noack 2017/09/15 22:52:44 Use const here?
Manish Jethani 2017/09/17 13:51:37 Done.
+ "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, {
+ code: selectors.join(", ") + "{display: none !important;}",
+ cssOrigin: "user",
+ frameId,
+ matchAboutBlank: true,
+ runAt: "document_start"
+ });
}
port.on("elemhide.getSelectors", (msg, sender) =>
{
- let selectors;
+ let selectors = null;
let trace = devtools && devtools.hasPanel(sender.page);
if (!checkWhitelisted(sender.page, sender.frame,
RegExpFilter.typeMap.DOCUMENT |
RegExpFilter.typeMap.ELEMHIDE))
{
let specificOnly = checkWhitelisted(sender.page, sender.frame,
RegExpFilter.typeMap.GENERICHIDE);
selectors = ElemHide.getSelectorsForDomain(
extractHostFromFrame(sender.frame),
specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING
);
}
- else
- {
- selectors = [];
- }
+
+ if (!selectors || selectors.length == 0)
+ return {};
Sebastian Noack 2017/09/15 22:52:44 Actually, we have to pass "trace", even if there a
Manish Jethani 2017/09/17 13:51:37 Done. See my other comments.
+
+ if (!userStyleSheetsSupported)
Manish Jethani 2017/09/15 21:26:09 I've kept the userStyleSheetsSupported flag since
+ return {selectors, trace, inject: true};
- if (selectors.length == 0 || userStylesheetsSupported &&
- hideElements(sender.page.id, sender.frame.id, selectors))
- {
- if (trace)
- return {selectors, trace: true, inject: false};
+ hideElements(sender.page.id, sender.frame.id, selectors);
- return {trace: false, inject: false};
- }
+ if (trace)
Manish Jethani 2017/09/15 21:26:09 This return statement could be merged into the nex
Sebastian Noack 2017/09/15 22:52:44 I see the point for not including selectors=null (
Manish Jethani 2017/09/17 13:51:37 Done.
+ return {selectors, trace: true};
- return {selectors, trace, inject: true};
+ return {};
});
port.on("elemhide.injectSelectors", (msg, sender) =>
{
- return hideElements(sender.page.id, sender.frame.id, msg.selectors);
+ hideElements(sender.page.id, sender.frame.id, msg.selectors);
});
« include.preload.js ('K') | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld