| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 const {Subscription} = require("subscriptionClasses"); | 23 const {Subscription} = require("subscriptionClasses"); |
| 24 const {defaultMatcher} = require("matcher"); | 24 const {defaultMatcher} = require("matcher"); |
| 25 const {FilterNotifier} = require("filterNotifier"); | 25 const {FilterNotifier} = require("filterNotifier"); |
| 26 const {Prefs} = require("prefs"); | 26 const {Prefs} = require("prefs"); |
| 27 const {checkWhitelisted, getKey} = require("whitelisting"); | 27 const {checkWhitelisted, getKey} = require("whitelisting"); |
| 28 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url"); | 28 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url"); |
| 29 const {port} = require("messaging"); | 29 const {port} = require("messaging"); |
| 30 const devtools = require("devtools"); | 30 const devtools = require("devtools"); |
| 31 | 31 |
| 32 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. | 32 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. |
| 33 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | 33 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; |
|
Sebastian Noack
2017/05/18 12:44:24
Unrelated, but note that this is also true for Fir
| |
| 34 | 34 |
| 35 let resourceTypeMappings = new Map([ | |
|
Sebastian Noack
2017/05/18 12:44:24
Nit: This is a mapping of resource types, so IMHO
Manish Jethani
2017/05/18 20:52:04
resourceTypes implies all resource types, but I've
| |
| 36 ["beacon", "PING"], | |
| 37 ["imageset", "IMAGE"], | |
| 38 ["sub_frame", "SUBDOCUMENT"], | |
| 39 ["web_manifest", "OTHER"], | |
|
Sebastian Noack
2017/05/18 12:44:24
I think we shouldn't hard-code the types we treat
Manish Jethani
2017/05/18 20:52:04
My reasoning was that we shouldn't block any resou
Sebastian Noack
2017/05/19 11:30:46
Sorry, I forgot to reply to this, since you addres
| |
| 40 ["xml_dtd", "OTHER"], | |
| 41 ["xslt", "OTHER"] | |
| 42 ]); | |
| 43 | |
| 44 let typeMasks = new Map( | |
| 45 Object.keys(chrome.webRequest.ResourceType) | |
| 46 .map(typeKey => chrome.webRequest.ResourceType[typeKey]) | |
| 47 .map(type => [type, RegExpFilter.typeMap[resourceTypeMappings.get(type)] || | |
| 48 RegExpFilter.typeMap[type.toUpperCase()] || 0]) | |
|
Sebastian Noack
2017/05/18 12:44:24
Please use RegExpFilter.typeMap.OTHER, rather than
Manish Jethani
2017/05/18 20:52:04
Done.
| |
| 49 ); | |
| 50 | |
| 35 function onBeforeRequestAsync(page, url, type, docDomain, | 51 function onBeforeRequestAsync(page, url, type, docDomain, |
| 36 thirdParty, sitekey, | 52 thirdParty, sitekey, |
| 37 specificOnly, filter) | 53 specificOnly, filter) |
| 38 { | 54 { |
| 39 if (filter) | 55 if (filter) |
| 40 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); | 56 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); |
| 41 | 57 |
| 42 if (devtools) | 58 if (devtools) |
| 43 { | 59 { |
| 44 devtools.logRequest( | 60 devtools.logRequest( |
| 45 page, url, type, docDomain, | 61 page, url, |
| 62 resourceTypeMappings.get(type) || type.toUpperCase(), docDomain, | |
| 46 thirdParty, sitekey, | 63 thirdParty, sitekey, |
| 47 specificOnly, filter | 64 specificOnly, filter |
| 48 ); | 65 ); |
| 49 } | 66 } |
| 50 } | 67 } |
| 51 | 68 |
| 52 ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => | 69 ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => |
| 53 { | 70 { |
| 54 if (checkWhitelisted(page, frame)) | 71 if (checkWhitelisted(page, frame)) |
| 55 return true; | 72 return true; |
| 56 | 73 |
| 57 let urlString = stringifyURL(url); | 74 let urlString = stringifyURL(url); |
| 58 let docDomain = extractHostFromFrame(frame); | 75 let docDomain = extractHostFromFrame(frame); |
| 59 let thirdParty = isThirdParty(url, docDomain); | 76 let thirdParty = isThirdParty(url, docDomain); |
| 60 let sitekey = getKey(page, frame); | 77 let sitekey = getKey(page, frame); |
| 61 | 78 |
| 62 let specificOnly = !!checkWhitelisted( | 79 let specificOnly = !!checkWhitelisted( |
| 63 page, frame, RegExpFilter.typeMap.GENERICBLOCK | 80 page, frame, RegExpFilter.typeMap.GENERICBLOCK |
| 64 ); | 81 ); |
| 65 | 82 |
| 66 let filter = defaultMatcher.matchesAny( | 83 let filter = defaultMatcher.matchesAny( |
| 67 urlString, RegExpFilter.typeMap[type], | 84 urlString, typeMasks.get(type), |
| 68 docDomain, thirdParty, sitekey, specificOnly | 85 docDomain, thirdParty, sitekey, specificOnly |
| 69 ); | 86 ); |
| 70 | 87 |
| 71 setTimeout(onBeforeRequestAsync, 0, page, urlString, | 88 setTimeout(onBeforeRequestAsync, 0, page, urlString, |
| 72 type, docDomain, | 89 type, docDomain, |
| 73 thirdParty, sitekey, | 90 thirdParty, sitekey, |
| 74 specificOnly, filter); | 91 specificOnly, filter); |
| 75 | 92 |
| 76 return !(filter instanceof BlockingFilter); | 93 return !(filter instanceof BlockingFilter); |
| 77 }); | 94 }); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 if (msg.requestType in chrome.webRequest.ResourceType) | 179 if (msg.requestType in chrome.webRequest.ResourceType) |
| 163 return false; | 180 return false; |
| 164 | 181 |
| 165 return ext.webRequest.onBeforeRequest._dispatch( | 182 return ext.webRequest.onBeforeRequest._dispatch( |
| 166 new URL(msg.url), | 183 new URL(msg.url), |
| 167 msg.requestType, | 184 msg.requestType, |
| 168 sender.page, | 185 sender.page, |
| 169 sender.frame | 186 sender.frame |
| 170 ).includes(false); | 187 ).includes(false); |
| 171 }); | 188 }); |
| OLD | NEW |