bug 492312: DocumentLoaded() called multiple times loading one page, r=mfinkle
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 08 Jun 2009 23:49:57 -0400
changeset 118 c335c76103d5964be0a9861e52e0660464a46b3f
parent 117 0567bf985e06bf238c02d509e186fba5da1d2746
child 119 4d6bf1b0b33d757ca5659dc44f98b3d720a9d36f
push id36
push usermfinkle@mozilla.com
push dateTue, 09 Jun 2009 03:51:07 +0000
reviewersmfinkle
bugs492312
bug 492312: DocumentLoaded() called multiple times loading one page, r=mfinkle
common/WebBrowserChrome.cpp
--- a/common/WebBrowserChrome.cpp
+++ b/common/WebBrowserChrome.cpp
@@ -38,16 +38,17 @@
 
 #include "WebBrowserChrome.h"
 #include "embed.h"
 
 #include "nsStringAPI.h"
 
 #include "nsIDOMWindow.h"
 #include "nsIURI.h"
+#include "nsIWebProgress.h"
 
 WebBrowserChrome::WebBrowserChrome(MozView* pAMozView) :
     mChromeFlags(0),
     mSizeSet(PR_FALSE),
     pMozView(pAMozView),
     mIsModal(PR_FALSE)
 {
     /* member initializers and constructor code */
@@ -161,39 +162,45 @@ NS_IMETHODIMP WebBrowserChrome::ExitModa
 
     pListener->ExitModal(aStatus);
     mIsModal = PR_FALSE;
     return NS_OK;
 }
 
 // ----- Progress Listener -----
 
-NS_IMETHODIMP WebBrowserChrome::OnStateChange(nsIWebProgress * /*aWebProgress*/,
+NS_IMETHODIMP WebBrowserChrome::OnStateChange(nsIWebProgress * aWebProgress,
                                               nsIRequest * /*aRequest*/,
                                               PRUint32 aStateFlags,
                                               nsresult /*aStatus*/)
 {
     MozViewListener* pListener = pMozView->GetListener();
     // XXX no one considered this case
     if (!pListener)
         return NS_OK;
 
     if ((aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_DOCUMENT)) {
         // if it was a chrome window and no one has already specified a size,
         // size to content
-        if (!mSizeSet &&
-            (mChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)) {
-            nsCOMPtr<nsIDOMWindow> contentWin;
-            mWebBrowser->GetContentDOMWindow(getter_AddRefs(contentWin));
+        nsCOMPtr<nsIDOMWindow> contentWin;
+        mWebBrowser->GetContentDOMWindow(getter_AddRefs(contentWin));
+        if (!mSizeSet && (mChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)) {
             if (contentWin)
                 contentWin->SizeToContent();
             SetVisibility(PR_TRUE);
         }
 
-        pListener->DocumentLoaded();
+        // XXXbz the fact that nsWebBrowser won't hand out its root web
+        // progress is ridiculous.
+        nsCOMPtr<nsIDOMWindow> progressWindow;
+        aWebProgress->GetDOMWindow(getter_AddRefs(progressWindow));
+        
+        // Make sure the current window is the main content window
+        if (SameCOMIdentity(progressWindow, contentWin))
+          pListener->DocumentLoaded();
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP WebBrowserChrome::OnProgressChange(nsIWebProgress * /*aWebProgress*/,
                                                  nsIRequest * /*aRequest*/,
                                                  PRInt32 /*aCurSelfProgress*/,