Bug 1460509 - part 83: Make HTMLEditRules::InsertBRIfNeeded() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: Kuga8LvWfaM
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -3340,23 +3340,16 @@ HTMLEditRules::DeleteNodeIfCollapsedText
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
-/**
- * InsertBRIfNeeded() determines if a br is needed for current selection to not
- * be spastic. If so, it inserts one. Callers responsibility to only call
- * with collapsed selection.
- *
- * @param aSelection The collapsed selection.
- */
nsresult
HTMLEditRules::InsertBRIfNeeded()
{
MOZ_ASSERT(IsEditorDataAvailable());
EditorRawDOMPoint atStartOfSelection(
EditorBase::GetStartPoint(&SelectionRef()));
if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
@@ -3376,16 +3369,19 @@ HTMLEditRules::InsertBRIfNeeded()
// if we are tucked between block boundaries then insert a br
// first check that we are allowed to
if (HTMLEditorRef().CanContainTag(*atStartOfSelection.GetContainer(),
*nsGkAtoms::br)) {
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(SelectionRef(),
atStartOfSelection,
nsIEditor::ePrevious);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
}
return NS_OK;
}
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -254,17 +254,22 @@ protected:
/**
* Called after deleting selected content.
* This method removes unnecessary empty nodes and/or inserts <br> if
* necessary.
*/
MOZ_MUST_USE nsresult DidDeleteSelection();
- nsresult InsertBRIfNeeded();
+ /**
+ * InsertBRIfNeeded() determines if a br is needed for current selection to
+ * not be spastic. If so, it inserts one. Callers responsibility to only
+ * call with collapsed selection.
+ */
+ MOZ_MUST_USE nsresult InsertBRIfNeeded();
/**
* CanContainParagraph() returns true if aElement can have a <p> element as
* its child or its descendant.
*/
bool CanContainParagraph(Element& aElement) const;
/**