Bug 1387406 - part1: nsDocShellEditorData should store editor as HTMLEditor r=smaug

The editor stored by nsDocShellEditorData should be always HTMLEditor.  So, it should store the editor as HTMLEditor and its getter and setter should treat the editor as HTMLEditor too.

MozReview-Commit-ID: GgfCd3zB887

--HG--
extra : rebase_source : 6c838a68911d47dce3aaf2dfc8bc6848e186e562
This commit is contained in:
Masayuki Nakano 2017-08-04 21:42:13 +09:00
Родитель eb06963c9e
Коммит 339262dc41
3 изменённых файлов: 53 добавлений и 38 удалений

Просмотреть файл

@ -24,6 +24,7 @@
#include "mozilla/dom/workers/ServiceWorkerManager.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/HTMLEditor.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "mozilla/StartupTimeline.h"
@ -13157,18 +13158,30 @@ nsDocShell::GetEditor(nsIEditor** aEditor)
return NS_OK;
}
return mEditorData->GetEditor(aEditor);
RefPtr<HTMLEditor> htmlEditor = mEditorData->GetHTMLEditor();
htmlEditor.forget(aEditor);
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetEditor(nsIEditor* aEditor)
{
if (!aEditor && !mEditorData) {
return NS_OK;
}
HTMLEditor* htmlEditor = aEditor ? aEditor->AsHTMLEditor() : nullptr;
// If TextEditor comes, throw an error.
if (aEditor && !htmlEditor) {
return NS_ERROR_INVALID_ARG;
}
nsresult rv = EnsureEditorData();
if (NS_FAILED(rv)) {
return rv;
}
return mEditorData->SetEditor(aEditor);
return mEditorData->SetHTMLEditor(htmlEditor);
}
NS_IMETHODIMP

Просмотреть файл

@ -13,12 +13,14 @@
#include "nsIEditingSession.h"
#include "nsIDocShell.h"
using namespace mozilla;
nsDocShellEditorData::nsDocShellEditorData(nsIDocShell* aOwningDocShell)
: mDocShell(aOwningDocShell)
, mDetachedEditingState(nsIHTMLDocument::eOff)
, mMakeEditable(false)
, mIsDetached(false)
, mDetachedMakeEditable(false)
, mDetachedEditingState(nsIHTMLDocument::eOff)
{
NS_ASSERTION(mDocShell, "Where is my docShell?");
}
@ -31,9 +33,9 @@ nsDocShellEditorData::~nsDocShellEditorData()
void
nsDocShellEditorData::TearDownEditor()
{
if (mEditor) {
mEditor->PreDestroy(false);
mEditor = nullptr;
if (mHTMLEditor) {
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor.forget();
htmlEditor->PreDestroy(false);
}
mEditingSession = nullptr;
mIsDetached = false;
@ -48,11 +50,11 @@ nsDocShellEditorData::MakeEditable(bool aInWaitForUriLoad)
// if we are already editable, and are getting turned off,
// nuke the editor.
if (mEditor) {
if (mHTMLEditor) {
NS_WARNING("Destroying existing editor on frame");
mEditor->PreDestroy(false);
mEditor = nullptr;
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor.forget();
htmlEditor->PreDestroy(false);
}
if (aInWaitForUriLoad) {
@ -64,7 +66,7 @@ nsDocShellEditorData::MakeEditable(bool aInWaitForUriLoad)
bool
nsDocShellEditorData::GetEditable()
{
return mMakeEditable || (mEditor != nullptr);
return mMakeEditable || (mHTMLEditor != nullptr);
}
nsresult
@ -98,29 +100,25 @@ nsDocShellEditorData::GetEditingSession(nsIEditingSession** aResult)
}
nsresult
nsDocShellEditorData::GetEditor(nsIEditor** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
NS_IF_ADDREF(*aResult = mEditor);
return NS_OK;
}
nsresult
nsDocShellEditorData::SetEditor(nsIEditor* aEditor)
nsDocShellEditorData::SetHTMLEditor(HTMLEditor* aHTMLEditor)
{
// destroy any editor that we have. Checks for equality are
// necessary to ensure that assigment into the nsCOMPtr does
// not temporarily reduce the refCount of the editor to zero
if (mEditor.get() != aEditor) {
if (mEditor) {
mEditor->PreDestroy(false);
mEditor = nullptr;
}
if (mHTMLEditor == aHTMLEditor) {
return NS_OK;
}
mEditor = aEditor; // owning addref
if (!mEditor) {
mMakeEditable = false;
}
if (mHTMLEditor) {
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor.forget();
htmlEditor->PreDestroy(false);
MOZ_ASSERT(!mHTMLEditor,
"Nested call of nsDocShellEditorData::SetHTMLEditor() detected");
}
mHTMLEditor = aHTMLEditor; // owning addref
if (!mHTMLEditor) {
mMakeEditable = false;
}
return NS_OK;

Просмотреть файл

@ -10,11 +10,12 @@
#include "nsCOMPtr.h"
#endif
#include "mozilla/HTMLEditor.h"
#include "mozilla/RefPtr.h"
#include "nsIHTMLDocument.h"
class nsIDocShell;
class nsIEditingSession;
class nsIEditor;
class nsDocShellEditorData
{
@ -26,8 +27,11 @@ public:
bool GetEditable();
nsresult CreateEditor();
nsresult GetEditingSession(nsIEditingSession** aResult);
nsresult GetEditor(nsIEditor** aResult);
nsresult SetEditor(nsIEditor* aEditor);
mozilla::HTMLEditor* GetHTMLEditor() const
{
return mHTMLEditor;
}
nsresult SetHTMLEditor(mozilla::HTMLEditor* aHTMLEditor);
void TearDownEditor();
nsresult DetachFromWindow();
nsresult ReattachToWindow(nsIDocShell* aDocShell);
@ -42,22 +46,22 @@ protected:
// Only present for the content root docShell. Session is owned here.
nsCOMPtr<nsIEditingSession> mEditingSession;
// If this frame is editable, store HTML editor here. It's owned here.
RefPtr<mozilla::HTMLEditor> mHTMLEditor;
// Backup for the corresponding nsIHTMLDocument's editing state while
// the editor is detached.
nsIHTMLDocument::EditingState mDetachedEditingState;
// Indicates whether to make an editor after a url load.
bool mMakeEditable;
// If this frame is editable, store editor here. Editor is owned here.
nsCOMPtr<nsIEditor> mEditor;
// Denotes if the editor is detached from its window. The editor is detached
// while it's stored in the session history bfcache.
bool mIsDetached;
// Backup for mMakeEditable while the editor is detached.
bool mDetachedMakeEditable;
// Backup for the corresponding nsIHTMLDocument's editing state while
// the editor is detached.
nsIHTMLDocument::EditingState mDetachedEditingState;
};
#endif // nsDocShellEditorData_h__