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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 if (name.indexOf("TYPE_") == 0 && name != "TYPE_DATAREQUEST") | 240 if (name.indexOf("TYPE_") == 0 && name != "TYPE_DATAREQUEST") |
241 types.set(iface[name], name.substr(5)); | 241 types.set(iface[name], name.substr(5)); |
242 | 242 |
243 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); | 243 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
244 registrar.registerFactory(this.classID, this.classDescription, this.contract
ID, this); | 244 registrar.registerFactory(this.classID, this.classDescription, this.contract
ID, this); |
245 | 245 |
246 let catMan = Utils.categoryManager; | 246 let catMan = Utils.categoryManager; |
247 for (let category of this.xpcom_categories) | 247 for (let category of this.xpcom_categories) |
248 catMan.addCategoryEntry(category, this.contractID, this.contractID, false,
true); | 248 catMan.addCategoryEntry(category, this.contractID, this.contractID, false,
true); |
249 | 249 |
250 Services.obs.addObserver(this, "content-document-global-created", true); | 250 Services.obs.addObserver(this, "document-element-inserted", true); |
251 | 251 |
252 onShutdown.add(() => | 252 onShutdown.add(() => |
253 { | 253 { |
254 Services.obs.removeObserver(this, "content-document-global-created"); | 254 Services.obs.removeObserver(this, "document-element-inserted"); |
255 | 255 |
256 for (let category of this.xpcom_categories) | 256 for (let category of this.xpcom_categories) |
257 catMan.deleteCategoryEntry(category, this.contractID, false); | 257 catMan.deleteCategoryEntry(category, this.contractID, false); |
258 | 258 |
259 registrar.unregisterFactory(this.classID, this); | 259 registrar.unregisterFactory(this.classID, this); |
260 }); | 260 }); |
261 }, | 261 }, |
262 | 262 |
263 // | 263 // |
264 // nsISupports interface implementation | 264 // nsISupports interface implementation |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 305 |
306 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode
, mimeType, extra) | 306 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode
, mimeType, extra) |
307 { | 307 { |
308 return Ci.nsIContentPolicy.ACCEPT; | 308 return Ci.nsIContentPolicy.ACCEPT; |
309 }, | 309 }, |
310 | 310 |
311 // | 311 // |
312 // nsIObserver interface implementation | 312 // nsIObserver interface implementation |
313 // | 313 // |
314 _openers: new WeakMap(), | 314 _openers: new WeakMap(), |
| 315 _alreadyLoaded: {}, |
315 | 316 |
316 observe: function(subject, topic, data, uri) | 317 observe: function(subject, topic, data, uri) |
317 { | 318 { |
318 switch (topic) | 319 switch (topic) |
319 { | 320 { |
320 case "content-document-global-created": | 321 case "document-element-inserted": |
321 { | 322 { |
322 let opener = this._openers.get(subject); | 323 let window = subject.defaultView; |
323 if (opener && Components.utils.isDeadWrapper(opener)) | 324 if (!window) |
| 325 return; |
| 326 |
| 327 let type = window.QueryInterface(Ci.nsIInterfaceRequestor) |
| 328 .getInterface(Ci.nsIWebNavigation) |
| 329 .QueryInterface(Ci.nsIDocShellTreeItem) |
| 330 .itemType; |
| 331 if (type != Ci.nsIDocShellTreeItem.typeContent) |
| 332 return; |
| 333 |
| 334 let opener = this._openers.get(window); |
| 335 if (opener == this._alreadyLoaded) |
| 336 { |
| 337 // This window has loaded already, ignore it regardless of whether |
| 338 // window.opener is still set. |
| 339 return; |
| 340 } |
| 341 |
| 342 if (opener && Cu.isDeadWrapper(opener)) |
324 opener = null; | 343 opener = null; |
325 | 344 |
326 if (!opener) | 345 if (!opener) |
327 { | 346 { |
328 // We don't know the opener for this window yet, try to find it | 347 // We don't know the opener for this window yet, try to find it |
329 if (subject instanceof Ci.nsIDOMWindow) | 348 opener = window.opener; |
330 opener = subject.opener; | |
331 | |
332 if (!opener) | 349 if (!opener) |
333 return; | 350 return; |
334 | 351 |
335 // The opener might be an intermediate window, get the real one | 352 // The opener might be an intermediate window, get the real one |
336 while (opener.location == "about:blank" && opener.opener) | 353 while (opener.location == "about:blank" && opener.opener) |
337 opener = opener.opener; | 354 opener = opener.opener; |
338 | 355 |
339 this._openers.set(subject, opener); | 356 this._openers.set(window, opener); |
| 357 |
| 358 let forgetPopup = event => |
| 359 { |
| 360 subject.removeEventListener("DOMContentLoaded", forgetPopup); |
| 361 this._openers.set(window, this._alreadyLoaded); |
| 362 }; |
| 363 subject.addEventListener("DOMContentLoaded", forgetPopup); |
340 } | 364 } |
341 | 365 |
342 if (!uri && subject instanceof Ci.nsIDOMWindow) | 366 if (!uri) |
343 uri = subject.location.href; | 367 uri = window.location.href; |
344 if (!shouldAllow(opener, opener.document, "POPUP", uri)) | 368 if (!shouldAllow(opener, opener.document, "POPUP", uri)) |
345 { | 369 { |
346 subject.stop(); | 370 window.stop(); |
347 Utils.runAsync(() => subject.close()); | 371 Utils.runAsync(() => window.close()); |
348 } | 372 } |
349 else if (uri == "about:blank") | 373 else if (uri == "about:blank") |
350 { | 374 { |
351 // An about:blank pop-up most likely means that a load will be | 375 // An about:blank pop-up most likely means that a load will be |
352 // initiated asynchronously. Wait for that. | 376 // initiated asynchronously. Wait for that. |
353 Utils.runAsync(() => | 377 Utils.runAsync(() => |
354 { | 378 { |
355 let channel = subject.QueryInterface(Ci.nsIInterfaceRequestor) | 379 let channel = window.QueryInterface(Ci.nsIInterfaceRequestor) |
356 .getInterface(Ci.nsIDocShell) | 380 .getInterface(Ci.nsIDocShell) |
357 .QueryInterface(Ci.nsIDocumentLoader) | 381 .QueryInterface(Ci.nsIDocumentLoader) |
358 .documentChannel; | 382 .documentChannel; |
359 if (channel) | 383 if (channel) |
360 this.observe(subject, topic, data, channel.URI.spec); | 384 this.observe(subject, topic, data, channel.URI.spec); |
361 }); | 385 }); |
362 } | 386 } |
363 break; | 387 break; |
364 } | 388 } |
365 } | 389 } |
366 }, | 390 }, |
367 | 391 |
368 // | 392 // |
(...skipping 18 matching lines...) Expand all Loading... |
387 return; | 411 return; |
388 | 412 |
389 if (contentType == Ci.nsIContentPolicy.TYPE_DOCUMENT) | 413 if (contentType == Ci.nsIContentPolicy.TYPE_DOCUMENT) |
390 { | 414 { |
391 if (wnd.history.length <= 1 && wnd.opener) | 415 if (wnd.history.length <= 1 && wnd.opener) |
392 { | 416 { |
393 // Special treatment for pop-up windows - this will close the window | 417 // Special treatment for pop-up windows - this will close the window |
394 // rather than preventing the redirect. Note that we might not have | 418 // rather than preventing the redirect. Note that we might not have |
395 // seen the original channel yet because the redirect happened before | 419 // seen the original channel yet because the redirect happened before |
396 // the async code in observe() had a chance to run. | 420 // the async code in observe() had a chance to run. |
397 this.observe(wnd, "content-document-global-created", null, oldChannel.
URI.spec); | 421 this.observe(wnd, "document-element-inserted", null, oldChannel.URI.sp
ec); |
398 this.observe(wnd, "content-document-global-created", null, newChannel.
URI.spec); | 422 this.observe(wnd, "document-element-inserted", null, newChannel.URI.sp
ec); |
399 } | 423 } |
400 return; | 424 return; |
401 } | 425 } |
402 | 426 |
403 shouldAllowAsync(wnd, wnd.document, types.get(contentType), newChannel.URI
.spec, function(allow) | 427 shouldAllowAsync(wnd, wnd.document, types.get(contentType), newChannel.URI
.spec, function(allow) |
404 { | 428 { |
405 callback.onRedirectVerifyCallback(allow ? Cr.NS_OK : Cr.NS_BINDING_ABORT
ED); | 429 callback.onRedirectVerifyCallback(allow ? Cr.NS_OK : Cr.NS_BINDING_ABORT
ED); |
406 }); | 430 }); |
407 async = true; | 431 async = true; |
408 } | 432 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 let weights = parentNode[property].split(","); | 509 let weights = parentNode[property].split(","); |
486 weights[index] = "0"; | 510 weights[index] = "0"; |
487 parentNode[property] = weights.join(","); | 511 parentNode[property] = weights.join(","); |
488 } | 512 } |
489 } | 513 } |
490 else | 514 else |
491 node.classList.add(cls); | 515 node.classList.add(cls); |
492 } | 516 } |
493 }); | 517 }); |
494 } | 518 } |
OLD | NEW |