OLD | NEW |
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 {ElemHideEmulation} = require("elemHideEmulation"); | 24 const {ElemHideEmulation} = require("elemHideEmulation"); |
25 const {checkWhitelisted} = require("whitelisting"); | 25 const {checkWhitelisted} = require("whitelisting"); |
26 const {extractHostFromFrame} = require("url"); | 26 const {extractHostFromFrame} = require("url"); |
27 const {port} = require("messaging"); | 27 const {port} = require("messaging"); |
28 const devtools = require("devtools"); | 28 const devtools = require("devtools"); |
| 29 const info = require("info"); |
29 | 30 |
30 const userStyleSheetsSupported = "extensionTypes" in chrome && | 31 const cssOriginSupported = "extensionTypes" in chrome && |
31 "CSSOrigin" in chrome.extensionTypes; | 32 "CSSOrigin" in chrome.extensionTypes; |
| 33 const userStyleSheetsSupported = cssOriginSupported || |
| 34 (info.platform == "chromium" && |
| 35 parseInt(info.platformVersion, 10) >= 60); |
32 | 36 |
33 function hideElements(tabId, frameId, selectors) | 37 function hideElements(tabId, frameId, selectors) |
34 { | 38 { |
35 chrome.tabs.insertCSS(tabId, { | 39 let options = { |
36 code: selectors.join(", ") + "{display: none !important;}", | 40 code: selectors.join(", ") + "{display: none !important;}", |
37 cssOrigin: "user", | |
38 frameId, | 41 frameId, |
39 matchAboutBlank: true, | 42 matchAboutBlank: true, |
40 runAt: "document_start" | 43 runAt: "document_start" |
41 }); | 44 }; |
| 45 |
| 46 if (cssOriginSupported) |
| 47 options.cssOrigin = "user"; |
| 48 |
| 49 chrome.tabs.insertCSS(tabId, options); |
42 } | 50 } |
43 | 51 |
44 port.on("elemhide.getSelectors", (msg, sender) => | 52 port.on("elemhide.getSelectors", (msg, sender) => |
45 { | 53 { |
46 let selectors = []; | 54 let selectors = []; |
47 let emulatedPatterns = []; | 55 let emulatedPatterns = []; |
48 let trace = devtools && devtools.hasPanel(sender.page); | 56 let trace = devtools && devtools.hasPanel(sender.page); |
49 let inject = !userStyleSheetsSupported; | 57 let inject = !userStyleSheetsSupported; |
50 | 58 |
51 if (!checkWhitelisted(sender.page, sender.frame, | 59 if (!checkWhitelisted(sender.page, sender.frame, |
(...skipping 20 matching lines...) Expand all Loading... |
72 if (trace || inject) | 80 if (trace || inject) |
73 response.selectors = selectors; | 81 response.selectors = selectors; |
74 | 82 |
75 return response; | 83 return response; |
76 }); | 84 }); |
77 | 85 |
78 port.on("elemhide.injectSelectors", (msg, sender) => | 86 port.on("elemhide.injectSelectors", (msg, sender) => |
79 { | 87 { |
80 hideElements(sender.page.id, sender.frame.id, msg.selectors); | 88 hideElements(sender.page.id, sender.frame.id, msg.selectors); |
81 }); | 89 }); |
OLD | NEW |