Permalink
Browse files

Do not register a new window if its state is completed, it could be t…

…oo late in some corner cases. See issue 5582
  • Loading branch information...
1 parent 86b8b59 commit c07f25e82519b4636722cc7e63086c191c3c16f2 @janodvarko janodvarko committed Jun 20, 2012
Showing with 27 additions and 8 deletions.
  1. +27 −8 extension/content/firebug/chrome/tabWatcher.js
@@ -433,7 +433,7 @@ Firebug.TabWatcher = Obj.extend(new Firebug.Listener(),
/**
* Attaches to a window that may be either top-level or a frame within the page.
*/
- watchWindow: function(win, context)
+ watchWindow: function(win, context, skipCompletedDocuments)
{
if (!context)
context = this.getContextByWindow(Win.getRootWindow(win));
@@ -445,6 +445,21 @@ Firebug.TabWatcher = Obj.extend(new Firebug.Listener(),
if (context)
TabWatcherUnloader.registerWindow(win);
+ try
+ {
+ // If the documents is already completed do not register the window
+ // it should be registered already at this point
+ // This condition avoids situation when "about:document-onload-blocker"
+ // and STATE_START is fired for a window, which is consequently never
+ // firing "unload" and so, stays registered within context.windows
+ // See issue 5582 (comment #4)
+ if (skipCompletedDocuments && win.document.readyState == "complete")
+ return;
+ }
+ catch (err)
+ {
+ }
+
// Unfortunately, dummy requests that trigger the call to watchWindow
// are called several times, so we have to avoid dispatching watchWindow
// more than once
@@ -453,8 +468,11 @@ Firebug.TabWatcher = Obj.extend(new Firebug.Listener(),
context.windows.push(win);
if (FBTrace.DBG_WINDOWS)
- FBTrace.sysout("-> watchWindow register *** FRAME *** to context for " +
- "win.location: " + location);
+ {
+ FBTrace.sysout("-> tabWatcher.watchWindow; " + Win.safeGetWindowLocation(win) +
+ " [" + Win.getWindowId(win).toString() + "] " + context.windows.length +
+ " - " + win.document.readyState);
+ }
Events.dispatch(this.fbListeners, "watchWindow", [context, win]);
@@ -509,7 +527,7 @@ Firebug.TabWatcher = Obj.extend(new Firebug.Listener(),
{
if (FBTrace.DBG_ERRORS)
{
- FBTrace.sysout("unwatchWindow: no context for win " +
+ FBTrace.sysout("unwatchWindow: ERROR no context for win " +
Win.safeGetWindowLocation(win));
}
return;
@@ -518,8 +536,9 @@ Firebug.TabWatcher = Obj.extend(new Firebug.Listener(),
var index = context.windows.indexOf(win);
if (FBTrace.DBG_WINDOWS)
{
- FBTrace.sysout("-> tabWatcher.unwatchWindow context: " + context.getName() +
- " index of win: " + index + "/" + context.windows.length, context.windows);
+ FBTrace.sysout("-> tabWatcher.unwatchWindow; " + Win.safeGetWindowLocation(win) +
+ " [" + Win.getWindowId(win).toString() + "] " + context.windows.length +
+ " - " + win.document.readyState);
}
if (index != -1)
@@ -890,7 +909,7 @@ var FrameProgressListener = Obj.extend(Http.BaseProgressListener,
FBTrace.sysout("-> FrameProgressListener.onStateChanged for: " +
Http.safeGetRequestName(request) + ", win: " + win.location.href +
", content URL: " + (win.document ? win.document.URL : "no content URL") +
- " " + Http.getStateDescription(flag));
+ " " + Http.getStateDescription(flag) + ", " + status);
}
if (flag & STATE_IS_REQUEST && flag & STATE_START)
@@ -914,7 +933,7 @@ var FrameProgressListener = Obj.extend(Http.BaseProgressListener,
}
else
{
- Firebug.TabWatcher.watchWindow(win);
+ Firebug.TabWatcher.watchWindow(win, null, true);
}
}
}

0 comments on commit c07f25e

Please sign in to comment.