| 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 // POPUP, CSP, REWRITE and ELEMHIDE filters aren't mapped to resource types. | 
| 
 
Sebastian Noack
2018/05/02 15:04:59
Nit: As this list growth, listing those filter opt
 
hub
2018/05/03 01:18:02
Done.
 
 | |
| 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 | 
| 197 getRelatedTabIds(details).then(tabIds => | 198 let log = logType => getRelatedTabIds(details).then(tabIds => | 
| 198 { | 199 { | 
| 199 logRequest(tabIds, urlString, type, docDomain, | 200 logRequest(tabIds, urlString, logType, docDomain, | 
| 200 thirdParty, sitekey, specificOnly, filter); | 201 thirdParty, sitekey, specificOnly, filter); | 
| 201 }); | 202 }); | 
| 202 | 203 | 
| 204 if (filter instanceof BlockingFilter && filter.rewrite) | |
| 
 
Manish Jethani
2018/04/30 20:24:58
I think maybe rewrite should be a separate module
 
hub
2018/05/01 18:32:36
This is a blocking filter with the rewrite option.
 
Sebastian Noack
2018/05/02 15:04:59
I agree that having the logic here is fine. Otherw
 
Manish Jethani
2018/05/02 16:13:45
Suppose there are two filters:
  /([^/]+\/)?bar$/
 
Sebastian Noack
2018/05/02 16:40:09
If we want to give precedence to blocking filters
 
Manish Jethani
2018/05/02 17:45:50
Yeah, I think that's fair.
I think defaultMatcher
 
hub
2018/05/03 01:18:02
I'm trying to actually keep it simple here.
 
Manish Jethani
2018/05/03 02:51:16
I'm OK with letting the filters with a rewrite opt
 
Sebastian Noack
2018/05/03 15:55:47
I don't quite get what we need another argument fo
 
Manish Jethani
2018/05/04 10:01:59
If the typeMask doesn't contain REWRITE it'll stil
 
Sebastian Noack
2018/05/04 15:17:16
Gotya. In fact REWRITE isn't even a flag in the ty
 
Manish Jethani
2018/05/04 15:37:47
Makes sense.
 
 | |
| 205 { | |
| 206 let rewritten = filter.doRewrite(urlString); | |
| 207 if (rewritten && rewritten != urlString) | |
| 208 { | |
| 209 log("REWRITE"); | |
| 210 | |
| 211 return {redirectUrl: rewritten}; | |
| 212 } | |
| 213 // we couldn't do the rewrite, so just let it through. | |
| 214 return; | |
| 215 } | |
| 216 | |
| 217 log(type); | |
| 
 
Sebastian Noack
2018/05/02 15:04:59
I'd rather move the logic around so that we don't
 
hub
2018/05/03 01:18:03
Done in a different way.
 
 | |
| 218 | |
| 203 if (filter instanceof BlockingFilter) | 219 if (filter instanceof BlockingFilter) | 
| 204 return {cancel: true}; | 220 return {cancel: true}; | 
| 205 }, {urls: ["<all_urls>"]}, ["blocking"]); | 221 }, {urls: ["<all_urls>"]}, ["blocking"]); | 
| 206 | 222 | 
| 207 port.on("filters.collapse", (message, sender) => | 223 port.on("filters.collapse", (message, sender) => | 
| 208 { | 224 { | 
| 209 let {page, frame} = sender; | 225 let {page, frame} = sender; | 
| 210 | 226 | 
| 211 if (checkWhitelisted(page, frame)) | 227 if (checkWhitelisted(page, frame)) | 
| 212 return false; | 228 return false; | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 } | 325 } | 
| 310 | 326 | 
| 311 FilterNotifier.on("subscription.added", onFilterChange); | 327 FilterNotifier.on("subscription.added", onFilterChange); | 
| 312 FilterNotifier.on("subscription.removed", onFilterChange); | 328 FilterNotifier.on("subscription.removed", onFilterChange); | 
| 313 FilterNotifier.on("subscription.updated", onFilterChange); | 329 FilterNotifier.on("subscription.updated", onFilterChange); | 
| 314 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); | 330 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); | 
| 315 FilterNotifier.on("filter.added", onFilterChange); | 331 FilterNotifier.on("filter.added", onFilterChange); | 
| 316 FilterNotifier.on("filter.removed", onFilterChange); | 332 FilterNotifier.on("filter.removed", onFilterChange); | 
| 317 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); | 333 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); | 
| 318 FilterNotifier.on("load", onFilterChange); | 334 FilterNotifier.on("load", onFilterChange); | 
| OLD | NEW |