Bug 1460509 - part 12: Make TextEditRules::WillInsertBreak() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 11 May 2018 18:49:44 +0900
changeset 798730 b86c8a4d3ec013edef48ebc5519070ff38a83bd2
parent 798729 e53a1cb59fd67c40304bd568da3d3a7e2569b87f
child 798731 b7fcbfde487a85e09afc57aa786988de6d7b264b
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 12: Make TextEditRules::WillInsertBreak() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: Ia5MJ465Hdf
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditRules.h
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -465,16 +465,19 @@ TextEditRules::WillInsertBreak(bool* aCa
     }
 
     *aCancel = false;
 
     // if the selection isn't collapsed, delete it.
     if (!SelectionRef().IsCollapsed()) {
       rv = TextEditorRef().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()
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -145,17 +145,28 @@ protected:
    * @param aMaxLength          The maximum string length which the editor
    *                            allows to set.
    */
   MOZ_MUST_USE nsresult
   WillInsertText(EditAction aAction, bool* aCancel, bool* aHandled,
                  const nsAString* inString, nsAString* outString,
                  int32_t aMaxLength);
 
-  nsresult WillInsertBreak(bool* aCancel, bool* aHandled, int32_t aMaxLength);
+  /**
+   * Called before inserting a line break into the editor.
+   * This method removes selected text if selection isn't collapsed.
+   * Therefore, this might cause destroying the editor.
+   *
+   * @param aCancel             Returns true if the operation is canceled.
+   * @param aHandled            Returns true if the edit action is handled.
+   * @param aMaxLength          The maximum string length which the editor
+   *                            allows to set.
+   */
+  MOZ_MUST_USE nsresult
+  WillInsertBreak(bool* aCancel, bool* aHandled, int32_t aMaxLength);
 
   /**
    * Called before setting text to the text editor.
    * This method may actually set text to it.  Therefore, this might cause
    * destroying the text editor.
    *
    * @param aCancel             Returns true if the operation is canceled.
    * @param aHandled            Returns true if the edit action is handled.