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 16 matching lines...) Expand all Loading... |
27 let {Utils} = require("utils"); | 27 let {Utils} = require("utils"); |
28 let {Prefs} = require("prefs"); | 28 let {Prefs} = require("prefs"); |
29 let {FilterStorage} = require("filterStorage"); | 29 let {FilterStorage} = require("filterStorage"); |
30 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); | 30 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); |
31 let {defaultMatcher} = require("matcher"); | 31 let {defaultMatcher} = require("matcher"); |
32 let {objectMouseEventHander} = require("objectTabs"); | 32 let {objectMouseEventHander} = require("objectTabs"); |
33 let {RequestNotifier} = require("requestNotifier"); | 33 let {RequestNotifier} = require("requestNotifier"); |
34 let {ElemHide} = require("elemHide"); | 34 let {ElemHide} = require("elemHide"); |
35 | 35 |
36 /** | 36 /** |
37 * Set of explicitly supported content types | |
38 * @type Set | |
39 */ | |
40 let contentTypes = new Set([ | |
41 "OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCUMENT", "DOCUMENT", | |
42 "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA", "ELEMHIDE", "POPUP", | |
43 "GENERICHIDE", "GENERICBLOCK" | |
44 ]); | |
45 | |
46 /** | |
47 * Set of content types that aren't associated with a visual document area | |
48 * @type Set | |
49 */ | |
50 let nonVisualTypes = new Set([ | |
51 "SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", | |
52 "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK" | |
53 ]); | |
54 | |
55 /** | |
56 * Randomly generated class name, to be applied to collapsed nodes. | 37 * Randomly generated class name, to be applied to collapsed nodes. |
57 */ | 38 */ |
58 let collapsedClass = ""; | 39 let collapsedClass = ""; |
59 | 40 |
60 /** | 41 /** |
61 * Maps numerical content type IDs to strings. | 42 * Maps numerical content type IDs to strings. |
62 * @type Map | 43 * @type Map |
63 */ | 44 */ |
64 let types = new Map(); | 45 let types = new Map(); |
65 | 46 |
66 /** | 47 /** |
67 * Public policy checking functions and auxiliary objects | 48 * Public policy checking functions and auxiliary objects |
68 * @class | 49 * @class |
69 */ | 50 */ |
70 var Policy = exports.Policy = | 51 var Policy = exports.Policy = |
71 { | 52 { |
72 /** | 53 /** |
73 * Map of localized content type names by their identifiers. | 54 * Set of explicitly supported content types |
74 * @type Map | 55 * @type Set |
75 */ | 56 */ |
76 localizedDescr: new Map(), | 57 contentTypes: new Set([ |
| 58 "OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCUMENT", "DOCUMENT
", |
| 59 "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA", "ELEMHIDE", "POPUP", |
| 60 "GENERICHIDE", "GENERICBLOCK" |
| 61 ]), |
| 62 |
| 63 /** |
| 64 * Set of content types that aren't associated with a visual document area |
| 65 * @type Set |
| 66 */ |
| 67 nonVisualTypes: new Set([ |
| 68 "SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", |
| 69 "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK" |
| 70 ]), |
77 | 71 |
78 /** | 72 /** |
79 * Map containing all schemes that should be ignored by content policy. | 73 * Map containing all schemes that should be ignored by content policy. |
80 * @type Set | 74 * @type Set |
81 */ | 75 */ |
82 whitelistSchemes: new Set(), | 76 whitelistSchemes: new Set(), |
83 | 77 |
84 /** | 78 /** |
85 * Called on module startup, initializes various exported properties. | 79 * Called on module startup, initializes various exported properties. |
86 */ | 80 */ |
87 init: function() | 81 init: function() |
88 { | 82 { |
89 // Populate types map | 83 // Populate types map |
90 let iface = Ci.nsIContentPolicy; | 84 let iface = Ci.nsIContentPolicy; |
91 for (let name in iface) | 85 for (let name in iface) |
92 if (name.indexOf("TYPE_") == 0 && name != "TYPE_DATAREQUEST") | 86 if (name.indexOf("TYPE_") == 0 && name != "TYPE_DATAREQUEST") |
93 types.set(iface[name], name.substr(5)); | 87 types.set(iface[name], name.substr(5)); |
94 | 88 |
95 // Populate localized type names | |
96 for (let typeName of contentTypes) | |
97 this.localizedDescr.set(typeName, Utils.getString("type_label_" + typeName
.toLowerCase())); | |
98 | |
99 // whitelisted URL schemes | 89 // whitelisted URL schemes |
100 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) | 90 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) |
101 this.whitelistSchemes.add(scheme); | 91 this.whitelistSchemes.add(scheme); |
102 | 92 |
103 // Generate class identifier used to collapse node and register correspondin
g | 93 // Generate class identifier used to collapse node and register correspondin
g |
104 // stylesheet. | 94 // stylesheet. |
105 let offset = "a".charCodeAt(0); | 95 let offset = "a".charCodeAt(0); |
106 for (let i = 0; i < 20; i++) | 96 for (let i = 0; i < 20; i++) |
107 collapsedClass += String.fromCharCode(offset + Math.random() * 26); | 97 collapsedClass += String.fromCharCode(offset + Math.random() * 26); |
108 | 98 |
(...skipping 16 matching lines...) Expand all Loading... |
125 * @param collapse {Boolean} true to force hiding of the node | 115 * @param collapse {Boolean} true to force hiding of the node |
126 * @return {Boolean} false if the node should be blocked | 116 * @return {Boolean} false if the node should be blocked |
127 */ | 117 */ |
128 processNode: function(wnd, node, contentType, location, collapse) | 118 processNode: function(wnd, node, contentType, location, collapse) |
129 { | 119 { |
130 let topWnd = wnd.top; | 120 let topWnd = wnd.top; |
131 if (!topWnd || !topWnd.location || !topWnd.location.href) | 121 if (!topWnd || !topWnd.location || !topWnd.location.href) |
132 return true; | 122 return true; |
133 | 123 |
134 // Interpret unknown types as "other" | 124 // Interpret unknown types as "other" |
135 if (!contentTypes.has(contentType)) | 125 if (!this.contentTypes.has(contentType)) |
136 contentType = "OTHER"; | 126 contentType = "OTHER"; |
137 | 127 |
138 let originWindow = Utils.getOriginWindow(wnd); | 128 let originWindow = Utils.getOriginWindow(wnd); |
139 let wndLocation = originWindow.location.href; | 129 let wndLocation = originWindow.location.href; |
140 let docDomain = getHostname(wndLocation); | 130 let docDomain = getHostname(wndLocation); |
141 let match = null; | 131 let match = null; |
142 let [sitekey, sitekeyWnd] = getSitekey(wnd); | 132 let [sitekey, sitekeyWnd] = getSitekey(wnd); |
143 let nogeneric = false; | 133 let nogeneric = false; |
144 | 134 |
145 function cleanWindowLocation(wnd) | 135 function cleanWindowLocation(wnd) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 if (nogeneric && match.isGeneric()) | 216 if (nogeneric && match.isGeneric()) |
227 return true; | 217 return true; |
228 } | 218 } |
229 | 219 |
230 let thirdParty = (contentType == "ELEMHIDE" ? false : isThirdParty(location,
docDomain)); | 220 let thirdParty = (contentType == "ELEMHIDE" ? false : isThirdParty(location,
docDomain)); |
231 | 221 |
232 if (!match && Prefs.enabled && RegExpFilter.typeMap.hasOwnProperty(contentTy
pe)) | 222 if (!match && Prefs.enabled && RegExpFilter.typeMap.hasOwnProperty(contentTy
pe)) |
233 { | 223 { |
234 match = defaultMatcher.matchesAny(location, RegExpFilter.typeMap[contentTy
pe], | 224 match = defaultMatcher.matchesAny(location, RegExpFilter.typeMap[contentTy
pe], |
235 docDomain, thirdParty, sitekey, nogeneri
c); | 225 docDomain, thirdParty, sitekey, nogeneri
c); |
236 if (match instanceof BlockingFilter && node.ownerDocument && !nonVisualTyp
es.has(contentType)) | 226 if (match instanceof BlockingFilter && node.ownerDocument && !this.nonVisu
alTypes.has(contentType)) |
237 { | 227 { |
238 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas
tcollapse); | 228 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas
tcollapse); |
239 if (collapse || prefCollapse) | 229 if (collapse || prefCollapse) |
240 schedulePostProcess(node); | 230 schedulePostProcess(node); |
241 } | 231 } |
242 | 232 |
243 // Track mouse events for objects | 233 // Track mouse events for objects |
244 if (!match && contentType == "OBJECT" && node.nodeType == Ci.nsIDOMNode.EL
EMENT_NODE) | 234 if (!match && contentType == "OBJECT" && node.nodeType == Ci.nsIDOMNode.EL
EMENT_NODE) |
245 { | 235 { |
246 node.addEventListener("mouseover", objectMouseEventHander, true); | 236 node.addEventListener("mouseover", objectMouseEventHander, true); |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 if (!wnd || wnd.closed) | 671 if (!wnd || wnd.closed) |
682 return; | 672 return; |
683 | 673 |
684 if (entry.type == "OBJECT") | 674 if (entry.type == "OBJECT") |
685 { | 675 { |
686 node.removeEventListener("mouseover", objectMouseEventHander, true); | 676 node.removeEventListener("mouseover", objectMouseEventHander, true); |
687 node.removeEventListener("mouseout", objectMouseEventHander, true); | 677 node.removeEventListener("mouseout", objectMouseEventHander, true); |
688 } | 678 } |
689 Policy.processNode(wnd, node, entry.type, entry.location, true); | 679 Policy.processNode(wnd, node, entry.type, entry.location, true); |
690 } | 680 } |
OLD | NEW |