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

Side by Side Diff: lib/contentFiltering.js

Issue 29894568: Issue 6999 - Generate style sheets in background page (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Sept. 28, 2018, 12:27 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 | « include.preload.js ('k') | 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return; 92 return;
93 93
94 browser.tabs.removeCSS(tabId, { 94 browser.tabs.removeCSS(tabId, {
95 code: styleSheet, 95 code: styleSheet,
96 cssOrigin: "user", 96 cssOrigin: "user",
97 frameId, 97 frameId,
98 matchAboutBlank: true 98 matchAboutBlank: true
99 }); 99 });
100 } 100 }
101 101
102 function updateFrameStyles(tabId, frameId, selectors, groupName, appendOnly) 102 function updateFrameStyles(tabId, frameId, styleSheet, groupName, appendOnly)
103 { 103 {
104 let styleSheet = "";
105 if (selectors.length > 0)
106 styleSheet = createStyleSheet(selectors);
107
108 let frame = ext.getFrame(tabId, frameId); 104 let frame = ext.getFrame(tabId, frameId);
109 if (!frame) 105 if (!frame)
110 return false; 106 return false;
111 107
112 if (!frame.injectedStyleSheets) 108 if (!frame.injectedStyleSheets)
113 frame.injectedStyleSheets = new Map(); 109 frame.injectedStyleSheets = new Map();
114 110
115 let oldStyleSheet = frame.injectedStyleSheets.get(groupName); 111 let oldStyleSheet = frame.injectedStyleSheets.get(groupName);
116 112
117 if (appendOnly && oldStyleSheet) 113 if (appendOnly && oldStyleSheet)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 { 185 {
190 // See the comment in the catch block associated with the call to 186 // See the comment in the catch block associated with the call to
191 // tabs.insertCSS for why we catch any error here and simply 187 // tabs.insertCSS for why we catch any error here and simply
192 // return a rejected promise. 188 // return a rejected promise.
193 return Promise.reject(error); 189 return Promise.reject(error);
194 } 190 }
195 } 191 }
196 192
197 port.on("content.applyFilters", (message, sender) => 193 port.on("content.applyFilters", (message, sender) =>
198 { 194 {
195 let styleSheet = "";
199 let selectors = []; 196 let selectors = [];
200 let emulatedPatterns = []; 197 let emulatedPatterns = [];
201 let trace = HitLogger.hasListener(sender.page.id); 198 let trace = HitLogger.hasListener(sender.page.id);
202 let inline = !userStyleSheetsSupported; 199 let inline = !userStyleSheetsSupported;
203 200
204 let {elemhide, snippets} = message.filterTypes || 201 let {elemhide, snippets} = message.filterTypes ||
205 {elemhide: true, snippets: true}; 202 {elemhide: true, snippets: true};
206 203
207 if (!checkWhitelisted(sender.page, sender.frame, null, 204 if (!checkWhitelisted(sender.page, sender.frame, null,
208 RegExpFilter.typeMap.DOCUMENT)) 205 RegExpFilter.typeMap.DOCUMENT))
(...skipping 18 matching lines...) Expand all
227 }); 224 });
228 } 225 }
229 } 226 }
230 227
231 if (elemhide && !checkWhitelisted(sender.page, sender.frame, null, 228 if (elemhide && !checkWhitelisted(sender.page, sender.frame, null,
232 RegExpFilter.typeMap.ELEMHIDE)) 229 RegExpFilter.typeMap.ELEMHIDE))
233 { 230 {
234 let specificOnly = checkWhitelisted(sender.page, sender.frame, null, 231 let specificOnly = checkWhitelisted(sender.page, sender.frame, null,
235 RegExpFilter.typeMap.GENERICHIDE); 232 RegExpFilter.typeMap.GENERICHIDE);
236 selectors = ElemHide.getSelectorsForDomain(docDomain, specificOnly); 233 selectors = ElemHide.getSelectorsForDomain(docDomain, specificOnly);
234 styleSheet = createStyleSheet(selectors);
237 235
238 for (let filter of ElemHideEmulation.getRulesForDomain(docDomain)) 236 for (let filter of ElemHideEmulation.getRulesForDomain(docDomain))
239 emulatedPatterns.push({selector: filter.selector, text: filter.text}); 237 emulatedPatterns.push({selector: filter.selector, text: filter.text});
240 } 238 }
241 } 239 }
242 240
243 if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id, 241 if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id,
244 selectors, "standard")) 242 styleSheet, "standard"))
245 { 243 {
246 inline = true; 244 inline = true;
247 } 245 }
248 246
249 let response = {trace, inline, emulatedPatterns}; 247 let response = {trace, inline, emulatedPatterns};
250 if (trace || inline) 248
249 if (inline)
250 response.styleSheet = styleSheet;
251
252 if (trace)
251 response.selectors = selectors; 253 response.selectors = selectors;
252 254
253 return response; 255 return response;
254 }); 256 });
255 257
256 port.on("elemhide.injectSelectors", (message, sender) => 258 port.on("elemhide.injectSelectors", (message, sender) =>
257 { 259 {
258 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, 260 updateFrameStyles(sender.page.id, sender.frame.id,
261 createStyleSheet(message.selectors),
259 message.groupName, message.appendOnly); 262 message.groupName, message.appendOnly);
260 }); 263 });
261 264
262 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) 265 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"})
263 .then(response => response.ok ? response.text() : "") 266 .then(response => response.ok ? response.text() : "")
264 .then(text => 267 .then(text =>
265 { 268 {
266 snippetsLibrarySource = text; 269 snippetsLibrarySource = text;
267 }); 270 });
OLDNEW
« no previous file with comments | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld