Bug 1460509 - part 31: Make HTMLEditRules::GetInlineStyles() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 14 May 2018 23:20:28 +0900
changeset 798749 2883b6d37cc69778dd9ba3190fd28bebb1048766
parent 798748 05a4ba8cb0b3ef67deb6de66bdc764f31e42b993
child 798750 4e5baa212eb0faf7e14d1e5bbd7bdb556065cebb
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 31: Make HTMLEditRules::GetInlineStyles() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: 3Nk1gBttuwM
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -8511,16 +8511,19 @@ HTMLEditRules::GetInlineStyles(nsINode* 
       isSet =
         HTMLEditorRef().IsTextPropertySetByContent(aNode, aStyleCache[j].tag,
                                                    aStyleCache[j].attr,
                                                    nullptr, &outValue);
     } else {
       isSet = CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(
                 aNode, aStyleCache[j].tag, aStyleCache[j].attr, outValue,
                 CSSEditUtils::eComputed);
+      if (NS_WARN_IF(!CanHandleEditAction())) {
+        return NS_ERROR_EDITOR_DESTROYED;
+      }
     }
     if (isSet) {
       aStyleCache[j].mPresent = true;
       aStyleCache[j].value.Assign(outValue);
     }
   }
   return NS_OK;
 }
@@ -8551,17 +8554,17 @@ HTMLEditRules::ReapplyCachedStyles()
     // Nothing to do
     return NS_OK;
   }
 
   StyleCache styleAtInsertionPoint[SIZE_STYLE_TABLE];
   InitStyleCacheArray(styleAtInsertionPoint);
   nsresult rv = GetInlineStyles(selNode, styleAtInsertionPoint);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return NS_OK;
+    return rv == NS_ERROR_EDITOR_DESTROYED ? NS_ERROR_EDITOR_DESTROYED : NS_OK;
   }
 
   for (size_t i = 0; i < SIZE_STYLE_TABLE; ++i) {
     if (mCachedStyles[i].mPresent) {
       bool bFirst, bAny, bAll;
       bFirst = bAny = bAll = false;
 
       nsAutoString curValue;
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -773,20 +773,21 @@ protected:
   /**
    * InitStyleCacheArray() initializes aStyleCache for usable with
    * GetInlineStyles().
    */
   void InitStyleCacheArray(StyleCache aStyleCache[SIZE_STYLE_TABLE]);
 
   /**
    * GetInlineStyles() retrieves the style of aNode and modifies each item of
-   * aStyleCache.
+   * aStyleCache.  This might cause flushing layout at retrieving computed
+   * values of CSS properties.
    */
-  nsresult GetInlineStyles(nsINode* aNode,
-                           StyleCache aStyleCache[SIZE_STYLE_TABLE]);
+  MOZ_MUST_USE nsresult
+  GetInlineStyles(nsINode* aNode, StyleCache aStyleCache[SIZE_STYLE_TABLE]);
 
 protected:
   HTMLEditor* mHTMLEditor;
   RefPtr<nsRange> mDocChangeRange;
   bool mListenerEnabled;
   bool mReturnInEmptyLIKillsList;
   bool mDidDeleteSelection;
   bool mDidRangedDelete;