LEFT | RIGHT |
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 /** | 18 /** |
19 * @fileOverview Content policy implementation, responsible for blocking things. | 19 * @fileOverview Content policy implementation, responsible for blocking things. |
20 */ | 20 */ |
21 | 21 |
22 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 22 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
23 Cu.import("resource://gre/modules/Services.jsm"); | 23 Cu.import("resource://gre/modules/Services.jsm"); |
24 | 24 |
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} = 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 * List of explicitly supported content types |
36 * @type Array of String | 36 * @type string[] |
37 */ | 37 */ |
38 let contentTypes = ["OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCU
MENT", "DOCUMENT", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA"]; | 38 let contentTypes = ["OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCU
MENT", "DOCUMENT", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA"]; |
39 | 39 |
40 /** | 40 /** |
41 * List of content types that aren't associated with a visual document area | 41 * List of content types that aren't associated with a visual document area |
42 * @type Array of String | 42 * @type string[] |
43 */ | 43 */ |
44 let nonVisualTypes = ["SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUE
ST", "FONT"]; | 44 let nonVisualTypes = ["SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUE
ST", "FONT"]; |
45 | 45 |
46 /** | 46 /** |
47 * Randomly generated class name, to be applied to collapsed nodes. | 47 * Randomly generated class name, to be applied to collapsed nodes. |
48 */ | 48 */ |
49 let collapsedClass = ""; | 49 let collapsedClass = ""; |
50 | 50 |
51 /** | 51 /** |
52 * Public policy checking functions and auxiliary objects | 52 * Public policy checking functions and auxiliary objects |
53 * @class | 53 * @class |
54 */ | 54 */ |
55 let Policy = exports.Policy = | 55 let Policy = exports.Policy = |
56 { | 56 { |
57 /** | 57 /** |
58 * Map of content type identifiers by their name. | 58 * Map of content type identifiers by their name. |
59 * @type Object | 59 * @type Object |
60 */ | 60 */ |
61 type: {}, | 61 type: {}, |
62 | 62 |
63 /** | 63 /** |
64 * Map of content type names by their identifiers (reverse of type map). | 64 * Map of content type names by their identifiers (reverse of type map). |
65 * @type Object | 65 * @type Object |
66 */ | 66 */ |
67 typeDescr: {}, | 67 typeDescr: {}, |
| 68 |
| 69 /** |
| 70 * Map of numerical content types with their corresponding masks |
| 71 * @type Object |
| 72 */ |
| 73 typeMask: {}, |
68 | 74 |
69 /** | 75 /** |
70 * Map of localized content type names by their identifiers. | 76 * Map of localized content type names by their identifiers. |
71 * @type Object | 77 * @type Object |
72 */ | 78 */ |
73 localizedDescr: {}, | 79 localizedDescr: {}, |
74 | 80 |
75 /** | 81 /** |
76 * Lists the non-visual content types. | 82 * Lists the non-visual content types. |
77 * @type Object | 83 * @type Object |
(...skipping 14 matching lines...) Expand all Loading... |
92 // type constant by type description and type description by type constant | 98 // type constant by type description and type description by type constant |
93 let iface = Ci.nsIContentPolicy; | 99 let iface = Ci.nsIContentPolicy; |
94 for (let typeName of contentTypes) | 100 for (let typeName of contentTypes) |
95 { | 101 { |
96 if ("TYPE_" + typeName in iface) | 102 if ("TYPE_" + typeName in iface) |
97 { | 103 { |
98 let id = iface["TYPE_" + typeName]; | 104 let id = iface["TYPE_" + typeName]; |
99 this.type[typeName] = id; | 105 this.type[typeName] = id; |
100 this.typeDescr[id] = typeName; | 106 this.typeDescr[id] = typeName; |
101 this.localizedDescr[id] = Utils.getString("type_label_" + typeName.toLow
erCase()); | 107 this.localizedDescr[id] = Utils.getString("type_label_" + typeName.toLow
erCase()); |
| 108 this.typeMask[id] = RegExpFilter.typeMap[typeName]; |
102 } | 109 } |
103 } | 110 } |
104 | 111 |
105 this.type.ELEMHIDE = 0xFFFD; | 112 this.type.ELEMHIDE = 0xFFFD; |
106 this.typeDescr[0xFFFD] = "ELEMHIDE"; | 113 this.typeDescr[0xFFFD] = "ELEMHIDE"; |
107 this.localizedDescr[0xFFFD] = Utils.getString("type_label_elemhide"); | 114 this.localizedDescr[0xFFFD] = Utils.getString("type_label_elemhide"); |
| 115 this.typeMask[0xFFFD] = RegExpFilter.typeMap.ELEMHIDE; |
108 | 116 |
109 this.type.POPUP = 0xFFFE; | 117 this.type.POPUP = 0xFFFE; |
110 this.typeDescr[0xFFFE] = "POPUP"; | 118 this.typeDescr[0xFFFE] = "POPUP"; |
111 this.localizedDescr[0xFFFE] = Utils.getString("type_label_popup"); | 119 this.localizedDescr[0xFFFE] = Utils.getString("type_label_popup"); |
| 120 this.typeMask[0xFFFE] = RegExpFilter.typeMap.POPUP; |
112 | 121 |
113 for (let type of nonVisualTypes) | 122 for (let type of nonVisualTypes) |
114 this.nonVisual[this.type[type]] = true; | 123 this.nonVisual[this.type[type]] = true; |
115 | 124 |
116 // whitelisted URL schemes | 125 // whitelisted URL schemes |
117 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) | 126 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) |
118 this.whitelistSchemes[scheme] = true; | 127 this.whitelistSchemes[scheme] = true; |
119 | 128 |
120 // Generate class identifier used to collapse node and register correspondin
g | 129 // Generate class identifier used to collapse node and register correspondin
g |
121 // stylesheet. | 130 // stylesheet. |
(...skipping 24 matching lines...) Expand all Loading... |
146 { | 155 { |
147 let topWnd = wnd.top; | 156 let topWnd = wnd.top; |
148 if (!topWnd || !topWnd.location || !topWnd.location.href) | 157 if (!topWnd || !topWnd.location || !topWnd.location.href) |
149 return true; | 158 return true; |
150 | 159 |
151 let originWindow = Utils.getOriginWindow(wnd); | 160 let originWindow = Utils.getOriginWindow(wnd); |
152 let wndLocation = originWindow.location.href; | 161 let wndLocation = originWindow.location.href; |
153 let docDomain = getHostname(wndLocation); | 162 let docDomain = getHostname(wndLocation); |
154 let match = null; | 163 let match = null; |
155 let [sitekey, sitekeyWnd] = getSitekey(wnd); | 164 let [sitekey, sitekeyWnd] = getSitekey(wnd); |
156 let genericblock = { match: null }; | 165 let nogeneric = false; |
| 166 |
157 if (!match && Prefs.enabled) | 167 if (!match && Prefs.enabled) |
158 { | 168 { |
159 let testWnd = wnd; | 169 let testWnd = wnd; |
160 let testSitekey = sitekey; | 170 let testSitekey = sitekey; |
161 let testSitekeyWnd = sitekeyWnd; | 171 let testSitekeyWnd = sitekeyWnd; |
162 let parentWndLocation = getWindowLocation(testWnd); | 172 let parentWndLocation = getWindowLocation(testWnd); |
163 while (true) | 173 while (true) |
164 { | 174 { |
165 let testWndLocation = parentWndLocation; | 175 let testWndLocation = parentWndLocation; |
166 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi
ndowLocation(testWnd.parent)); | 176 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi
ndowLocation(testWnd.parent)); |
167 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit
ekey); | 177 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit
ekey); |
168 | 178 |
169 if (match instanceof WhitelistFilter) | 179 if (match instanceof WhitelistFilter) |
170 { | 180 { |
171 FilterStorage.increaseHitCount(match, wnd); | 181 FilterStorage.increaseHitCount(match, wnd); |
172 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU
MENT, getHostname(parentWndLocation), false, testWndLocation, match); | 182 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU
MENT, getHostname(parentWndLocation), false, testWndLocation, match); |
173 return true; | 183 return true; |
174 } | 184 } |
175 else if (!(genericblock.match instanceof WhitelistFilter) && contentType
!= Policy.type.ELEMHIDE) | 185 |
176 { | 186 let genericType = (contentType == Policy.type.ELEMHIDE ? |
177 let parentDocDomain = getHostname(parentWndLocation); | 187 RegExpFilter.typeMap.GENERICHIDE : |
178 genericblock.match = defaultMatcher.matchesAny(testWndLocation, "GENER
ICBLOCK", parentDocDomain, false); | 188 RegExpFilter.typeMap.GENERICBLOCK); |
179 if (genericblock.match instanceof WhitelistFilter) | 189 let parentDocDomain = getHostname(parentWndLocation); |
180 { | 190 let nogenericMatch = defaultMatcher.matchesAny( |
181 genericblock.parentDocDomain = parentDocDomain; | 191 testWndLocation, genericType, parentDocDomain, false, testSitekey |
182 genericblock.testWnd = testWnd; | 192 ); |
183 genericblock.testWndLocation = testWndLocation; | 193 if (nogenericMatch instanceof WhitelistFilter) |
184 } | 194 { |
| 195 nogeneric = true; |
| 196 |
| 197 FilterStorage.increaseHitCount(nogenericMatch, wnd); |
| 198 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, |
| 199 parentDocDomain, false, testWndLocation, |
| 200 nogenericMatch); |
185 } | 201 } |
186 | 202 |
187 if (testWnd.parent == testWnd) | 203 if (testWnd.parent == testWnd) |
188 break; | 204 break; |
189 | 205 |
190 if (testWnd == testSitekeyWnd) | 206 if (testWnd == testSitekeyWnd) |
191 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); | 207 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); |
192 testWnd = testWnd.parent; | 208 testWnd = testWnd.parent; |
193 } | 209 } |
194 } | 210 } |
195 | 211 |
196 // Data loaded by plugins should be attached to the document | 212 // Data loaded by plugins should be attached to the document |
197 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO
MElement) | 213 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO
MElement) |
198 node = node.ownerDocument; | 214 node = node.ownerDocument; |
199 | 215 |
200 // Fix type for objects misrepresented as frames or images | 216 // Fix type for objects misrepresented as frames or images |
201 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec
tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) | 217 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec
tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) |
202 contentType = Policy.type.OBJECT; | 218 contentType = Policy.type.OBJECT; |
203 | 219 |
204 let locationText = location.spec; | 220 let locationText = location.spec; |
205 if (!match && contentType == Policy.type.ELEMHIDE) | 221 if (!match && contentType == Policy.type.ELEMHIDE) |
206 { | 222 { |
207 let testWnd = wnd; | 223 let testWnd = wnd; |
208 let parentWndLocation = getWindowLocation(testWnd); | 224 let parentWndLocation = getWindowLocation(testWnd); |
209 while (true) | 225 while (true) |
210 { | 226 { |
211 let testWndLocation = parentWndLocation; | 227 let testWndLocation = parentWndLocation; |
212 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi
ndowLocation(testWnd.parent)); | 228 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi
ndowLocation(testWnd.parent)); |
213 let parentDocDomain = getHostname(parentWndLocation); | 229 let parentDocDomain = getHostname(parentWndLocation); |
214 match = defaultMatcher.matchesAny(testWndLocation, "ELEMHIDE", parentDoc
Domain, false); | 230 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap.
ELEMHIDE, parentDocDomain, false, sitekey); |
215 | |
216 if (!(match instanceof WhitelistFilter) && (!location.domains || locatio
n.domains[""])) | |
217 match = defaultMatcher.matchesAny(testWndLocation, "GENERICHIDE", pare
ntDocDomain, false); | |
218 | |
219 if (match instanceof WhitelistFilter) | 231 if (match instanceof WhitelistFilter) |
220 { | 232 { |
221 FilterStorage.increaseHitCount(match, wnd); | 233 FilterStorage.increaseHitCount(match, wnd); |
222 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par
entDocDomain, false, testWndLocation, match); | 234 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par
entDocDomain, false, testWndLocation, match); |
223 return true; | 235 return true; |
224 } | 236 } |
225 | 237 |
226 if (testWnd.parent == testWnd) | 238 if (testWnd.parent == testWnd) |
227 break; | 239 break; |
228 else | 240 else |
229 testWnd = testWnd.parent; | 241 testWnd = testWnd.parent; |
230 } | 242 } |
231 | 243 |
232 match = location; | 244 match = location; |
233 locationText = match.text.replace(/^.*?#/, '#'); | 245 locationText = match.text.replace(/^.*?#/, '#'); |
234 location = locationText; | 246 location = locationText; |
235 | 247 |
236 if (!match.isActiveOnDomain(docDomain)) | 248 if (!match.isActiveOnDomain(docDomain)) |
237 return true; | 249 return true; |
238 | 250 |
239 let exception = ElemHide.getException(match, docDomain); | 251 let exception = ElemHide.getException(match, docDomain); |
240 if (exception) | 252 if (exception) |
241 { | 253 { |
242 FilterStorage.increaseHitCount(exception, wnd); | 254 FilterStorage.increaseHitCount(exception, wnd); |
243 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false,
locationText, exception); | 255 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false,
locationText, exception); |
244 return true; | 256 return true; |
245 } | 257 } |
| 258 |
| 259 if (nogeneric && match.isGeneric()) |
| 260 return true; |
246 } | 261 } |
247 | 262 |
248 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty
(location, docDomain)); | 263 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty
(location, docDomain)); |
249 | 264 |
250 if (!match && Prefs.enabled) | 265 if (!match && Prefs.enabled && contentType in Policy.typeMask) |
251 { | 266 { |
252 match = defaultMatcher.matchesAny(locationText, Policy.typeDescr[contentTy
pe] || "", docDomain, thirdParty, sitekey); | 267 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp
e], |
253 if (match instanceof BlockingFilter) | 268 docDomain, thirdParty, sitekey, nogeneri
c); |
254 { | 269 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType
in Policy.nonVisual)) |
255 if ((!match.domains || match.domains[""]) && genericblock.match instance
of WhitelistFilter) | 270 { |
256 { | 271 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas
tcollapse); |
257 FilterStorage.increaseHitCount(genericblock.match, wnd); | 272 if (collapse || prefCollapse) |
258 RequestNotifier.addNodeData( | 273 schedulePostProcess(node); |
259 genericblock.testWnd.document, | |
260 topWnd, contentType, | |
261 genericblock.parentDocDomain, | |
262 false, genericblock.testWndLocation, | |
263 genericblock.match | |
264 ); | |
265 return true; | |
266 } | |
267 | |
268 if (node.ownerDocument && !(contentType in Policy.nonVisual)) | |
269 { | |
270 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.f
astcollapse); | |
271 if (collapse || prefCollapse) | |
272 schedulePostProcess(node); | |
273 } | |
274 } | 274 } |
275 | 275 |
276 // Track mouse events for objects | 276 // Track mouse events for objects |
277 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI
DOMNode.ELEMENT_NODE) | 277 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI
DOMNode.ELEMENT_NODE) |
278 { | 278 { |
279 node.addEventListener("mouseover", objectMouseEventHander, true); | 279 node.addEventListener("mouseover", objectMouseEventHander, true); |
280 node.addEventListener("mouseout", objectMouseEventHander, true); | 280 node.addEventListener("mouseout", objectMouseEventHander, true); |
281 } | 281 } |
282 } | 282 } |
283 | 283 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 return null; | 317 return null; |
318 | 318 |
319 if (!parentUrl) | 319 if (!parentUrl) |
320 parentUrl = url; | 320 parentUrl = url; |
321 | 321 |
322 // Ignore fragment identifier | 322 // Ignore fragment identifier |
323 let index = url.indexOf("#"); | 323 let index = url.indexOf("#"); |
324 if (index >= 0) | 324 if (index >= 0) |
325 url = url.substring(0, index); | 325 url = url.substring(0, index); |
326 | 326 |
327 let result = defaultMatcher.matchesAny(url, "DOCUMENT", getHostname(parentUr
l), false, sitekey); | 327 let result = defaultMatcher.matchesAny(url, RegExpFilter.typeMap.DOCUMENT, g
etHostname(parentUrl), false, sitekey); |
328 return (result instanceof WhitelistFilter ? result : null); | 328 return (result instanceof WhitelistFilter ? result : null); |
329 }, | 329 }, |
330 | 330 |
331 /** | 331 /** |
332 * Checks whether the page loaded in a window is whitelisted for indication in
the UI. | 332 * Checks whether the page loaded in a window is whitelisted for indication in
the UI. |
333 * @param wnd {nsIDOMWindow} | 333 * @param wnd {nsIDOMWindow} |
334 * @return {Filter} matching exception rule or null if not whitelisted | 334 * @return {Filter} matching exception rule or null if not whitelisted |
335 */ | 335 */ |
336 isWindowWhitelisted: function(wnd) | 336 isWindowWhitelisted: function(wnd) |
337 { | 337 { |
338 return Policy.isWhitelisted(getWindowLocation(wnd)); | 338 return Policy.isWhitelisted(getWindowLocation(wnd)); |
339 }, | 339 }, |
340 | 340 |
341 /** | 341 /** |
342 * Asynchronously re-checks filters for given nodes. | 342 * Asynchronously re-checks filters for given nodes. |
343 */ | 343 * @param {Node[]} nodes |
344 refilterNodes: function(/**Node[]*/ nodes, /**RequestEntry*/ entry) | 344 * @param {RequestEntry} entry |
| 345 */ |
| 346 refilterNodes: function(nodes, entry) |
345 { | 347 { |
346 // Ignore nodes that have been blocked already | 348 // Ignore nodes that have been blocked already |
347 if (entry.filter && !(entry.filter instanceof WhitelistFilter)) | 349 if (entry.filter && !(entry.filter instanceof WhitelistFilter)) |
348 return; | 350 return; |
349 | 351 |
350 for (let node of nodes) | 352 for (let node of nodes) |
351 Utils.runAsync(refilterNode, this, node, entry); | 353 Utils.runAsync(() => refilterNode(node, entry)); |
352 } | 354 } |
353 }; | 355 }; |
354 Policy.init(); | 356 Policy.init(); |
355 | 357 |
356 /** | 358 /** |
357 * Actual nsIContentPolicy and nsIChannelEventSink implementation | 359 * Actual nsIContentPolicy and nsIChannelEventSink implementation |
358 * @class | 360 * @class |
359 */ | 361 */ |
360 let PolicyImplementation = | 362 let PolicyImplementation = |
361 { | 363 { |
362 classDescription: "Adblock Plus content policy", | 364 classDescription: "Adblock Plus content policy", |
363 classID: Components.ID("cfeaabe6-1dd1-11b2-a0c6-cb5c268894c9"), | 365 classID: Components.ID("cfeaabe6-1dd1-11b2-a0c6-cb5c268894c9"), |
364 contractID: "@adblockplus.org/abp/policy;1", | 366 contractID: "@adblockplus.org/abp/policy;1", |
365 xpcom_categories: ["content-policy", "net-channel-event-sinks"], | 367 xpcom_categories: ["content-policy", "net-channel-event-sinks"], |
366 | 368 |
367 /** | 369 /** |
368 * Registers the content policy on startup. | 370 * Registers the content policy on startup. |
369 */ | 371 */ |
370 init: function() | 372 init: function() |
371 { | 373 { |
372 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); | 374 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
373 try | 375 try |
374 { | 376 { |
375 registrar.registerFactory(this.classID, this.classDescription, this.contra
ctID, this); | 377 registrar.registerFactory(this.classID, this.classDescription, this.contra
ctID, this); |
376 } | 378 } |
377 catch (e if e.result == Cr.NS_ERROR_FACTORY_EXISTS) | 379 catch (e) |
378 { | 380 { |
379 // See bug 924340 - it might be too early to init now, the old version | 381 // See bug 924340 - it might be too early to init now, the old version |
380 // we are replacing didn't finish removing itself yet. | 382 // we are replacing didn't finish removing itself yet. |
381 Utils.runAsync(this.init.bind(this)); | 383 if (e.result == Cr.NS_ERROR_FACTORY_EXISTS) |
382 return; | 384 { |
| 385 Utils.runAsync(this.init.bind(this)); |
| 386 return; |
| 387 } |
| 388 |
| 389 Cu.reportError(e); |
383 } | 390 } |
384 | 391 |
385 let catMan = Utils.categoryManager; | 392 let catMan = Utils.categoryManager; |
386 for (let category of this.xpcom_categories) | 393 for (let category of this.xpcom_categories) |
387 catMan.addCategoryEntry(category, this.contractID, this.contractID, false,
true); | 394 catMan.addCategoryEntry(category, this.contractID, this.contractID, false,
true); |
388 | 395 |
389 // http-on-opening-request is new in Gecko 18, http-on-modify-request can | 396 // http-on-opening-request is new in Gecko 18, http-on-modify-request can |
390 // be used in earlier releases. | 397 // be used in earlier releases. |
391 let httpTopic = "http-on-opening-request"; | 398 let httpTopic = "http-on-opening-request"; |
392 if (Services.vc.compare(Utils.platformVersion, "18.0") < 0) | 399 if (Services.vc.compare(Utils.platformVersion, "18.0") < 0) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 { | 485 { |
479 case "content-document-global-created": | 486 case "content-document-global-created": |
480 { | 487 { |
481 if (!(subject instanceof Ci.nsIDOMWindow) || !subject.opener) | 488 if (!(subject instanceof Ci.nsIDOMWindow) || !subject.opener) |
482 return; | 489 return; |
483 | 490 |
484 let uri = additional || Utils.makeURI(subject.location.href); | 491 let uri = additional || Utils.makeURI(subject.location.href); |
485 if (!Policy.processNode(subject.opener, subject.opener.document, Policy.
type.POPUP, uri, false)) | 492 if (!Policy.processNode(subject.opener, subject.opener.document, Policy.
type.POPUP, uri, false)) |
486 { | 493 { |
487 subject.stop(); | 494 subject.stop(); |
488 Utils.runAsync(subject.close, subject); | 495 Utils.runAsync(() => subject.close()); |
489 } | 496 } |
490 else if (uri.spec == "about:blank") | 497 else if (uri.spec == "about:blank") |
491 { | 498 { |
492 // An about:blank pop-up most likely means that a load will be | 499 // An about:blank pop-up most likely means that a load will be |
493 // initiated synchronously. Set a flag for our "http-on-opening-reques
t" | 500 // initiated synchronously. Set a flag for our "http-on-opening-reques
t" |
494 // handler. | 501 // handler. |
495 this.expectingPopupLoad = true; | 502 this.expectingPopupLoad = true; |
496 Utils.runAsync(function() | 503 Utils.runAsync(function() |
497 { | 504 { |
498 this.expectingPopupLoad = false; | 505 this.expectingPopupLoad = false; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 { | 628 { |
622 if (outer) | 629 if (outer) |
623 throw Cr.NS_ERROR_NO_AGGREGATION; | 630 throw Cr.NS_ERROR_NO_AGGREGATION; |
624 return this.QueryInterface(iid); | 631 return this.QueryInterface(iid); |
625 } | 632 } |
626 }; | 633 }; |
627 PolicyImplementation.init(); | 634 PolicyImplementation.init(); |
628 | 635 |
629 /** | 636 /** |
630 * Nodes scheduled for post-processing (might be null). | 637 * Nodes scheduled for post-processing (might be null). |
631 * @type Array of Node | 638 * @type Node[] |
632 */ | 639 */ |
633 let scheduledNodes = null; | 640 let scheduledNodes = null; |
634 | 641 |
635 /** | 642 /** |
636 * Schedules a node for post-processing. | 643 * Schedules a node for post-processing. |
637 */ | 644 */ |
638 function schedulePostProcess(/**Element*/ node) | 645 function schedulePostProcess(/**Element*/ node) |
639 { | 646 { |
640 if (scheduledNodes) | 647 if (scheduledNodes) |
641 scheduledNodes.push(node); | 648 scheduledNodes.push(node); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 if (!wnd || wnd.closed) | 818 if (!wnd || wnd.closed) |
812 return; | 819 return; |
813 | 820 |
814 if (entry.type == Policy.type.OBJECT) | 821 if (entry.type == Policy.type.OBJECT) |
815 { | 822 { |
816 node.removeEventListener("mouseover", objectMouseEventHander, true); | 823 node.removeEventListener("mouseover", objectMouseEventHander, true); |
817 node.removeEventListener("mouseout", objectMouseEventHander, true); | 824 node.removeEventListener("mouseout", objectMouseEventHander, true); |
818 } | 825 } |
819 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true)
; | 826 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true)
; |
820 } | 827 } |
LEFT | RIGHT |