Left: | ||
Right: |
OLD | NEW |
---|---|
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.ww.registerNotification(this); | 37 Services.obs.addObserver(this, "chrome-document-global-created", false); |
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.ww.unregisterNotification(this); | 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]), | |
54 | 55 |
55 shutdown: function() | 56 shutdown: function() |
56 { | 57 { |
57 if (!this._shutdownHandler) | 58 if (!this._shutdownHandler) |
58 return; | 59 return; |
59 | 60 |
60 onShutdown.remove(this._shutdownHandler); | 61 onShutdown.remove(this._shutdownHandler); |
61 this._shutdownHandler(); | 62 this._shutdownHandler(); |
62 this._shutdownHandler = null; | 63 this._shutdownHandler = null; |
63 }, | 64 }, |
64 | 65 |
65 observe: function(subject, topic, data) | 66 observe: function(subject, topic, data) |
66 { | 67 { |
67 if (topic == "domwindowopened") | 68 if (subject.location.href !== "about:blank") |
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 { | 69 { |
69 if (this._when == "start") | 70 if (this._when == "start") |
70 { | 71 { |
71 this._listener.applyToWindow(window); | 72 this._listener.applyToWindow(window); |
72 return; | 73 return; |
73 } | 74 } |
74 | 75 |
75 let window = subject.QueryInterface(Ci.nsIDOMWindow); | 76 let window = subject.QueryInterface(Ci.nsIDOMWindow); |
76 let event = (this._when == "ready" ? "DOMContentLoaded" : "load"); | 77 let event = (this._when == "ready" ? "DOMContentLoaded" : "load"); |
77 let listener = function() | 78 let listener = function() |
78 { | 79 { |
79 window.removeEventListener(event, listener, false); | 80 window.removeEventListener(event, listener, false); |
80 if (this._shutdownHandler) | 81 if (this._shutdownHandler && window.document.documentElement.getAttribut e("windowtype") == "navigator:browser") |
Wladimir Palant
2012/10/30 17:20:21
Is this debug code? Please remove.
| |
81 this._listener.applyToWindow(window); | 82 this._listener.applyToWindow(window); |
82 }.bind(this); | 83 }.bind(this); |
83 window.addEventListener(event, listener, false); | 84 window.addEventListener(event, listener, false); |
84 } | 85 } |
85 }, | 86 }, |
86 | 87 |
87 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse rver]) | 88 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse rver]) |
88 }; | 89 }; |
OLD | NEW |