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

Side by Side Diff: lib/requestBlocker.js

Issue 29739603: Issue 6544 - Prevent requests sent by Chrome or Adblock Plus from being blocked (Closed)
Patch Set: Created April 2, 2018, 3:03 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 | « no previous file | no next file » | 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 11 matching lines...) Expand all
22 const {Filter, RegExpFilter, BlockingFilter} = require("filterClasses"); 22 const {Filter, RegExpFilter, BlockingFilter} = require("filterClasses");
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 const extensionProtocol = new URL(browser.extension.getURL("")).protocol;
33
32 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. 34 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests.
33 if (!browser.webRequest.ResourceType || 35 if (!browser.webRequest.ResourceType ||
34 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType)) 36 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType))
35 { 37 {
36 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 38 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
37 } 39 }
38 40
39 // Map of content types reported by the browser to the respecitve content types 41 // 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. 42 // used by Adblock Plus. Other content types are simply mapped to OTHER.
41 let resourceTypes = new Map(function*() 43 let resourceTypes = new Map(function*()
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // Filter out requests from non web protocols. Ideally, we'd explicitly 134 // Filter out requests from non web protocols. Ideally, we'd explicitly
133 // specify the protocols we are interested in (i.e. http://, https://, 135 // specify the protocols we are interested in (i.e. http://, https://,
134 // ws:// and wss://) with the url patterns, given below, when adding this 136 // ws:// and wss://) with the url patterns, given below, when adding this
135 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket 137 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket
136 // protocol and is causing an error if it is given. 138 // protocol and is causing an error if it is given.
137 let url = new URL(details.url); 139 let url = new URL(details.url);
138 if (url.protocol != "http:" && url.protocol != "https:" && 140 if (url.protocol != "http:" && url.protocol != "https:" &&
139 url.protocol != "ws:" && url.protocol != "wss:") 141 url.protocol != "ws:" && url.protocol != "wss:")
140 return; 142 return;
141 143
142 let originUrl = null; 144 // Firefox provides us with the full origin URL, while Chromium (>=63)
kzar 2018/04/03 12:06:45 This diff doesn't seem right, I don't see this stu
kzar 2018/04/03 12:45:50 Oh I see, it's based on these changes https://code
143 if (details.originUrl) 145 // provides only the protocol + host of the (top-level) document which
144 { 146 // the request originates from through the "initiator" property.
145 originUrl = new URL(details.originUrl); 147 let originUrl = details.originUrl ? new URL(details.originUrl) :
148 details.initiator ? new URL(details.initiator) : null;
146 149
147 // Firefox (only) allows to intercept requests sent by the browser 150 // Firefox allows to intercept requests sent by all extensions or
148 // and other extensions. We don't want to block these. 151 // the browser (i.e. chrome://), while Chromium only allows to interecept
kzar 2018/04/03 12:06:45 Do you mean chrome:// for Firefox? Also how come t
Sebastian Noack 2018/04/03 23:36:28 Yes, "chrome:" is the protocol for content that is
kzar 2018/04/04 17:38:44 Acknowledged.
Sebastian Noack 2018/04/05 00:23:24 I changed the scope of this change, now also ignor
149 if (originUrl.protocol == "chrome:" || 152 // requests sent by this extension. We don't want to block any of these.
150 originUrl.protocol == "moz-extension:") 153 if (originUrl && (originUrl.protocol == extensionProtocol ||
151 return; 154 originUrl.protocol == "chrome:"))
152 } 155 return;
153 // Fallback to "initiator" on Chrome >=63. It doesn't include the
154 // path (unlike "originUrl" on Firefox), but is still good enough
155 // (in case the tab/frame is unknown) for the $domain filter option
156 // and most document exception rules which only match the domain part.
157 else if (details.initiator)
158 originUrl = new URL(details.initiator);
159 156
160 let page = null; 157 let page = null;
161 let frame = null; 158 let frame = null;
162 if (details.tabId != -1) 159 if (details.tabId != -1)
163 { 160 {
164 page = new ext.Page({id: details.tabId}); 161 page = new ext.Page({id: details.tabId});
165 frame = ext.getFrame( 162 frame = ext.getFrame(
166 details.tabId, 163 details.tabId,
167 // We are looking for the frame that contains the element which 164 // We are looking for the frame that contains the element which
168 // has triggered this request. For most requests (e.g. images) we 165 // has triggered this request. For most requests (e.g. images) we
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 272
276 port.on("request.blockedByRTCWrapper", (msg, sender) => 273 port.on("request.blockedByRTCWrapper", (msg, sender) =>
277 { 274 {
278 return ext.webRequest.onBeforeRequest._dispatch( 275 return ext.webRequest.onBeforeRequest._dispatch(
279 new URL(msg.url), 276 new URL(msg.url),
280 "webrtc", 277 "webrtc",
281 sender.page, 278 sender.page,
282 sender.frame 279 sender.frame
283 ).includes(false); 280 ).includes(false);
284 }); 281 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld