| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 130 function updateFrameStyles(tabId, frameId, selectors, groupName, appendOnly) | 130 function updateFrameStyles(tabId, frameId, selectors, groupName, appendOnly) | 
| 131 { | 131 { | 
| 132   let styleSheet = ""; | 132   let styleSheet = ""; | 
| 133   if (selectors.length > 0) | 133   if (selectors.length > 0) | 
| 134     styleSheet = createStyleSheet(selectors); | 134     styleSheet = createStyleSheet(selectors); | 
| 135 | 135 | 
| 136   let frame = ext.getFrame(tabId, frameId); | 136   let frame = ext.getFrame(tabId, frameId); | 
| 137   if (!frame) | 137   if (!frame) | 
| 138     return false; | 138     return false; | 
| 139 | 139 | 
| 140   if (!frame.injectedSelectors) | 140   if (!frame.injectedStyleSheets) | 
| 141     frame.injectedSelectors = new Map(); | 141     frame.injectedStyleSheets = new Map(); | 
| 142 | 142 | 
| 143   let oldSelectors = frame.injectedSelectors.get(groupName); | 143   let oldStyleSheet = frame.injectedStyleSheets.get(groupName); | 
| 144   let oldStyleSheet = oldSelectors ? createStyleSheet(oldSelectors) : null; |  | 
| 145 | 144 | 
| 146   if (appendOnly && oldStyleSheet) | 145   if (appendOnly && oldStyleSheet) | 
| 147     styleSheet = oldStyleSheet + styleSheet; | 146     styleSheet = oldStyleSheet + styleSheet; | 
| 148 | 147 | 
| 149   // Ideally we would compare the old and new style sheets and skip this code | 148   // Ideally we would compare the old and new style sheets and skip this code | 
| 150   // if they're the same, but the old style sheet can be a leftover from a | 149   // if they're the same, but the old style sheet can be a leftover from a | 
| 151   // previous instance of the frame. We must add the new style sheet | 150   // previous instance of the frame. We must add the new style sheet | 
| 152   // regardless. | 151   // regardless. | 
| 153 | 152 | 
| 154   // Add the new style sheet first to keep previously hidden elements from | 153   // Add the new style sheet first to keep previously hidden elements from | 
| 155   // reappearing momentarily. | 154   // reappearing momentarily. | 
| 156   if (styleSheet && !addStyleSheet(tabId, frameId, styleSheet)) | 155   if (styleSheet && !addStyleSheet(tabId, frameId, styleSheet)) | 
| 157     return false; | 156     return false; | 
| 158 | 157 | 
| 159   // Sometimes the old and new style sheets can be exactly the same. In such a | 158   // Sometimes the old and new style sheets can be exactly the same. In such a | 
| 160   // case, do not remove the "old" style sheet, because it is in fact the new | 159   // case, do not remove the "old" style sheet, because it is in fact the new | 
| 161   // style sheet now. | 160   // style sheet now. | 
| 162   if (oldStyleSheet && oldStyleSheet != styleSheet) | 161   if (oldStyleSheet && oldStyleSheet != styleSheet) | 
| 163     removeStyleSheet(tabId, frameId, oldStyleSheet); | 162     removeStyleSheet(tabId, frameId, oldStyleSheet); | 
| 164 | 163 | 
| 165   if (selectors.length > 0) | 164   // The standard style sheet is ~660 KB per frame (as of Adblock Plus 3.3.2). | 
| 166     frame.injectedSelectors.set(groupName, selectors); | 165   // Keeping it in memory would only really be useful on Firefox, which allows | 
|  | 166   // us to remove it via the tabs.removeCSS API. By choosing not to hold on to | 
|  | 167   // it, we save potentially several megabytes per tab (#6967). | 
|  | 168   if (groupName != "standard") | 
|  | 169     frame.injectedStyleSheets.set(groupName, styleSheet); | 
| 167   return true; | 170   return true; | 
| 168 } | 171 } | 
| 169 | 172 | 
| 170 function getExecutableCode(script) | 173 function getExecutableCode(script) | 
| 171 { | 174 { | 
| 172   let code = executableCode.get(script); | 175   let code = executableCode.get(script); | 
| 173   if (code) | 176   if (code) | 
| 174     return code; | 177     return code; | 
| 175 | 178 | 
| 176   code = compileScript(script, [snippetsLibrarySource]); | 179   code = compileScript(script, [snippetsLibrarySource]); | 
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 290   updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, | 293   updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, | 
| 291                     message.groupName, message.appendOnly); | 294                     message.groupName, message.appendOnly); | 
| 292 }); | 295 }); | 
| 293 | 296 | 
| 294 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) | 297 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) | 
| 295 .then(response => response.ok ? response.text() : "") | 298 .then(response => response.ok ? response.text() : "") | 
| 296 .then(text => | 299 .then(text => | 
| 297 { | 300 { | 
| 298   snippetsLibrarySource = text; | 301   snippetsLibrarySource = text; | 
| 299 }); | 302 }); | 
| LEFT | RIGHT | 
|---|