| 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 | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 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 const info = require("info"); | 
| 30 | 30 | 
| 31 // Chromium's support for tabs.removeCSS is still a work in progress and the | 31 // Chromium's support for tabs.removeCSS is still a work in progress and the | 
| 32 // API is likely to be different from Firefox's; for now we just don't use it | 32 // API is likely to be different from Firefox's; for now we just don't use it | 
| 33 // at all, even if it's available. | 33 // at all, even if it's available. | 
| 34 // See https://crbug.com/608854 | 34 // See https://crbug.com/608854 | 
| 35 const styleSheetRemovalSupported = "removeCSS" in browser.tabs && | 35 const styleSheetRemovalSupported = info.platform == "gecko"; | 
| 36                                    info.platform == "gecko"; |  | 
| 37 | 36 | 
| 38 const selectorGroupSize = 1024; | 37 const selectorGroupSize = 1024; | 
| 39 | 38 | 
| 40 let userStyleSheetsSupported = true; | 39 let userStyleSheetsSupported = true; | 
| 41 | 40 | 
| 42 function* splitSelectors(selectors) | 41 function* splitSelectors(selectors) | 
| 43 { | 42 { | 
| 44   // Chromium's Blink engine supports only up to 8,192 simple selectors, and | 43   // Chromium's Blink engine supports only up to 8,192 simple selectors, and | 
| 45   // even fewer compound selectors, in a rule. The exact number of selectors | 44   // even fewer compound selectors, in a rule. The exact number of selectors | 
| 46   // that would work depends on their sizes (e.g. "#foo .bar" has a size of 2). | 45   // that would work depends on their sizes (e.g. "#foo .bar" has a size of 2). | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 74     browser.tabs.insertCSS(tabId, { | 73     browser.tabs.insertCSS(tabId, { | 
| 75       code: styleSheet, | 74       code: styleSheet, | 
| 76       cssOrigin: "user", | 75       cssOrigin: "user", | 
| 77       frameId, | 76       frameId, | 
| 78       matchAboutBlank: true, | 77       matchAboutBlank: true, | 
| 79       runAt: "document_start" | 78       runAt: "document_start" | 
| 80     }); | 79     }); | 
| 81   } | 80   } | 
| 82   catch (error) | 81   catch (error) | 
| 83   { | 82   { | 
| 84     if (/\bError processing cssOrigin\b/.test(error.message) == -1) |  | 
| 85       throw error; |  | 
| 86 |  | 
| 87     userStyleSheetsSupported = false; | 83     userStyleSheetsSupported = false; | 
| 88   } | 84   } | 
| 89 | 85 | 
| 90   return userStyleSheetsSupported; | 86   return userStyleSheetsSupported; | 
| 91 } | 87 } | 
| 92 | 88 | 
| 93 function removeStyleSheet(tabId, frameId, styleSheet) | 89 function removeStyleSheet(tabId, frameId, styleSheet) | 
| 94 { | 90 { | 
| 95   if (!styleSheetRemovalSupported) | 91   if (!styleSheetRemovalSupported) | 
| 96     return; | 92     return; | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 153     selectors = ElemHide.getSelectorsForDomain( | 149     selectors = ElemHide.getSelectorsForDomain( | 
| 154       hostname, | 150       hostname, | 
| 155       specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING | 151       specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.ALL_MATCHING | 
| 156     ); | 152     ); | 
| 157 | 153 | 
| 158     for (let filter of ElemHideEmulation.getRulesForDomain(hostname)) | 154     for (let filter of ElemHideEmulation.getRulesForDomain(hostname)) | 
| 159       emulatedPatterns.push({selector: filter.selector, text: filter.text}); | 155       emulatedPatterns.push({selector: filter.selector, text: filter.text}); | 
| 160   } | 156   } | 
| 161 | 157 | 
| 162   if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id, | 158   if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id, | 
| 163                                     selectors)) | 159                                     selectors, "standard")) | 
| 164   { | 160   { | 
| 165     inline = true; | 161     inline = true; | 
| 166   } | 162   } | 
| 167 | 163 | 
| 168   let response = {trace, inline, emulatedPatterns}; | 164   let response = {trace, inline, emulatedPatterns}; | 
| 169   if (trace || inline) | 165   if (trace || inline) | 
| 170     response.selectors = selectors; | 166     response.selectors = selectors; | 
| 171 | 167 | 
| 172   // If we can't remove user style sheets using tabs.removeCSS, we'll only keep | 168   // If we can't remove user style sheets using tabs.removeCSS, we'll only keep | 
| 173   // adding them, which could cause problems with emulation filters as | 169   // adding them, which could cause problems with emulation filters as | 
| 174   // described in issue #5864. Instead, we can just ask the content script to | 170   // described in issue #5864. Instead, we can just ask the content script to | 
| 175   // add styles for emulation filters inline. | 171   // add styles for emulation filters inline. | 
| 176   if (!styleSheetRemovalSupported) | 172   if (!styleSheetRemovalSupported) | 
| 177     response.inlineEmulated = true; | 173     response.inlineEmulated = true; | 
| 178 | 174 | 
| 179   return response; | 175   return response; | 
| 180 }); | 176 }); | 
| 181 | 177 | 
| 182 port.on("elemhide.injectSelectors", (message, sender) => | 178 port.on("elemhide.injectSelectors", (message, sender) => | 
| 183 { | 179 { | 
| 184   updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, | 180   updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, | 
| 185                     message.groupName); | 181                     message.groupName); | 
| 186 }); | 182 }); | 
| LEFT | RIGHT | 
|---|