Left: | ||
Right: |
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 browser && | 31 const userStyleSheetsSupported = ("extensionTypes" in browser && |
31 "CSSOrigin" in browser.extensionTypes; | 32 "CSSOrigin" in browser.extensionTypes) || |
33 (info.platform == "chromium" && | |
34 parseInt(info.platformVersion, 10) >= 66); | |
Sebastian Noack
2018/01/31 11:23:37
Perhaps, we should consider going back to the try-
Manish Jethani
2018/01/31 12:36:27
What if Edge adds support for cssOrigin but behave
| |
35 const styleSheetRemovalSupported = "removeCSS" in browser.tabs && | |
36 info.platform != "chromium"; | |
kzar
2018/01/31 11:11:32
IMO we only know removeCSS works on Gecko and so w
Sebastian Noack
2018/01/31 11:23:37
Why not just checking for presence of "removeCSS"?
kzar
2018/01/31 11:25:29
Well as we discussed in IRC don't we agree it woul
Sebastian Noack
2018/01/31 11:54:44
Well, we were talking about cssOrigin, which is no
kzar
2018/01/31 11:57:56
Fair enough, if you both agree to do it that way I
Manish Jethani
2018/01/31 12:36:27
Makes sense.
Done.
Manish Jethani
2018/01/31 12:36:27
With tabs.removeCSS specifically we're thinking of
Manish Jethani
2018/01/31 12:36:27
See my other comment. In the case of tabs.removeCS
| |
37 | |
32 const selectorGroupSize = 1024; | 38 const selectorGroupSize = 1024; |
33 | 39 |
34 function* splitSelectors(selectors) | 40 function* splitSelectors(selectors) |
35 { | 41 { |
36 // Chromium's Blink engine supports only up to 8,192 simple selectors, and | 42 // Chromium's Blink engine supports only up to 8,192 simple selectors, and |
37 // even fewer compound selectors, in a rule. The exact number of selectors | 43 // even fewer compound selectors, in a rule. The exact number of selectors |
38 // that would work depends on their sizes (e.g. "#foo .bar" has a size of 2). | 44 // that would work depends on their sizes (e.g. "#foo .bar" has a size of 2). |
39 // Since we don't know the sizes of the selectors here, we simply split them | 45 // Since we don't know the sizes of the selectors here, we simply split them |
40 // into groups of 1,024, based on the reasonable assumption that the average | 46 // into groups of 1,024, based on the reasonable assumption that the average |
41 // selector won't have a size greater than 8. The alternative would be to | 47 // selector won't have a size greater than 8. The alternative would be to |
(...skipping 23 matching lines...) Expand all Loading... | |
65 code: styleSheet, | 71 code: styleSheet, |
66 cssOrigin: "user", | 72 cssOrigin: "user", |
67 frameId, | 73 frameId, |
68 matchAboutBlank: true, | 74 matchAboutBlank: true, |
69 runAt: "document_start" | 75 runAt: "document_start" |
70 }); | 76 }); |
71 } | 77 } |
72 | 78 |
73 function removeStyleSheet(tabId, frameId, styleSheet) | 79 function removeStyleSheet(tabId, frameId, styleSheet) |
74 { | 80 { |
81 // Chromium's support for tabs.removeCSS is still a work in progress and the | |
kzar
2018/01/31 11:11:32
IMO this comment should go by the styleSheetRemova
Manish Jethani
2018/01/31 12:36:27
Done.
| |
82 // API is likely to be different from Firefox's; for now we just don't use it | |
83 // at all, even if it's available. | |
84 // See https://crbug.com/608854 | |
85 if (!styleSheetRemovalSupported) | |
86 return; | |
87 | |
75 browser.tabs.removeCSS(tabId, { | 88 browser.tabs.removeCSS(tabId, { |
76 code: styleSheet, | 89 code: styleSheet, |
77 cssOrigin: "user", | 90 cssOrigin: "user", |
78 frameId, | 91 frameId, |
79 matchAboutBlank: true | 92 matchAboutBlank: true |
80 }); | 93 }); |
81 } | 94 } |
82 | 95 |
83 function updateFrameStyles(tabId, frameId, selectors, groupName) | 96 function updateFrameStyles(tabId, frameId, selectors, groupName) |
84 { | 97 { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 emulatedPatterns.push({selector: filter.selector, text: filter.text}); | 148 emulatedPatterns.push({selector: filter.selector, text: filter.text}); |
136 } | 149 } |
137 | 150 |
138 if (!inline) | 151 if (!inline) |
139 updateFrameStyles(sender.page.id, sender.frame.id, selectors); | 152 updateFrameStyles(sender.page.id, sender.frame.id, selectors); |
140 | 153 |
141 let response = {trace, inline, emulatedPatterns}; | 154 let response = {trace, inline, emulatedPatterns}; |
142 if (trace || inline) | 155 if (trace || inline) |
143 response.selectors = selectors; | 156 response.selectors = selectors; |
144 | 157 |
158 // If we can't remove user style sheets using tabs.removeCSS, we'll only keep | |
159 // adding them, which could cause problems with emulated filters as described | |
160 // in issue #5864. Instead, we can just ask the content script to add styles | |
161 // for emulated filters inline. | |
162 if (!styleSheetRemovalSupported) | |
163 response.inlineEmulated = true; | |
164 | |
145 return response; | 165 return response; |
146 }); | 166 }); |
147 | 167 |
148 port.on("elemhide.injectSelectors", (message, sender) => | 168 port.on("elemhide.injectSelectors", (message, sender) => |
149 { | 169 { |
150 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, | 170 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, |
151 message.groupName); | 171 message.groupName); |
152 }); | 172 }); |
OLD | NEW |