Bug 1460509 - part 51: Make HTMLEditRules::WillInsertBreak() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 16 May 2018 13:49:56 +0900
changeset 798769 1a7f408752c5f201df8759648d8ea8bd2a63b743
parent 798768 4b8964cc9f1759bbdff80dda48bfde1817697c33
child 798770 916a369f60b3f0230cc18fcb11915bc52f9af9d3
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 51: Make HTMLEditRules::WillInsertBreak() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: 2oTOmT4HSv7
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -1768,16 +1768,19 @@ HTMLEditRules::WillInsertBreak(bool* aCa
   *aCancel = false;
   *aHandled = false;
 
   // If the selection isn't collapsed, delete it.
   if (!SelectionRef().IsCollapsed()) {
     nsresult rv =
       HTMLEditorRef().DeleteSelectionAsAction(nsIEditor::eNone,
                                               nsIEditor::eStrip);
+    if (NS_WARN_IF(!CanHandleEditAction())) {
+      return NS_ERROR_EDITOR_DESTROYED;
+    }
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   WillInsert(aCancel);
 
   // Initialize out param.  We want to ignore result of WillInsert().
@@ -1921,16 +1924,19 @@ HTMLEditRules::WillInsertBreak(bool* aCa
   // make block have a line.  Then code further below will put in a second br.)
   if (IsEmptyBlockElement(*blockParent, IgnoreSingleBR::eNo)) {
     AutoEditorDOMPointChildInvalidator lockOffset(atStartOfSelection);
     EditorRawDOMPoint endOfBlockParent;
     endOfBlockParent.SetToEndOf(blockParent);
     RefPtr<Element> brElement =
       HTMLEditorRef().InsertBrElementWithTransaction(SelectionRef(),
                                                      endOfBlockParent);
+    if (NS_WARN_IF(!CanHandleEditAction())) {
+      return NS_ERROR_EDITOR_DESTROYED;
+    }
     if (NS_WARN_IF(!brElement)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   nsCOMPtr<Element> listItem = IsInListItem(blockParent);
   if (listItem && listItem != host) {
     nsresult rv =
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -153,16 +153,25 @@ protected:
   void WillInsert(bool* aCancel);
   nsresult WillInsertText(EditAction aAction,
                           bool* aCancel,
                           bool* aHandled,
                           const nsAString* inString,
                           nsAString* outString,
                           int32_t aMaxLength);
   nsresult WillLoadHTML(bool* aCancel);
+
+  /**
+   * WillInsertBreak() is called when insertParagraph command is executed
+   * or something equivalent.  This method actually tries to insert new
+   * paragraph or <br> element, etc.
+   *
+   * @param aCancel             Returns true if target node is not editable.
+   * @param aHandled            Returns true if actually insert new break.
+   */
   nsresult WillInsertBreak(bool* aCancel, bool* aHandled);
 
   void DeleteNodeIfCollapsedText(nsINode& aNode);
 
   /**
    * InsertBRElement() inserts a <br> element into aInsertToBreak.
    *
    * @param aInsertToBreak      The point where new <br> element will be