| 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 12 matching lines...) Expand all Loading... |
| 23 require("../adblockpluscore/lib/filterClasses"); | 23 require("../adblockpluscore/lib/filterClasses"); |
| 24 const {Subscription} = require("../adblockpluscore/lib/subscriptionClasses"); | 24 const {Subscription} = require("../adblockpluscore/lib/subscriptionClasses"); |
| 25 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); | 25 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); |
| 26 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); | 26 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); |
| 27 const {Prefs} = require("./prefs"); | 27 const {Prefs} = require("./prefs"); |
| 28 const {checkWhitelisted, getKey} = require("./whitelisting"); | 28 const {checkWhitelisted, getKey} = require("./whitelisting"); |
| 29 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("./url"); | 29 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("./url"); |
| 30 const {port} = require("./messaging"); | 30 const {port} = require("./messaging"); |
| 31 const devtools = require("./devtools"); | 31 const devtools = require("./devtools"); |
| 32 | 32 |
| 33 const extensionProtocol = new URL(browser.extension.getURL("")).protocol; |
| 34 |
| 33 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. | 35 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. |
| 34 if (!browser.webRequest.ResourceType || | 36 if (!browser.webRequest.ResourceType || |
| 35 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType)) | 37 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType)) |
| 36 { | 38 { |
| 37 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | 39 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; |
| 38 } | 40 } |
| 39 | 41 |
| 40 // 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 |
| 41 // 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. |
| 42 let resourceTypes = new Map(function*() | 44 let resourceTypes = new Map(function*() |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // Filter out requests from non web protocols. Ideally, we'd explicitly | 124 // Filter out requests from non web protocols. Ideally, we'd explicitly |
| 123 // specify the protocols we are interested in (i.e. http://, https://, | 125 // specify the protocols we are interested in (i.e. http://, https://, |
| 124 // 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 |
| 125 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket | 127 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket |
| 126 // protocol and is causing an error if it is given. | 128 // protocol and is causing an error if it is given. |
| 127 let url = new URL(details.url); | 129 let url = new URL(details.url); |
| 128 if (url.protocol != "http:" && url.protocol != "https:" && | 130 if (url.protocol != "http:" && url.protocol != "https:" && |
| 129 url.protocol != "ws:" && url.protocol != "wss:") | 131 url.protocol != "ws:" && url.protocol != "wss:") |
| 130 return; | 132 return; |
| 131 | 133 |
| 132 let originUrl = null; | 134 // Firefox provides us with the full origin URL, while Chromium (>=63) |
| 133 if (details.originUrl) | 135 // provides only the protocol + host of the (top-level) document which |
| 136 // the request originates from through the "initiator" property. |
| 137 let originUrl = details.originUrl ? new URL(details.originUrl) : |
| 138 details.initiator ? new URL(details.initiator) : null; |
| 139 |
| 140 // Ignore requests sent by extensions or by the browser itself: |
| 141 // * Firefox intercepts requests sent by any extensions, indicated with |
| 142 // an "originURL" starting with "moz-extension:". |
| 143 // * Chromium intercepts requests sent by this extension only, indicated |
| 144 // on Chromium >=63 with an "initiator" starting with "chrome-extension:". |
| 145 // * On Firefox, requests that don't relate to any document or extension are |
| 146 // indicated with an "originUrl" starting with "chrome:". |
| 147 // * On Chromium >=63, requests that don't relate to any document or extension |
| 148 // have no "initiator". But since on older Chromium versions, no request |
| 149 // has an "initiator", we have to check for the tabId as well. |
| 150 if (originUrl) |
| 134 { | 151 { |
| 135 originUrl = new URL(details.originUrl); | 152 if (originUrl.protocol == extensionProtocol || |
| 136 | 153 originUrl.protocol == "chrome:") |
| 137 // Firefox (only) allows to intercept requests sent by the browser | |
| 138 // and other extensions. We don't want to block these. | |
| 139 if (originUrl.protocol == "chrome:" || | |
| 140 originUrl.protocol == "moz-extension:") | |
| 141 return; | 154 return; |
| 142 } | 155 } |
| 143 // Fallback to "initiator" on Chrome >=63. It doesn't include the | 156 else if (details.tabId == -1) |
| 144 // path (unlike "originUrl" on Firefox), but is still good enough | 157 return; |
| 145 // (in case the tab/frame is unknown) for the $domain filter option | |
| 146 // and most document exception rules which only match the domain part. | |
| 147 else if (details.initiator) | |
| 148 originUrl = new URL(details.initiator); | |
| 149 | 158 |
| 150 let page = null; | 159 let page = null; |
| 151 let frame = null; | 160 let frame = null; |
| 152 if (details.tabId != -1) | 161 if (details.tabId != -1) |
| 153 { | 162 { |
| 154 page = new ext.Page({id: details.tabId}); | 163 page = new ext.Page({id: details.tabId}); |
| 155 frame = ext.getFrame( | 164 frame = ext.getFrame( |
| 156 details.tabId, | 165 details.tabId, |
| 157 // We are looking for the frame that contains the element which | 166 // We are looking for the frame that contains the element which |
| 158 // has triggered this request. For most requests (e.g. images) we | 167 // has triggered this request. For most requests (e.g. images) we |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 274 |
| 266 port.on("request.blockedByRTCWrapper", (msg, sender) => | 275 port.on("request.blockedByRTCWrapper", (msg, sender) => |
| 267 { | 276 { |
| 268 return ext.webRequest.onBeforeRequest._dispatch( | 277 return ext.webRequest.onBeforeRequest._dispatch( |
| 269 new URL(msg.url), | 278 new URL(msg.url), |
| 270 "webrtc", | 279 "webrtc", |
| 271 sender.page, | 280 sender.page, |
| 272 sender.frame | 281 sender.frame |
| 273 ).includes(false); | 282 ).includes(false); |
| 274 }); | 283 }); |
| OLD | NEW |