Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/windowObserver.js

Issue 11624001: Fixed: WindowObserver ignoring primary browser window if instantiated before window visible (Closed)
Patch Set: Created Sept. 9, 2013, 2:54 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/windowObserver.js
===================================================================
--- a/lib/windowObserver.js
+++ b/lib/windowObserver.js
@@ -35,6 +35,7 @@
this._listener = listener;
this._when = when;
+ let windows = [];
let e = Services.wm.getZOrderDOMWindowEnumerator(null, true);
if (!e.hasMoreElements())
{
@@ -43,11 +44,18 @@
}
Wladimir Palant 2013/09/11 11:31:26 I think we can drop the fallback here, ww.getWindo
while (e.hasMoreElements())
{
- let window = e.getNext().QueryInterface(Ci.nsIDOMWindow);
- if (when == "start" || window.document.readyState == "complete")
- this._listener.applyToWindow(window);
- else
- this.observe(window, "chrome-document-global-created", null);
+ let element = e.getNext();
+ this._addWindowListener(element);
+ windows.push(element);
+ }
+
+ // Check if there are any windows that we missed because they are not visible yet
+ let eAll = Services.ww.getWindowEnumerator();
+ while (eAll.hasMoreElements())
+ {
+ let element = eAll.getNext();
+ if (windows.indexOf(element) < 0)
+ this._addWindowListener(element);
Wladimir Palant 2013/09/11 11:31:26 I'd rather have windows.push(element) here - simpl
}
Services.obs.addObserver(this, "chrome-document-global-created", true);
@@ -68,6 +76,15 @@
_when: null,
_shutdownHandler: null,
+ _addWindowListener: function(e)
+ {
+ let window = e.QueryInterface(Ci.nsIDOMWindow);
+ if (this._when == "start" || window.document.readyState == "complete")
+ this._listener.applyToWindow(window);
+ else
+ this.observe(window, "chrome-document-global-created", null);
+ },
+
shutdown: function()
{
if (!this._shutdownHandler)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld