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 796824 33fd00f9fa4b65703a6cfa11ca6721c5ea8c7ef4
parent 796823 46b44c0d0fb145692b7429b09341ce8373266345
child 796825 3f48ab31b2246eb7fb85fee7c4bd43e1a5b40a6b
push id110360
push usermasayuki@d-toybox.com
push dateFri, 18 May 2018 10:24:57 +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.