| 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 20 matching lines...) Expand all Loading... |
| 31 let {defaultMatcher} = require("matcher"); | 31 let {defaultMatcher} = require("matcher"); |
| 32 let {ElemHide} = require("elemHide"); | 32 let {ElemHide} = require("elemHide"); |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Public policy checking functions and auxiliary objects | 35 * Public policy checking functions and auxiliary objects |
| 36 * @class | 36 * @class |
| 37 */ | 37 */ |
| 38 var Policy = exports.Policy = | 38 var Policy = exports.Policy = |
| 39 { | 39 { |
| 40 /** | 40 /** |
| 41 * Set of explicitly supported content types | |
| 42 * @type Set.<string> | |
| 43 */ | |
| 44 contentTypes: new Set([ | |
| 45 "OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCUMENT", "DOCUMENT
", | |
| 46 "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA", "PING", "ELEMHIDE", | |
| 47 "POPUP", "GENERICHIDE", "GENERICBLOCK" | |
| 48 ]), | |
| 49 | |
| 50 /** | |
| 51 * Map of content types reported by Firefox to the respecitve content types | 41 * Map of content types reported by Firefox to the respecitve content types |
| 52 * used by Adblock Plus. Other content types are simply mapped to OTHER. | 42 * used by Adblock Plus. Other content types are simply mapped to OTHER. |
| 53 * @type Map.<string,string> | 43 * @type Map.<string,string> |
| 54 */ | 44 */ |
| 55 contentTypesMap: new Map([ | 45 contentTypes: new Map(function* () |
| 46 { |
| 56 // Treat navigator.sendBeacon() the same as <a ping>, | 47 // Treat navigator.sendBeacon() the same as <a ping>, |
| 57 // it's essentially the same concept - merely generalized. | 48 // it's essentially the same concept - merely generalized. |
| 58 ["BEACON", "PING"], | 49 yield ["BEACON", "PING"]; |
| 59 | 50 |
| 60 // Treat <img srcset> and <picture> the same as other images. | 51 // Treat <img srcset> and <picture> the same as other images. |
| 61 ["IMAGESET", "IMAGE"], | 52 yield ["IMAGESET", "IMAGE"]; |
| 62 | 53 |
| 63 // Treat fetch() the same as XMLHttpRequest, | 54 // Treat fetch() the same as XMLHttpRequest, |
| 64 // it's essentially the same - merely a more modern API. | 55 // it's essentially the same - merely a more modern API. |
| 65 ["FETCH", "XMLHTTPREQUEST"] | 56 yield ["FETCH", "XMLHTTPREQUEST"]; |
| 66 ]), | 57 |
| 58 // Everything else is mapped to itself |
| 59 for (let contentType of ["OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", |
| 60 "SUBDOCUMENT", "DOCUMENT", "XMLHTTPREQUEST", |
| 61 "OBJECT_SUBREQUEST", "FONT", "MEDIA", "PING", |
| 62 "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK"]
) |
| 63 yield [contentType, contentType]; |
| 64 }()), |
| 67 | 65 |
| 68 /** | 66 /** |
| 69 * 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 |
| 70 * @type Set.<string> | 68 * @type Set.<string> |
| 71 */ | 69 */ |
| 72 nonVisualTypes: new Set([ | 70 nonVisualTypes: new Set([ |
| 73 "SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", | 71 "SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", |
| 74 "PING", "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK" | 72 "PING", "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK" |
| 75 ]), | 73 ]), |
| 76 | 74 |
| 77 /** | 75 /** |
| 78 * Map containing all schemes that should be ignored by content policy. | 76 * Map containing all schemes that should be ignored by content policy. |
| 79 * @type Set.<string> | 77 * @type Set.<string> |
| 80 */ | 78 */ |
| 81 whitelistSchemes: new Set(), | 79 whitelistSchemes: new Set(), |
| 82 | 80 |
| 83 /** | 81 /** |
| 84 * Called on module startup, initializes various exported properties. | 82 * Called on module startup, initializes various exported properties. |
| 85 */ | 83 */ |
| 86 init: function() | 84 init: function() |
| 87 { | 85 { |
| 88 for (let contentType of this.contentTypes) | |
| 89 this.contentTypesMap.set(contentType, contentType); | |
| 90 | |
| 91 // whitelisted URL schemes | 86 // whitelisted URL schemes |
| 92 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) | 87 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) |
| 93 this.whitelistSchemes.add(scheme); | 88 this.whitelistSchemes.add(scheme); |
| 94 | 89 |
| 95 Utils.addChildMessageListener("AdblockPlus:ShouldAllow", message => this.sho
uldAllow(message)); | 90 Utils.addChildMessageListener("AdblockPlus:ShouldAllow", message => this.sho
uldAllow(message)); |
| 96 | 91 |
| 97 // Generate class identifier used to collapse nodes and register | 92 // Generate class identifier used to collapse nodes and register |
| 98 // corresponding stylesheet. | 93 // corresponding stylesheet. |
| 99 let collapsedClass = ""; | 94 let collapsedClass = ""; |
| 100 let offset = "a".charCodeAt(0); | 95 let offset = "a".charCodeAt(0); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 function response(allow, collapse) | 135 function response(allow, collapse) |
| 141 { | 136 { |
| 142 return {allow, collapse, hits}; | 137 return {allow, collapse, hits}; |
| 143 } | 138 } |
| 144 | 139 |
| 145 // Ignore whitelisted schemes | 140 // Ignore whitelisted schemes |
| 146 if (!this.isBlockableScheme(location)) | 141 if (!this.isBlockableScheme(location)) |
| 147 return response(true, false); | 142 return response(true, false); |
| 148 | 143 |
| 149 // Interpret unknown types as "other" | 144 // Interpret unknown types as "other" |
| 150 contentType = this.contentTypesMap.get(contentType) || "OTHER"; | 145 contentType = this.contentTypes.get(contentType) || "OTHER"; |
| 151 | 146 |
| 152 let wndLocation = frames[0].location; | 147 let wndLocation = frames[0].location; |
| 153 let docDomain = getHostname(wndLocation); | 148 let docDomain = getHostname(wndLocation); |
| 154 let match = null; | 149 let match = null; |
| 155 let [sitekey, sitekeyFrame] = getSitekey(frames); | 150 let [sitekey, sitekeyFrame] = getSitekey(frames); |
| 156 let nogeneric = false; | 151 let nogeneric = false; |
| 157 if (!match && Prefs.enabled) | 152 if (!match && Prefs.enabled) |
| 158 { | 153 { |
| 159 let testSitekey = sitekey; | 154 let testSitekey = sitekey; |
| 160 let testSitekeyFrame = sitekeyFrame; | 155 let testSitekeyFrame = sitekeyFrame; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 { | 400 { |
| 406 // EffectiveTLDService throws on IP addresses, just compare the host name | 401 // EffectiveTLDService throws on IP addresses, just compare the host name |
| 407 let host = ""; | 402 let host = ""; |
| 408 try | 403 try |
| 409 { | 404 { |
| 410 host = uri.host; | 405 host = uri.host; |
| 411 } catch (e) {} | 406 } catch (e) {} |
| 412 return host != docDomain; | 407 return host != docDomain; |
| 413 } | 408 } |
| 414 } | 409 } |
| OLD | NEW |