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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 if (!(browser.webRequest.ResourceType)) | 63 if (!(browser.webRequest.ResourceType)) |
64 return; | 64 return; |
65 | 65 |
66 for (let type in browser.webRequest.ResourceType) | 66 for (let type in browser.webRequest.ResourceType) |
67 yield resourceTypes.get(browser.webRequest.ResourceType[type]) || "OTHER"; | 67 yield resourceTypes.get(browser.webRequest.ResourceType[type]) || "OTHER"; |
68 | 68 |
69 // WEBRTC gets addressed through a workaround, even if the webRequest API is | 69 // WEBRTC gets addressed through a workaround, even if the webRequest API is |
70 // lacking support to block this kind of a request. | 70 // lacking support to block this kind of a request. |
71 yield "WEBRTC"; | 71 yield "WEBRTC"; |
72 | 72 |
73 // POPUP, CSP and ELEMHIDE filters aren't mapped to resource types. | 73 // These filter types aren't mapped to resource types. |
74 yield "POPUP"; | 74 yield "POPUP"; |
75 yield "ELEMHIDE"; | 75 yield "ELEMHIDE"; |
76 yield "CSP"; | 76 yield "CSP"; |
77 }()); | 77 }()); |
78 | 78 |
79 function getDocumentInfo(page, frame, originUrl) | 79 function getDocumentInfo(page, frame, originUrl) |
80 { | 80 { |
81 return [ | 81 return [ |
82 extractHostFromFrame(frame, originUrl), | 82 extractHostFromFrame(frame, originUrl), |
83 getKey(page, frame, originUrl), | 83 getKey(page, frame, originUrl), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 url = details.initiator + "/*"; // is equivalent to "originUrl" on Firefox | 116 url = details.initiator + "/*"; // is equivalent to "originUrl" on Firefox |
117 // except that its not a full URL but just | 117 // except that its not a full URL but just |
118 // an origin (proto + host). | 118 // an origin (proto + host). |
119 else | 119 else |
120 return Promise.resolve([]); | 120 return Promise.resolve([]); |
121 | 121 |
122 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); | 122 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); |
123 } | 123 } |
124 | 124 |
125 function logRequest(tabIds, url, type, docDomain, thirdParty, | 125 function logRequest(tabIds, url, type, docDomain, thirdParty, |
126 sitekey, specificOnly, filter) | 126 sitekey, specificOnly, filter, rewrittenTo) |
127 { | 127 { |
128 if (filter) | 128 if (filter) |
129 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); | 129 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); |
130 | 130 |
131 devtools.logRequest( | 131 devtools.logRequest( |
132 tabIds, url, type, docDomain, | 132 tabIds, url, type, docDomain, |
133 thirdParty, sitekey, | 133 thirdParty, sitekey, |
134 specificOnly, filter | 134 specificOnly, filter, rewrittenTo |
135 ); | 135 ); |
136 } | 136 } |
137 | 137 |
138 browser.webRequest.onBeforeRequest.addListener(details => | 138 browser.webRequest.onBeforeRequest.addListener(details => |
139 { | 139 { |
140 // Never block top-level documents. | 140 // Never block top-level documents. |
141 if (details.type == "main_frame") | 141 if (details.type == "main_frame") |
142 return; | 142 return; |
143 | 143 |
144 // Filter out requests from non web protocols. Ideally, we'd explicitly | 144 // Filter out requests from non web protocols. Ideally, we'd explicitly |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 | 187 |
188 if (checkWhitelisted(page, frame, originUrl)) | 188 if (checkWhitelisted(page, frame, originUrl)) |
189 return; | 189 return; |
190 | 190 |
191 let type = resourceTypes.get(details.type) || "OTHER"; | 191 let type = resourceTypes.get(details.type) || "OTHER"; |
192 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, | 192 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, |
193 originUrl); | 193 originUrl); |
194 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, | 194 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, |
195 sitekey, specificOnly); | 195 sitekey, specificOnly); |
196 | 196 |
197 let result; | |
198 let rewrittenTo; | |
199 | |
200 if (filter instanceof BlockingFilter) | |
201 { | |
202 if (filter.rewrite) | |
203 { | |
204 let rewritten = filter.rewriteUrl(urlString); | |
Manish Jethani
2018/05/04 20:49:47
We don't need rewritten, we can just assign rewrit
hub
2018/05/04 20:51:49
already done
| |
205 if (rewritten == urlString) | |
Manish Jethani
2018/05/04 20:49:47
Nit: since the if block spans multiple lines, we s
hub
2018/05/04 20:51:49
Acknowledged.
| |
206 // we couldn't do the rewrite, so just let it through. | |
Sebastian Noack
2018/05/04 19:46:36
The request should still be logged.
Just for clar
Manish Jethani
2018/05/04 20:06:12
Agreed.
Manish Jethani
2018/05/04 20:27:24
To be clear, I'm OK with the check here even thoug
hub
2018/05/04 20:48:08
Ok, I'll log.
hub
2018/05/04 20:48:08
Last time I checked, Chrome (66) did that too.
hub
2018/05/04 20:48:08
Done this.
| |
207 return; | |
208 | |
209 rewrittenTo = rewritten; | |
210 result = {redirectUrl: rewritten}; | |
211 } | |
212 else | |
213 result = {cancel: true}; | |
214 } | |
215 | |
197 getRelatedTabIds(details).then(tabIds => | 216 getRelatedTabIds(details).then(tabIds => |
198 { | 217 { |
199 logRequest(tabIds, urlString, type, docDomain, | 218 logRequest(tabIds, urlString, type, docDomain, |
200 thirdParty, sitekey, specificOnly, filter); | 219 thirdParty, sitekey, specificOnly, filter, rewrittenTo); |
201 }); | 220 }); |
202 | 221 |
203 if (filter instanceof BlockingFilter) | 222 return result; |
204 return {cancel: true}; | |
205 }, {urls: ["<all_urls>"]}, ["blocking"]); | 223 }, {urls: ["<all_urls>"]}, ["blocking"]); |
206 | 224 |
207 port.on("filters.collapse", (message, sender) => | 225 port.on("filters.collapse", (message, sender) => |
208 { | 226 { |
209 let {page, frame} = sender; | 227 let {page, frame} = sender; |
210 | 228 |
211 if (checkWhitelisted(page, frame)) | 229 if (checkWhitelisted(page, frame)) |
212 return false; | 230 return false; |
213 | 231 |
214 let blocked = false; | 232 let blocked = false; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 } | 327 } |
310 | 328 |
311 FilterNotifier.on("subscription.added", onFilterChange); | 329 FilterNotifier.on("subscription.added", onFilterChange); |
312 FilterNotifier.on("subscription.removed", onFilterChange); | 330 FilterNotifier.on("subscription.removed", onFilterChange); |
313 FilterNotifier.on("subscription.updated", onFilterChange); | 331 FilterNotifier.on("subscription.updated", onFilterChange); |
314 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); | 332 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); |
315 FilterNotifier.on("filter.added", onFilterChange); | 333 FilterNotifier.on("filter.added", onFilterChange); |
316 FilterNotifier.on("filter.removed", onFilterChange); | 334 FilterNotifier.on("filter.removed", onFilterChange); |
317 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); | 335 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); |
318 FilterNotifier.on("load", onFilterChange); | 336 FilterNotifier.on("load", onFilterChange); |
OLD | NEW |