| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 30 matching lines...) Expand all Loading... |
| 41 * Set of explicitly supported content types | 41 * Set of explicitly supported content types |
| 42 * @type Set.<string> | 42 * @type Set.<string> |
| 43 */ | 43 */ |
| 44 contentTypes: new Set([ | 44 contentTypes: new Set([ |
| 45 "OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCUMENT", "DOCUMENT
", | 45 "OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCUMENT", "DOCUMENT
", |
| 46 "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA", "PING", "ELEMHIDE", | 46 "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA", "PING", "ELEMHIDE", |
| 47 "POPUP", "GENERICHIDE", "GENERICBLOCK" | 47 "POPUP", "GENERICHIDE", "GENERICBLOCK" |
| 48 ]), | 48 ]), |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * |
| 52 */ |
| 53 contentTypesMap: new Map([ |
| 54 // Treat navigator.sendBeacon() the same as <a ping>, |
| 55 // it's essentially the same concept - merely generalized. |
| 56 ["BEACON", "PING"], |
| 57 |
| 58 // Treat <img srcset> and <picture> the same as other images. |
| 59 ["IMAGESET", "IMAGE"], |
| 60 |
| 61 // Treat fetch() the same as XMLHttpRequest, |
| 62 // it's essentially the same - merely a more modern API. |
| 63 ["FETCH", "XMLHTTPREQUEST"] |
| 64 ]), |
| 65 |
| 66 /** |
| 51 * Set of content types that aren't associated with a visual document area | 67 * Set of content types that aren't associated with a visual document area |
| 52 * @type Set.<string> | 68 * @type Set.<string> |
| 53 */ | 69 */ |
| 54 nonVisualTypes: new Set([ | 70 nonVisualTypes: new Set([ |
| 55 "SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", | 71 "SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", |
| 56 "PING", "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK" | 72 "PING", "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK" |
| 57 ]), | 73 ]), |
| 58 | 74 |
| 59 /** | 75 /** |
| 60 * Map containing all schemes that should be ignored by content policy. | 76 * Map containing all schemes that should be ignored by content policy. |
| 61 * @type Set.<string> | 77 * @type Set.<string> |
| 62 */ | 78 */ |
| 63 whitelistSchemes: new Set(), | 79 whitelistSchemes: new Set(), |
| 64 | 80 |
| 65 /** | 81 /** |
| 66 * Called on module startup, initializes various exported properties. | 82 * Called on module startup, initializes various exported properties. |
| 67 */ | 83 */ |
| 68 init: function() | 84 init: function() |
| 69 { | 85 { |
| 86 for (let contentType of this.contentTypes) |
| 87 this.contentTypesMap.set(contentType, contentType); |
| 88 |
| 70 // whitelisted URL schemes | 89 // whitelisted URL schemes |
| 71 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) | 90 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) |
| 72 this.whitelistSchemes.add(scheme); | 91 this.whitelistSchemes.add(scheme); |
| 73 | 92 |
| 74 Utils.addChildMessageListener("AdblockPlus:ShouldAllow", message => this.sho
uldAllow(message)); | 93 Utils.addChildMessageListener("AdblockPlus:ShouldAllow", message => this.sho
uldAllow(message)); |
| 75 | 94 |
| 76 // Generate class identifier used to collapse nodes and register | 95 // Generate class identifier used to collapse nodes and register |
| 77 // corresponding stylesheet. | 96 // corresponding stylesheet. |
| 78 let collapsedClass = ""; | 97 let collapsedClass = ""; |
| 79 let offset = "a".charCodeAt(0); | 98 let offset = "a".charCodeAt(0); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 137 |
| 119 function response(allow, collapse) | 138 function response(allow, collapse) |
| 120 { | 139 { |
| 121 return {allow, collapse, hits}; | 140 return {allow, collapse, hits}; |
| 122 } | 141 } |
| 123 | 142 |
| 124 // Ignore whitelisted schemes | 143 // Ignore whitelisted schemes |
| 125 if (!this.isBlockableScheme(location)) | 144 if (!this.isBlockableScheme(location)) |
| 126 return response(true, false); | 145 return response(true, false); |
| 127 | 146 |
| 128 // Treat navigator.sendBeacon() the same as <a ping>, it's essentially the | |
| 129 // same concept - merely generalized. | |
| 130 if (contentType == "BEACON") | |
| 131 contentType = "PING"; | |
| 132 | |
| 133 // Interpret unknown types as "other" | 147 // Interpret unknown types as "other" |
| 134 if (!this.contentTypes.has(contentType)) | 148 contentType = this.contentTypesMap.get(contentType) || "OTHER"; |
| 135 contentType = "OTHER"; | |
| 136 | 149 |
| 137 let wndLocation = frames[0].location; | 150 let wndLocation = frames[0].location; |
| 138 let docDomain = getHostname(wndLocation); | 151 let docDomain = getHostname(wndLocation); |
| 139 let match = null; | 152 let match = null; |
| 140 let [sitekey, sitekeyFrame] = getSitekey(frames); | 153 let [sitekey, sitekeyFrame] = getSitekey(frames); |
| 141 let nogeneric = false; | 154 let nogeneric = false; |
| 142 if (!match && Prefs.enabled) | 155 if (!match && Prefs.enabled) |
| 143 { | 156 { |
| 144 let testSitekey = sitekey; | 157 let testSitekey = sitekey; |
| 145 let testSitekeyFrame = sitekeyFrame; | 158 let testSitekeyFrame = sitekeyFrame; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 { | 413 { |
| 401 // EffectiveTLDService throws on IP addresses, just compare the host name | 414 // EffectiveTLDService throws on IP addresses, just compare the host name |
| 402 let host = ""; | 415 let host = ""; |
| 403 try | 416 try |
| 404 { | 417 { |
| 405 host = uri.host; | 418 host = uri.host; |
| 406 } catch (e) {} | 419 } catch (e) {} |
| 407 return host != docDomain; | 420 return host != docDomain; |
| 408 } | 421 } |
| 409 } | 422 } |
| OLD | NEW |