Title: [273650] trunk/Source/WebCore
Revision
273650
Author
cl...@igalia.com
Date
2021-03-01 07:34:03 -0800 (Mon, 01 Mar 2021)

Log Message

CSSFontFace should not need its m_fontSelector data member
https://bugs.webkit.org/show_bug.cgi?id=208351
<rdar://problem/74346302>

Reviewed by Darin Adler.

Move the m_fontSelector member of CSSFontFace onto CSSFontFaceSource,
the only place where it's actually required.

No new tests because there is no behavior change.

* css/CSSFontFace.cpp:
(WebCore::CSSFontFace::appendSources):
(WebCore::CSSFontFace::create):
(WebCore::CSSFontFace::document):
(WebCore::CSSFontFace::opportunisticallyStartFontDataURLLoading):
(WebCore::CSSFontFace::pump):
(WebCore::CSSFontFace::font):
* css/CSSFontFace.h:
* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::CSSFontFaceSource):
(WebCore::CSSFontFaceSource::opportunisticallyStartFontDataURLLoading):
(WebCore::CSSFontFaceSource::load):
* css/CSSFontFaceSource.h:
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::opportunisticallyStartFontDataURLLoading):
* css/FontFace.cpp:
(WebCore::populateFontFaceWithArrayBuffer):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (273649 => 273650)


--- trunk/Source/WebCore/ChangeLog	2021-03-01 15:00:20 UTC (rev 273649)
+++ trunk/Source/WebCore/ChangeLog	2021-03-01 15:34:03 UTC (rev 273650)
@@ -1,3 +1,34 @@
+2021-03-01  Chris Lord  <cl...@igalia.com>
+
+        CSSFontFace should not need its m_fontSelector data member
+        https://bugs.webkit.org/show_bug.cgi?id=208351
+        <rdar://problem/74346302>
+
+        Reviewed by Darin Adler.
+
+        Move the m_fontSelector member of CSSFontFace onto CSSFontFaceSource,
+        the only place where it's actually required.
+
+        No new tests because there is no behavior change.
+
+        * css/CSSFontFace.cpp:
+        (WebCore::CSSFontFace::appendSources):
+        (WebCore::CSSFontFace::create):
+        (WebCore::CSSFontFace::document):
+        (WebCore::CSSFontFace::opportunisticallyStartFontDataURLLoading):
+        (WebCore::CSSFontFace::pump):
+        (WebCore::CSSFontFace::font):
+        * css/CSSFontFace.h:
+        * css/CSSFontFaceSource.cpp:
+        (WebCore::CSSFontFaceSource::CSSFontFaceSource):
+        (WebCore::CSSFontFaceSource::opportunisticallyStartFontDataURLLoading):
+        (WebCore::CSSFontFaceSource::load):
+        * css/CSSFontFaceSource.h:
+        * css/CSSFontSelector.cpp:
+        (WebCore::CSSFontSelector::opportunisticallyStartFontDataURLLoading):
+        * css/FontFace.cpp:
+        (WebCore::populateFontFaceWithArrayBuffer):
+
 2021-03-01  Rob Buis  <rb...@igalia.com>
 
         Change order in RenderBlock::availableLogicalHeightForPercentageComputation

Modified: trunk/Source/WebCore/css/CSSFontFace.cpp (273649 => 273650)


--- trunk/Source/WebCore/css/CSSFontFace.cpp	2021-03-01 15:00:20 UTC (rev 273649)
+++ trunk/Source/WebCore/css/CSSFontFace.cpp	2021-03-01 15:34:03 UTC (rev 273650)
@@ -78,10 +78,11 @@
             bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled());
             if (allowDownloading && item.isSupportedFormat() && document) {
                 if (CachedFont* cachedFont = item.cachedFont(document, foundSVGFont, isInitiatingElementInUserAgentShadowTree))
-                    source = makeUnique<CSSFontFaceSource>(fontFace, item.resource(), cachedFont);
+                    source = makeUnique<CSSFontFaceSource>(fontFace, item.resource(), document->fontSelector(), *cachedFont);
             }
         } else
-            source = makeUnique<CSSFontFaceSource>(fontFace, item.resource(), nullptr, fontFaceElement);
+            source = (fontFaceElement ? makeUnique<CSSFontFaceSource>(fontFace, item.resource(), *fontFaceElement)
+                : makeUnique<CSSFontFaceSource>(fontFace, item.resource()));
 
         if (source)
             fontFace.adoptSource(WTFMove(source));
@@ -89,12 +90,12 @@
     fontFace.sourcesPopulated();
 }
 
-CSSFontFace::CSSFontFace(CSSFontSelector* fontSelector, StyleRuleFontFace* cssConnection, FontFace* wrapper, bool isLocalFallback)
-    : CSSFontFace(fontSelector && fontSelector->document() ? &fontSelector->document()->settings() : nullptr, cssConnection, wrapper, isLocalFallback)
+Ref<CSSFontFace> CSSFontFace::create(CSSFontSelector* fontSelector, StyleRuleFontFace* cssConnection, FontFace* wrapper, bool isLocalFallback)
 {
-    m_fontSelector = makeWeakPtr(fontSelector); // FIXME: Ideally this data member would go away (https://bugs.webkit.org/show_bug.cgi?id=208351).
+    auto result = adoptRef(*new CSSFontFace((fontSelector && fontSelector->document()) ? &fontSelector->document()->settings() : nullptr, cssConnection, wrapper, isLocalFallback));
     if (fontSelector)
-        addClient(*fontSelector);
+        result->addClient(*fontSelector);
+    return result;
 }
 
 CSSFontFace::CSSFontFace(const Settings* settings, StyleRuleFontFace* cssConnection, FontFace* wrapper, bool isLocalFallback)
@@ -383,6 +384,13 @@
     fontLoadEventOccurred();
 }
 
+Document* CSSFontFace::document()
+{
+    if (m_wrapper && is<Document>(m_wrapper->scriptExecutionContext()))
+        return &downcast<Document>(*m_wrapper->scriptExecutionContext());
+    return nullptr;
+}
+
 bool CSSFontFace::computeFailureState() const
 {
     if (status() == Status::Failure)
@@ -548,11 +556,11 @@
     fontLoadEventOccurred();
 }
 
-void CSSFontFace::opportunisticallyStartFontDataURLLoading(CSSFontSelector& fontSelector)
+void CSSFontFace::opportunisticallyStartFontDataURLLoading()
 {
     // We don't want to go crazy here and blow the cache. Usually these data URLs are the first item in the src: list, so let's just check that one.
     if (!m_sources.isEmpty())
-        m_sources[0]->opportunisticallyStartFontDataURLLoading(fontSelector);
+        m_sources[0]->opportunisticallyStartFontDataURLLoading();
 }
 
 size_t CSSFontFace::pump(ExternalResourceDownloadPolicy policy)
@@ -579,7 +587,7 @@
             if (policy == ExternalResourceDownloadPolicy::Allow || !source->requiresExternalResource()) {
                 if (policy == ExternalResourceDownloadPolicy::Allow && m_status == Status::Pending)
                     setStatus(Status::Loading);
-                source->load(m_fontSelector.get());
+                source->load(document());
             }
         }
 
@@ -651,7 +659,7 @@
     for (size_t i = startIndex; i < m_sources.size(); ++i) {
         auto& source = m_sources[i];
         if (source->status() == CSSFontFaceSource::Status::Pending && (policy == ExternalResourceDownloadPolicy::Allow || !source->requiresExternalResource()))
-            source->load(m_fontSelector.get());
+            source->load(document());
 
         switch (source->status()) {
         case CSSFontFaceSource::Status::Pending:

Modified: trunk/Source/WebCore/css/CSSFontFace.h (273649 => 273650)


--- trunk/Source/WebCore/css/CSSFontFace.h	2021-03-01 15:00:20 UTC (rev 273649)
+++ trunk/Source/WebCore/css/CSSFontFace.h	2021-03-01 15:34:03 UTC (rev 273650)
@@ -60,10 +60,7 @@
 class CSSFontFace final : public RefCounted<CSSFontFace> {
     WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(CSSFontFace);
 public:
-    static Ref<CSSFontFace> create(CSSFontSelector* fontSelector, StyleRuleFontFace* cssConnection = nullptr, FontFace* wrapper = nullptr, bool isLocalFallback = false)
-    {
-        return adoptRef(*new CSSFontFace(fontSelector, cssConnection, wrapper, isLocalFallback));
-    }
+    static Ref<CSSFontFace> create(CSSFontSelector*, StyleRuleFontFace* cssConnection = nullptr, FontFace* wrapper = nullptr, bool isLocalFallback = false);
     virtual ~CSSFontFace();
 
     // FIXME: These functions don't need to have boolean return values.
@@ -112,7 +109,7 @@
 
     bool computeFailureState() const;
 
-    void opportunisticallyStartFontDataURLLoading(CSSFontSelector&);
+    void opportunisticallyStartFontDataURLLoading();
 
     void adoptSource(std::unique_ptr<CSSFontFaceSource>&&);
     void sourcesPopulated() { m_sourcesPopulated = true; }
@@ -167,7 +164,6 @@
     void setErrorState();
 
 private:
-    CSSFontFace(CSSFontSelector*, StyleRuleFontFace*, FontFace*, bool isLocalFallback);
     CSSFontFace(const Settings*, StyleRuleFontFace*, FontFace*, bool isLocalFallback);
 
     size_t pump(ExternalResourceDownloadPolicy);
@@ -179,6 +175,8 @@
     void fontLoadEventOccurred();
     void timeoutFired();
 
+    Document* document();
+
     RefPtr<CSSValueList> m_families;
     Vector<UnicodeRange> m_ranges;
 
@@ -186,7 +184,6 @@
     FontLoadingBehavior m_loadingBehavior { FontLoadingBehavior::Auto };
 
     Vector<std::unique_ptr<CSSFontFaceSource>, 0, CrashOnOverflow, 0> m_sources;
-    WeakPtr<CSSFontSelector> m_fontSelector; // FIXME: Ideally this data member would go away (https://bugs.webkit.org/show_bug.cgi?id=208351).
     RefPtr<StyleRuleFontFace> m_cssConnection;
     HashSet<Client*> m_clients;
     WeakPtr<FontFace> m_wrapper;

Modified: trunk/Source/WebCore/css/CSSFontFaceSource.cpp (273649 => 273650)


--- trunk/Source/WebCore/css/CSSFontFaceSource.cpp	2021-03-01 15:00:20 UTC (rev 273649)
+++ trunk/Source/WebCore/css/CSSFontFaceSource.cpp	2021-03-01 15:34:03 UTC (rev 273650)
@@ -66,22 +66,25 @@
     m_status = newStatus;
 }
 
-CSSFontFaceSource::CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, CachedFont* font, SVGFontFaceElement* fontFace, RefPtr<JSC::ArrayBufferView>&& arrayBufferView)
+CSSFontFaceSource::CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI)
     : m_familyNameOrURI(familyNameOrURI)
-    , m_font(font)
     , m_face(owner)
-    , m_immediateSource(WTFMove(arrayBufferView))
-    , m_svgFontFaceElement(makeWeakPtr(fontFace))
-    , m_hasSVGFontFaceElement(m_svgFontFaceElement)
 {
+}
+
+CSSFontFaceSource::CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, CSSFontSelector& fontSelector, CachedFont& font)
+    : m_familyNameOrURI(familyNameOrURI)
+    , m_face(owner)
+    , m_fontSelector(makeWeakPtr(fontSelector))
+    , m_font(&font)
+{
     // This may synchronously call fontLoaded().
-    if (m_font)
-        m_font->addClient(*this);
+    m_font->addClient(*this);
 
-    if (status() == Status::Pending && m_font && m_font->isLoaded()) {
+    if (status() == Status::Pending && m_font->isLoaded()) {
         setStatus(Status::Loading);
         if (!shouldIgnoreFontLoadCompletions()) {
-            if (m_font && m_font->errorOccurred())
+            if (m_font->errorOccurred())
                 setStatus(Status::Failure);
             else
                 setStatus(Status::Success);
@@ -89,6 +92,21 @@
     }
 }
 
+CSSFontFaceSource::CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, SVGFontFaceElement& fontFace)
+    : m_familyNameOrURI(familyNameOrURI)
+    , m_face(owner)
+    , m_svgFontFaceElement(makeWeakPtr(fontFace))
+    , m_hasSVGFontFaceElement(true)
+{
+}
+
+CSSFontFaceSource::CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, Ref<JSC::ArrayBufferView>&& arrayBufferView)
+    : m_familyNameOrURI(familyNameOrURI)
+    , m_face(owner)
+    , m_immediateSource(WTFMove(arrayBufferView))
+{
+}
+
 CSSFontFaceSource::~CSSFontFaceSource()
 {
     if (m_font)
@@ -100,10 +118,10 @@
     return m_face.shouldIgnoreFontLoadCompletions();
 }
 
-void CSSFontFaceSource::opportunisticallyStartFontDataURLLoading(CSSFontSelector& fontSelector)
+void CSSFontFaceSource::opportunisticallyStartFontDataURLLoading()
 {
     if (status() == Status::Pending && m_font && m_font->url().protocolIsData() && m_familyNameOrURI.length() < MB)
-        load(&fontSelector);
+        load();
 }
 
 void CSSFontFaceSource::fontLoaded(CachedFont& loadedFont)
@@ -132,13 +150,13 @@
     m_face.fontLoaded(*this);
 }
 
-void CSSFontFaceSource::load(CSSFontSelector* fontSelector)
+void CSSFontFaceSource::load(Document* document)
 {
     setStatus(Status::Loading);
 
     if (m_font) {
-        ASSERT(fontSelector);
-        fontSelector->beginLoadingFontSoon(*m_font);
+        ASSERT(m_fontSelector);
+        m_fontSelector->beginLoadingFontSoon(*m_font);
     } else {
         bool success = false;
         if (m_hasSVGFontFaceElement) {
@@ -167,10 +185,8 @@
             fontDescription.setComputedSize(1);
             fontDescription.setShouldAllowUserInstalledFonts(m_face.allowUserInstalledFonts());
             success = FontCache::singleton().fontForFamily(fontDescription, m_familyNameOrURI, nullptr, FontSelectionSpecifiedCapabilities(), true);
-            if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled()) {
-                if (auto* document = fontSelector->document())
-                    ResourceLoadObserver::shared().logFontLoad(*document, m_familyNameOrURI.string(), success);
-            }
+            if (document && RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
+                ResourceLoadObserver::shared().logFontLoad(*document, m_familyNameOrURI.string(), success);
         }
         setStatus(success ? Status::Success : Status::Failure);
     }

Modified: trunk/Source/WebCore/css/CSSFontFaceSource.h (273649 => 273650)


--- trunk/Source/WebCore/css/CSSFontFaceSource.h	2021-03-01 15:00:20 UTC (rev 273649)
+++ trunk/Source/WebCore/css/CSSFontFaceSource.h	2021-03-01 15:34:03 UTC (rev 273650)
@@ -35,6 +35,7 @@
 
 class CSSFontFace;
 class CSSFontSelector;
+class Document;
 class Font;
 struct FontCustomPlatformData;
 class FontDescription;
@@ -49,7 +50,10 @@
 class CSSFontFaceSource final : public CachedFontClient {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, CachedFont* = nullptr, SVGFontFaceElement* = nullptr, RefPtr<JSC::ArrayBufferView>&& = nullptr);
+    CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI);
+    CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, CSSFontSelector&, CachedFont&);
+    CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, SVGFontFaceElement&);
+    CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, Ref<JSC::ArrayBufferView>&&);
     virtual ~CSSFontFaceSource();
 
     //                      => Success
@@ -67,9 +71,9 @@
 
     const AtomString& familyNameOrURI() const { return m_familyNameOrURI; }
 
-    void opportunisticallyStartFontDataURLLoading(CSSFontSelector&);
+    void opportunisticallyStartFontDataURLLoading();
 
-    void load(CSSFontSelector*);
+    void load(Document* = nullptr);
     RefPtr<Font> font(const FontDescription&, bool syntheticBold, bool syntheticItalic, const FontFeatureSettings&, FontSelectionSpecifiedCapabilities);
 
     CachedFont* cachedFont() const { return m_font.get(); }
@@ -85,8 +89,9 @@
     void setStatus(Status);
 
     AtomString m_familyNameOrURI; // URI for remote, built-in font name for local.
-    CachedResourceHandle<CachedFont> m_font; // For remote fonts, a pointer to our cached resource.
     CSSFontFace& m_face; // Our owning font face.
+    WeakPtr<CSSFontSelector> m_fontSelector; // For remote fonts, to orchestrate loading.
+    CachedResourceHandle<CachedFont> m_font; // Also for remote fonts, a pointer to our cached resource.
 
     RefPtr<SharedBuffer> m_generatedOTFBuffer;
     RefPtr<JSC::ArrayBufferView> m_immediateSource;
@@ -96,7 +101,7 @@
     std::unique_ptr<FontCustomPlatformData> m_inDocumentCustomPlatformData;
 
     Status m_status { Status::Pending };
-    bool m_hasSVGFontFaceElement;
+    bool m_hasSVGFontFaceElement { false };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/CSSFontSelector.cpp (273649 => 273650)


--- trunk/Source/WebCore/css/CSSFontSelector.cpp	2021-03-01 15:00:20 UTC (rev 273649)
+++ trunk/Source/WebCore/css/CSSFontSelector.cpp	2021-03-01 15:34:03 UTC (rev 273650)
@@ -245,7 +245,7 @@
     if (!segmentedFontFace)
         return;
     for (auto& face : segmentedFontFace->constituentFaces())
-        face->opportunisticallyStartFontDataURLLoading(*this);
+        face->opportunisticallyStartFontDataURLLoading();
 }
 
 void CSSFontSelector::fontLoaded(CSSFontFace&)

Modified: trunk/Source/WebCore/css/FontFace.cpp (273649 => 273650)


--- trunk/Source/WebCore/css/FontFace.cpp	2021-03-01 15:00:20 UTC (rev 273649)
+++ trunk/Source/WebCore/css/FontFace.cpp	2021-03-01 15:34:03 UTC (rev 273650)
@@ -50,7 +50,7 @@
 
 static bool populateFontFaceWithArrayBuffer(CSSFontFace& fontFace, Ref<JSC::ArrayBufferView>&& arrayBufferView)
 {
-    auto source = makeUnique<CSSFontFaceSource>(fontFace, String(), nullptr, nullptr, WTFMove(arrayBufferView));
+    auto source = makeUnique<CSSFontFaceSource>(fontFace, String(), WTFMove(arrayBufferView));
     fontFace.adoptSource(WTFMove(source));
     return false;
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to