Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/contentFiltering.js

Issue 29885568: Issue 6967 - Hold on to only non-standard style sheets (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Sept. 19, 2018, 5:52 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.injectedStyleSheets) 140 if (!frame.injectedSelectors)
141 frame.injectedStyleSheets = new Map(); 141 frame.injectedSelectors = new Map();
142 142
143 let oldStyleSheet = frame.injectedStyleSheets.get(groupName); 143 let oldSelectors = frame.injectedSelectors.get(groupName);
144 let oldStyleSheet = oldSelectors ? createStyleSheet(oldSelectors) : null;
144 145
145 if (appendOnly && oldStyleSheet) 146 if (appendOnly && oldStyleSheet)
146 styleSheet = oldStyleSheet + styleSheet; 147 styleSheet = oldStyleSheet + styleSheet;
147 148
148 // Ideally we would compare the old and new style sheets and skip this code 149 // Ideally we would compare the old and new style sheets and skip this code
149 // if they're the same, but the old style sheet can be a leftover from a 150 // if they're the same, but the old style sheet can be a leftover from a
150 // previous instance of the frame. We must add the new style sheet 151 // previous instance of the frame. We must add the new style sheet
151 // regardless. 152 // regardless.
152 153
153 // Add the new style sheet first to keep previously hidden elements from 154 // Add the new style sheet first to keep previously hidden elements from
154 // reappearing momentarily. 155 // reappearing momentarily.
155 if (styleSheet && !addStyleSheet(tabId, frameId, styleSheet)) 156 if (styleSheet && !addStyleSheet(tabId, frameId, styleSheet))
156 return false; 157 return false;
157 158
158 // Sometimes the old and new style sheets can be exactly the same. In such a 159 // Sometimes the old and new style sheets can be exactly the same. In such a
159 // case, do not remove the "old" style sheet, because it is in fact the new 160 // case, do not remove the "old" style sheet, because it is in fact the new
160 // style sheet now. 161 // style sheet now.
161 if (oldStyleSheet && oldStyleSheet != styleSheet) 162 if (oldStyleSheet && oldStyleSheet != styleSheet)
162 removeStyleSheet(tabId, frameId, oldStyleSheet); 163 removeStyleSheet(tabId, frameId, oldStyleSheet);
163 164
164 frame.injectedStyleSheets.set(groupName, styleSheet); 165 if (selectors.length > 0)
166 frame.injectedSelectors.set(groupName, selectors);
165 return true; 167 return true;
166 } 168 }
167 169
168 function getExecutableCode(script) 170 function getExecutableCode(script)
169 { 171 {
170 let code = executableCode.get(script); 172 let code = executableCode.get(script);
171 if (code) 173 if (code)
172 return code; 174 return code;
173 175
174 code = compileScript(script, [snippetsLibrarySource]); 176 code = compileScript(script, [snippetsLibrarySource]);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, 290 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors,
289 message.groupName, message.appendOnly); 291 message.groupName, message.appendOnly);
290 }); 292 });
291 293
292 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) 294 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"})
293 .then(response => response.ok ? response.text() : "") 295 .then(response => response.ok ? response.text() : "")
294 .then(text => 296 .then(text =>
295 { 297 {
296 snippetsLibrarySource = text; 298 snippetsLibrarySource = text;
297 }); 299 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld