| 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 // Map of content types reported by the browser to the respecitve content types | |
| 37 // used by Adblock Plus. Other content types are simply mapped to OTHER. | |
| 38 let resourceTypes = new Map(function*() | |
| 39 { | |
| 40 for (let type of Object.keys(RegExpFilter.typeMap)) | |
|
Manish Jethani
2017/05/19 23:44:15
This by the way could just be:
yield* Object.ke
Sebastian Noack
2017/05/20 06:42:37
It seems all versions of Chrome that support gener
Manish Jethani
2017/05/20 18:50:47
Done.
| |
| 41 yield [type.toLowerCase(), type]; | |
| 42 | |
| 43 yield ["sub_frame", "SUBDOCUMENT"]; | |
| 44 | |
| 45 // Treat navigator.sendBeacon() the same as <a ping>, it's essentially the | |
| 46 // same concept - merely generalized. | |
| 47 yield ["beacon", "PING"]; | |
| 48 | |
| 49 // Treat <img srcset> and <picture> the same as other images. | |
| 50 yield ["imageset", "IMAGE"]; | |
| 51 }()); | |
| 52 | |
| 35 function onBeforeRequestAsync(page, url, type, docDomain, | 53 function onBeforeRequestAsync(page, url, type, docDomain, |
| 36 thirdParty, sitekey, | 54 thirdParty, sitekey, |
| 37 specificOnly, filter) | 55 specificOnly, filter) |
| 38 { | 56 { |
| 39 if (filter) | 57 if (filter) |
| 40 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); | 58 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); |
| 41 | 59 |
| 42 if (devtools) | 60 if (devtools) |
| 43 { | 61 { |
| 44 devtools.logRequest( | 62 devtools.logRequest( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 56 | 74 |
| 57 let urlString = stringifyURL(url); | 75 let urlString = stringifyURL(url); |
| 58 let docDomain = extractHostFromFrame(frame); | 76 let docDomain = extractHostFromFrame(frame); |
| 59 let thirdParty = isThirdParty(url, docDomain); | 77 let thirdParty = isThirdParty(url, docDomain); |
| 60 let sitekey = getKey(page, frame); | 78 let sitekey = getKey(page, frame); |
| 61 | 79 |
| 62 let specificOnly = !!checkWhitelisted( | 80 let specificOnly = !!checkWhitelisted( |
| 63 page, frame, RegExpFilter.typeMap.GENERICBLOCK | 81 page, frame, RegExpFilter.typeMap.GENERICBLOCK |
| 64 ); | 82 ); |
| 65 | 83 |
| 84 let mappedType = resourceTypes.get(type) || "OTHER"; | |
| 85 | |
| 66 let filter = defaultMatcher.matchesAny( | 86 let filter = defaultMatcher.matchesAny( |
| 67 urlString, RegExpFilter.typeMap[type], | 87 urlString, RegExpFilter.typeMap[mappedType], |
| 68 docDomain, thirdParty, sitekey, specificOnly | 88 docDomain, thirdParty, sitekey, specificOnly |
| 69 ); | 89 ); |
| 70 | 90 |
| 71 setTimeout(onBeforeRequestAsync, 0, page, urlString, | 91 setTimeout(onBeforeRequestAsync, 0, page, urlString, |
| 72 type, docDomain, | 92 mappedType, docDomain, |
| 73 thirdParty, sitekey, | 93 thirdParty, sitekey, |
| 74 specificOnly, filter); | 94 specificOnly, filter); |
| 75 | 95 |
| 76 return !(filter instanceof BlockingFilter); | 96 return !(filter instanceof BlockingFilter); |
| 77 }); | 97 }); |
| 78 | 98 |
| 79 port.on("filters.collapse", (message, sender) => | 99 port.on("filters.collapse", (message, sender) => |
| 80 { | 100 { |
| 81 if (checkWhitelisted(sender.page, sender.frame)) | 101 if (checkWhitelisted(sender.page, sender.frame)) |
| 82 return false; | 102 return false; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 if (msg.requestType in chrome.webRequest.ResourceType) | 182 if (msg.requestType in chrome.webRequest.ResourceType) |
| 163 return false; | 183 return false; |
| 164 | 184 |
| 165 return ext.webRequest.onBeforeRequest._dispatch( | 185 return ext.webRequest.onBeforeRequest._dispatch( |
| 166 new URL(msg.url), | 186 new URL(msg.url), |
| 167 msg.requestType, | 187 msg.requestType, |
| 168 sender.page, | 188 sender.page, |
| 169 sender.frame | 189 sender.frame |
| 170 ).includes(false); | 190 ).includes(false); |
| 171 }); | 191 }); |
| OLD | NEW |