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: Add comment explaining when we inject styles Created April 18, 2017, 9:20 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..1ef27a2a2af6eff21491c1e782fc4d3e603d75da 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 = true;
+
port.on("get-selectors", (msg, sender) =>
{
let selectors;
@@ -45,7 +48,35 @@ port.on("get-selectors", (msg, sender) =>
selectors = [];
}
- return {selectors, trace};
+ if (!tryInsertCSS)
+ 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)
kzar 2017/04/20 06:17:15 From the discussion in the Chromium issue it seems
Manish Jethani 2017/04/20 12:50:32 Yeah, this makes sense. I've added a userStyleshee
kzar 2017/04/21 11:20:22 Nice, looks good. Could you update the issue descr
+ tryInsertCSS = false;
+
+ let response = {trace, inject: !!error};
+
+ if (trace || error)
+ response.selectors = selectors;
+
+ resolve(response);
+ });
+ });
+});
+
+port.on("hide-elements", (msg, sender) =>
+{
+ 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