Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 Cu.import("resource://gre/modules/Services.jsm"); | 7 Cu.import("resource://gre/modules/Services.jsm"); |
8 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 8 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
9 | 9 |
10 exports.WindowObserver = WindowObserver; | 10 exports.WindowObserver = WindowObserver; |
(...skipping 16 matching lines...) Expand all Loading... | |
27 let e = Services.ww.getWindowEnumerator(); | 27 let e = Services.ww.getWindowEnumerator(); |
28 while (e.hasMoreElements()) | 28 while (e.hasMoreElements()) |
29 { | 29 { |
30 let window = e.getNext().QueryInterface(Ci.nsIDOMWindow); | 30 let window = e.getNext().QueryInterface(Ci.nsIDOMWindow); |
31 if (when == "start" || window.document.readyState == "complete") | 31 if (when == "start" || window.document.readyState == "complete") |
32 this._listener.applyToWindow(window); | 32 this._listener.applyToWindow(window); |
33 else | 33 else |
34 this.observe(window, "domwindowopened", null); | 34 this.observe(window, "domwindowopened", null); |
35 } | 35 } |
36 | 36 |
37 Services.obs.addObserver(this, "chrome-document-global-created", false); | 37 Services.obs.addObserver(this, "chrome-document-global-created", true); |
Wladimir Palant
2012/10/30 17:20:21
Please use weak references just in case. Meaning t
| |
38 | 38 |
39 this._shutdownHandler = function() | 39 this._shutdownHandler = function() |
40 { | 40 { |
41 let e = Services.ww.getWindowEnumerator(); | 41 let e = Services.ww.getWindowEnumerator(); |
42 while (e.hasMoreElements()) | 42 while (e.hasMoreElements()) |
43 this._listener.removeFromWindow(e.getNext().QueryInterface(Ci.nsIDOMWindow )); | 43 this._listener.removeFromWindow(e.getNext().QueryInterface(Ci.nsIDOMWindow )); |
44 | 44 |
45 Services.obs.removeObserver(this, "chrome-document-global-created"); | 45 Services.obs.removeObserver(this, "chrome-document-global-created"); |
46 }.bind(this); | 46 }.bind(this); |
47 onShutdown.add(this._shutdownHandler); | 47 onShutdown.add(this._shutdownHandler); |
48 } | 48 } |
49 WindowObserver.prototype = | 49 WindowObserver.prototype = |
50 { | 50 { |
51 _listener: null, | 51 _listener: null, |
52 _when: null, | 52 _when: null, |
53 _shutdownHandler: null, | 53 _shutdownHandler: null, |
54 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), | |
55 | 54 |
56 shutdown: function() | 55 shutdown: function() |
57 { | 56 { |
58 if (!this._shutdownHandler) | 57 if (!this._shutdownHandler) |
59 return; | 58 return; |
60 | 59 |
61 onShutdown.remove(this._shutdownHandler); | 60 onShutdown.remove(this._shutdownHandler); |
62 this._shutdownHandler(); | 61 this._shutdownHandler(); |
63 this._shutdownHandler = null; | 62 this._shutdownHandler = null; |
64 }, | 63 }, |
65 | 64 |
66 observe: function(subject, topic, data) | 65 observe: function(subject, topic, data) |
67 { | 66 { |
68 if (subject.location.href !== "about:blank") | 67 // Make sure page is not about:blank (work-around for bug 795961) |
Wladimir Palant
2012/10/30 17:20:21
Please check |subject instanceof Ci.nsIDOMWindow|
Wladimir Palant
2012/10/30 18:52:22
Forgot to mention: there should be a link to Bugzi
| |
68 if (subject instanceof Ci.nsIDOMWindow && subject.location.href !== "about:b lank") | |
69 { | 69 { |
70 if (this._when == "start") | 70 if (this._when == "start") |
71 { | 71 { |
72 this._listener.applyToWindow(window); | 72 this._listener.applyToWindow(window); |
73 return; | 73 return; |
74 } | 74 } |
75 | 75 |
76 let window = subject.QueryInterface(Ci.nsIDOMWindow); | 76 let window = subject.QueryInterface(Ci.nsIDOMWindow); |
77 let event = (this._when == "ready" ? "DOMContentLoaded" : "load"); | 77 let event = (this._when == "ready" ? "DOMContentLoaded" : "load"); |
78 let listener = function() | 78 let listener = function() |
79 { | 79 { |
80 window.removeEventListener(event, listener, false); | 80 window.removeEventListener(event, listener, false); |
81 if (this._shutdownHandler && window.document.documentElement.getAttribut e("windowtype") == "navigator:browser") | 81 if (this._shutdownHandler) |
Wladimir Palant
2012/10/30 17:20:21
Is this debug code? Please remove.
| |
82 this._listener.applyToWindow(window); | 82 this._listener.applyToWindow(window); |
83 }.bind(this); | 83 }.bind(this); |
84 window.addEventListener(event, listener, false); | 84 window.addEventListener(event, listener, false); |
85 } | 85 } |
86 }, | 86 }, |
87 | 87 |
88 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse rver]) | 88 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse rver]) |
89 }; | 89 }; |
LEFT | RIGHT |