| 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 can't distinguish between OBJECT_SUBREQUEST and OBJECT |
|
Sebastian Noack
2017/05/18 21:33:41
Nit: Thanks for updating the comment, but it's sti
Manish Jethani
2017/05/18 21:49:34
Done.
| |
| 33 // requests. | |
| 33 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | 34 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; |
| 34 | 35 |
| 36 let resourceTypeMapping = new Map([ | |
| 37 ["beacon", "PING"], | |
| 38 ["imageset", "IMAGE"], | |
| 39 ["sub_frame", "SUBDOCUMENT"] | |
| 40 ]); | |
| 41 | |
| 42 let typeMasks = new Map( | |
| 43 Object.keys(chrome.webRequest.ResourceType) | |
| 44 .map(typeKey => chrome.webRequest.ResourceType[typeKey]) | |
| 45 .map(type => [type, RegExpFilter.typeMap[resourceTypeMapping.get(type)] || | |
| 46 RegExpFilter.typeMap[type.toUpperCase()] || | |
| 47 RegExpFilter.typeMap.OTHER]) | |
| 48 ); | |
| 49 | |
| 35 function onBeforeRequestAsync(page, url, type, docDomain, | 50 function onBeforeRequestAsync(page, url, type, docDomain, |
| 36 thirdParty, sitekey, | 51 thirdParty, sitekey, |
| 37 specificOnly, filter) | 52 specificOnly, filter) |
| 38 { | 53 { |
| 39 if (filter) | 54 if (filter) |
| 40 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); | 55 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); |
| 41 | 56 |
| 42 if (devtools) | 57 if (devtools) |
| 43 { | 58 { |
| 44 devtools.logRequest( | 59 devtools.logRequest( |
| 45 page, url, type, docDomain, | 60 page, url, |
| 61 resourceTypeMapping.get(type) || type.toUpperCase(), docDomain, | |
|
Sebastian Noack
2017/05/18 21:33:42
In case of the resource types we handle as OTHER,
Manish Jethani
2017/05/18 21:49:34
Oops, somehow I missed this. Fixed.
| |
| 46 thirdParty, sitekey, | 62 thirdParty, sitekey, |
| 47 specificOnly, filter | 63 specificOnly, filter |
| 48 ); | 64 ); |
| 49 } | 65 } |
| 50 } | 66 } |
| 51 | 67 |
| 52 ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => | 68 ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => |
| 53 { | 69 { |
| 54 if (checkWhitelisted(page, frame)) | 70 if (checkWhitelisted(page, frame)) |
| 55 return true; | 71 return true; |
| 56 | 72 |
| 57 let urlString = stringifyURL(url); | 73 let urlString = stringifyURL(url); |
| 58 let docDomain = extractHostFromFrame(frame); | 74 let docDomain = extractHostFromFrame(frame); |
| 59 let thirdParty = isThirdParty(url, docDomain); | 75 let thirdParty = isThirdParty(url, docDomain); |
| 60 let sitekey = getKey(page, frame); | 76 let sitekey = getKey(page, frame); |
| 61 | 77 |
| 62 let specificOnly = !!checkWhitelisted( | 78 let specificOnly = !!checkWhitelisted( |
| 63 page, frame, RegExpFilter.typeMap.GENERICBLOCK | 79 page, frame, RegExpFilter.typeMap.GENERICBLOCK |
| 64 ); | 80 ); |
| 65 | 81 |
| 66 let filter = defaultMatcher.matchesAny( | 82 let filter = defaultMatcher.matchesAny( |
| 67 urlString, RegExpFilter.typeMap[type], | 83 urlString, typeMasks.get(type), |
| 68 docDomain, thirdParty, sitekey, specificOnly | 84 docDomain, thirdParty, sitekey, specificOnly |
| 69 ); | 85 ); |
| 70 | 86 |
| 71 setTimeout(onBeforeRequestAsync, 0, page, urlString, | 87 setTimeout(onBeforeRequestAsync, 0, page, urlString, |
| 72 type, docDomain, | 88 type, docDomain, |
| 73 thirdParty, sitekey, | 89 thirdParty, sitekey, |
| 74 specificOnly, filter); | 90 specificOnly, filter); |
| 75 | 91 |
| 76 return !(filter instanceof BlockingFilter); | 92 return !(filter instanceof BlockingFilter); |
| 77 }); | 93 }); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 if (msg.requestType in chrome.webRequest.ResourceType) | 178 if (msg.requestType in chrome.webRequest.ResourceType) |
| 163 return false; | 179 return false; |
| 164 | 180 |
| 165 return ext.webRequest.onBeforeRequest._dispatch( | 181 return ext.webRequest.onBeforeRequest._dispatch( |
| 166 new URL(msg.url), | 182 new URL(msg.url), |
| 167 msg.requestType, | 183 msg.requestType, |
| 168 sender.page, | 184 sender.page, |
| 169 sender.frame | 185 sender.frame |
| 170 ).includes(false); | 186 ).includes(false); |
| 171 }); | 187 }); |
| OLD | NEW |