Bug 1460509 - part 37: Make HTMLEditRules::MakeBlockquote() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: 3pUx52d6EYd
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -7971,45 +7971,46 @@ HTMLEditRules::ReturnInListItem(Element&
ErrorResult error;
SelectionRef().Collapse(EditorRawDOMPoint(&aListItem, 0), error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
return NS_OK;
}
-/**
- * MakeBlockquote() puts the list of nodes into one or more blockquotes.
- */
nsresult
HTMLEditRules::MakeBlockquote(nsTArray<OwningNonNull<nsINode>>& aNodeArray)
{
MOZ_ASSERT(IsEditorDataAvailable());
// The idea here is to put the nodes into a minimal number of blockquotes.
// When the user blockquotes something, they expect one blockquote. That may
// not be possible (for instance, if they have two table cells selected, you
// need two blockquotes inside the cells).
- nsCOMPtr<Element> curBlock;
+ RefPtr<Element> curBlock;
nsCOMPtr<nsINode> prevParent;
for (auto& curNode : aNodeArray) {
// Get the node to act on, and its location
- NS_ENSURE_STATE(curNode->IsContent());
+ if (NS_WARN_IF(!curNode->IsContent())) {
+ return NS_ERROR_FAILURE;
+ }
// If the node is a table element or list item, dive inside
if (HTMLEditUtils::IsTableElementButNotTable(curNode) ||
HTMLEditUtils::IsListItem(curNode)) {
// Forget any previous block
curBlock = nullptr;
// Recursion time
nsTArray<OwningNonNull<nsINode>> childArray;
GetChildNodesForOperation(*curNode, childArray);
nsresult rv = MakeBlockquote(childArray);
- NS_ENSURE_SUCCESS(rv, rv);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
}
// If the node has different parent than previous node, further nodes in a
// new parent
if (prevParent) {
if (prevParent != curNode->GetParentNode()) {
// Forget any previous blockquote node we were using
curBlock = nullptr;
@@ -8026,27 +8027,33 @@ HTMLEditRules::MakeBlockquote(nsTArray<O
MaybeSplitAncestorsForInsertWithTransaction(*nsGkAtoms::blockquote,
atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
curBlock =
HTMLEditorRef().CreateNodeWithTransaction(*nsGkAtoms::blockquote,
splitNodeResult.SplitPoint());
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(!curBlock)) {
return NS_ERROR_FAILURE;
}
// remember our new block for postprocessing
mNewBlock = curBlock;
// note: doesn't matter if we set mNewBlock multiple times.
}
nsresult rv =
HTMLEditorRef().MoveNodeToEndWithTransaction(*curNode->AsContent(),
*curBlock);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
return NS_OK;
}
nsresult
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -513,17 +513,27 @@ protected:
*
* @param aNodeArray Must be descendants of a node.
* @param aBlockTag The element name of new block elements.
*/
MOZ_MUST_USE nsresult
ApplyBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
nsAtom& aBlockTag);
- nsresult MakeBlockquote(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
+ /**
+ * MakeBlockquote() inserts at least one <blockquote> element and moves
+ * nodes in aNodeArray into new <blockquote> elements. If aNodeArray
+ * includes a table related element except <table>, this calls itself
+ * recursively to insert <blockquote> into the cell.
+ *
+ * @param aNodeArray Nodes which will be moved into created
+ * <blockquote> elements.
+ */
+ MOZ_MUST_USE nsresult
+ MakeBlockquote(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
/**
* MaybeSplitAncestorsForInsertWithTransaction() does nothing if container of
* aStartOfDeepestRightNode can have an element whose tag name is aTag.
* Otherwise, looks for an ancestor node which is or is in active editing
* host and can have an element whose name is aTag. If there is such
* ancestor, its descendants are split.
*