Left: | ||
Right: |
OLD | NEW |
---|---|
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 Loading... | |
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 const ignoredOrigins = new Set([extensionProtocol, "chrome:"]); | |
34 | |
32 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. | 35 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. |
33 if (!browser.webRequest.ResourceType || | 36 if (!browser.webRequest.ResourceType || |
34 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType)) | 37 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType)) |
35 { | 38 { |
36 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | 39 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; |
37 } | 40 } |
38 | 41 |
39 // Map of content types reported by the browser to the respecitve content types | 42 // 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. | 43 // used by Adblock Plus. Other content types are simply mapped to OTHER. |
41 let resourceTypes = new Map(function*() | 44 let resourceTypes = new Map(function*() |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 // Filter out requests from non web protocols. Ideally, we'd explicitly | 124 // Filter out requests from non web protocols. Ideally, we'd explicitly |
122 // specify the protocols we are interested in (i.e. http://, https://, | 125 // specify the protocols we are interested in (i.e. http://, https://, |
123 // ws:// and wss://) with the url patterns, given below, when adding this | 126 // ws:// and wss://) with the url patterns, given below, when adding this |
124 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket | 127 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket |
125 // protocol and is causing an error if it is given. | 128 // protocol and is causing an error if it is given. |
126 let url = new URL(details.url); | 129 let url = new URL(details.url); |
127 if (url.protocol != "http:" && url.protocol != "https:" && | 130 if (url.protocol != "http:" && url.protocol != "https:" && |
128 url.protocol != "ws:" && url.protocol != "wss:") | 131 url.protocol != "ws:" && url.protocol != "wss:") |
129 return; | 132 return; |
130 | 133 |
131 let originUrl = null; | 134 // Firefox provides us with the full origin URL, while Chromium (>=63) |
132 if (details.originUrl) | 135 // provides only the protocol + host of the (top-level) document which |
133 { | 136 // the request originates from through the "initiator" property. |
134 originUrl = new URL(details.originUrl); | 137 let originUrl = details.originUrl ? new URL(details.originUrl) : |
138 details.initiator ? new URL(details.initiator) : null; | |
135 | 139 |
136 // Firefox (only) allows to intercept requests sent by the browser | 140 // Ignore requests sent by extensions or by the browser itself: |
137 // and other extensions. We don't want to block these. | 141 // * Firefox intercepts requests sent by any extensions, indicated with |
138 if (originUrl.protocol == "chrome:" || | 142 // an "originURL" starting with "moz-extension:". |
139 originUrl.protocol == "moz-extension:") | 143 // * Chromium intercepts requests sent by this extension only, indicated |
140 return; | 144 // on Chromium >=63 with an "initiator" starting with "chrome-extension:". |
141 } | 145 // * On Firefox, requests that don't relate to any document or extension are |
142 // Fallback to "initiator" on Chrome >=63. It doesn't include the | 146 // indicated with an "originUrl" starting with "chrome:". |
143 // path (unlike "originUrl" on Firefox), but is still good enough | 147 // * On Chromium >=63, requests that don't relate to any document or extension |
144 // (in case the tab/frame is unknown) for the $domain filter option | 148 // have no "initiator". But since on older Chromium versions, no request |
145 // and most document exception rules which only match the domain part. | 149 // has an "initiator", we have to check for the tabId as well. |
146 else if (details.initiator) | 150 if (originUrl ? ignoredOrigins.has(originUrl.protocol) : details.tabId == -1) |
kzar
2018/04/06 14:48:10
Or perhaps like this?
if (originUrl && ignoredOri
Sebastian Noack
2018/04/06 17:55:46
These checks aren't equivalent. We only want to ba
kzar
2018/04/09 11:08:44
Ah right I see. Thing is I think this demonstrates
Sebastian Noack
2018/04/09 21:37:16
I don't see how the ternary operation is any more
| |
147 originUrl = new URL(details.initiator); | 151 return; |
148 | 152 |
149 let page = null; | 153 let page = null; |
150 let frame = null; | 154 let frame = null; |
151 if (details.tabId != -1) | 155 if (details.tabId != -1) |
152 { | 156 { |
153 page = new ext.Page({id: details.tabId}); | 157 page = new ext.Page({id: details.tabId}); |
154 frame = ext.getFrame( | 158 frame = ext.getFrame( |
155 details.tabId, | 159 details.tabId, |
156 // We are looking for the frame that contains the element which | 160 // We are looking for the frame that contains the element which |
157 // has triggered this request. For most requests (e.g. images) we | 161 // has triggered this request. For most requests (e.g. images) we |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 | 268 |
265 port.on("request.blockedByRTCWrapper", (msg, sender) => | 269 port.on("request.blockedByRTCWrapper", (msg, sender) => |
266 { | 270 { |
267 return ext.webRequest.onBeforeRequest._dispatch( | 271 return ext.webRequest.onBeforeRequest._dispatch( |
268 new URL(msg.url), | 272 new URL(msg.url), |
269 "webrtc", | 273 "webrtc", |
270 sender.page, | 274 sender.page, |
271 sender.frame | 275 sender.frame |
272 ).includes(false); | 276 ).includes(false); |
273 }); | 277 }); |
OLD | NEW |