Bug 525153: In DocumentViewerImpl::LoadComplete, don't call OnPageShow if docshell is being destroyed. r=smaug sr=bz
authorDaniel Holbert <dholbert@cs.stanford.edu>
Sat, 31 Oct 2009 17:06:47 -0700
changeset 34446 2801b05bb7ccc199dac77fc08f88b52e4a65bfc1
parent 34445 4597c9ddc1ff118469825beb040484fe602f8368
child 34447 c38d6ec28c453e7b727f02de6394cffc3e891f63
push idunknown
push userunknown
push dateunknown
reviewerssmaug, bz
bugs525153
milestone1.9.3a1pre
Bug 525153: In DocumentViewerImpl::LoadComplete, don't call OnPageShow if docshell is being destroyed. r=smaug sr=bz
content/smil/nsSMILCSSProperty.cpp
layout/base/nsDocumentViewer.cpp
--- a/content/smil/nsSMILCSSProperty.cpp
+++ b/content/smil/nsSMILCSSProperty.cpp
@@ -67,18 +67,21 @@ GetCSSComputedValue(nsIContent* aElem,
                     nsAString& aResult)
 {
   NS_ENSURE_TRUE(nsSMILCSSProperty::IsPropertyAnimatable(aPropID),
                  PR_FALSE);
 
   nsIDocument* doc = aElem->GetCurrentDoc();
   NS_ABORT_IF_FALSE(doc,"any target element that's actively being animated "
                     "must be in a document");
+
+  nsPIDOMWindow* win = doc->GetWindow();
+  NS_ABORT_IF_FALSE(win, "actively animated document w/ no window");
   nsRefPtr<nsComputedDOMStyle>
-    computedStyle(doc->GetWindow()->LookupComputedStyleFor(aElem));
+    computedStyle(win->LookupComputedStyleFor(aElem));
   if (computedStyle) {
     // NOTE: This will produce an empty string for shorthand values
     computedStyle->GetPropertyValue(aPropID, aResult);
     return PR_TRUE;
   }
   return PR_FALSE;
 }
 
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -1049,18 +1049,29 @@ DocumentViewerImpl::LoadComplete(nsresul
     }
   } else {
     // XXX: Should fire error event to the document...
   }
 
   // Notify the document that it has been shown (regardless of whether
   // it was just loaded). Note: mDocument may be null now if the above
   // firing of onload caused the document to unload.
-  if (mDocument)
-    mDocument->OnPageShow(restoring, nsnull);
+  if (mDocument) {
+    // Re-get window, since it might have changed during above firing of onload
+    window = mDocument->GetWindow();
+    if (window) {
+      nsIDocShell *docShell = window->GetDocShell();
+      PRBool beingDestroyed;
+      if (docShell &&
+          NS_SUCCEEDED(docShell->IsBeingDestroyed(&beingDestroyed)) &&
+          !beingDestroyed) {
+        mDocument->OnPageShow(restoring, nsnull);
+      }
+    }
+  }
 
   // Now that the document has loaded, we can tell the presshell
   // to unsuppress painting.
   if (mPresShell && !mStopped) {
     nsCOMPtr<nsIPresShell> shellDeathGrip(mPresShell);
     mPresShell->UnsuppressPainting();
     // mPresShell could have been removed now, see bug 378682/421432
     if (mPresShell) {
@@ -3997,17 +4008,17 @@ DocumentViewerImpl::Cancel()
   return mPrintEngine->Cancelled();
 }
 
 /* void exitPrintPreview (); */
 NS_IMETHODIMP
 DocumentViewerImpl::ExitPrintPreview()
 {
   printf("TEST-INFO ExitPrintPreview: mPrintEngine=%p, GetIsPrinting()=%d\n",
-         mPrintEngine.get(), GetIsPrinting());
+         static_cast<void*>(mPrintEngine.get()), GetIsPrinting());
   if (GetIsPrinting())
     return NS_ERROR_FAILURE;
   NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_FAILURE);
 
   if (GetIsPrintPreview()) {
     ReturnToGalleyPresentation();
   }
   return NS_OK;