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 15 matching lines...) Expand all Loading... |
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 | 29 |
30 const userStyleSheetsSupported = "extensionTypes" in browser && | 30 const userStyleSheetsSupported = "extensionTypes" in browser && |
31 "CSSOrigin" in browser.extensionTypes; | 31 "CSSOrigin" in browser.extensionTypes; |
32 const selectorGroupSize = 1024; | 32 const selectorGroupSize = 1024; |
33 | 33 |
34 function* splitSelectors(selectors) | 34 function* splitSelectors(selectors) |
35 { | 35 { |
36 // Chromium's Blink engine supports only up to 8,192 selectors; more | 36 // Chromium's Blink engine supports only up to 8,192 simple selectors, and |
37 // specifically, it ignores any selectors that start at index 8192 or beyond | 37 // even fewer compound selectors, in a rule. The exact number of selectors |
38 // in the list of plain selectors. In order to avoid spilling outside of this | 38 // that would work depends on their sizes (e.g. "#foo .bar" has a size of 2). |
39 // range, we simply add multiple rules in groups of up to 1,024 selectors | 39 // Since we don't know the sizes of the selectors here, we simply split them |
40 // each. | 40 // 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 |
| 42 // calculate the sizes of the selectors and divide them up accordingly, but |
| 43 // this approach is more efficient and has worked well in practice. In theory |
| 44 // this could still lead to some selectors not working on Chromium, but it is |
| 45 // highly unlikely. |
41 // See issue #6298 and https://crbug.com/804179 | 46 // See issue #6298 and https://crbug.com/804179 |
42 for (let i = 0; i < selectors.length; i += selectorGroupSize) | 47 for (let i = 0; i < selectors.length; i += selectorGroupSize) |
43 yield selectors.slice(i, i + selectorGroupSize); | 48 yield selectors.slice(i, i + selectorGroupSize); |
44 } | 49 } |
45 | 50 |
46 function* createRules(selectors) | 51 function* createRules(selectors) |
47 { | 52 { |
48 for (let selectorGroup of splitSelectors(selectors)) | 53 for (let selectorGroup of splitSelectors(selectors)) |
49 yield selectorGroup.join(", ") + " {display: none !important;}"; | 54 yield selectorGroup.join(", ") + " {display: none !important;}"; |
50 } | 55 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 response.selectors = selectors; | 143 response.selectors = selectors; |
139 | 144 |
140 return response; | 145 return response; |
141 }); | 146 }); |
142 | 147 |
143 port.on("elemhide.injectSelectors", (message, sender) => | 148 port.on("elemhide.injectSelectors", (message, sender) => |
144 { | 149 { |
145 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, | 150 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, |
146 message.groupName); | 151 message.groupName); |
147 }); | 152 }); |
LEFT | RIGHT |