Bug 1460509 - part 52: Make HTMLEditRules::LoadHTML() 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:56:33 +0900
changeset 798770 916a369f60b3f0230cc18fcb11915bc52f9af9d3
parent 798769 1a7f408752c5f201df8759648d8ea8bd2a63b743
child 798771 9c4903ab97c67f78c72047867a80401357646840
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 52: Make HTMLEditRules::LoadHTML() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: IKjTmm738Yg
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -687,17 +687,17 @@ HTMLEditRules::WillDoAction(Selection* a
   switch (aInfo->action) {
     case EditAction::insertText:
     case EditAction::insertIMEText:
       UndefineCaretBidiLevel();
       return WillInsertText(aInfo->action, aCancel, aHandled,
                             aInfo->inString, aInfo->outString,
                             aInfo->maxLength);
     case EditAction::loadHTML:
-      return WillLoadHTML(aCancel);
+      return WillLoadHTML();
     case EditAction::insertBreak:
       UndefineCaretBidiLevel();
       return WillInsertBreak(aCancel, aHandled);
     case EditAction::deleteSelection:
       return WillDeleteSelection(aInfo->collapsedAction, aInfo->stripWrappers,
                                  aCancel, aHandled);
     case EditAction::makeList:
       return WillMakeList(aInfo->blockType, aInfo->entireList,
@@ -1702,32 +1702,29 @@ HTMLEditRules::WillInsertText(EditAction
   rv = mDocChangeRange->CollapseTo(pointToInsert);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::WillLoadHTML(bool* aCancel)
+HTMLEditRules::WillLoadHTML()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (NS_WARN_IF(!aCancel)) {
-    return NS_ERROR_INVALID_ARG;
-  }
-
-  *aCancel = false;
-
   // Delete mBogusNode if it exists. If we really need one,
   // it will be added during post-processing in AfterEditInner().
 
   if (mBogusNode) {
     DebugOnly<nsresult> rv =
       HTMLEditorRef().DeleteNodeWithTransaction(*mBogusNode);
+    if (NS_WARN_IF(!CanHandleEditAction())) {
+      return NS_ERROR_EDITOR_DESTROYED;
+    }
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
       "Failed to remove the bogus node");
     mBogusNode = nullptr;
   }
 
   return NS_OK;
 }
 
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -152,17 +152,22 @@ 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);
+
+  /**
+   * WillLoadHTML() is called before loading enter document from source.
+   * This removes bogus node if there is.
+   */
+  MOZ_MUST_USE nsresult WillLoadHTML();
 
   /**
    * 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.