LEFT | RIGHT |
(no file at all) | |
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 }); | 98 }); |
99 } | 99 } |
100 | 100 |
101 function updateFrameStyles(tabId, frameId, styleSheet, groupName = "standard", | 101 function updateFrameStyles(tabId, frameId, styleSheet, groupName = "standard", |
102 appendOnly = false) | 102 appendOnly = false) |
103 { | 103 { |
104 let frame = ext.getFrame(tabId, frameId); | 104 let frame = ext.getFrame(tabId, frameId); |
105 if (!frame) | 105 if (!frame) |
106 return false; | 106 return false; |
107 | 107 |
108 if (!frame.injectedStyleSheets) | 108 if (!frame.state.injectedStyleSheets) |
109 frame.injectedStyleSheets = new Map(); | 109 frame.state.injectedStyleSheets = new Map(); |
110 | 110 |
111 let oldStyleSheet = frame.injectedStyleSheets.get(groupName); | 111 let oldStyleSheet = frame.state.injectedStyleSheets.get(groupName); |
112 | 112 |
113 if (appendOnly && oldStyleSheet) | 113 if (appendOnly && oldStyleSheet) |
114 styleSheet = oldStyleSheet + styleSheet; | 114 styleSheet = oldStyleSheet + styleSheet; |
115 | 115 |
116 // Ideally we would compare the old and new style sheets and skip this code | 116 // Ideally we would compare the old and new style sheets and skip this code |
117 // if they're the same, but the old style sheet can be a leftover from a | 117 // if they're the same. But first we need to ensure that there are no edge |
118 // previous instance of the frame. We must add the new style sheet | 118 // cases that would cause the old style sheet to be a leftover from a |
119 // regardless. | 119 // previous instance of the frame (see issue #7180). For now, we add the new |
| 120 // style sheet regardless. |
120 | 121 |
121 // Add the new style sheet first to keep previously hidden elements from | 122 // Add the new style sheet first to keep previously hidden elements from |
122 // reappearing momentarily. | 123 // reappearing momentarily. |
123 if (styleSheet && !addStyleSheet(tabId, frameId, styleSheet)) | 124 if (styleSheet && !addStyleSheet(tabId, frameId, styleSheet)) |
124 return false; | 125 return false; |
125 | 126 |
126 // Sometimes the old and new style sheets can be exactly the same. In such a | 127 // Sometimes the old and new style sheets can be exactly the same. In such a |
127 // case, do not remove the "old" style sheet, because it is in fact the new | 128 // case, do not remove the "old" style sheet, because it is in fact the new |
128 // style sheet now. | 129 // style sheet now. |
129 if (oldStyleSheet && oldStyleSheet != styleSheet) | 130 if (oldStyleSheet && oldStyleSheet != styleSheet) |
130 removeStyleSheet(tabId, frameId, oldStyleSheet); | 131 removeStyleSheet(tabId, frameId, oldStyleSheet); |
131 | 132 |
132 // The standard style sheet is ~660 KB per frame (as of Adblock Plus 3.3.2). | 133 // The standard style sheet is ~660 KB per frame (as of Adblock Plus 3.3.2). |
133 // Keeping it in memory would only really be useful on Firefox, which allows | 134 // Keeping it in memory would only really be useful on Firefox, which allows |
134 // us to remove it via the tabs.removeCSS API. By choosing not to hold on to | 135 // us to remove it via the tabs.removeCSS API. By choosing not to hold on to |
135 // it, we save potentially several megabytes per tab (#6967). | 136 // it, we save potentially several megabytes per tab (#6967). |
136 if (groupName != "standard") | 137 if (groupName != "standard") |
137 frame.injectedStyleSheets.set(groupName, styleSheet); | 138 frame.state.injectedStyleSheets.set(groupName, styleSheet); |
138 return true; | 139 return true; |
139 } | 140 } |
140 | 141 |
141 function getExecutableCode(script) | 142 function getExecutableCode(script) |
142 { | 143 { |
143 let code = executableCode.get(script); | 144 let code = executableCode.get(script); |
144 if (code) | 145 if (code) |
145 return code; | 146 return code; |
146 | 147 |
147 code = compileScript(script, [snippetsLibrarySource]); | 148 code = compileScript(script, [snippetsLibrarySource]); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 return [...rulesFromStyleSheet(styleSheet)]; | 265 return [...rulesFromStyleSheet(styleSheet)]; |
265 } | 266 } |
266 }); | 267 }); |
267 | 268 |
268 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) | 269 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) |
269 .then(response => response.ok ? response.text() : "") | 270 .then(response => response.ok ? response.text() : "") |
270 .then(text => | 271 .then(text => |
271 { | 272 { |
272 snippetsLibrarySource = text; | 273 snippetsLibrarySource = text; |
273 }); | 274 }); |
LEFT | RIGHT |