Bug 1460509 - part 83: Make HTMLEditRules::InsertBRIfNeeded() 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 12:41:53 +0900
changeset 798801 6bb7d22f611594454450aab5317d4fcba1383705
parent 798800 6c46689d352d82ceeb6ce3f08a2685d8dab7992a
child 798802 7139ea7fac9d4bae7e8342e51cb7490855aa9a77
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 83: Make HTMLEditRules::InsertBRIfNeeded() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: Kuga8LvWfaM
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -3340,23 +3340,16 @@ HTMLEditRules::DeleteNodeIfCollapsedText
     return NS_ERROR_EDITOR_DESTROYED;
   }
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
-/**
- * InsertBRIfNeeded() determines if a br is needed for current selection to not
- * be spastic.  If so, it inserts one.  Callers responsibility to only call
- * with collapsed selection.
- *
- * @param aSelection        The collapsed selection.
- */
 nsresult
 HTMLEditRules::InsertBRIfNeeded()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   EditorRawDOMPoint atStartOfSelection(
                       EditorBase::GetStartPoint(&SelectionRef()));
   if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
@@ -3376,16 +3369,19 @@ HTMLEditRules::InsertBRIfNeeded()
     // if we are tucked between block boundaries then insert a br
     // first check that we are allowed to
     if (HTMLEditorRef().CanContainTag(*atStartOfSelection.GetContainer(),
                                       *nsGkAtoms::br)) {
       RefPtr<Element> brElement =
         HTMLEditorRef().InsertBrElementWithTransaction(SelectionRef(),
                                                        atStartOfSelection,
                                                        nsIEditor::ePrevious);
+      if (NS_WARN_IF(!CanHandleEditAction())) {
+        return NS_ERROR_EDITOR_DESTROYED;
+      }
       if (NS_WARN_IF(!brElement)) {
         return NS_ERROR_FAILURE;
       }
       return NS_OK;
     }
   }
   return NS_OK;
 }
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -254,17 +254,22 @@ protected:
 
   /**
    * Called after deleting selected content.
    * This method removes unnecessary empty nodes and/or inserts <br> if
    * necessary.
    */
   MOZ_MUST_USE nsresult DidDeleteSelection();
 
-  nsresult InsertBRIfNeeded();
+  /**
+   * InsertBRIfNeeded() determines if a br is needed for current selection to
+   * not be spastic.  If so, it inserts one.  Callers responsibility to only
+   * call with collapsed selection.
+   */
+  MOZ_MUST_USE nsresult InsertBRIfNeeded();
 
   /**
    * CanContainParagraph() returns true if aElement can have a <p> element as
    * its child or its descendant.
    */
   bool CanContainParagraph(Element& aElement) const;
 
   /**