Bug 1460509 - part 52: Make HTMLEditRules::LoadHTML() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: IKjTmm738Yg
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -687,17 +687,17 @@ HTMLEditRules::WillDoAction(Selection* a
switch (aInfo->action) {
case EditAction::insertText:
case EditAction::insertIMEText:
UndefineCaretBidiLevel();
return WillInsertText(aInfo->action, aCancel, aHandled,
aInfo->inString, aInfo->outString,
aInfo->maxLength);
case EditAction::loadHTML:
- return WillLoadHTML(aCancel);
+ return WillLoadHTML();
case EditAction::insertBreak:
UndefineCaretBidiLevel();
return WillInsertBreak(aCancel, aHandled);
case EditAction::deleteSelection:
return WillDeleteSelection(aInfo->collapsedAction, aInfo->stripWrappers,
aCancel, aHandled);
case EditAction::makeList:
return WillMakeList(aInfo->blockType, aInfo->entireList,
@@ -1702,32 +1702,29 @@ HTMLEditRules::WillInsertText(EditAction
rv = mDocChangeRange->CollapseTo(pointToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
-HTMLEditRules::WillLoadHTML(bool* aCancel)
+HTMLEditRules::WillLoadHTML()
{
MOZ_ASSERT(IsEditorDataAvailable());
- if (NS_WARN_IF(!aCancel)) {
- return NS_ERROR_INVALID_ARG;
- }
-
- *aCancel = false;
-
// Delete mBogusNode if it exists. If we really need one,
// it will be added during post-processing in AfterEditInner().
if (mBogusNode) {
DebugOnly<nsresult> rv =
HTMLEditorRef().DeleteNodeWithTransaction(*mBogusNode);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"Failed to remove the bogus node");
mBogusNode = nullptr;
}
return NS_OK;
}
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -152,17 +152,22 @@ protected:
void WillInsert(bool* aCancel);
nsresult WillInsertText(EditAction aAction,
bool* aCancel,
bool* aHandled,
const nsAString* inString,
nsAString* outString,
int32_t aMaxLength);
- nsresult WillLoadHTML(bool* aCancel);
+
+ /**
+ * WillLoadHTML() is called before loading enter document from source.
+ * This removes bogus node if there is.
+ */
+ MOZ_MUST_USE nsresult WillLoadHTML();
/**
* WillInsertBreak() is called when insertParagraph command is executed
* or something equivalent. This method actually tries to insert new
* paragraph or <br> element, etc.
*
* @param aCancel Returns true if target node is not editable.
* @param aHandled Returns true if actually insert new break.