Bug 1460509 - part 40: Make HTMLEditRules::ReturnInParagraph() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 15 May 2018 16:22:59 +0900
changeset 798758 b9ab6125007ace745d804062c150d8a001567960
parent 798757 86b9a8f9acfab8ef16f9e6c6463c3a73bc030b4d
child 798759 188287c29177ed4e25ea5a5cd02348ff85941172
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
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
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- 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