Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 "use strict"; |
21 | 21 |
22 const {Filter, RegExpFilter, BlockingFilter} = require("filterClasses"); | 22 const {Filter, RegExpFilter, BlockingFilter} = |
23 const {Subscription} = require("subscriptionClasses"); | 23 require("../adblockpluscore/lib/filterClasses"); |
24 const {defaultMatcher} = require("matcher"); | 24 const {Subscription} = require("../adblockpluscore/lib/subscriptionClasses"); |
25 const {FilterNotifier} = require("filterNotifier"); | 25 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); |
26 const {Prefs} = require("prefs"); | 26 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); |
27 const {checkWhitelisted, getKey} = require("whitelisting"); | 27 const {Prefs} = require("./prefs"); |
28 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url"); | 28 const {checkWhitelisted, getKey} = require("./whitelisting"); |
29 const {port} = require("messaging"); | 29 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("./url"); |
30 const devtools = require("devtools"); | 30 const {port} = require("./messaging"); |
31 const devtools = require("./devtools"); | |
31 | 32 |
32 const extensionProtocol = new URL(browser.extension.getURL("")).protocol; | 33 const extensionProtocol = new URL(browser.extension.getURL("")).protocol; |
33 | 34 |
34 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. | 35 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. |
35 if (!browser.webRequest.ResourceType || | 36 if (!browser.webRequest.ResourceType || |
36 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType)) | 37 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType)) |
37 { | 38 { |
38 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | 39 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; |
39 } | 40 } |
40 | 41 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 }()); | 77 }()); |
77 | 78 |
78 function getRelatedTabIds(details) | 79 function getRelatedTabIds(details) |
79 { | 80 { |
80 // This is the common case, the request is associated with a single tab. | 81 // This is the common case, the request is associated with a single tab. |
81 // If tabId is -1, its not (e.g. the request was sent by | 82 // If tabId is -1, its not (e.g. the request was sent by |
82 // a Service/Shared Worker) and we have to identify the related tabs. | 83 // a Service/Shared Worker) and we have to identify the related tabs. |
83 if (details.tabId != -1) | 84 if (details.tabId != -1) |
84 return Promise.resolve([details.tabId]); | 85 return Promise.resolve([details.tabId]); |
85 | 86 |
86 // Firefox >=48 provides "originUrl" indicating the URL of the tab | 87 let url; // Firefox provides "originUrl" indicating the |
87 // that caused this request. In case of Service/Shared Worker, | 88 if (details.originUrl) // URL of the tab that caused this request. |
88 // this is URL of the tab that caused the worker to be spawned. | 89 url = details.originUrl; // In case of Service/Shared Worker, this is the |
89 if (details.originUrl) | 90 // URL of the tab that caused the worker to spawn. |
90 return browser.tabs.query({url: details.originUrl}).then( | 91 |
91 tabs => tabs.map(tab => tab.id) | 92 else if (details.initiator) // Chromium >=63 provides "intiator" which |
92 ); | 93 url = details.initiator + "/*"; // is equivalent to "originUrl" on Firefox |
93 | 94 // except that its not a full URL but just |
94 // Chromium >=63 provides "intiator" which is equivalent to "originUrl" on | 95 // an origin (proto + host). |
95 // Firefox except that its not a full URL but just an origin (proto + host). | 96 else |
96 // So we have to find each tab with an URL of the same origin. | 97 return Promise.resolve([]); |
97 if (details.initiator) | 98 |
98 return browser.tabs.query({}).then(tabs => | 99 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); |
99 { | |
100 let tabIds = []; | |
101 for (let tab of tabs) | |
102 { | |
103 if (new URL(tab.url).origin == details.initiator) | |
104 tabIds.push(tab.id); | |
105 } | |
106 return tabIds; | |
107 }); | |
108 | |
109 return Promise.resolve([]); | |
110 } | 100 } |
111 | 101 |
112 function logRequest(details, url, type, docDomain, thirdParty, | 102 function logRequest(details, url, type, docDomain, thirdParty, |
113 sitekey, specificOnly, filter) | 103 sitekey, specificOnly, filter) |
114 { | 104 { |
115 getRelatedTabIds(details).then(tabIds => | 105 getRelatedTabIds(details).then(tabIds => |
116 { | 106 { |
117 if (filter) | 107 if (filter) |
118 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); | 108 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); |
119 | 109 |
(...skipping 20 matching lines...) Expand all Loading... | |
140 if (url.protocol != "http:" && url.protocol != "https:" && | 130 if (url.protocol != "http:" && url.protocol != "https:" && |
141 url.protocol != "ws:" && url.protocol != "wss:") | 131 url.protocol != "ws:" && url.protocol != "wss:") |
142 return; | 132 return; |
143 | 133 |
144 // Firefox provides us with the full origin URL, while Chromium (>=63) | 134 // Firefox provides us with the full origin URL, while Chromium (>=63) |
145 // provides only the protocol + host of the (top-level) document which | 135 // provides only the protocol + host of the (top-level) document which |
146 // the request originates from through the "initiator" property. | 136 // the request originates from through the "initiator" property. |
147 let originUrl = details.originUrl ? new URL(details.originUrl) : | 137 let originUrl = details.originUrl ? new URL(details.originUrl) : |
148 details.initiator ? new URL(details.initiator) : null; | 138 details.initiator ? new URL(details.initiator) : null; |
149 | 139 |
150 // Firefox allows to intercept requests sent by all extensions or | 140 // Ignore requests sent by extensions or by the browser itself: |
151 // the browser (i.e. chrome://), while Chromium only allows to interecept | 141 // * Firefox intercepts requests sent by any extensions, indicated with |
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
| |
152 // requests sent by this extension. We don't want to block any of these. | 142 // an "originURL" starting with "moz-extension:". |
153 if (originUrl && (originUrl.protocol == extensionProtocol || | 143 // * Chromium intercepts requests sent by this extension only, indicated |
154 originUrl.protocol == "chrome:")) | 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) | |
151 { | |
152 if (originUrl.protocol == extensionProtocol || | |
153 originUrl.protocol == "chrome:") | |
154 return; | |
155 } | |
156 else if (details.tabId == -1) | |
155 return; | 157 return; |
156 | 158 |
157 let page = null; | 159 let page = null; |
158 let frame = null; | 160 let frame = null; |
159 if (details.tabId != -1) | 161 if (details.tabId != -1) |
160 { | 162 { |
161 page = new ext.Page({id: details.tabId}); | 163 page = new ext.Page({id: details.tabId}); |
162 frame = ext.getFrame( | 164 frame = ext.getFrame( |
163 details.tabId, | 165 details.tabId, |
164 // We are looking for the frame that contains the element which | 166 // We are looking for the frame that contains the element which |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 | 274 |
273 port.on("request.blockedByRTCWrapper", (msg, sender) => | 275 port.on("request.blockedByRTCWrapper", (msg, sender) => |
274 { | 276 { |
275 return ext.webRequest.onBeforeRequest._dispatch( | 277 return ext.webRequest.onBeforeRequest._dispatch( |
276 new URL(msg.url), | 278 new URL(msg.url), |
277 "webrtc", | 279 "webrtc", |
278 sender.page, | 280 sender.page, |
279 sender.frame | 281 sender.frame |
280 ).includes(false); | 282 ).includes(false); |
281 }); | 283 }); |
LEFT | RIGHT |