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

Unified Diff: background.js

Issue 29410607: Issue 5090 - Use user stylesheets for element hiding if possible (Closed)
Patch Set: Created April 12, 2017, 10:59 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 | « no previous file | ext/background.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
diff --git a/background.js b/background.js
index cb7a861be117f6a390b74ffa1370bb9de50ba33f..0d67a098747746acd0ca6c7d6da2441fdd36635c 100644
--- a/background.js
+++ b/background.js
@@ -21,9 +21,12 @@ const {RegExpFilter} = require("filterClasses");
const {ElemHide} = require("elemHide");
const {checkWhitelisted} = require("whitelisting");
const {extractHostFromFrame} = require("url");
+const {hideElements} = require("css");
const {port} = require("messaging");
const devtools = require("devtools");
+let tryInsertCSS = typeof browser != "undefined";
+
port.on("get-selectors", (msg, sender) =>
{
let selectors;
@@ -45,7 +48,35 @@ port.on("get-selectors", (msg, sender) =>
selectors = [];
}
- return {selectors, trace};
+ if (!tryInsertCSS)
Sebastian Noack 2017/04/12 12:21:18 Chrome and Firefox should use the same code path.
Manish Jethani 2017/04/12 12:32:30 We have to remember whether it failed so we don't
Sebastian Noack 2017/04/12 12:54:43 Chrome is also going to add support for user style
Wladimir Palant 2017/04/12 13:37:57 Are you certain? I am not aware of Firefox exposin
Manish Jethani 2017/04/12 14:27:01 My bad, it is implemented but it takes a callback
+ return {selectors, trace, inject: true};
+
+ return new Promise(resolve =>
+ {
+ hideElements(sender.page.id, sender.frame.id, selectors, error =>
+ {
+ if (error && /\bError processing cssOrigin\b/.test(error.message) != -1)
+ tryInsertCSS = false;
+
+ let response = {trace, inject: !!error};
+
+ if (trace || error)
+ response.selectors = selectors;
+
+ resolve(response);
+ });
+ });
+});
+
+port.on("hide-elements", (msg, sender) =>
Sebastian Noack 2017/04/12 12:21:18 This is out of scope of what is defined in the iss
Wladimir Palant 2017/04/12 12:25:56 Yes, this is an aspect we missed when describing t
Sebastian Noack 2017/04/12 12:54:43 Keep, in mind that with -abp-selector/:has there w
+{
+ return new Promise(resolve =>
+ {
+ hideElements(sender.page.id, sender.frame.id, msg.selectors, error =>
+ {
+ resolve({success: !error});
+ });
+ });
});
port.on("forward", (msg, sender) =>
« no previous file with comments | « no previous file | ext/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld