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: Check platform and platform version for user stylesheet support Created April 20, 2017, 12:42 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 | ext/background.js » ('j') | lib/css.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
diff --git a/background.js b/background.js
index cb7a861be117f6a390b74ffa1370bb9de50ba33f..243628d159da0c23fab35de53715324de3113d60 100644
--- a/background.js
+++ b/background.js
@@ -21,6 +21,7 @@ const {RegExpFilter} = require("filterClasses");
const {ElemHide} = require("elemHide");
const {checkWhitelisted} = require("whitelisting");
const {extractHostFromFrame} = require("url");
+const {userStylesheetsSupported, hideElements} = require("css");
const {port} = require("messaging");
const devtools = require("devtools");
@@ -45,7 +46,32 @@ port.on("get-selectors", (msg, sender) =>
selectors = [];
}
- return {selectors, trace};
+ if (!userStylesheetsSupported)
+ return {selectors, trace, inject: true};
+
+ return new Promise(resolve =>
+ {
+ hideElements(sender.page.id, sender.frame.id, selectors, error =>
+ {
+ 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') | lib/css.js » ('J')

Powered by Google App Engine
This is Rietveld