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

Delta Between Two Patch Sets: lib/requestBlocker.js

Issue 29680696: [$csp4 adblockpluschrome] Issue 5241 - Add support for Content Security Policy filters (Closed)
Left Patch Set: Get the parent frame's hostname where possible Created March 15, 2018, 6:17 p.m.
Right Patch Set: Rebased Created March 26, 2018, 6:22 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 | « lib/devtools.js ('k') | no next file » | 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 exports.filterTypes = new Set(function*() 56 exports.filterTypes = new Set(function*()
57 { 57 {
58 // Microsoft Edge does not have webRequest.ResourceType or the devtools panel. 58 // Microsoft Edge does not have webRequest.ResourceType or the devtools panel.
59 // Since filterTypes is only used by devtools, we can just bail out here. 59 // Since filterTypes is only used by devtools, we can just bail out here.
60 if (!(browser.webRequest.ResourceType)) 60 if (!(browser.webRequest.ResourceType))
61 return; 61 return;
62 62
63 for (let type in browser.webRequest.ResourceType) 63 for (let type in browser.webRequest.ResourceType)
64 yield resourceTypes.get(browser.webRequest.ResourceType[type]) || "OTHER"; 64 yield resourceTypes.get(browser.webRequest.ResourceType[type]) || "OTHER";
65 65
66 // WEBSOCKET and WEBRTC get addressed through workarounds, even if the 66 // WEBRTC gets addressed through a workaround, even if the webRequest API is
67 // webRequest API is lacking support to block these kind of requests. 67 // lacking support to block this kind of a request.
68 yield "WEBSOCKET";
69 yield "WEBRTC"; 68 yield "WEBRTC";
70 69
71 // POPUP, CSP and ELEMHIDE filters aren't blocked on the request level but by 70 // POPUP, CSP and ELEMHIDE filters aren't mapped to resource types.
72 // other means. They don't have a corresponding value in
73 // webRequest.ResourceType.
74 yield "POPUP"; 71 yield "POPUP";
75 yield "ELEMHIDE"; 72 yield "ELEMHIDE";
76 yield "CSP"; 73 yield "CSP";
77 }()); 74 }());
78 75
79 function onBeforeRequestAsync(page, url, type, docDomain, 76 function onBeforeRequestAsync(page, url, type, docDomain,
80 thirdParty, sitekey, 77 thirdParty, sitekey,
81 specificOnly, filter) 78 specificOnly, filter)
82 { 79 {
83 if (filter) 80 if (filter)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 197
201 FilterNotifier.on("subscription.added", onFilterChange); 198 FilterNotifier.on("subscription.added", onFilterChange);
202 FilterNotifier.on("subscription.removed", onFilterChange); 199 FilterNotifier.on("subscription.removed", onFilterChange);
203 FilterNotifier.on("subscription.updated", onFilterChange); 200 FilterNotifier.on("subscription.updated", onFilterChange);
204 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 201 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
205 FilterNotifier.on("filter.added", onFilterChange); 202 FilterNotifier.on("filter.added", onFilterChange);
206 FilterNotifier.on("filter.removed", onFilterChange); 203 FilterNotifier.on("filter.removed", onFilterChange);
207 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 204 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
208 FilterNotifier.on("load", onFilterChange); 205 FilterNotifier.on("load", onFilterChange);
209 206
210 port.on("request.blockedByWrapper", (msg, sender) => 207 port.on("request.blockedByRTCWrapper", (msg, sender) =>
211 { 208 {
212 // Chrome 58 onwards directly supports WebSocket blocking, so we can ignore
213 // messages from the wrapper here (see https://crbug.com/129353). Hopefully
214 // WebRTC will be supported soon too (see https://crbug.com/707683).
215 // Edge supports neither webRequest.ResourceType nor WebSocket blocking yet:
216 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/102973 76/
217 if (browser.webRequest.ResourceType &&
218 (msg.requestType.toUpperCase() in browser.webRequest.ResourceType))
219 {
220 return false;
221 }
222
223 return ext.webRequest.onBeforeRequest._dispatch( 209 return ext.webRequest.onBeforeRequest._dispatch(
224 new URL(msg.url), 210 new URL(msg.url),
225 msg.requestType, 211 "webrtc",
226 sender.page, 212 sender.page,
227 sender.frame 213 sender.frame
228 ).includes(false); 214 ).includes(false);
229 }); 215 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld