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 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return; | 90 return; |
91 | 91 |
92 browser.tabs.removeCSS(tabId, { | 92 browser.tabs.removeCSS(tabId, { |
93 code: styleSheet, | 93 code: styleSheet, |
94 cssOrigin: "user", | 94 cssOrigin: "user", |
95 frameId, | 95 frameId, |
96 matchAboutBlank: true | 96 matchAboutBlank: true |
97 }); | 97 }); |
98 } | 98 } |
99 | 99 |
100 function updateFrameStyles(tabId, frameId, selectors, groupName, appendOnly) | 100 function updateFrameStyles(tabId, frameId, styleSheet, groupName = "standard", |
| 101 appendOnly = false) |
101 { | 102 { |
102 let styleSheet = ""; | |
103 if (selectors.length > 0) | |
104 styleSheet = createStyleSheet(selectors); | |
105 | |
106 let frame = ext.getFrame(tabId, frameId); | 103 let frame = ext.getFrame(tabId, frameId); |
107 if (!frame) | 104 if (!frame) |
108 return false; | 105 return false; |
109 | 106 |
110 if (!frame.injectedStyleSheets) | 107 if (!frame.injectedStyleSheets) |
111 frame.injectedStyleSheets = new Map(); | 108 frame.injectedStyleSheets = new Map(); |
112 | 109 |
113 let oldStyleSheet = frame.injectedStyleSheets.get(groupName); | 110 let oldStyleSheet = frame.injectedStyleSheets.get(groupName); |
114 | 111 |
115 if (appendOnly && oldStyleSheet) | 112 if (appendOnly && oldStyleSheet) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 { | 184 { |
188 // See the comment in the catch block associated with the call to | 185 // See the comment in the catch block associated with the call to |
189 // tabs.insertCSS for why we catch any error here and simply | 186 // tabs.insertCSS for why we catch any error here and simply |
190 // return a rejected promise. | 187 // return a rejected promise. |
191 return Promise.reject(error); | 188 return Promise.reject(error); |
192 } | 189 } |
193 } | 190 } |
194 | 191 |
195 port.on("content.applyFilters", (message, sender) => | 192 port.on("content.applyFilters", (message, sender) => |
196 { | 193 { |
197 let selectors = []; | 194 let styleSheet = {code: "", selectors: []}; |
198 let emulatedPatterns = []; | 195 let emulatedPatterns = []; |
199 let trace = HitLogger.hasListener(sender.page.id); | 196 let trace = HitLogger.hasListener(sender.page.id); |
200 let inline = !userStyleSheetsSupported; | 197 let inline = !userStyleSheetsSupported; |
201 | 198 |
202 let {elemhide, snippets} = message.filterTypes || | 199 let {elemhide, snippets} = message.filterTypes || |
203 {elemhide: true, snippets: true}; | 200 {elemhide: true, snippets: true}; |
204 | 201 |
205 if (!checkWhitelisted(sender.page, sender.frame, null, | 202 if (!checkWhitelisted(sender.page, sender.frame, null, |
206 RegExpFilter.typeMap.DOCUMENT)) | 203 RegExpFilter.typeMap.DOCUMENT)) |
207 { | 204 { |
(...skipping 16 matching lines...) Expand all Loading... |
224 }, filter); | 221 }, filter); |
225 }); | 222 }); |
226 } | 223 } |
227 } | 224 } |
228 | 225 |
229 if (elemhide && !checkWhitelisted(sender.page, sender.frame, null, | 226 if (elemhide && !checkWhitelisted(sender.page, sender.frame, null, |
230 RegExpFilter.typeMap.ELEMHIDE)) | 227 RegExpFilter.typeMap.ELEMHIDE)) |
231 { | 228 { |
232 let specificOnly = checkWhitelisted(sender.page, sender.frame, null, | 229 let specificOnly = checkWhitelisted(sender.page, sender.frame, null, |
233 RegExpFilter.typeMap.GENERICHIDE); | 230 RegExpFilter.typeMap.GENERICHIDE); |
234 selectors = ElemHide.getSelectorsForDomain(docDomain, specificOnly); | 231 styleSheet = ElemHide.generateStyleSheetForDomain(docDomain, specificOnly, |
| 232 trace); |
235 | 233 |
236 for (let filter of ElemHideEmulation.getRulesForDomain(docDomain)) | 234 for (let filter of ElemHideEmulation.getRulesForDomain(docDomain)) |
237 emulatedPatterns.push({selector: filter.selector, text: filter.text}); | 235 emulatedPatterns.push({selector: filter.selector, text: filter.text}); |
238 } | 236 } |
239 } | 237 } |
240 | 238 |
241 if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id, | 239 if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id, |
242 selectors, "standard")) | 240 styleSheet.code)) |
243 { | 241 { |
244 inline = true; | 242 inline = true; |
245 } | 243 } |
246 | 244 |
247 let response = {trace, inline, emulatedPatterns}; | 245 let response = {trace, inline, emulatedPatterns}; |
248 if (trace || inline) | 246 |
249 response.selectors = selectors; | 247 if (inline) |
| 248 response.styleSheet = styleSheet; |
| 249 else if (trace) |
| 250 response.styleSheet = {selectors: styleSheet.selectors}; |
250 | 251 |
251 return response; | 252 return response; |
252 }); | 253 }); |
253 | 254 |
254 port.on("content.injectSelectors", (message, sender) => | 255 port.on("content.injectSelectors", (message, sender) => |
255 { | 256 { |
256 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, | 257 let styleSheet = createStyleSheet(message.selectors); |
257 message.groupName, message.appendOnly); | 258 if (!userStyleSheetsSupported || |
| 259 !updateFrameStyles(sender.page.id, sender.frame.id, styleSheet, |
| 260 message.groupName, message.appendOnly)) |
| 261 { |
| 262 return styleSheet; |
| 263 } |
258 }); | 264 }); |
259 | 265 |
260 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) | 266 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) |
261 .then(response => response.ok ? response.text() : "") | 267 .then(response => response.ok ? response.text() : "") |
262 .then(text => | 268 .then(text => |
263 { | 269 { |
264 snippetsLibrarySource = text; | 270 snippetsLibrarySource = text; |
265 }); | 271 }); |
OLD | NEW |