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

Delta Between Two Patch Sets: lib/csp.js

Issue 29705719: Issue 6402 - Split filter hit / request logging out into own API (Closed)
Left Patch Set: Another try at uploading the rebase diff Created May 9, 2018, 2:11 p.m.
Right Patch Set: Addressed Manish's feedback Created May 9, 2018, 5:53 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 | « include.preload.js ('k') | lib/cssInjection.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 13 matching lines...) Expand all
24 const {checkWhitelisted} = require("./whitelisting"); 24 const {checkWhitelisted} = require("./whitelisting");
25 const {FilterNotifier} = require("filterNotifier"); 25 const {FilterNotifier} = require("filterNotifier");
26 const {logRequest} = require("./hitLogger"); 26 const {logRequest} = require("./hitLogger");
27 27
28 const {typeMap} = RegExpFilter; 28 const {typeMap} = RegExpFilter;
29 29
30 browser.webRequest.onHeadersReceived.addListener(details => 30 browser.webRequest.onHeadersReceived.addListener(details =>
31 { 31 {
32 let url = new URL(details.url); 32 let url = new URL(details.url);
33 let parentFrame = ext.getFrame(details.tabId, details.parentFrameId); 33 let parentFrame = ext.getFrame(details.tabId, details.parentFrameId);
34 let docDomain = extractHostFromFrame(parentFrame) || url.hostname; 34 let hostname = extractHostFromFrame(parentFrame) || url.hostname;
Manish Jethani 2018/05/09 15:11:11 This should remain hostname?
kzar 2018/05/09 17:58:41 Done.
35 let thirdParty = isThirdParty(url, docDomain); 35 let thirdParty = isThirdParty(url, hostname);
36 36
37 let cspMatch = defaultMatcher.matchesAny(details.url, typeMap.CSP, docDomain, 37 let cspMatch = defaultMatcher.matchesAny(details.url, typeMap.CSP, hostname,
38 thirdParty, null, false); 38 thirdParty, null, false);
39 if (cspMatch) 39 if (cspMatch)
40 { 40 {
41 let page = new ext.Page({id: details.tabId, url: details.url}); 41 let page = new ext.Page({id: details.tabId, url: details.url});
42 let frame = ext.getFrame(details.tabId, details.frameId); 42 let frame = ext.getFrame(details.tabId, details.frameId);
43 43
44 if (checkWhitelisted(page, frame)) 44 if (checkWhitelisted(page, frame))
45 return; 45 return;
46 46
47 // To avoid an extra matchesAny for the common case we assumed no 47 // To avoid an extra matchesAny for the common case we assumed no
48 // $genericblock filters applied when searching for a matching $csp filter. 48 // $genericblock filters applied when searching for a matching $csp filter.
49 // We must now pay the price by first checking for a $genericblock filter 49 // We must now pay the price by first checking for a $genericblock filter
50 // and if necessary that our $csp filter is specific. 50 // and if necessary that our $csp filter is specific.
51 let specificOnly = !!checkWhitelisted(page, frame, null, 51 let specificOnly = !!checkWhitelisted(page, frame, null,
52 typeMap.GENERICBLOCK); 52 typeMap.GENERICBLOCK);
53 if (specificOnly) 53 if (specificOnly)
54 { 54 {
55 cspMatch = defaultMatcher.matchesAny(details.url, typeMap.CSP, docDomain, 55 cspMatch = defaultMatcher.matchesAny(details.url, typeMap.CSP, hostname,
56 thirdParty, null, specificOnly); 56 thirdParty, null, specificOnly);
57 if (!cspMatch) 57 if (!cspMatch)
58 return; 58 return;
59 } 59 }
60 60
61 logRequest( 61 logRequest([details.tabId], {
62 [details.tabId], 62 url: details.url, type: "CSP", docDomain: hostname,
63 {url: details.url, type: "CSP", docDomain, thirdParty, specificOnly}, 63 thirdParty, specificOnly
64 cspMatch 64 }, cspMatch);
65 );
66 FilterNotifier.emit("filter.hitCount", cspMatch, 0, 0, [details.tabId]); 65 FilterNotifier.emit("filter.hitCount", cspMatch, 0, 0, [details.tabId]);
67 66
68 if (cspMatch instanceof WhitelistFilter) 67 if (cspMatch instanceof WhitelistFilter)
69 return; 68 return;
70 69
71 details.responseHeaders.push({ 70 details.responseHeaders.push({
72 name: "Content-Security-Policy", 71 name: "Content-Security-Policy",
73 value: cspMatch.csp 72 value: cspMatch.csp
74 }); 73 });
75 74
76 return {responseHeaders: details.responseHeaders}; 75 return {responseHeaders: details.responseHeaders};
77 } 76 }
78 }, { 77 }, {
79 urls: ["http://*/*", "https://*/*"], 78 urls: ["http://*/*", "https://*/*"],
80 types: ["main_frame", "sub_frame"] 79 types: ["main_frame", "sub_frame"]
81 }, ["blocking", "responseHeaders"]); 80 }, ["blocking", "responseHeaders"]);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld