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

Side by Side Diff: lib/requestBlocker.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 /** @module requestBlocker */ 18 /** @module requestBlocker */
19 19
20 "use strict"; 20 import {Filter, RegExpFilter, BlockingFilter} from "filterClasses";
21 21 import {Subscription} from "subscriptionClasses";
22 const {Filter, RegExpFilter, BlockingFilter} = require("filterClasses"); 22 import {defaultMatcher} from "matcher";
23 const {Subscription} = require("subscriptionClasses"); 23 import {FilterNotifier} from "filterNotifier";
24 const {defaultMatcher} = require("matcher"); 24 import {Prefs} from "prefs";
25 const {FilterNotifier} = require("filterNotifier"); 25 import {checkWhitelisted, getKey} from "whitelisting";
26 const {Prefs} = require("prefs"); 26 import {stringifyURL, extractHostFromFrame, isThirdParty} from "url";
27 const {checkWhitelisted, getKey} = require("whitelisting"); 27 import {port} from "messaging";
28 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url"); 28 import devtools from "devtools";
29 const {port} = require("messaging");
30 const devtools = require("devtools");
31 29
32 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. 30 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests.
33 if (!browser.webRequest.ResourceType || 31 if (!browser.webRequest.ResourceType ||
34 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType)) 32 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType))
35 { 33 {
36 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 34 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
37 } 35 }
38 36
39 // Map of content types reported by the browser to the respecitve content types 37 // Map of content types reported by the browser to the respecitve content types
40 // used by Adblock Plus. Other content types are simply mapped to OTHER. 38 // used by Adblock Plus. Other content types are simply mapped to OTHER.
41 let resourceTypes = new Map(function*() 39 let resourceTypes = new Map(function*()
42 { 40 {
43 for (let type in RegExpFilter.typeMap) 41 for (let type in RegExpFilter.typeMap)
44 yield [type.toLowerCase(), type]; 42 yield [type.toLowerCase(), type];
45 43
46 yield ["sub_frame", "SUBDOCUMENT"]; 44 yield ["sub_frame", "SUBDOCUMENT"];
47 45
48 // Treat navigator.sendBeacon() the same as <a ping>, it's essentially the 46 // Treat navigator.sendBeacon() the same as <a ping>, it's essentially the
49 // same concept - merely generalized. 47 // same concept - merely generalized.
50 yield ["beacon", "PING"]; 48 yield ["beacon", "PING"];
51 49
52 // Treat <img srcset> and <picture> the same as other images. 50 // Treat <img srcset> and <picture> the same as other images.
53 yield ["imageset", "IMAGE"]; 51 yield ["imageset", "IMAGE"];
54 }()); 52 }());
55 53
56 exports.filterTypes = new Set(function*() 54 export const filterTypes = new Set(function*()
57 { 55 {
58 // Microsoft Edge does not have webRequest.ResourceType or the devtools panel. 56 // 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. 57 // Since filterTypes is only used by devtools, we can just bail out here.
60 if (!(browser.webRequest.ResourceType)) 58 if (!(browser.webRequest.ResourceType))
61 return; 59 return;
62 60
63 for (let type in browser.webRequest.ResourceType) 61 for (let type in browser.webRequest.ResourceType)
64 yield resourceTypes.get(browser.webRequest.ResourceType[type]) || "OTHER"; 62 yield resourceTypes.get(browser.webRequest.ResourceType[type]) || "OTHER";
65 63
66 // WEBSOCKET and WEBRTC get addressed through workarounds, even if the 64 // WEBSOCKET and WEBRTC get addressed through workarounds, even if the
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return false; 216 return false;
219 } 217 }
220 218
221 return ext.webRequest.onBeforeRequest._dispatch( 219 return ext.webRequest.onBeforeRequest._dispatch(
222 new URL(msg.url), 220 new URL(msg.url),
223 msg.requestType, 221 msg.requestType,
224 sender.page, 222 sender.page,
225 sender.frame 223 sender.frame
226 ).includes(false); 224 ).includes(false);
227 }); 225 });
OLDNEW
« lib/.eslintrc.json ('K') | « lib/prefs.js ('k') | lib/stats.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld