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 14 matching lines...) Expand all Loading... |
25 let {Utils} = require("utils"); | 25 let {Utils} = require("utils"); |
26 let {Prefs} = require("prefs"); | 26 let {Prefs} = require("prefs"); |
27 let {FilterStorage} = require("filterStorage"); | 27 let {FilterStorage} = require("filterStorage"); |
28 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); | 28 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); |
29 let {defaultMatcher} = require("matcher"); | 29 let {defaultMatcher} = require("matcher"); |
30 let {objectMouseEventHander} = require("objectTabs"); | 30 let {objectMouseEventHander} = require("objectTabs"); |
31 let {RequestNotifier} = require("requestNotifier"); | 31 let {RequestNotifier} = require("requestNotifier"); |
32 let {ElemHide} = require("elemHide"); | 32 let {ElemHide} = require("elemHide"); |
33 | 33 |
34 /** | 34 /** |
35 * List of explicitly supported content types | 35 * Set of explicitly supported content types |
36 * @type string[] | 36 * @type Set |
37 */ | 37 */ |
38 let contentTypes = ["OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCU
MENT", "DOCUMENT", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA"]; | 38 let contentTypes = new Set([ |
| 39 "OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCUMENT", "DOCUMENT", |
| 40 "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA", "ELEMHIDE", "POPUP", |
| 41 "GENERICHIDE", "GENERICBLOCK" |
| 42 ]); |
39 | 43 |
40 /** | 44 /** |
41 * List of content types that aren't associated with a visual document area | 45 * Set of content types that aren't associated with a visual document area |
42 * @type string[] | 46 * @type Set |
43 */ | 47 */ |
44 let nonVisualTypes = ["SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUE
ST", "FONT"]; | 48 let nonVisualTypes = new Set([ |
| 49 "SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", |
| 50 "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK" |
| 51 ]); |
45 | 52 |
46 /** | 53 /** |
47 * Randomly generated class name, to be applied to collapsed nodes. | 54 * Randomly generated class name, to be applied to collapsed nodes. |
48 */ | 55 */ |
49 let collapsedClass = ""; | 56 let collapsedClass = ""; |
50 | 57 |
51 /** | 58 /** |
| 59 * Maps numerical content type IDs to strings. |
| 60 * @type Map |
| 61 */ |
| 62 let types = new Map(); |
| 63 |
| 64 /** |
| 65 * Numerical ID for fake ELEMHIDE type. |
| 66 */ |
| 67 const TYPE_ELEMHIDE = 0xFFFD; |
| 68 |
| 69 /** |
| 70 * Numerical ID for fake POPUP type. |
| 71 */ |
| 72 const TYPE_POPUP = 0xFFFE; |
| 73 |
| 74 /** |
52 * Public policy checking functions and auxiliary objects | 75 * Public policy checking functions and auxiliary objects |
53 * @class | 76 * @class |
54 */ | 77 */ |
55 var Policy = exports.Policy = | 78 var Policy = exports.Policy = |
56 { | 79 { |
57 /** | 80 /** |
58 * Map of content type identifiers by their name. | 81 * Map of localized content type names by their identifiers. |
59 * @type Object | 82 * @type Map |
60 */ | 83 */ |
61 type: {}, | 84 localizedDescr: new Map(), |
62 | |
63 /** | |
64 * Map of content type names by their identifiers (reverse of type map). | |
65 * @type Object | |
66 */ | |
67 typeDescr: {}, | |
68 | |
69 /** | |
70 * Map of numerical content types with their corresponding masks | |
71 * @type Object | |
72 */ | |
73 typeMask: {}, | |
74 | |
75 /** | |
76 * Map of localized content type names by their identifiers. | |
77 * @type Object | |
78 */ | |
79 localizedDescr: {}, | |
80 | |
81 /** | |
82 * Lists the non-visual content types. | |
83 * @type Object | |
84 */ | |
85 nonVisual: {}, | |
86 | 85 |
87 /** | 86 /** |
88 * Map containing all schemes that should be ignored by content policy. | 87 * Map containing all schemes that should be ignored by content policy. |
89 * @type Object | 88 * @type Object |
90 */ | 89 */ |
91 whitelistSchemes: {}, | 90 whitelistSchemes: {}, |
92 | 91 |
93 /** | 92 /** |
94 * Called on module startup, initializes various exported properties. | 93 * Called on module startup, initializes various exported properties. |
95 */ | 94 */ |
96 init: function() | 95 init: function() |
97 { | 96 { |
98 // type constant by type description and type description by type constant | 97 // Populate types map |
99 let iface = Ci.nsIContentPolicy; | 98 let iface = Ci.nsIContentPolicy; |
| 99 for (let name in iface) |
| 100 if (name.indexOf("TYPE_") == 0 && name != "TYPE_DATAREQUEST") |
| 101 types.set(iface[name], name.substr(5)); |
| 102 types.set(TYPE_ELEMHIDE, "ELEMHIDE"); |
| 103 types.set(TYPE_POPUP, "POPUP"); |
| 104 |
| 105 // Populate localized type names |
100 for (let typeName of contentTypes) | 106 for (let typeName of contentTypes) |
101 { | 107 this.localizedDescr.set(typeName, Utils.getString("type_label_" + typeName
.toLowerCase())); |
102 if ("TYPE_" + typeName in iface) | |
103 { | |
104 let id = iface["TYPE_" + typeName]; | |
105 this.type[typeName] = id; | |
106 this.typeDescr[id] = typeName; | |
107 this.localizedDescr[id] = Utils.getString("type_label_" + typeName.toLow
erCase()); | |
108 this.typeMask[id] = RegExpFilter.typeMap[typeName]; | |
109 } | |
110 } | |
111 | |
112 this.type.GENERICBLOCK = 0xFFFB; | |
113 this.typeDescr[0xFFFB] = "GENERICBLOCK"; | |
114 this.localizedDescr[0xFFFB] = Utils.getString("type_label_genericblock"); | |
115 this.typeMask[0xFFFB] = RegExpFilter.typeMap.GENERICBLOCK; | |
116 | |
117 this.type.GENERICHIDE = 0xFFFC; | |
118 this.typeDescr[0xFFFC] = "GENERICHIDE"; | |
119 this.localizedDescr[0xFFFC] = Utils.getString("type_label_generichide"); | |
120 this.typeMask[0xFFFC] = RegExpFilter.typeMap.GENERICHIDE; | |
121 | |
122 this.type.ELEMHIDE = 0xFFFD; | |
123 this.typeDescr[0xFFFD] = "ELEMHIDE"; | |
124 this.localizedDescr[0xFFFD] = Utils.getString("type_label_elemhide"); | |
125 this.typeMask[0xFFFD] = RegExpFilter.typeMap.ELEMHIDE; | |
126 | |
127 this.type.POPUP = 0xFFFE; | |
128 this.typeDescr[0xFFFE] = "POPUP"; | |
129 this.localizedDescr[0xFFFE] = Utils.getString("type_label_popup"); | |
130 this.typeMask[0xFFFE] = RegExpFilter.typeMap.POPUP; | |
131 | |
132 for (let type of nonVisualTypes) | |
133 this.nonVisual[this.type[type]] = true; | |
134 | 108 |
135 // whitelisted URL schemes | 109 // whitelisted URL schemes |
136 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) | 110 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) |
137 this.whitelistSchemes[scheme] = true; | 111 this.whitelistSchemes[scheme] = true; |
138 | 112 |
139 // Generate class identifier used to collapse node and register correspondin
g | 113 // Generate class identifier used to collapse node and register correspondin
g |
140 // stylesheet. | 114 // stylesheet. |
141 let offset = "a".charCodeAt(0); | 115 let offset = "a".charCodeAt(0); |
142 for (let i = 0; i < 20; i++) | 116 for (let i = 0; i < 20; i++) |
143 collapsedClass += String.fromCharCode(offset + Math.random() * 26); | 117 collapsedClass += String.fromCharCode(offset + Math.random() * 26); |
(...skipping 16 matching lines...) Expand all Loading... |
160 * @param location {nsIURI} | 134 * @param location {nsIURI} |
161 * @param collapse {Boolean} true to force hiding of the node | 135 * @param collapse {Boolean} true to force hiding of the node |
162 * @return {Boolean} false if the node should be blocked | 136 * @return {Boolean} false if the node should be blocked |
163 */ | 137 */ |
164 processNode: function(wnd, node, contentType, location, collapse) | 138 processNode: function(wnd, node, contentType, location, collapse) |
165 { | 139 { |
166 let topWnd = wnd.top; | 140 let topWnd = wnd.top; |
167 if (!topWnd || !topWnd.location || !topWnd.location.href) | 141 if (!topWnd || !topWnd.location || !topWnd.location.href) |
168 return true; | 142 return true; |
169 | 143 |
| 144 // Interpret unknown types as "other" |
| 145 if (!contentTypes.has(contentType)) |
| 146 contentType = "OTHER"; |
| 147 |
170 let originWindow = Utils.getOriginWindow(wnd); | 148 let originWindow = Utils.getOriginWindow(wnd); |
171 let wndLocation = originWindow.location.href; | 149 let wndLocation = originWindow.location.href; |
172 let docDomain = getHostname(wndLocation); | 150 let docDomain = getHostname(wndLocation); |
173 let match = null; | 151 let match = null; |
174 let [sitekey, sitekeyWnd] = getSitekey(wnd); | 152 let [sitekey, sitekeyWnd] = getSitekey(wnd); |
175 let nogeneric = false; | 153 let nogeneric = false; |
176 | 154 |
177 function cleanWindowLocation(wnd) | 155 function cleanWindowLocation(wnd) |
178 { | 156 { |
179 let url = getWindowLocation(wnd); | 157 let url = getWindowLocation(wnd); |
(...skipping 10 matching lines...) Expand all Loading... |
190 let testSitekey = sitekey; | 168 let testSitekey = sitekey; |
191 let testSitekeyWnd = sitekeyWnd; | 169 let testSitekeyWnd = sitekeyWnd; |
192 let parentWndLocation = cleanWindowLocation(testWnd); | 170 let parentWndLocation = cleanWindowLocation(testWnd); |
193 while (true) | 171 while (true) |
194 { | 172 { |
195 let testWndLocation = parentWndLocation; | 173 let testWndLocation = parentWndLocation; |
196 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : clean
WindowLocation(testWnd.parent)); | 174 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : clean
WindowLocation(testWnd.parent)); |
197 let parentDocDomain = getHostname(parentWndLocation); | 175 let parentDocDomain = getHostname(parentWndLocation); |
198 | 176 |
199 let typeMap = RegExpFilter.typeMap.DOCUMENT; | 177 let typeMap = RegExpFilter.typeMap.DOCUMENT; |
200 if (contentType == Policy.type.ELEMHIDE) | 178 if (contentType == "ELEMHIDE") |
201 typeMap = typeMap | RegExpFilter.typeMap.ELEMHIDE; | 179 typeMap = typeMap | RegExpFilter.typeMap.ELEMHIDE; |
202 let whitelistMatch = defaultMatcher.matchesAny(testWndLocation, typeMap,
parentDocDomain, false, sitekey); | 180 let whitelistMatch = defaultMatcher.matchesAny(testWndLocation, typeMap,
parentDocDomain, false, sitekey); |
203 if (whitelistMatch instanceof WhitelistFilter) | 181 if (whitelistMatch instanceof WhitelistFilter) |
204 { | 182 { |
205 FilterStorage.increaseHitCount(whitelistMatch, wnd); | 183 FilterStorage.increaseHitCount(whitelistMatch, wnd); |
206 RequestNotifier.addNodeData(testWnd.document, topWnd, | 184 RequestNotifier.addNodeData(testWnd.document, topWnd, |
207 (whitelistMatch.contentType & RegExpFilter.typeMap.DOCUMENT) ? Polic
y.type.DOCUMENT : Policy.type.ELEMHIDE, | 185 (whitelistMatch.contentType & RegExpFilter.typeMap.DOCUMENT) ? "DOCU
MENT" : "ELEMHIDE", |
208 parentDocDomain, false, testWndLocation, whitelistMatch); | 186 parentDocDomain, false, testWndLocation, whitelistMatch); |
209 return true; | 187 return true; |
210 } | 188 } |
211 | 189 |
212 let genericType = (contentType == Policy.type.ELEMHIDE ? | 190 let genericType = (contentType == "ELEMHIDE" ? "GENERICHIDE" : "GENERICB
LOCK"); |
213 Policy.type.GENERICHIDE : | |
214 Policy.type.GENERICBLOCK); | |
215 let nogenericMatch = defaultMatcher.matchesAny(testWndLocation, | 191 let nogenericMatch = defaultMatcher.matchesAny(testWndLocation, |
216 Policy.typeMask[genericType], parentDocDomain, false, testSitekey); | 192 RegExpFilter.typeMap[genericType], parentDocDomain, false, testSitek
ey); |
217 if (nogenericMatch instanceof WhitelistFilter) | 193 if (nogenericMatch instanceof WhitelistFilter) |
218 { | 194 { |
219 nogeneric = true; | 195 nogeneric = true; |
220 | 196 |
221 FilterStorage.increaseHitCount(nogenericMatch, wnd); | 197 FilterStorage.increaseHitCount(nogenericMatch, wnd); |
222 RequestNotifier.addNodeData(testWnd.document, topWnd, genericType, | 198 RequestNotifier.addNodeData(testWnd.document, topWnd, genericType, |
223 parentDocDomain, false, testWndLocation, | 199 parentDocDomain, false, testWndLocation, |
224 nogenericMatch); | 200 nogenericMatch); |
225 } | 201 } |
226 | 202 |
227 if (testWnd.parent == testWnd) | 203 if (testWnd.parent == testWnd) |
228 break; | 204 break; |
229 | 205 |
230 if (testWnd == testSitekeyWnd) | 206 if (testWnd == testSitekeyWnd) |
231 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); | 207 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); |
232 testWnd = testWnd.parent; | 208 testWnd = testWnd.parent; |
233 } | 209 } |
234 } | 210 } |
235 | 211 |
236 // Data loaded by plugins should be attached to the document | 212 // Data loaded by plugins should be attached to the document |
237 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO
MElement) | 213 if (contentType == "OBJECT_SUBREQUEST" && node instanceof Ci.nsIDOMElement) |
238 node = node.ownerDocument; | 214 node = node.ownerDocument; |
239 | 215 |
240 // Fix type for objects misrepresented as frames or images | 216 // Fix type for objects misrepresented as frames or images |
241 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec
tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) | 217 if (contentType != "OBJECT" && (node instanceof Ci.nsIDOMHTMLObjectElement |
| node instanceof Ci.nsIDOMHTMLEmbedElement)) |
242 contentType = Policy.type.OBJECT; | 218 contentType = "OBJECT"; |
243 | 219 |
244 let locationText = location.spec; | 220 let locationText = location.spec; |
245 if (!match && contentType == Policy.type.ELEMHIDE) | 221 if (!match && contentType == "ELEMHIDE") |
246 { | 222 { |
247 match = location; | 223 match = location; |
248 locationText = match.text.replace(/^.*?#/, '#'); | 224 locationText = match.text.replace(/^.*?#/, '#'); |
249 location = locationText; | 225 location = locationText; |
250 | 226 |
251 if (!match.isActiveOnDomain(docDomain)) | 227 if (!match.isActiveOnDomain(docDomain)) |
252 return true; | 228 return true; |
253 | 229 |
254 let exception = ElemHide.getException(match, docDomain); | 230 let exception = ElemHide.getException(match, docDomain); |
255 if (exception) | 231 if (exception) |
256 { | 232 { |
257 FilterStorage.increaseHitCount(exception, wnd); | 233 FilterStorage.increaseHitCount(exception, wnd); |
258 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false,
locationText, exception); | 234 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false,
locationText, exception); |
259 return true; | 235 return true; |
260 } | 236 } |
261 | 237 |
262 if (nogeneric && match.isGeneric()) | 238 if (nogeneric && match.isGeneric()) |
263 return true; | 239 return true; |
264 } | 240 } |
265 | 241 |
266 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty
(location, docDomain)); | 242 let thirdParty = (contentType == "ELEMHIDE" ? false : isThirdParty(location,
docDomain)); |
267 | 243 |
268 if (!match && Prefs.enabled && contentType in Policy.typeMask) | 244 if (!match && Prefs.enabled && RegExpFilter.typeMap.hasOwnProperty(contentTy
pe)) |
269 { | 245 { |
270 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp
e], | 246 match = defaultMatcher.matchesAny(locationText, RegExpFilter.typeMap[conte
ntType], |
271 docDomain, thirdParty, sitekey, nogeneri
c); | 247 docDomain, thirdParty, sitekey, nogeneri
c); |
272 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType
in Policy.nonVisual)) | 248 if (match instanceof BlockingFilter && node.ownerDocument && !nonVisualTyp
es.has(contentType)) |
273 { | 249 { |
274 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas
tcollapse); | 250 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas
tcollapse); |
275 if (collapse || prefCollapse) | 251 if (collapse || prefCollapse) |
276 schedulePostProcess(node); | 252 schedulePostProcess(node); |
277 } | 253 } |
278 | 254 |
279 // Track mouse events for objects | 255 // Track mouse events for objects |
280 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI
DOMNode.ELEMENT_NODE) | 256 if (!match && contentType == "OBJECT" && node.nodeType == Ci.nsIDOMNode.EL
EMENT_NODE) |
281 { | 257 { |
282 node.addEventListener("mouseover", objectMouseEventHander, true); | 258 node.addEventListener("mouseover", objectMouseEventHander, true); |
283 node.addEventListener("mouseout", objectMouseEventHander, true); | 259 node.addEventListener("mouseout", objectMouseEventHander, true); |
284 } | 260 } |
285 } | 261 } |
286 | 262 |
287 // Store node data | 263 // Store node data |
288 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdParty
, locationText, match); | 264 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdParty
, locationText, match); |
289 if (match) | 265 if (match) |
290 FilterStorage.increaseHitCount(match, wnd); | 266 FilterStorage.increaseHitCount(match, wnd); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIObserver, | 377 QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIObserver, |
402 Ci.nsIChannelEventSink, Ci.nsIFactory, Ci.nsISupportsWeakReference]), | 378 Ci.nsIChannelEventSink, Ci.nsIFactory, Ci.nsISupportsWeakReference]), |
403 | 379 |
404 // | 380 // |
405 // nsIContentPolicy interface implementation | 381 // nsIContentPolicy interface implementation |
406 // | 382 // |
407 | 383 |
408 shouldLoad: function(contentType, contentLocation, requestOrigin, node, mimeTy
peGuess, extra) | 384 shouldLoad: function(contentType, contentLocation, requestOrigin, node, mimeTy
peGuess, extra) |
409 { | 385 { |
410 // Ignore requests without context and top-level documents | 386 // Ignore requests without context and top-level documents |
411 if (!node || contentType == Policy.type.DOCUMENT) | 387 if (!node || contentType == Ci.nsIContentPolicy.TYPE_DOCUMENT) |
412 return Ci.nsIContentPolicy.ACCEPT; | 388 return Ci.nsIContentPolicy.ACCEPT; |
413 | 389 |
414 // Ignore standalone objects | 390 // Ignore standalone objects |
415 if (contentType == Policy.type.OBJECT && node.ownerDocument && !/^text\/|[+\
/]xml$/.test(node.ownerDocument.contentType)) | 391 if (contentType == Ci.nsIContentPolicy.TYPE_OBJECT && node.ownerDocument &&
!/^text\/|[+\/]xml$/.test(node.ownerDocument.contentType)) |
416 return Ci.nsIContentPolicy.ACCEPT; | 392 return Ci.nsIContentPolicy.ACCEPT; |
417 | 393 |
418 let wnd = Utils.getWindow(node); | 394 let wnd = Utils.getWindow(node); |
419 if (!wnd) | 395 if (!wnd) |
420 return Ci.nsIContentPolicy.ACCEPT; | 396 return Ci.nsIContentPolicy.ACCEPT; |
421 | 397 |
422 // Ignore whitelisted schemes | 398 // Ignore whitelisted schemes |
423 let location = Utils.unwrapURL(contentLocation); | 399 let location = Utils.unwrapURL(contentLocation); |
424 if (!Policy.isBlockableScheme(location)) | 400 if (!Policy.isBlockableScheme(location)) |
425 return Ci.nsIContentPolicy.ACCEPT; | 401 return Ci.nsIContentPolicy.ACCEPT; |
426 | 402 |
427 // Interpret unknown types as "other" | 403 let result = Policy.processNode(wnd, node, types.get(contentType), location,
false); |
428 if (!(contentType in Policy.typeDescr)) | |
429 contentType = Policy.type.OTHER; | |
430 | |
431 let result = Policy.processNode(wnd, node, contentType, location, false); | |
432 return (result ? Ci.nsIContentPolicy.ACCEPT : Ci.nsIContentPolicy.REJECT_REQ
UEST); | 404 return (result ? Ci.nsIContentPolicy.ACCEPT : Ci.nsIContentPolicy.REJECT_REQ
UEST); |
433 }, | 405 }, |
434 | 406 |
435 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode
, mimeType, extra) | 407 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode
, mimeType, extra) |
436 { | 408 { |
437 return Ci.nsIContentPolicy.ACCEPT; | 409 return Ci.nsIContentPolicy.ACCEPT; |
438 }, | 410 }, |
439 | 411 |
440 // | 412 // |
441 // nsIObserver interface implementation | 413 // nsIObserver interface implementation |
442 // | 414 // |
443 observe: function(subject, topic, data, additional) | 415 observe: function(subject, topic, data, additional) |
444 { | 416 { |
445 switch (topic) | 417 switch (topic) |
446 { | 418 { |
447 case "content-document-global-created": | 419 case "content-document-global-created": |
448 { | 420 { |
449 if (!(subject instanceof Ci.nsIDOMWindow) || !subject.opener) | 421 if (!(subject instanceof Ci.nsIDOMWindow) || !subject.opener) |
450 return; | 422 return; |
451 | 423 |
452 let uri = additional || Utils.makeURI(subject.location.href); | 424 let uri = additional || Utils.makeURI(subject.location.href); |
453 if (!Policy.processNode(subject.opener, subject.opener.document, Policy.
type.POPUP, uri, false)) | 425 if (!Policy.processNode(subject.opener, subject.opener.document, "POPUP"
, uri, false)) |
454 { | 426 { |
455 subject.stop(); | 427 subject.stop(); |
456 Utils.runAsync(() => subject.close()); | 428 Utils.runAsync(() => subject.close()); |
457 } | 429 } |
458 else if (uri.spec == "about:blank") | 430 else if (uri.spec == "about:blank") |
459 { | 431 { |
460 // An about:blank pop-up most likely means that a load will be | 432 // An about:blank pop-up most likely means that a load will be |
461 // initiated asynchronously. Wait for that. | 433 // initiated asynchronously. Wait for that. |
462 Utils.runAsync(function() | 434 Utils.runAsync(function() |
463 { | 435 { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 { | 472 { |
501 // Special treatment for pop-up windows. Note that we might not have | 473 // Special treatment for pop-up windows. Note that we might not have |
502 // seen the original channel yet because the redirect happened before | 474 // seen the original channel yet because the redirect happened before |
503 // the async code in observe() had a chance to run. | 475 // the async code in observe() had a chance to run. |
504 this.observe(wnd, "content-document-global-created", null, oldChannel.
URI); | 476 this.observe(wnd, "content-document-global-created", null, oldChannel.
URI); |
505 this.observe(wnd, "content-document-global-created", null, newChannel.
URI); | 477 this.observe(wnd, "content-document-global-created", null, newChannel.
URI); |
506 } | 478 } |
507 return; | 479 return; |
508 } | 480 } |
509 | 481 |
510 if (!Policy.processNode(wnd, wnd.document, contentType, newChannel.URI, fa
lse)) | 482 if (!Policy.processNode(wnd, wnd.document, types.get(contentType), newChan
nel.URI, false)) |
511 result = Cr.NS_BINDING_ABORTED; | 483 result = Cr.NS_BINDING_ABORTED; |
512 } | 484 } |
513 catch (e) | 485 catch (e) |
514 { | 486 { |
515 // We shouldn't throw exceptions here - this will prevent the redirect. | 487 // We shouldn't throw exceptions here - this will prevent the redirect. |
516 Cu.reportError(e); | 488 Cu.reportError(e); |
517 } | 489 } |
518 finally | 490 finally |
519 { | 491 { |
520 callback.onRedirectVerifyCallback(result); | 492 callback.onRedirectVerifyCallback(result); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 | 684 |
713 /** | 685 /** |
714 * Re-checks filters on an element. | 686 * Re-checks filters on an element. |
715 */ | 687 */ |
716 function refilterNode(/**Node*/ node, /**RequestEntry*/ entry) | 688 function refilterNode(/**Node*/ node, /**RequestEntry*/ entry) |
717 { | 689 { |
718 let wnd = Utils.getWindow(node); | 690 let wnd = Utils.getWindow(node); |
719 if (!wnd || wnd.closed) | 691 if (!wnd || wnd.closed) |
720 return; | 692 return; |
721 | 693 |
722 if (entry.type == Policy.type.OBJECT) | 694 if (entry.type == "OBJECT") |
723 { | 695 { |
724 node.removeEventListener("mouseover", objectMouseEventHander, true); | 696 node.removeEventListener("mouseover", objectMouseEventHander, true); |
725 node.removeEventListener("mouseout", objectMouseEventHander, true); | 697 node.removeEventListener("mouseout", objectMouseEventHander, true); |
726 } | 698 } |
727 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true)
; | 699 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true)
; |
728 } | 700 } |
OLD | NEW |