Bug 1460509 - part 16: Make HTMLEditRules::DidAbsolutePosition() 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 19:39:26 +0900
changeset 798734 f0d8798b6529323b8a7837f135715823de4d7b52
parent 798733 b5fa0e2d42cb8d904b483d27b74088e97a2e6aa5
child 798735 f38656bd5025dc67547854c02553c9e5aa57432a
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 16: Make HTMLEditRules::DidAbsolutePosition() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: BBAvHn08og4
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -10198,16 +10198,19 @@ nsresult
 HTMLEditRules::DidAbsolutePosition()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   if (!mNewBlock) {
     return NS_OK;
   }
   nsresult rv = HTMLEditorRef().SetPositionToAbsoluteOrStatic(*mNewBlock, true);
+  if (NS_WARN_IF(!CanHandleEditAction())) {
+    return NS_ERROR_EDITOR_DESTROYED;
+  }
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::WillRemoveAbsolutePosition(bool* aCancel,
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -286,17 +286,26 @@ protected:
   WillRelativeChangeZIndex(int32_t aChange, bool* aCancel, bool* aHandled);
 
   nsresult WillMakeDefListItem(const nsAString* aBlockType, bool aEntireList,
                                bool* aCancel, bool* aHandled);
   nsresult WillMakeBasicBlock(const nsAString& aBlockType,
                               bool* aCancel, bool* aHandled);
   nsresult MakeBasicBlock(nsAtom& aBlockType);
   nsresult DidMakeBasicBlock(RulesInfo* aInfo, nsresult aResult);
-  nsresult DidAbsolutePosition();
+
+  /**
+   * Called if nobody handles the edit action to make an element absolute
+   * positioned.
+   * This method actually changes the element which is computed by
+   * WillAbsolutePosition() to absolute positioned.
+   * Therefore, this might cause destroying the HTML editor.
+   */
+  MOZ_MUST_USE nsresult DidAbsolutePosition();
+
   nsresult AlignInnerBlocks(nsINode& aNode, const nsAString& aAlignType);
   nsresult AlignBlockContents(nsINode& aNode, const nsAString& aAlignType);
   nsresult AppendInnerFormatNodes(nsTArray<OwningNonNull<nsINode>>& aArray,
                                   nsINode* aNode);
   nsresult GetFormatString(nsINode* aNode, nsAString &outFormat);
   enum class Lists { no, yes };
   enum class Tables { no, yes };
   void GetInnerContent(nsINode& aNode,