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

Side by Side Diff: lib/requestBlocker.js

Issue 29570614: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Use callback-based API for storage Created Oct. 9, 2017, 4:01 p.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 | « lib/prefs.js ('k') | lib/stats.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
(...skipping 12 matching lines...) Expand all
23 const {Subscription} = require("subscriptionClasses"); 23 const {Subscription} = require("subscriptionClasses");
24 const {defaultMatcher} = require("matcher"); 24 const {defaultMatcher} = require("matcher");
25 const {FilterNotifier} = require("filterNotifier"); 25 const {FilterNotifier} = require("filterNotifier");
26 const {Prefs} = require("prefs"); 26 const {Prefs} = require("prefs");
27 const {checkWhitelisted, getKey} = require("whitelisting"); 27 const {checkWhitelisted, getKey} = require("whitelisting");
28 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url"); 28 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url");
29 const {port} = require("messaging"); 29 const {port} = require("messaging");
30 const devtools = require("devtools"); 30 const devtools = require("devtools");
31 31
32 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. 32 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests.
33 if (!chrome.webRequest.ResourceType || 33 if (!browser.webRequest.ResourceType ||
34 !("OBJECT_SUBREQUEST" in chrome.webRequest.ResourceType)) 34 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType))
35 { 35 {
36 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 36 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
37 } 37 }
38 38
39 // Map of content types reported by the browser to the respecitve content types 39 // 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. 40 // used by Adblock Plus. Other content types are simply mapped to OTHER.
41 let resourceTypes = new Map(function*() 41 let resourceTypes = new Map(function*()
42 { 42 {
43 for (let type in RegExpFilter.typeMap) 43 for (let type in RegExpFilter.typeMap)
44 yield [type.toLowerCase(), type]; 44 yield [type.toLowerCase(), type];
45 45
46 yield ["sub_frame", "SUBDOCUMENT"]; 46 yield ["sub_frame", "SUBDOCUMENT"];
47 47
48 // Treat navigator.sendBeacon() the same as <a ping>, it's essentially the 48 // Treat navigator.sendBeacon() the same as <a ping>, it's essentially the
49 // same concept - merely generalized. 49 // same concept - merely generalized.
50 yield ["beacon", "PING"]; 50 yield ["beacon", "PING"];
51 51
52 // Treat <img srcset> and <picture> the same as other images. 52 // Treat <img srcset> and <picture> the same as other images.
53 yield ["imageset", "IMAGE"]; 53 yield ["imageset", "IMAGE"];
54 }()); 54 }());
55 55
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 (!(chrome.webRequest.ResourceType)) 60 if (!(browser.webRequest.ResourceType))
61 return; 61 return;
62 62
63 for (let type in chrome.webRequest.ResourceType) 63 for (let type in browser.webRequest.ResourceType)
64 yield resourceTypes.get(chrome.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 // WEBSOCKET and WEBRTC get addressed through workarounds, even if the
67 // webRequest API is lacking support to block these kind of requests. 67 // webRequest API is lacking support to block these kind of requests.
68 yield "WEBSOCKET"; 68 yield "WEBSOCKET";
69 yield "WEBRTC"; 69 yield "WEBRTC";
70 70
71 // POPUP and ELEMHIDE filters aren't blocked on the request level but by other 71 // POPUP and ELEMHIDE filters aren't blocked on the request level but by other
72 // means. They don't have a corresponding value in webRequest.ResourceType. 72 // means. They don't have a corresponding value in webRequest.ResourceType.
73 yield "POPUP"; 73 yield "POPUP";
74 yield "ELEMHIDE"; 74 yield "ELEMHIDE";
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 205 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
206 FilterNotifier.on("load", onFilterChange); 206 FilterNotifier.on("load", onFilterChange);
207 207
208 port.on("request.blockedByWrapper", (msg, sender) => 208 port.on("request.blockedByWrapper", (msg, sender) =>
209 { 209 {
210 // Chrome 58 onwards directly supports WebSocket blocking, so we can ignore 210 // Chrome 58 onwards directly supports WebSocket blocking, so we can ignore
211 // messages from the wrapper here (see https://crbug.com/129353). Hopefully 211 // messages from the wrapper here (see https://crbug.com/129353). Hopefully
212 // WebRTC will be supported soon too (see https://crbug.com/707683). 212 // WebRTC will be supported soon too (see https://crbug.com/707683).
213 // Edge supports neither webRequest.ResourceType nor WebSocket blocking yet: 213 // Edge supports neither webRequest.ResourceType nor WebSocket blocking yet:
214 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/102973 76/ 214 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/102973 76/
215 if (chrome.webRequest.ResourceType && 215 if (browser.webRequest.ResourceType &&
216 (msg.requestType.toUpperCase() in chrome.webRequest.ResourceType)) 216 (msg.requestType.toUpperCase() in browser.webRequest.ResourceType))
217 { 217 {
218 return false; 218 return false;
219 } 219 }
220 220
221 return ext.webRequest.onBeforeRequest._dispatch( 221 return ext.webRequest.onBeforeRequest._dispatch(
222 new URL(msg.url), 222 new URL(msg.url),
223 msg.requestType, 223 msg.requestType,
224 sender.page, 224 sender.page,
225 sender.frame 225 sender.frame
226 ).includes(false); 226 ).includes(false);
227 }); 227 });
OLDNEW
« no previous file with comments | « lib/prefs.js ('k') | lib/stats.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld