| Index: lib/requestBlocker.js |
| =================================================================== |
| --- a/lib/requestBlocker.js |
| +++ b/lib/requestBlocker.js |
| @@ -27,27 +27,44 @@ |
| const {checkWhitelisted, getKey} = require("whitelisting"); |
| const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url"); |
| const {port} = require("messaging"); |
| const devtools = require("devtools"); |
| // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. |
| 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
|
| +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
|
| + ["beacon", "PING"], |
| + ["imageset", "IMAGE"], |
| + ["sub_frame", "SUBDOCUMENT"], |
| + ["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
|
| + ["xml_dtd", "OTHER"], |
| + ["xslt", "OTHER"] |
| +]); |
| + |
| +let typeMasks = new Map( |
| + Object.keys(chrome.webRequest.ResourceType) |
| + .map(typeKey => chrome.webRequest.ResourceType[typeKey]) |
| + .map(type => [type, RegExpFilter.typeMap[resourceTypeMappings.get(type)] || |
| + 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.
|
| +); |
| + |
| function onBeforeRequestAsync(page, url, type, docDomain, |
| thirdParty, sitekey, |
| specificOnly, filter) |
| { |
| if (filter) |
| FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); |
| if (devtools) |
| { |
| devtools.logRequest( |
| - page, url, type, docDomain, |
| + page, url, |
| + resourceTypeMappings.get(type) || type.toUpperCase(), docDomain, |
| thirdParty, sitekey, |
| specificOnly, filter |
| ); |
| } |
| } |
| ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => |
| { |
| @@ -59,17 +76,17 @@ |
| let thirdParty = isThirdParty(url, docDomain); |
| let sitekey = getKey(page, frame); |
| let specificOnly = !!checkWhitelisted( |
| page, frame, RegExpFilter.typeMap.GENERICBLOCK |
| ); |
| let filter = defaultMatcher.matchesAny( |
| - urlString, RegExpFilter.typeMap[type], |
| + urlString, typeMasks.get(type), |
| docDomain, thirdParty, sitekey, specificOnly |
| ); |
| setTimeout(onBeforeRequestAsync, 0, page, urlString, |
| type, docDomain, |
| thirdParty, sitekey, |
| specificOnly, filter); |