Bug 1460509 - part 40: Make HTMLEditRules::ReturnInParagraph() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: cnR8uXTfno
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -7610,16 +7610,20 @@ HTMLEditRules::ReturnInParagraph(Element
brContent = nullptr;
}
} else {
if (doesCRCreateNewP) {
ErrorResult error;
nsCOMPtr<nsIContent> newLeftDivOrP =
HTMLEditorRef().SplitNodeWithTransaction(pointToSplitParentDivOrP,
error);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ error.SuppressException();
+ return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
+ }
if (NS_WARN_IF(error.Failed())) {
return EditActionResult(error.StealNSResult());
}
pointToSplitParentDivOrP.SetToEndOf(newLeftDivOrP);
}
// We need to put new <br> after the left node if given node was split
// above.
@@ -7643,29 +7647,27 @@ HTMLEditRules::ReturnInParagraph(Element
splitAfterNewBR = true;
}
}
if (!pointToInsertBR.IsSet() && TextEditUtils::IsBreak(nearNode)) {
brContent = nearNode;
}
}
if (pointToInsertBR.IsSet()) {
- // Don't modify the DOM tree if HTMLEditor is destroyed.
- if (NS_WARN_IF(HTMLEditorRef().Destroyed())) {
- return EditActionResult(NS_ERROR_NOT_AVAILABLE);
- }
-
// if CR does not create a new P, default to BR creation
if (NS_WARN_IF(!doesCRCreateNewP)) {
return EditActionResult(NS_OK);
}
brContent =
HTMLEditorRef().InsertBrElementWithTransaction(SelectionRef(),
pointToInsertBR);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
+ }
NS_WARNING_ASSERTION(brContent, "Failed to create a <br> element");
if (splitAfterNewBR) {
// We split the parent after the br we've just inserted.
pointToSplitParentDivOrP.Set(brContent);
DebugOnly<bool> advanced = pointToSplitParentDivOrP.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset after the new <br>");
}
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -377,17 +377,17 @@ protected:
* split at start of first selection range.
*
* @param aParentDivOrP The parent block. This must be <p> or <div>
* element.
* @return Returns with NS_OK if this doesn't meat any
* unexpected situation. If this method tries to
* split the paragraph, marked as handled.
*/
- EditActionResult ReturnInParagraph(Element& aParentDivOrP);
+ MOZ_MUST_USE EditActionResult ReturnInParagraph(Element& aParentDivOrP);
/**
* SplitParagraph() splits the parent block, aPara, at aSelNode - aOffset.
*
* @param aParentDivOrP The parent block to be split. This must be <p>
* or <div> element.
* @param aStartOfRightNode The point to be start of right node after
* split. This must be descendant of