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 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 the old style sheet can be a leftover from a |
118 // previous instance of the frame. We must add the new style sheet | 118 // previous instance of the frame. We must add the new style sheet |
119 // regardless. | 119 // regardless. |
120 | 120 |
121 // Add the new style sheet first to keep previously hidden elements from | 121 // Add the new style sheet first to keep previously hidden elements from |
122 // reappearing momentarily. | 122 // reappearing momentarily. |
123 if (styleSheet && !addStyleSheet(tabId, frameId, styleSheet)) | 123 if (styleSheet && !addStyleSheet(tabId, frameId, styleSheet)) |
124 return false; | 124 return false; |
125 | 125 |
126 // Sometimes the old and new style sheets can be exactly the same. In such a | 126 // 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 | 127 // case, do not remove the "old" style sheet, because it is in fact the new |
128 // style sheet now. | 128 // style sheet now. |
129 if (oldStyleSheet && oldStyleSheet != styleSheet) | 129 if (oldStyleSheet && oldStyleSheet != styleSheet) |
130 removeStyleSheet(tabId, frameId, oldStyleSheet); | 130 removeStyleSheet(tabId, frameId, oldStyleSheet); |
131 | 131 |
132 // The standard style sheet is ~660 KB per frame (as of Adblock Plus 3.3.2). | 132 // 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 | 133 // 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 | 134 // 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). | 135 // it, we save potentially several megabytes per tab (#6967). |
136 if (groupName != "standard") | 136 if (groupName != "standard") |
137 frame.injectedStyleSheets.set(groupName, styleSheet); | 137 frame.state.injectedStyleSheets.set(groupName, styleSheet); |
138 return true; | 138 return true; |
139 } | 139 } |
140 | 140 |
141 function getExecutableCode(script) | 141 function getExecutableCode(script) |
142 { | 142 { |
143 let code = executableCode.get(script); | 143 let code = executableCode.get(script); |
144 if (code) | 144 if (code) |
145 return code; | 145 return code; |
146 | 146 |
147 code = compileScript(script, [snippetsLibrarySource]); | 147 code = compileScript(script, [snippetsLibrarySource]); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 return [...rulesFromStyleSheet(styleSheet)]; | 264 return [...rulesFromStyleSheet(styleSheet)]; |
265 } | 265 } |
266 }); | 266 }); |
267 | 267 |
268 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) | 268 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) |
269 .then(response => response.ok ? response.text() : "") | 269 .then(response => response.ok ? response.text() : "") |
270 .then(text => | 270 .then(text => |
271 { | 271 { |
272 snippetsLibrarySource = text; | 272 snippetsLibrarySource = text; |
273 }); | 273 }); |
OLD | NEW |