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

Side by Side Diff: lib/csp.js

Issue 29570614: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Rebase Created Oct. 13, 2017, 4:53 a.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') | lib/cssInjection.js » ('j') | 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 // The webRequest API doesn't support WebSocket connection blocking in Microsoft 20 // The webRequest API doesn't support WebSocket connection blocking in Microsoft
21 // Edge and versions of Chrome before 58. Therefore for those we inject CSP 21 // Edge and versions of Chrome before 58. Therefore for those we inject CSP
22 // headers below as a workaround. See https://crbug.com/129353 and 22 // headers below as a workaround. See https://crbug.com/129353 and
23 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10297376 / 23 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10297376 /
24 if (!chrome.webRequest.ResourceType || 24 if (!browser.webRequest.ResourceType ||
25 !("WEBSOCKET" in chrome.webRequest.ResourceType)) 25 !("WEBSOCKET" in browser.webRequest.ResourceType))
26 { 26 {
27 const {defaultMatcher} = require("matcher"); 27 const {defaultMatcher} = require("matcher");
28 const {BlockingFilter, RegExpFilter} = require("filterClasses"); 28 const {BlockingFilter, RegExpFilter} = require("filterClasses");
29 const {getDecodedHostname} = require("url"); 29 const {getDecodedHostname} = require("url");
30 const {checkWhitelisted} = require("whitelisting"); 30 const {checkWhitelisted} = require("whitelisting");
31 31
32 chrome.webRequest.onHeadersReceived.addListener(details => 32 browser.webRequest.onHeadersReceived.addListener(details =>
33 { 33 {
34 let hostname = getDecodedHostname(new URL(details.url)); 34 let hostname = getDecodedHostname(new URL(details.url));
35 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET, 35 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET,
36 hostname, false, null, true); 36 hostname, false, null, true);
37 if (match instanceof BlockingFilter && 37 if (match instanceof BlockingFilter &&
38 !checkWhitelisted(new ext.Page({id: details.tabId}), 38 !checkWhitelisted(new ext.Page({id: details.tabId}),
39 ext.getFrame(details.tabId, details.frameId))) 39 ext.getFrame(details.tabId, details.frameId)))
40 { 40 {
41 details.responseHeaders.push({ 41 details.responseHeaders.push({
42 name: "Content-Security-Policy", 42 name: "Content-Security-Policy",
(...skipping 17 matching lines...) Expand all
60 } 60 }
61 }, { 61 }, {
62 urls: ["http://*/*", "https://*/*"], 62 urls: ["http://*/*", "https://*/*"],
63 // We must also intercept script requests since otherwise Web Workers can 63 // We must also intercept script requests since otherwise Web Workers can
64 // be abused to execute scripts for which our Content Security Policy 64 // be abused to execute scripts for which our Content Security Policy
65 // won't be injected. 65 // won't be injected.
66 // https://github.com/gorhill/uBO-Extra/issues/19 66 // https://github.com/gorhill/uBO-Extra/issues/19
67 types: ["main_frame", "sub_frame", "script"] 67 types: ["main_frame", "sub_frame", "script"]
68 }, ["blocking", "responseHeaders"]); 68 }, ["blocking", "responseHeaders"]);
69 } 69 }
OLDNEW
« no previous file with comments | « include.preload.js ('k') | lib/cssInjection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld