Bug 1460509 - part 34: Make HTMLEditRules::MaybeSplitAncestorsForInsertWithTransaction() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 14 May 2018 23:55:53 +0900
changeset 798752 cf57752d514063481155c116e01d856a4cd1b63f
parent 798751 ab036ff607ee93a005f7d9e0ca8421a7a76c1dc3
child 798753 f94116dd9e963c971e6b9bc9027188fa4646f6d6
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 34: Make HTMLEditRules::MaybeSplitAncestorsForInsertWithTransaction() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: 7MqtKPNAOZ1
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -8380,16 +8380,19 @@ HTMLEditRules::MaybeSplitAncestorsForIns
     return SplitNodeResult(aStartOfDeepestRightNode);
   }
 
   SplitNodeResult splitNodeResult =
     HTMLEditorRef().SplitNodeDeepWithTransaction(
                       *pointToInsert.GetChild(),
                       aStartOfDeepestRightNode,
                       SplitAtEdges::eAllowToCreateEmptyContainer);
+  if (NS_WARN_IF(!CanHandleEditAction())) {
+    return SplitNodeResult(NS_ERROR_EDITOR_DESTROYED);
+  }
   NS_WARNING_ASSERTION(splitNodeResult.Succeeded(),
     "Failed to split the node for insert the element");
   return splitNodeResult;
 }
 
 nsresult
 HTMLEditRules::JoinNearestEditableNodesWithTransaction(
                  nsIContent& aNodeLeft,
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -523,19 +523,19 @@ protected:
    *                                    after calling this method.
    * @param aStartOfDeepestRightNode    The start point of deepest right node.
    *                                    This point must be descendant of
    *                                    active editing host.
    * @return                            When succeeded, SplitPoint() returns
    *                                    the point to insert the element.
    */
   template<typename PT, typename CT>
-  SplitNodeResult MaybeSplitAncestorsForInsertWithTransaction(
-                    nsAtom& aTag,
-                    const EditorDOMPointBase<PT, CT>& aStartOfDeepestRightNode);
+  MOZ_MUST_USE SplitNodeResult
+  MaybeSplitAncestorsForInsertWithTransaction(
+    nsAtom& aTag, const EditorDOMPointBase<PT, CT>& aStartOfDeepestRightNode);
 
   /**
    * JoinNearestEditableNodesWithTransaction() joins two editable nodes which
    * are themselves or the nearest editable node of aLeftNode and aRightNode.
    * XXX This method's behavior is odd.  For example, if user types Backspace
    *     key at the second editable paragraph in this case:
    *     <div contenteditable>
    *       <p>first editable paragraph</p>