Fixed nsDocShell leak and nsEditingSession init after forced reload of document. b=180146, r=cmanske, sr=sfraser
This commit is contained in:
Родитель
adf0c88e29
Коммит
c0c570c34e
|
@ -3009,6 +3009,9 @@ nsDocShell::Destroy()
|
|||
mContentListener->SetParentContentListener(nsnull);
|
||||
NS_RELEASE(mContentListener);
|
||||
}
|
||||
|
||||
delete mEditorData;
|
||||
mEditorData = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
nsresult GetOrCreateEditingSession(nsIEditingSession **outEditingSession);
|
||||
nsresult GetOrCreateEditingSession(nsIEditingSession **outEditingSession, PRBool inAllowCreation);
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -146,6 +146,9 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow,
|
|||
mEditorType.Truncate();
|
||||
mEditorFlags = 0;
|
||||
|
||||
// Always remove existing editor
|
||||
TearDownEditorOnWindow(aWindow);
|
||||
|
||||
// Tells embedder that startup is in progress
|
||||
mEditorStatus = eEditorCreationInProgress;
|
||||
|
||||
|
@ -174,7 +177,7 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow,
|
|||
&mBaseCommandControllerId);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// the second is an controller to monitor doc state,
|
||||
// The second is a controller to monitor doc state,
|
||||
// such as creation and "dirty flag"
|
||||
rv = SetupEditorCommandController("@mozilla.org/editor/editordocstatecontroller;1",
|
||||
aWindow,
|
||||
|
@ -452,13 +455,15 @@ NS_IMETHODIMP
|
|||
nsEditingSession::TearDownEditorOnWindow(nsIDOMWindow *aWindow)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
||||
if (mStateMaintainer)
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
rv = GetEditorForWindow(aWindow, getter_AddRefs(editor));
|
||||
if (editor)
|
||||
{
|
||||
// If we had an editor -- we are loading a new URL into existing window
|
||||
|
||||
// Remove all the listeners
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
editor->GetSelection(getter_AddRefs(selection));
|
||||
|
@ -488,8 +493,16 @@ nsEditingSession::TearDownEditorOnWindow(nsIDOMWindow *aWindow)
|
|||
rv = SetEditorOnControllers(aWindow, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No editor: we have a new window and previous controllers
|
||||
// were destroyed with the contentWindow.
|
||||
// Clear IDs to trigger creation of new controllers
|
||||
mBaseCommandControllerId = 0;
|
||||
mDocStateControllerId = 0;
|
||||
mHTMLCommandControllerId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIEditorDocShell> editorDocShell;
|
||||
rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
|
Загрузка…
Ссылка в новой задаче