Fixed nsDocShell leak and nsEditingSession init after forced reload of document. b=180146, r=cmanske, sr=sfraser

git-svn-id: svn://10.0.0.236/trunk@134171 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
cmanske%netscape.com
2002-11-20 06:23:05 +00:00
parent 886c145069
commit f3b0cea7ba
4 changed files with 38 additions and 9 deletions

View File

@@ -51,13 +51,22 @@ nsDocShellEditorData::nsDocShellEditorData(nsIDocShell* inOwningDocShell)
----------------------------------------------------------------------------*/
nsDocShellEditorData::~nsDocShellEditorData()
{
if (mEditor)
// Get editing session on the root docShell
nsCOMPtr <nsIEditingSession> editingSession;
nsresult rv = GetOrCreateEditingSession(getter_AddRefs(editingSession), PR_FALSE);
if (editingSession)
{
nsCOMPtr<nsIDOMWindow> domWindow = do_GetInterface(mDocShell);
// This will eventually call nsDocShellEditorData::SetEditor(nsnull)
// which will call mEditorPreDestroy() and delete the editor
editingSession->TearDownEditorOnWindow(domWindow);
}
else if (mEditor) // Should never have this w/o nsEditingSession!
{
mEditor->PreDestroy();
mEditor = nsnull; // explicit clear to make destruction order predictable
}
mEditingSession = nsnull;
}
@@ -127,7 +136,7 @@ nsresult
nsDocShellEditorData::GetEditingSession(nsIEditingSession **outEditingSession)
{
NS_ENSURE_ARG_POINTER(outEditingSession);
return GetOrCreateEditingSession(outEditingSession);
return GetOrCreateEditingSession(outEditingSession, PR_TRUE);
}
@@ -180,7 +189,7 @@ nsDocShellEditorData::SetEditor(nsIEditor *inEditor)
----------------------------------------------------------------------------*/
nsresult
nsDocShellEditorData::GetOrCreateEditingSession(nsIEditingSession **outEditingSession)
nsDocShellEditorData::GetOrCreateEditingSession(nsIEditingSession **outEditingSession, PRBool inAllowCreation)
{
NS_ENSURE_ARG_POINTER(outEditingSession);
*outEditingSession = nsnull;
@@ -203,6 +212,10 @@ nsDocShellEditorData::GetOrCreateEditingSession(nsIEditingSession **outEditingSe
// if necessary.
if (!mEditingSession)
{
// Caller doesn't want a new EditingSession if it doesn't already exist
if (!inAllowCreation)
return NS_OK;
mEditingSession = do_CreateInstance("@mozilla.org/editor/editingsession;1", &rv);
if (NS_FAILED(rv)) return rv;