Bug 484890 - Use a weak pointer for docshell in editing session; r=sicking a1.9.1.10=dveditz
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 18 Mar 2010 12:12:37 -0400
changeset 26850 d360dfcc44b08f00ad95b25b80e6af663fe18de9
parent 26845 4a19f13381759250e4524c808e8cfa1f03855ec5
child 26851 60604e85cfa55261c1a4b7e7cf6654b73f801ce4
push id2318
push usereakhgari@mozilla.com
push dateMon, 22 Mar 2010 15:47:36 +0000
reviewerssicking
bugs484890
milestone1.9.1.10pre
Bug 484890 - Use a weak pointer for docshell in editing session; r=sicking a1.9.1.10=dveditz
editor/composer/src/nsEditingSession.cpp
editor/composer/src/nsEditingSession.h
--- a/editor/composer/src/nsEditingSession.cpp
+++ b/editor/composer/src/nsEditingSession.cpp
@@ -1053,32 +1053,33 @@ nsEditingSession::EndDocumentLoad(nsIWeb
             mLoadBlankDocTimer->Cancel();
             mLoadBlankDocTimer = NULL;
           }
   
           mLoadBlankDocTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
           if (NS_FAILED(rv)) return rv;
 
           mEditorStatus = eEditorCreationInProgress;
+          mDocShell = do_GetWeakReference(docShell);
           mLoadBlankDocTimer->InitWithFuncCallback(
                                           nsEditingSession::TimerCallback,
-                                          (void*)docShell,
+                                          static_cast<void*> (mDocShell.get()),
                                           10, nsITimer::TYPE_ONE_SHOT);
         }
       }
     }
   }
   return rv;
 }
 
 
 void
 nsEditingSession::TimerCallback(nsITimer* aTimer, void* aClosure)
 {
-  nsCOMPtr<nsIDocShell> docShell = (nsIDocShell*)aClosure;
+  nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(static_cast<nsIWeakReference*> (aClosure));
   if (docShell)
   {
     nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
     if (webNav)
       webNav->LoadURI(NS_LITERAL_STRING("about:blank").get(),
                       0, nsnull, nsnull, nsnull);
   }
 }
--- a/editor/composer/src/nsEditingSession.h
+++ b/editor/composer/src/nsEditingSession.h
@@ -162,13 +162,16 @@ protected:
 
   // Save the editor type so we can create the editor after loading uri
   nsCString       mEditorType; 
   PRUint32        mEditorFlags;
   PRUint32        mEditorStatus;
   PRUint32        mBaseCommandControllerId;
   PRUint32        mDocStateControllerId;
   PRUint32        mHTMLCommandControllerId;
+
+  // Make sure the docshell we use is safe
+  nsWeakPtr       mDocShell;
 };
 
 
 
 #endif // nsEditingSession_h__