http/tests/navigation/page-cache-fontfaceset.html is flaky crashing
https://bugs.webkit.org/show_bug.cgi?id=209881
<rdar://problem/61114827>

Reviewed by Darin Adler.

Make sure CSSFontSelector::m_beginLoadingTimer uses a SuspendableTimer instead of a regular
timer so that it cannot fire while in the back/forward cache and start a load.

No new tests, covered by existing test.

* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::CSSFontSelector):
(WebCore::CSSFontSelector::clearDocument):
* css/CSSFontSelector.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@259367 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index ded931a..bbbb217 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,5 +1,23 @@
 2020-04-01  Chris Dumez  <cdumez@apple.com>
 
+        http/tests/navigation/page-cache-fontfaceset.html is flaky crashing
+        https://bugs.webkit.org/show_bug.cgi?id=209881
+        <rdar://problem/61114827>
+
+        Reviewed by Darin Adler.
+
+        Make sure CSSFontSelector::m_beginLoadingTimer uses a SuspendableTimer instead of a regular
+        timer so that it cannot fire while in the back/forward cache and start a load.
+
+        No new tests, covered by existing test.
+
+        * css/CSSFontSelector.cpp:
+        (WebCore::CSSFontSelector::CSSFontSelector):
+        (WebCore::CSSFontSelector::clearDocument):
+        * css/CSSFontSelector.h:
+
+2020-04-01  Chris Dumez  <cdumez@apple.com>
+
         ASSERTION FAILED: m_wrapper on webgl/max-active-contexts-webglcontextlost-prevent-default.html
         https://bugs.webkit.org/show_bug.cgi?id=209863
         <rdar://problem/61164936>
diff --git a/Source/WebCore/css/CSSFontSelector.cpp b/Source/WebCore/css/CSSFontSelector.cpp
index 2d48721..6726c7b 100644
--- a/Source/WebCore/css/CSSFontSelector.cpp
+++ b/Source/WebCore/css/CSSFontSelector.cpp
@@ -64,7 +64,7 @@
 CSSFontSelector::CSSFontSelector(Document& document)
     : m_document(makeWeakPtr(document))
     , m_cssFontFaceSet(CSSFontFaceSet::create(this))
-    , m_beginLoadingTimer(*this, &CSSFontSelector::beginLoadTimerFired)
+    , m_beginLoadingTimer(&document, *this, &CSSFontSelector::beginLoadTimerFired)
     , m_uniqueId(++fontSelectorId)
     , m_version(0)
 {
@@ -72,6 +72,8 @@
     FontCache::singleton().addClient(*this);
     m_cssFontFaceSet->addClient(*this);
     LOG(Fonts, "CSSFontSelector %p ctor", this);
+
+    m_beginLoadingTimer.suspendIfNeeded();
 }
 
 CSSFontSelector::~CSSFontSelector()
@@ -336,7 +338,7 @@
         return;
     }
 
-    m_beginLoadingTimer.stop();
+    m_beginLoadingTimer.cancel();
 
     CachedResourceLoader& cachedResourceLoader = m_document->cachedResourceLoader();
     for (auto& fontHandle : m_fontsToBeginLoading) {
diff --git a/Source/WebCore/css/CSSFontSelector.h b/Source/WebCore/css/CSSFontSelector.h
index e70b8cb..3eaa68e 100644
--- a/Source/WebCore/css/CSSFontSelector.h
+++ b/Source/WebCore/css/CSSFontSelector.h
@@ -30,7 +30,7 @@
 #include "CachedResourceHandle.h"
 #include "Font.h"
 #include "FontSelector.h"
-#include "Timer.h"
+#include "SuspendableTimer.h"
 #include <memory>
 #include <wtf/Forward.h>
 #include <wtf/HashSet.h>
@@ -112,7 +112,7 @@
     Vector<CachedResourceHandle<CachedFont>> m_fontsToBeginLoading;
     HashSet<RefPtr<CSSFontFace>> m_cssConnectionsPossiblyToRemove;
     HashSet<RefPtr<StyleRuleFontFace>> m_cssConnectionsEncounteredDuringBuild;
-    Timer m_beginLoadingTimer;
+    SuspendableTimer m_beginLoadingTimer;
 
     unsigned m_uniqueId;
     unsigned m_version;