| 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 11 matching lines...) Expand all Loading... | |
| 22 const {Filter, RegExpFilter, BlockingFilter} = require("filterClasses"); | 22 const {Filter, RegExpFilter, BlockingFilter} = require("filterClasses"); |
| 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 and Firefox (WebExtensions) can't distinguish between |
| 33 // OBJECT_SUBREQUEST and OBJECT requests. | |
| 33 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | 34 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; |
| 34 | 35 |
| 36 let resourceTypes = new Map( | |
| 37 Object.keys(RegExpFilter.typeMap).map(type => [type.toLowerCase(), type]) | |
| 38 .concat([ | |
| 39 // 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.
| |
| 40 // mapped here is implicitly mapped to "OTHER". | |
| 41 ["beacon", "PING"], | |
| 42 ["imageset", "IMAGE"], | |
| 43 ["sub_frame", "SUBDOCUMENT"] | |
| 44 ]) | |
| 45 ); | |
| 46 | |
| 35 function onBeforeRequestAsync(page, url, type, docDomain, | 47 function onBeforeRequestAsync(page, url, type, docDomain, |
| 36 thirdParty, sitekey, | 48 thirdParty, sitekey, |
| 37 specificOnly, filter) | 49 specificOnly, filter) |
| 38 { | 50 { |
| 39 if (filter) | 51 if (filter) |
| 40 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); | 52 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); |
| 41 | 53 |
| 42 if (devtools) | 54 if (devtools) |
| 43 { | 55 { |
| 44 devtools.logRequest( | 56 devtools.logRequest( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 56 | 68 |
| 57 let urlString = stringifyURL(url); | 69 let urlString = stringifyURL(url); |
| 58 let docDomain = extractHostFromFrame(frame); | 70 let docDomain = extractHostFromFrame(frame); |
| 59 let thirdParty = isThirdParty(url, docDomain); | 71 let thirdParty = isThirdParty(url, docDomain); |
| 60 let sitekey = getKey(page, frame); | 72 let sitekey = getKey(page, frame); |
| 61 | 73 |
| 62 let specificOnly = !!checkWhitelisted( | 74 let specificOnly = !!checkWhitelisted( |
| 63 page, frame, RegExpFilter.typeMap.GENERICBLOCK | 75 page, frame, RegExpFilter.typeMap.GENERICBLOCK |
| 64 ); | 76 ); |
| 65 | 77 |
| 78 let mappedType = resourceTypes.get(type) || "OTHER"; | |
| 79 | |
| 66 let filter = defaultMatcher.matchesAny( | 80 let filter = defaultMatcher.matchesAny( |
| 67 urlString, RegExpFilter.typeMap[type], | 81 urlString, RegExpFilter.typeMap[mappedType], |
| 68 docDomain, thirdParty, sitekey, specificOnly | 82 docDomain, thirdParty, sitekey, specificOnly |
| 69 ); | 83 ); |
| 70 | 84 |
| 71 setTimeout(onBeforeRequestAsync, 0, page, urlString, | 85 setTimeout(onBeforeRequestAsync, 0, page, urlString, |
| 72 type, docDomain, | 86 mappedType, docDomain, |
| 73 thirdParty, sitekey, | 87 thirdParty, sitekey, |
| 74 specificOnly, filter); | 88 specificOnly, filter); |
| 75 | 89 |
| 76 return !(filter instanceof BlockingFilter); | 90 return !(filter instanceof BlockingFilter); |
| 77 }); | 91 }); |
| 78 | 92 |
| 79 port.on("filters.collapse", (message, sender) => | 93 port.on("filters.collapse", (message, sender) => |
| 80 { | 94 { |
| 81 if (checkWhitelisted(sender.page, sender.frame)) | 95 if (checkWhitelisted(sender.page, sender.frame)) |
| 82 return false; | 96 return false; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 if (msg.requestType in chrome.webRequest.ResourceType) | 176 if (msg.requestType in chrome.webRequest.ResourceType) |
| 163 return false; | 177 return false; |
| 164 | 178 |
| 165 return ext.webRequest.onBeforeRequest._dispatch( | 179 return ext.webRequest.onBeforeRequest._dispatch( |
| 166 new URL(msg.url), | 180 new URL(msg.url), |
| 167 msg.requestType, | 181 msg.requestType, |
| 168 sender.page, | 182 sender.page, |
| 169 sender.frame | 183 sender.frame |
| 170 ).includes(false); | 184 ).includes(false); |
| 171 }); | 185 }); |
| OLD | NEW |