Bug 1460509 - part 78: Make HTMLEditRules::MoveBlock() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 18 May 2018 00:08:58 +0900
changeset 798796 f5c3002d1913b0adb7bffccae797e61a0a3d8b2f
parent 798795 97f28b39d4d325c7f74c0a1f24118e9a65fa4e87
child 798797 08075e6ebd789de21355f55131c6cb186e28719b
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 78: Make HTMLEditRules::MoveBlock() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: 7RKXiYaH2l0
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -3478,16 +3478,21 @@ HTMLEditRules::TryToJoinBlocksWithTransa
       // XXX Although, we don't do nothing here, but for keeping traditional
       //     behavior, we should mark as handled.
       ret.MarkAsHandled();
     } else {
       // XXX Why do we ignore the result of MoveBlock()?
       EditActionResult retMoveBlock =
         MoveBlock(*leftBlock, *rightBlock,
                   -1, atRightBlockChild.Offset());
+      if (NS_WARN_IF(retMoveBlock.Rv() == NS_ERROR_EDITOR_DESTROYED)) {
+        return ret;
+      }
+      NS_WARNING_ASSERTION(retMoveBlock.Succeeded(),
+        "Failed to move contents of the right block to the left block");
       if (retMoveBlock.Handled()) {
         ret.MarkAsHandled();
       }
       // Now, all children of rightBlock were moved to leftBlock.  So,
       // atRightBlockChild is now invalid.
       atRightBlockChild.Clear();
     }
     if (brNode &&
@@ -3701,16 +3706,19 @@ HTMLEditRules::MoveBlock(Element& aLeftB
     if (IsBlockNode(arrayOfNodes[i])) {
       // For block nodes, move their contents only, then delete block.
       ret |=
         MoveContents(*arrayOfNodes[i]->AsElement(), aLeftBlock, &aLeftOffset);
       if (NS_WARN_IF(ret.Failed())) {
         return ret;
       }
       rv = HTMLEditorRef().DeleteNodeWithTransaction(*arrayOfNodes[i]);
+      if (NS_WARN_IF(!CanHandleEditAction())) {
+        return ret.SetResult(NS_ERROR_EDITOR_DESTROYED);
+      }
       NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
         "Failed to remove a block node");
       ret.MarkAsHandled();
     } else {
       // Otherwise move the content as is, checking against the DTD.
       ret |=
         MoveNodeSmart(*arrayOfNodes[i]->AsContent(), aLeftBlock, &aLeftOffset);
       if (NS_WARN_IF(ret.Rv() == NS_ERROR_EDITOR_DESTROYED)) {
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -294,18 +294,19 @@ protected:
    * MoveBlock() moves the content from aRightBlock starting from aRightOffset
    * into aLeftBlock at aLeftOffset. Note that the "block" can be inline nodes
    * between <br>s, or between blocks, etc.  DTD containment rules are followed
    * throughout.
    *
    * @return            Sets handled to true if this actually joins the nodes.
    *                    canceled is always false.
    */
-  EditActionResult MoveBlock(Element& aLeftBlock, Element& aRightBlock,
-                             int32_t aLeftOffset, int32_t aRightOffset);
+  MOZ_MUST_USE EditActionResult
+  MoveBlock(Element& aLeftBlock, Element& aRightBlock,
+            int32_t aLeftOffset, int32_t aRightOffset);
 
   /**
    * MoveNodeSmart() moves aNode to (aDestElement, aInOutDestOffset).
    * DTD containment rules are followed throughout.
    *
    * @param aOffset                 returns the point after inserted content.
    * @return                        Sets true to handled if this actually moves
    *                                the nodes.