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

Side by Side Diff: lib/csp.js

Issue 29715577: Issue 6449 - Switch to Harmony modules (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Add lib/.eslintrc.json Created March 6, 2018, 10:30 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
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 import {defaultMatcher} from "matcher";
19 import {BlockingFilter, RegExpFilter} from "filterClasses";
20 import {getDecodedHostname} from "url";
21 import {checkWhitelisted} from "whitelisting";
19 22
20 // The webRequest API doesn't support WebSocket connection blocking in Microsoft 23 // 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 24 // 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 25 // headers below as a workaround. See https://crbug.com/129353 and
23 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10297376 / 26 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10297376 /
24 if (!browser.webRequest.ResourceType || 27 if (!browser.webRequest.ResourceType ||
25 !("WEBSOCKET" in browser.webRequest.ResourceType)) 28 !("WEBSOCKET" in browser.webRequest.ResourceType))
26 { 29 {
27 const {defaultMatcher} = require("matcher");
28 const {BlockingFilter, RegExpFilter} = require("filterClasses");
29 const {getDecodedHostname} = require("url");
30 const {checkWhitelisted} = require("whitelisting");
31
32 browser.webRequest.onHeadersReceived.addListener(details => 30 browser.webRequest.onHeadersReceived.addListener(details =>
33 { 31 {
34 let hostname = getDecodedHostname(new URL(details.url)); 32 let hostname = getDecodedHostname(new URL(details.url));
35 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET, 33 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET,
36 hostname, false, null, true); 34 hostname, false, null, true);
37 if (match instanceof BlockingFilter && 35 if (match instanceof BlockingFilter &&
38 !checkWhitelisted(new ext.Page({id: details.tabId}), 36 !checkWhitelisted(new ext.Page({id: details.tabId}),
39 ext.getFrame(details.tabId, details.frameId))) 37 ext.getFrame(details.tabId, details.frameId)))
40 { 38 {
41 details.responseHeaders.push({ 39 details.responseHeaders.push({
(...skipping 18 matching lines...) Expand all
60 } 58 }
61 }, { 59 }, {
62 urls: ["http://*/*", "https://*/*"], 60 urls: ["http://*/*", "https://*/*"],
63 // We must also intercept script requests since otherwise Web Workers can 61 // We must also intercept script requests since otherwise Web Workers can
64 // be abused to execute scripts for which our Content Security Policy 62 // be abused to execute scripts for which our Content Security Policy
65 // won't be injected. 63 // won't be injected.
66 // https://github.com/gorhill/uBO-Extra/issues/19 64 // https://github.com/gorhill/uBO-Extra/issues/19
67 types: ["main_frame", "sub_frame", "script"] 65 types: ["main_frame", "sub_frame", "script"]
68 }, ["blocking", "responseHeaders"]); 66 }, ["blocking", "responseHeaders"]);
69 } 67 }
OLDNEW
« lib/.eslintrc.json ('K') | « lib/.eslintrc.json ('k') | lib/cssInjection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld