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 // POPUP, CSP, REWRITE and ELEMHIDE filters 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 yield "REWRITE"; |
77 }()); | 78 }()); |
78 | 79 |
79 function getDocumentInfo(page, frame, originUrl) | 80 function getDocumentInfo(page, frame, originUrl) |
80 { | 81 { |
81 return [ | 82 return [ |
82 extractHostFromFrame(frame, originUrl), | 83 extractHostFromFrame(frame, originUrl), |
83 getKey(page, frame, originUrl), | 84 getKey(page, frame, originUrl), |
84 !!checkWhitelisted(page, frame, originUrl, | 85 !!checkWhitelisted(page, frame, originUrl, |
85 RegExpFilter.typeMap.GENERICBLOCK) | 86 RegExpFilter.typeMap.GENERICBLOCK) |
86 ]; | 87 ]; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 188 |
188 if (checkWhitelisted(page, frame, originUrl)) | 189 if (checkWhitelisted(page, frame, originUrl)) |
189 return; | 190 return; |
190 | 191 |
191 let type = resourceTypes.get(details.type) || "OTHER"; | 192 let type = resourceTypes.get(details.type) || "OTHER"; |
192 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, | 193 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, |
193 originUrl); | 194 originUrl); |
194 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, | 195 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, |
195 sitekey, specificOnly); | 196 sitekey, specificOnly); |
196 | 197 |
| 198 if (filter instanceof BlockingFilter && filter.rewrite) |
| 199 { |
| 200 let rewritten = filter.doRewrite(urlString); |
| 201 if (rewritten && rewritten != urlString) |
| 202 { |
| 203 getRelatedTabIds(details).then(tabIds => |
| 204 { |
| 205 logRequest(tabIds, urlString, "REWRITE", docDomain, |
| 206 thirdParty, sitekey, specificOnly, filter); |
| 207 }); |
| 208 |
| 209 return {redirectUrl: rewritten}; |
| 210 } |
| 211 // we couldn't do the rewrite, so just let it through. |
| 212 return; |
| 213 } |
| 214 |
197 getRelatedTabIds(details).then(tabIds => | 215 getRelatedTabIds(details).then(tabIds => |
198 { | 216 { |
199 logRequest(tabIds, urlString, type, docDomain, | 217 logRequest(tabIds, urlString, type, docDomain, |
200 thirdParty, sitekey, specificOnly, filter); | 218 thirdParty, sitekey, specificOnly, filter); |
201 }); | 219 }); |
202 | 220 |
203 if (filter instanceof BlockingFilter) | 221 if (filter instanceof BlockingFilter) |
204 return {cancel: true}; | 222 return {cancel: true}; |
205 }, {urls: ["<all_urls>"]}, ["blocking"]); | 223 }, {urls: ["<all_urls>"]}, ["blocking"]); |
206 | 224 |
(...skipping 102 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 |