Bug 1460509 - part 72: Mark HTMLEditRules::WillRemoveList() as MOZ_MUST_USE since it may return NS_ERROR_EDITOR_DESTROYED r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 17 May 2018 20:27:53 +0900
changeset 798790 84c52ed3b7c0c73944a053dcbe72e89fca525c6b
parent 798789 bb20a0b9d5f005293116c9cb99277637c2127482
child 798791 e98e1f80a80fdfcfd57d56579a8589285c9a5df1
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 72: Mark HTMLEditRules::WillRemoveList() as MOZ_MUST_USE since it may return NS_ERROR_EDITOR_DESTROYED r?m_kato Additionally, it creates AutoSelectionRestorer. So, this patch adds CanHandleEditAction() check after its caller since even if it returns NS_OK, the editor might have been gone. MozReview-Commit-ID: BgIbpHFFPE1
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -715,18 +715,27 @@ HTMLEditRules::WillDoAction(Selection* a
     case EditAction::setAbsolutePosition:
       return WillAbsolutePosition(aCancel, aHandled);
     case EditAction::removeAbsolutePosition:
       return WillRemoveAbsolutePosition(aCancel, aHandled);
     case EditAction::align:
       return WillAlign(*aInfo->alignType, aCancel, aHandled);
     case EditAction::makeBasicBlock:
       return WillMakeBasicBlock(*aInfo->blockType, aCancel, aHandled);
-    case EditAction::removeList:
-      return WillRemoveList(aInfo->bOrdered, aCancel, aHandled);
+    case EditAction::removeList: {
+      nsresult rv = WillRemoveList(aCancel, aHandled);
+      if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED) ||
+          NS_WARN_IF(!CanHandleEditAction())) {
+        return NS_ERROR_EDITOR_DESTROYED;
+      }
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+      return NS_OK;
+    }
     case EditAction::makeDefListItem:
       return WillMakeDefListItem(aInfo->blockType,
                                  aInfo->entireList, aCancel, aHandled);
     case EditAction::insertElement: {
       nsresult rv = WillInsert(aCancel);
       if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
         return NS_ERROR_EDITOR_DESTROYED;
       }
@@ -4228,20 +4237,18 @@ HTMLEditRules::WillMakeList(const nsAStr
         return rv;
       }
     }
   }
 
   return NS_OK;
 }
 
-
 nsresult
-HTMLEditRules::WillRemoveList(bool aOrdered,
-                              bool* aCancel,
+HTMLEditRules::WillRemoveList(bool* aCancel,
                               bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
     return NS_ERROR_INVALID_ARG;
   }
   // initialize out param
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -321,17 +321,26 @@ protected:
                                 int32_t* aInOutDestOffset);
 
   nsresult DeleteNonTableElements(nsINode* aNode);
   nsresult WillMakeList(const nsAString* aListType,
                         bool aEntireList,
                         const nsAString* aBulletType,
                         bool* aCancel, bool* aHandled,
                         const nsAString* aItemType = nullptr);
-  nsresult WillRemoveList(bool aOrdered, bool* aCancel, bool* aHandled);
+
+  /**
+   * Called before removing a list element.  This method actually removes
+   * list elements and list item elements at Selection.  And move contents
+   * in them where the removed list was.
+   *
+   * @param aCancel             Returns true if the operation is canceled.
+   * @param aHandled            Returns true if the edit action is handled.
+   */
+  MOZ_MUST_USE nsresult WillRemoveList(bool* aCancel, bool* aHandled);
 
   /**
    * Called before indenting around Selection.  This method actually tries to
    * indent the contents.
    *
    * @param aCancel             Returns true if the operation is canceled.
    * @param aHandled            Returns true if the edit action is handled.
    */