| Index: lib/requestBlocker.js |
| =================================================================== |
| --- a/lib/requestBlocker.js |
| +++ b/lib/requestBlocker.js |
| @@ -24,19 +24,31 @@ |
| const {defaultMatcher} = require("matcher"); |
| const {FilterNotifier} = require("filterNotifier"); |
| const {Prefs} = require("prefs"); |
| 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. |
| +// Chrome and Firefox (WebExtensions) can't distinguish between |
| +// OBJECT_SUBREQUEST and OBJECT requests. |
| RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; |
| +let resourceTypes = new Map( |
| + Object.keys(RegExpFilter.typeMap).map(type => [type.toLowerCase(), type]) |
| + .concat([ |
| + // Map unsupported resource types to types we support. Anything that isn't |
|
Sebastian Noack
2017/05/19 17:47:41
I wouldn't consider these resource types "unsuppor
Manish Jethani
2017/05/19 23:44:15
OK, I've just copied that comment over and changed
Sebastian Noack
2017/05/20 06:42:37
As I said, I don't have a strong opinion. So if yo
Manish Jethani
2017/05/20 18:50:47
Acknowledged.
|
| + // mapped here is implicitly mapped to "OTHER". |
| + ["beacon", "PING"], |
| + ["imageset", "IMAGE"], |
| + ["sub_frame", "SUBDOCUMENT"] |
| + ]) |
| +); |
| + |
| function onBeforeRequestAsync(page, url, type, docDomain, |
| thirdParty, sitekey, |
| specificOnly, filter) |
| { |
| if (filter) |
| FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); |
| if (devtools) |
| @@ -58,23 +70,25 @@ |
| let docDomain = extractHostFromFrame(frame); |
| let thirdParty = isThirdParty(url, docDomain); |
| let sitekey = getKey(page, frame); |
| let specificOnly = !!checkWhitelisted( |
| page, frame, RegExpFilter.typeMap.GENERICBLOCK |
| ); |
| + let mappedType = resourceTypes.get(type) || "OTHER"; |
| + |
| let filter = defaultMatcher.matchesAny( |
| - urlString, RegExpFilter.typeMap[type], |
| + urlString, RegExpFilter.typeMap[mappedType], |
| docDomain, thirdParty, sitekey, specificOnly |
| ); |
| setTimeout(onBeforeRequestAsync, 0, page, urlString, |
| - type, docDomain, |
| + mappedType, docDomain, |
| thirdParty, sitekey, |
| specificOnly, filter); |
| return !(filter instanceof BlockingFilter); |
| }); |
| port.on("filters.collapse", (message, sender) => |
| { |