| 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 contentFiltering */ | 18 /** @module contentFiltering */ |
| 19 | 19 |
| 20 "use strict"; | 20 "use strict"; |
| 21 | 21 |
| 22 const {RegExpFilter} = require("../adblockpluscore/lib/filterClasses"); | 22 const {RegExpFilter} = require("../adblockpluscore/lib/filterClasses"); |
| 23 const {ElemHide, createStyleSheet} = require("../adblockpluscore/lib/elemHide"); | 23 const {ElemHide, createStyleSheet, |
| 24 rulesFromStyleSheet} = require("../adblockpluscore/lib/elemHide"); |
| 24 const {ElemHideEmulation} = require("../adblockpluscore/lib/elemHideEmulation"); | 25 const {ElemHideEmulation} = require("../adblockpluscore/lib/elemHideEmulation"); |
| 25 const {filterNotifier} = require("../adblockpluscore/lib/filterNotifier"); | 26 const {filterNotifier} = require("../adblockpluscore/lib/filterNotifier"); |
| 26 const {Snippets, compileScript} = require("../adblockpluscore/lib/snippets"); | 27 const {Snippets, compileScript} = require("../adblockpluscore/lib/snippets"); |
| 27 const {checkWhitelisted} = require("./whitelisting"); | 28 const {checkWhitelisted} = require("./whitelisting"); |
| 28 const {extractHostFromFrame} = require("./url"); | 29 const {extractHostFromFrame} = require("./url"); |
| 29 const {port} = require("./messaging"); | 30 const {port} = require("./messaging"); |
| 30 const {HitLogger, logRequest} = require("./hitLogger"); | 31 const {HitLogger, logRequest} = require("./hitLogger"); |
| 31 const info = require("info"); | 32 const info = require("info"); |
| 32 | 33 |
| 33 // Chromium's support for tabs.removeCSS is still a work in progress and the | 34 // Chromium's support for tabs.removeCSS is still a work in progress and the |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 }, filter); | 222 }, filter); |
| 222 }); | 223 }); |
| 223 } | 224 } |
| 224 } | 225 } |
| 225 | 226 |
| 226 if (elemhide && !checkWhitelisted(sender.page, sender.frame, null, | 227 if (elemhide && !checkWhitelisted(sender.page, sender.frame, null, |
| 227 RegExpFilter.typeMap.ELEMHIDE)) | 228 RegExpFilter.typeMap.ELEMHIDE)) |
| 228 { | 229 { |
| 229 let specificOnly = checkWhitelisted(sender.page, sender.frame, null, | 230 let specificOnly = checkWhitelisted(sender.page, sender.frame, null, |
| 230 RegExpFilter.typeMap.GENERICHIDE); | 231 RegExpFilter.typeMap.GENERICHIDE); |
| 231 styleSheet = ElemHide.generateStyleSheetForDomain(docDomain, specificOnly, | 232 styleSheet = ElemHide.generateStyleSheetForDomain(docDomain, specificOnly, |
| 232 trace); | 233 trace); |
| 233 | 234 |
| 234 for (let filter of ElemHideEmulation.getRulesForDomain(docDomain)) | 235 for (let filter of ElemHideEmulation.getRulesForDomain(docDomain)) |
| 235 emulatedPatterns.push({selector: filter.selector, text: filter.text}); | 236 emulatedPatterns.push({selector: filter.selector, text: filter.text}); |
| 236 } | 237 } |
| 237 } | 238 } |
| 238 | 239 |
| 239 if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id, | 240 if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id, |
| 240 styleSheet.code)) | 241 styleSheet.code)) |
| 241 { | 242 { |
| 242 inline = true; | 243 inline = true; |
| 243 } | 244 } |
| 244 | 245 |
| 245 let response = {trace, inline, emulatedPatterns}; | 246 let response = {trace, inline, emulatedPatterns}; |
| 246 | 247 |
| 247 if (inline) | 248 if (inline) |
| 248 response.styleSheet = styleSheet; | 249 response.rules = [...rulesFromStyleSheet(styleSheet.code)]; |
| 249 else if (trace) | 250 |
| 250 response.styleSheet = {selectors: styleSheet.selectors}; | 251 if (trace) |
| 252 response.selectors = styleSheet.selectors; |
| 251 | 253 |
| 252 return response; | 254 return response; |
| 253 }); | 255 }); |
| 254 | 256 |
| 255 port.on("content.injectSelectors", (message, sender) => | 257 port.on("content.injectSelectors", (message, sender) => |
| 256 { | 258 { |
| 257 updateFrameStyles(sender.page.id, sender.frame.id, | 259 let styleSheet = createStyleSheet(message.selectors); |
| 258 createStyleSheet(message.selectors), | 260 if (!userStyleSheetsSupported || |
| 259 message.groupName, message.appendOnly); | 261 !updateFrameStyles(sender.page.id, sender.frame.id, styleSheet, |
| 262 message.groupName, message.appendOnly)) |
| 263 { |
| 264 return [...rulesFromStyleSheet(styleSheet)]; |
| 265 } |
| 260 }); | 266 }); |
| 261 | 267 |
| 262 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) | 268 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) |
| 263 .then(response => response.ok ? response.text() : "") | 269 .then(response => response.ok ? response.text() : "") |
| 264 .then(text => | 270 .then(text => |
| 265 { | 271 { |
| 266 snippetsLibrarySource = text; | 272 snippetsLibrarySource = text; |
| 267 }); | 273 }); |
| LEFT | RIGHT |