Bug 1460509 - part 6: Make TextEditRules::RemoveRedundantTrailingBR() 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 16:36:07 +0900
changeset 798724 456816b935ea0e2bc8052cdeaba65d2186928248
parent 798723 284b619f2e968cb81ccd55b941a5d85bd63c3f48
child 798725 848da409dcf41cd4c3e4299565b6a4a07f44a5ed
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 6: Make TextEditRules::RemoveRedundantTrailingBR() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: HpFo0SiTBWJ
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditRules.h
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -1352,16 +1352,19 @@ TextEditRules::RemoveRedundantTrailingBR
   RefPtr<Element> childElement = child->AsElement();
   if (!TextEditUtils::IsMozBR(childElement)) {
     return NS_OK;
   }
 
   // Rather than deleting this node from the DOM tree we should instead
   // morph this br into the bogus node
   childElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::type, true);
+  if (NS_WARN_IF(!CanHandleEditAction())) {
+    return NS_ERROR_EDITOR_DESTROYED;
+  }
 
   // set mBogusNode to be this <br>
   mBogusNode = childElement;
 
   // give it the bogus node attribute
   childElement->SetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom,
                         kMOZEditorBogusNodeValue, false);
   return NS_OK;
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -174,17 +174,17 @@ protected:
                           nsAString* aOutText,
                           uint32_t aFlags,
                           bool* aOutCancel,
                           bool* aHandled);
 
   /**
    * Check for and replace a redundant trailing break.
    */
-  nsresult RemoveRedundantTrailingBR();
+  MOZ_MUST_USE nsresult RemoveRedundantTrailingBR();
 
   /**
    * Creates a trailing break in the text doc if there is not one already.
    */
   MOZ_MUST_USE nsresult CreateTrailingBRIfNeeded();
 
   /**
    * Creates a bogus <br> node if the root element has no editable content.