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

Delta Between Two Patch Sets: lib/contentFiltering.js

Issue 29865587: Issue 6843 - Log snippet filter hits (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Rebased and addressed comments Created Aug. 27, 2018, 12:56 p.m.
Right Patch Set: rebased on top of issue 6889 Created Aug. 28, 2018, 3:14 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « dependencies ('k') | lib/hitLogger.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // this is exactly, but we simply ignore the error. 204 // this is exactly, but we simply ignore the error.
205 if (/^No frame with id \d+ in tab \d+\.$/.test(error.message)) 205 if (/^No frame with id \d+ in tab \d+\.$/.test(error.message))
206 return; 206 return;
207 207
208 throw error; 208 throw error;
209 }); 209 });
210 } 210 }
211 catch (error) 211 catch (error)
212 { 212 {
213 // See the comment in the catch block associated with the call to 213 // See the comment in the catch block associated with the call to
214 // tabs.insertCSS for why we catch and simply reject the promise. 214 // tabs.insertCSS for why we catch any error here and simply
215 // return a rejected promise.
215 return Promise.reject(error); 216 return Promise.reject(error);
216 } 217 }
217 } 218 }
218 219
219 port.on("content.applyFilters", (message, sender) => 220 port.on("content.applyFilters", (message, sender) =>
220 { 221 {
221 let selectors = []; 222 let selectors = [];
222 let emulatedPatterns = []; 223 let emulatedPatterns = [];
223 let trace = HitLogger.hasListener(sender.page.id); 224 let trace = HitLogger.hasListener(sender.page.id);
224 let inline = !userStyleSheetsSupported; 225 let inline = !userStyleSheetsSupported;
225 226
226 let {elemhide, snippets} = message.filterTypes || 227 let {elemhide, snippets} = message.filterTypes ||
227 {elemhide: true, snippets: true}; 228 {elemhide: true, snippets: true};
228 229
229 if (!checkWhitelisted(sender.page, sender.frame, null, 230 if (!checkWhitelisted(sender.page, sender.frame, null,
230 RegExpFilter.typeMap.DOCUMENT)) 231 RegExpFilter.typeMap.DOCUMENT))
231 { 232 {
232 let docDomain = extractHostFromFrame(sender.frame); 233 let docDomain = extractHostFromFrame(sender.frame);
233 234
234 if (snippets) 235 if (snippets)
235 { 236 {
236 for (let filter of Snippets.getFiltersForDomain(docDomain)) 237 for (let filter of Snippets.getFiltersForDomain(docDomain))
237 executeScript(filter.script, sender.page.id, sender.frame.id) 238 {
238 .then(() => 239 executeScript(filter.script, sender.page.id, sender.frame.id).then(() =>
239 { 240 {
240 let tabIds = [sender.page.id]; 241 let tabIds = [sender.page.id];
241 if (filter) 242 if (filter)
242 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); 243 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds);
243 244
244 logRequest(tabIds, { 245 logRequest(tabIds, {
245 url: sender.frame.url.href, type: "SNIPPET", 246 url: sender.frame.url.href,
247 type: "SNIPPET",
246 docDomain 248 docDomain
247 }, filter); 249 }, filter);
248 }); 250 });
251 }
249 } 252 }
250 253
251 if (elemhide && !checkWhitelisted(sender.page, sender.frame, null, 254 if (elemhide && !checkWhitelisted(sender.page, sender.frame, null,
252 RegExpFilter.typeMap.ELEMHIDE)) 255 RegExpFilter.typeMap.ELEMHIDE))
253 { 256 {
254 let specificOnly = checkWhitelisted(sender.page, sender.frame, null, 257 let specificOnly = checkWhitelisted(sender.page, sender.frame, null,
255 RegExpFilter.typeMap.GENERICHIDE); 258 RegExpFilter.typeMap.GENERICHIDE);
256 selectors = ElemHide.getSelectorsForDomain(docDomain, specificOnly); 259 selectors = ElemHide.getSelectorsForDomain(docDomain, specificOnly);
257 260
258 for (let filter of ElemHideEmulation.getRulesForDomain(docDomain)) 261 for (let filter of ElemHideEmulation.getRulesForDomain(docDomain))
(...skipping 26 matching lines...) Expand all
285 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, 288 updateFrameStyles(sender.page.id, sender.frame.id, message.selectors,
286 message.groupName, message.appendOnly); 289 message.groupName, message.appendOnly);
287 }); 290 });
288 291
289 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"}) 292 fetch(browser.extension.getURL("/snippets.js"), {cache: "no-cache"})
290 .then(response => response.ok ? response.text() : "") 293 .then(response => response.ok ? response.text() : "")
291 .then(text => 294 .then(text =>
292 { 295 {
293 snippetsLibrarySource = text; 296 snippetsLibrarySource = text;
294 }); 297 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld