| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of the Adblock Plus build tools, | 2 * This file is part of the Adblock Plus build tools, |
| 3 * Copyright (C) 2006-2012 Eyeo GmbH | 3 * Copyright (C) 2006-2012 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 24 matching lines...) Expand all Loading... |
| 35 this._listener = listener; | 35 this._listener = listener; |
| 36 this._when = when; | 36 this._when = when; |
| 37 | 37 |
| 38 let e = Services.ww.getWindowEnumerator(); | 38 let e = Services.ww.getWindowEnumerator(); |
| 39 while (e.hasMoreElements()) | 39 while (e.hasMoreElements()) |
| 40 { | 40 { |
| 41 let window = e.getNext().QueryInterface(Ci.nsIDOMWindow); | 41 let window = e.getNext().QueryInterface(Ci.nsIDOMWindow); |
| 42 if (when == "start" || window.document.readyState == "complete") | 42 if (when == "start" || window.document.readyState == "complete") |
| 43 this._listener.applyToWindow(window); | 43 this._listener.applyToWindow(window); |
| 44 else | 44 else |
| 45 this.observe(window, "domwindowopened", null); | 45 this.observe(window, "chrome-document-global-created", null); |
| 46 } | 46 } |
| 47 | 47 |
| 48 Services.obs.addObserver(this, "chrome-document-global-created", true); | 48 Services.obs.addObserver(this, "chrome-document-global-created", true); |
| 49 | 49 |
| 50 this._shutdownHandler = function() | 50 this._shutdownHandler = function() |
| 51 { | 51 { |
| 52 let e = Services.ww.getWindowEnumerator(); | 52 let e = Services.ww.getWindowEnumerator(); |
| 53 while (e.hasMoreElements()) | 53 while (e.hasMoreElements()) |
| 54 this._listener.removeFromWindow(e.getNext().QueryInterface(Ci.nsIDOMWindow
)); | 54 this._listener.removeFromWindow(e.getNext().QueryInterface(Ci.nsIDOMWindow
)); |
| 55 | 55 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 68 if (!this._shutdownHandler) | 68 if (!this._shutdownHandler) |
| 69 return; | 69 return; |
| 70 | 70 |
| 71 onShutdown.remove(this._shutdownHandler); | 71 onShutdown.remove(this._shutdownHandler); |
| 72 this._shutdownHandler(); | 72 this._shutdownHandler(); |
| 73 this._shutdownHandler = null; | 73 this._shutdownHandler = null; |
| 74 }, | 74 }, |
| 75 | 75 |
| 76 observe: function(subject, topic, data) | 76 observe: function(subject, topic, data) |
| 77 { | 77 { |
| 78 // Make sure page is not about:blank (work-around for bug 795961) | 78 if (topic == "chrome-document-global-created") |
| 79 if (subject instanceof Ci.nsIDOMWindow && subject.location.href !== "about:b
lank") | |
| 80 { | 79 { |
| 80 let window = subject.QueryInterface(Ci.nsIDOMWindow); |
| 81 if (this._when == "start") | 81 if (this._when == "start") |
| 82 { | 82 { |
| 83 this._listener.applyToWindow(window); | 83 this._listener.applyToWindow(window); |
| 84 return; | 84 return; |
| 85 } | 85 } |
| 86 | 86 |
| 87 let window = subject.QueryInterface(Ci.nsIDOMWindow); | |
| 88 let event = (this._when == "ready" ? "DOMContentLoaded" : "load"); | 87 let event = (this._when == "ready" ? "DOMContentLoaded" : "load"); |
| 89 let listener = function() | 88 let listener = function() |
| 90 { | 89 { |
| 91 window.removeEventListener(event, listener, false); | 90 window.removeEventListener(event, listener, false); |
| 92 if (this._shutdownHandler) | 91 if (this._shutdownHandler) |
| 93 this._listener.applyToWindow(window); | 92 this._listener.applyToWindow(window); |
| 94 }.bind(this); | 93 }.bind(this); |
| 95 window.addEventListener(event, listener, false); | 94 window.addEventListener(event, listener, false); |
| 96 } | 95 } |
| 97 }, | 96 }, |
| 98 | 97 |
| 99 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse
rver]) | 98 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse
rver]) |
| 100 }; | 99 }; |
| OLD | NEW |