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

Delta Between Two Patch Sets: lib/cssInjection.js

Issue 29545645: Issue 5695 - Use tabs.insertCSS if extensionTypes.CSSOrigin exists (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Created Sept. 15, 2017, 12:58 p.m.
Right Patch Set: Flatten out logic and remove blank line Created Sept. 20, 2017, 2:14 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « include.preload.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** @module cssInjection */ 18 /** @module cssInjection */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {RegExpFilter} = require("filterClasses"); 22 const {RegExpFilter} = require("filterClasses");
23 const {ElemHide} = require("elemHide"); 23 const {ElemHide} = require("elemHide");
24 const {checkWhitelisted} = require("whitelisting"); 24 const {checkWhitelisted} = require("whitelisting");
25 const {extractHostFromFrame} = require("url"); 25 const {extractHostFromFrame} = require("url");
26 const {port} = require("messaging"); 26 const {port} = require("messaging");
27 const devtools = require("devtools"); 27 const devtools = require("devtools");
28 28
29 let userStyleSheetsSupported = "extensionTypes" in chrome && 29 const 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
30 "CSSOrigin" in chrome.extensionTypes; 30 "CSSOrigin" in chrome.extensionTypes;
31 31
32 function hideElements(tabId, frameId, selectors) 32 function hideElements(tabId, frameId, selectors)
33 { 33 {
34 chrome.tabs.insertCSS(tabId, 34 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.
35 { 35 code: selectors.join(", ") + "{display: none !important;}",
36 code: selectors.join(", ") + "{display: none !important;}", 36 cssOrigin: "user",
37 cssOrigin: "user", 37 frameId,
38 frameId, 38 matchAboutBlank: true,
39 matchAboutBlank: true, 39 runAt: "document_start"
40 runAt: "document_start" 40 });
41 }
42 );
43 } 41 }
44 42
45 port.on("elemhide.getSelectors", (msg, sender) => 43 port.on("elemhide.getSelectors", (msg, sender) =>
46 { 44 {
47 let selectors; 45 let selectors = [];
48 let trace = devtools && devtools.hasPanel(sender.page); 46 let trace = devtools && devtools.hasPanel(sender.page);
47 let inject = !userStyleSheetsSupported;
49 48
50 if (!checkWhitelisted(sender.page, sender.frame, 49 if (!checkWhitelisted(sender.page, sender.frame,
51 RegExpFilter.typeMap.DOCUMENT | 50 RegExpFilter.typeMap.DOCUMENT |
52 RegExpFilter.typeMap.ELEMHIDE)) 51 RegExpFilter.typeMap.ELEMHIDE))
53 { 52 {
54 let specificOnly = checkWhitelisted(sender.page, sender.frame, 53 let specificOnly = checkWhitelisted(sender.page, sender.frame,
55 RegExpFilter.typeMap.GENERICHIDE); 54 RegExpFilter.typeMap.GENERICHIDE);
56 selectors = ElemHide.getSelectorsForDomain( 55 selectors = ElemHide.getSelectorsForDomain(
57 extractHostFromFrame(sender.frame), 56 extractHostFromFrame(sender.frame),
58 specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING 57 specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING
59 ); 58 );
60 } 59 }
61 else
62 {
63 selectors = [];
64 }
65 60
66 if (selectors.length == 0 || userStyleSheetsSupported) 61 if (!inject && selectors.length > 0)
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
67 { 62 hideElements(sender.page.id, sender.frame.id, selectors);
68 if (userStyleSheetsSupported && selectors.length > 0)
69 hideElements(sender.page.id, sender.frame.id, selectors);
Manish Jethani 2017/09/15 13:02:42 If userStyleSheetsSupported is true then a call to
70 63
71 if (trace) 64 let response = {trace, inject};
72 return {selectors, trace: true, inject: false}; 65 if (trace || inject)
66 response.selectors = selectors;
73 67
74 return {trace: false, inject: false}; 68 return response;
75 }
76
77 return {selectors, trace, inject: true};
78 }); 69 });
79 70
80 port.on("elemhide.injectSelectors", (msg, sender) => 71 port.on("elemhide.injectSelectors", (msg, sender) =>
81 { 72 {
82 if (userStyleSheetsSupported) 73 hideElements(sender.page.id, sender.frame.id, msg.selectors);
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.
83 hideElements(sender.page.id, sender.frame.id, msg.selectors);
84 }); 74 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld