Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 && |
Sebastian Noack
2017/09/15 22:52:44
Use const here?
Manish Jethani
2017/09/17 13:51:37
Done.
| |
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, { |
35 code: selectors.join(", ") + "{display: none !important;}", | 35 code: selectors.join(", ") + "{display: none !important;}", |
36 cssOrigin: "user", | 36 cssOrigin: "user", |
37 frameId, | 37 frameId, |
38 matchAboutBlank: true, | 38 matchAboutBlank: true, |
39 runAt: "document_start" | 39 runAt: "document_start" |
40 }); | 40 }); |
41 } | 41 } |
42 | 42 |
43 port.on("elemhide.getSelectors", (msg, sender) => | 43 port.on("elemhide.getSelectors", (msg, sender) => |
44 { | 44 { |
45 let selectors = null; | 45 let selectors = []; |
46 let trace = devtools && devtools.hasPanel(sender.page); | 46 let trace = devtools && devtools.hasPanel(sender.page); |
47 let inject = !userStyleSheetsSupported; | |
47 | 48 |
48 if (!checkWhitelisted(sender.page, sender.frame, | 49 if (!checkWhitelisted(sender.page, sender.frame, |
49 RegExpFilter.typeMap.DOCUMENT | | 50 RegExpFilter.typeMap.DOCUMENT | |
50 RegExpFilter.typeMap.ELEMHIDE)) | 51 RegExpFilter.typeMap.ELEMHIDE)) |
51 { | 52 { |
52 let specificOnly = checkWhitelisted(sender.page, sender.frame, | 53 let specificOnly = checkWhitelisted(sender.page, sender.frame, |
53 RegExpFilter.typeMap.GENERICHIDE); | 54 RegExpFilter.typeMap.GENERICHIDE); |
54 selectors = ElemHide.getSelectorsForDomain( | 55 selectors = ElemHide.getSelectorsForDomain( |
55 extractHostFromFrame(sender.frame), | 56 extractHostFromFrame(sender.frame), |
56 specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING | 57 specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING |
57 ); | 58 ); |
58 } | 59 } |
59 | 60 |
60 if (!selectors || selectors.length == 0) | 61 if (!inject && selectors.length > 0) |
61 return {}; | 62 hideElements(sender.page.id, sender.frame.id, selectors); |
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.
| |
62 | 63 |
63 if (!userStyleSheetsSupported) | 64 let response = {trace, inject}; |
Manish Jethani
2017/09/15 21:26:09
I've kept the userStyleSheetsSupported flag since
| |
64 return {selectors, trace, inject: true}; | 65 if (trace || inject) |
66 response.selectors = selectors; | |
65 | 67 |
66 hideElements(sender.page.id, sender.frame.id, selectors); | 68 return response; |
67 | |
68 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.
| |
69 return {selectors, trace: true}; | |
70 | |
71 return {}; | |
72 }); | 69 }); |
73 | 70 |
74 port.on("elemhide.injectSelectors", (msg, sender) => | 71 port.on("elemhide.injectSelectors", (msg, sender) => |
75 { | 72 { |
76 hideElements(sender.page.id, sender.frame.id, msg.selectors); | 73 hideElements(sender.page.id, sender.frame.id, msg.selectors); |
77 }); | 74 }); |
LEFT | RIGHT |