Diff
Modified: trunk/Source/WebCore/ChangeLog (275816 => 275817)
--- trunk/Source/WebCore/ChangeLog 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/ChangeLog 2021-04-12 09:26:42 UTC (rev 275817)
@@ -1,3 +1,98 @@
+2021-04-12 Chris Lord <[email protected]>
+
+ Refactor font loading to make it possible for Worker to implement it
+ https://bugs.webkit.org/show_bug.cgi?id=224277
+
+ Reviewed by Darin Adler.
+
+ Introduce FontLoadRequest and FontLoadRequestClient as an abstraction
+ separate from CachedFont and CachedFontClient to allow for separate
+ implementations. Also move Document-specific font-loading behaviour
+ from CSSFontSelector into Document and add non-Document specific
+ accessors to ScriptExecutionContext.
+
+ These changes should allow for custom font loading to be implementable
+ on a Worker, which will be necessary for FontFace support in
+ OffscreenCanvas.
+
+ No new tests, no change in behavior.
+
+ * Headers.cmake: Added FontLoadRequest.h, CachedFontLoadRequest.h
+ and DocumentFontLoader.h.
+ * Sources.txt: Added DocumentFontLoader.cpp.
+ * WebCore.xcodeproj/project.pbxproj: Added files listed above.
+
+ * css/CSSFontFace.cpp: Update to not require Document for custom font loading.
+ (WebCore::CSSFontFace::appendSources):
+
+ * css/CSSFontFaceSource.cpp: Update to use FontLoadRequest instead of CachedFont.
+ (WebCore::CSSFontFaceSource::CSSFontFaceSource):
+ (WebCore::CSSFontFaceSource::~CSSFontFaceSource):
+ (WebCore::CSSFontFaceSource::opportunisticallyStartFontDataURLLoading):
+ (WebCore::CSSFontFaceSource::fontLoaded):
+ (WebCore::CSSFontFaceSource::load):
+ (WebCore::CSSFontFaceSource::font):
+ (WebCore::CSSFontFaceSource::isSVGFontFaceSource const):
+ * css/CSSFontFaceSource.h:
+
+ * css/CSSFontFaceSrcValue.cpp: Update to use FontLoadRequest and
+ ScriptExecutionContext instead of CachedResourceLoader.
+ (WebCore::CSSFontFaceSrcValue::fontLoadRequest):
+ * css/CSSFontFaceSrcValue.h:
+
+ * css/CSSFontSelector.cpp: Remove Document-specific code.
+ (WebCore::CSSFontSelector::CSSFontSelector):
+ (WebCore::CSSFontSelector::~CSSFontSelector):
+ (WebCore::CSSFontSelector::clearFonts):
+ * css/CSSFontSelector.h:
+
+ * dom/Document.cpp: Implement ScriptExecutionContext::fontLoadRequest
+ and ::beginLoadingFontSoon.
+ (WebCore::Document::~Document):
+ (WebCore::Document::removedLastRef):
+ (WebCore::Document::resolveStyle):
+ (WebCore::Document::suspendFontLoading):
+ (WebCore::Document::fontLoadRequest):
+ (WebCore::Document::beginLoadingFontSoon):
+ (WebCore::Document::suspend):
+ (WebCore::Document::resume):
+ * dom/Document.h:
+
+ * dom/DocumentFontLoader.cpp: Added. New class to handle Document-specific
+ font-loading code that was previously in CSSFontSelector and
+ CSSFontFaceSrcValue.
+ (WebCore::DocumentFontLoader::DocumentFontLoader):
+ (WebCore::DocumentFontLoader::~DocumentFontLoader):
+ (WebCore::DocumentFontLoader::cachedFont):
+ (WebCore::DocumentFontLoader::beginLoadingFontSoon):
+ (WebCore::DocumentFontLoader::loadPendingFonts):
+ (WebCore::DocumentFontLoader::fontLoadingTimerFired):
+ (WebCore::DocumentFontLoader::stopLoadingAndClearFonts):
+ (WebCore::DocumentFontLoader::suspendFontLoading):
+ (WebCore::DocumentFontLoader::resumeFontLoading):
+ * dom/DocumentFontLoader.h:
+
+ * dom/ScriptExecutionContext.cpp: Add functions to initiate font load requests.
+ (WebCore::ScriptExecutionContext::fontLoadRequest):
+ * dom/ScriptExecutionContext.h:
+ (WebCore::ScriptExecutionContext::beginLoadingFontSoon):
+
+ * loader/DocumentLoader.cpp: CSSFontSelector::suspendFontLoadingTimer
+ is now Document::suspendFontLoading.
+ (WebCore::DocumentLoader::stopLoading):
+
+ * loader/FontLoadRequest.h: Added. An interface to manage font loading
+ that abstracts some of the behaviour of CachedResource, CachedFont and
+ CachedFontClient.
+ (WebCore::FontLoadRequestClient::fontLoaded):
+ (WebCore::FontLoadRequestClient::isCachedFontLoadRequest const):
+
+ * loader/cache/CachedFontLoadRequest.h: Added. An implementation of
+ FontLoadRequest for CachedFont.
+
+ * workers/WorkerGlobalScope.cpp: Remove now-redundant CSSFontSelector call.
+ (WebCore::WorkerGlobalScope::~WorkerGlobalScope):
+
2021-04-12 Adrian Perez de Castro <[email protected]>
[WPE][GTK] Use g_object_notify_by_pspec() whenever possible
Modified: trunk/Source/WebCore/Headers.cmake (275816 => 275817)
--- trunk/Source/WebCore/Headers.cmake 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/Headers.cmake 2021-04-12 09:26:42 UTC (rev 275817)
@@ -437,6 +437,7 @@
dom/DeviceOrientationData.h
dom/DeviceOrientationOrMotionPermissionState.h
dom/Document.h
+ dom/DocumentFontLoader.h
dom/DocumentFragment.h
dom/DocumentFullscreen.h
dom/DocumentMarker.h
@@ -777,6 +778,7 @@
loader/EmptyClients.h
loader/EmptyFrameLoaderClient.h
loader/FetchOptions.h
+ loader/FontLoadRequest.h
loader/FormState.h
loader/FormSubmission.h
loader/FrameLoadRequest.h
@@ -829,6 +831,7 @@
loader/archive/mhtml/MHTMLArchive.h
+ loader/cache/CachedFontLoadRequest.h
loader/cache/CachePolicy.h
loader/cache/CachedImage.h
loader/cache/CachedImageClient.h
Modified: trunk/Source/WebCore/Sources.txt (275816 => 275817)
--- trunk/Source/WebCore/Sources.txt 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/Sources.txt 2021-04-12 09:26:42 UTC (rev 275817)
@@ -922,6 +922,7 @@
dom/DeviceOrientationData.cpp
dom/DeviceOrientationEvent.cpp
dom/Document.cpp
+dom/DocumentFontLoader.cpp
dom/DocumentFragment.cpp
dom/DocumentMarkerController.cpp
dom/DocumentParser.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (275816 => 275817)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-04-12 09:26:42 UTC (rev 275817)
@@ -2045,6 +2045,7 @@
6565820209D1508D000E61D7 /* XLinkNames.h in Headers */ = {isa = PBXBuildFile; fileRef = 656581EB09D1508D000E61D7 /* XLinkNames.h */; };
656D37320ADBA5DE00A4554D /* LoaderNSURLExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D371A0ADBA5DE00A4554D /* LoaderNSURLExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
656D37360ADBA5DE00A4554D /* DocumentLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D371E0ADBA5DE00A4554D /* DocumentLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 658436860AE01B7400E53743 /* FontLoadRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 658436850AE01B7400E53743 /* FontLoadRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
656D373A0ADBA5DE00A4554D /* FormState.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37220ADBA5DE00A4554D /* FormState.h */; settings = {ATTRIBUTES = (Private, ); }; };
656D373C0ADBA5DE00A4554D /* FrameLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37240ADBA5DE00A4554D /* FrameLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
656D373E0ADBA5DE00A4554D /* FrameLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37260ADBA5DE00A4554D /* FrameLoaderClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -2896,6 +2897,7 @@
93F198F608245E59001E9ABC /* TextResourceDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = F523D27902DE43D7018635CA /* TextResourceDecoder.h */; settings = {ATTRIBUTES = (Private, ); }; };
93F1991808245E59001E9ABC /* Range.h in Headers */ = {isa = PBXBuildFile; fileRef = F523D30402DE4476018635CA /* Range.h */; settings = {ATTRIBUTES = (Private, ); }; };
93F1992F08245E59001E9ABC /* Cursor.h in Headers */ = {isa = PBXBuildFile; fileRef = F587868402DE3B8601EA4122 /* Cursor.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 83F1995008245E59001E9ABC /* CachedFontLoadRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 8587864902DE3A9A01EA4122 /* CachedFontLoadRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
93F1995008245E59001E9ABC /* CachePolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = F587864902DE3A9A01EA4122 /* CachePolicy.h */; settings = {ATTRIBUTES = (Private, ); }; };
93F1996308245E59001E9ABC /* SSLKeyGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = F587866202DE3B1101EA4122 /* SSLKeyGenerator.h */; settings = {ATTRIBUTES = (Private, ); }; };
93F1998C08245E59001E9ABC /* RenderTreeAsText.h in Headers */ = {isa = PBXBuildFile; fileRef = 93955A4103D72932008635CE /* RenderTreeAsText.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -3479,6 +3481,7 @@
A8185F3909765766005826D9 /* DocumentType.h in Headers */ = {isa = PBXBuildFile; fileRef = A8185F3109765765005826D9 /* DocumentType.h */; settings = {ATTRIBUTES = (Private, ); }; };
A8185F3B09765766005826D9 /* DOMImplementation.h in Headers */ = {isa = PBXBuildFile; fileRef = A8185F3309765765005826D9 /* DOMImplementation.h */; settings = {ATTRIBUTES = (Private, ); }; };
A8185F3D09765766005826D9 /* DocumentFragment.h in Headers */ = {isa = PBXBuildFile; fileRef = A8185F3509765765005826D9 /* DocumentFragment.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ A8185F4509765766005826D9 /* DocumentFontLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = A8185F3559765765005826D9 /* DocumentFontLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
A8185F4009765766005826D9 /* Document.h in Headers */ = {isa = PBXBuildFile; fileRef = A8185F3809765765005826D9 /* Document.h */; settings = {ATTRIBUTES = (Private, ); }; };
A818721B0977D3C0005826D9 /* NodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = A81872100977D3C0005826D9 /* NodeList.h */; settings = {ATTRIBUTES = (Private, ); }; };
A818721C0977D3C0005826D9 /* ContainerNode.h in Headers */ = {isa = PBXBuildFile; fileRef = A81872110977D3C0005826D9 /* ContainerNode.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -9768,6 +9771,7 @@
656D371E0ADBA5DE00A4554D /* DocumentLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DocumentLoader.h; sourceTree = "<group>"; };
656D37220ADBA5DE00A4554D /* FormState.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FormState.h; sourceTree = "<group>"; };
656D37230ADBA5DE00A4554D /* FormState.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FormState.cpp; sourceTree = "<group>"; };
+ 658436850AE01B7400E53743 /* FontLoadRequest.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FontLoadRequest.h; sourceTree = "<group>"; };
656D37240ADBA5DE00A4554D /* FrameLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FrameLoader.h; sourceTree = "<group>"; };
656D37260ADBA5DE00A4554D /* FrameLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FrameLoaderClient.h; sourceTree = "<group>"; };
656D37270ADBA5DE00A4554D /* ResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ResourceLoader.h; sourceTree = "<group>"; };
@@ -12942,9 +12946,11 @@
A8185F3209765765005826D9 /* DocumentType.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentType.cpp; sourceTree = "<group>"; };
A8185F3309765765005826D9 /* DOMImplementation.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMImplementation.h; sourceTree = "<group>"; };
A8185F3409765765005826D9 /* Document.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Document.cpp; sourceTree = "<group>"; };
+ A8185F3459765765005826D9 /* DocumentFontLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentFontLoader.cpp; sourceTree = "<group>"; };
A8185F3509765765005826D9 /* DocumentFragment.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DocumentFragment.h; sourceTree = "<group>"; };
A8185F3609765765005826D9 /* DOMImplementation.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DOMImplementation.cpp; sourceTree = "<group>"; };
A8185F3709765765005826D9 /* DocumentFragment.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentFragment.cpp; sourceTree = "<group>"; };
+ A8185F3559765765005826D9 /* DocumentFontLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DocumentFontLoader.h; sourceTree = "<group>"; };
A8185F3809765765005826D9 /* Document.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Document.h; sourceTree = "<group>"; };
A81872100977D3C0005826D9 /* NodeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NodeList.h; sourceTree = "<group>"; };
A81872110977D3C0005826D9 /* ContainerNode.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ContainerNode.h; sourceTree = "<group>"; };
@@ -16859,6 +16865,7 @@
F55B3DAC1251F12D003EF269 /* WeekInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeekInputType.h; sourceTree = "<group>"; };
F58784F002DE375901EA4122 /* CursorMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CursorMac.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587854C02DE375901EA4122 /* WebCoreFrameView.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreFrameView.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
+ 8587864902DE3A9A01EA4122 /* CachedFontLoadRequest.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = CachedFontLoadRequest.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587864902DE3A9A01EA4122 /* CachePolicy.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = CachePolicy.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587866202DE3B1101EA4122 /* SSLKeyGenerator.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = SSLKeyGenerator.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587868402DE3B8601EA4122 /* Cursor.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = Cursor.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
@@ -25948,6 +25955,7 @@
BC64B4C90CB4295D005F2B62 /* CachedFont.cpp */,
BC64B4CA0CB4295D005F2B62 /* CachedFont.h */,
1AEF4E66170E160300AB2799 /* CachedFontClient.h */,
+ 8587864902DE3A9A01EA4122 /* CachedFontLoadRequest.h */,
BCB16C020979C3BD00467741 /* CachedImage.cpp */,
BCB16C030979C3BD00467741 /* CachedImage.h */,
319FBD5D15D2F444009640A6 /* CachedImageClient.h */,
@@ -27597,6 +27605,7 @@
CEBB8C3220786DCB00039547 /* FetchIdioms.cpp */,
CEBB8C3120786DCB00039547 /* FetchIdioms.h */,
41AD75391CEF6BCE00A31486 /* FetchOptions.h */,
+ 658436850AE01B7400E53743 /* FontLoadRequest.h */,
656D37230ADBA5DE00A4554D /* FormState.cpp */,
656D37220ADBA5DE00A4554D /* FormState.h */,
41885B9211B6FDA6003383BB /* FormSubmission.cpp */,
@@ -30301,6 +30310,8 @@
A8185F3809765765005826D9 /* Document.h */,
6548E24809E1E04D00AF8020 /* Document.idl */,
8329A4171EC25B2B008ED4BE /* DocumentAndElementEventHandlers.idl */,
+ A8185F3459765765005826D9 /* DocumentFontLoader.cpp */,
+ A8185F3559765765005826D9 /* DocumentFontLoader.h */,
A8185F3709765765005826D9 /* DocumentFragment.cpp */,
A8185F3509765765005826D9 /* DocumentFragment.h */,
1A494ED50A123F1A00FDAFC1 /* DocumentFragment.idl */,
@@ -31627,6 +31638,7 @@
BCB16C1A0979C3BD00467741 /* CachedCSSStyleSheet.h in Headers */,
BC64B4CC0CB4295D005F2B62 /* CachedFont.h in Headers */,
1AEF4E67170E160300AB2799 /* CachedFontClient.h in Headers */,
+ 83F1995008245E59001E9ABC /* CachedFontLoadRequest.h in Headers */,
51C0AA390F2AA10A001648C2 /* CachedFrame.h in Headers */,
51CBFC990D10E483002DBF51 /* CachedFramePlatformData.h in Headers */,
830030F81B7D3B7800ED3AAC /* CachedHTMLCollection.h in Headers */,
@@ -32170,6 +32182,7 @@
B2F34FE60E82F81400F627CD /* DNS.h in Headers */,
7EE6846F12D26E3800E73215 /* DNSResolveQueueCFNet.h in Headers */,
A8185F4009765766005826D9 /* Document.h in Headers */,
+ A8185F4509765766005826D9 /* DocumentFontLoader.h in Headers */,
A8185F3D09765766005826D9 /* DocumentFragment.h in Headers */,
CD92F5132260FFEE00F87BB3 /* DocumentFullscreen.h in Headers */,
41826BF223FB597700B922B1 /* DocumentIdentifier.h in Headers */,
@@ -32440,6 +32453,7 @@
1C24EEA51C729CE40080F8FC /* FontFaceSet.h in Headers */,
1C12AC2B1EE778AE0079E0A0 /* FontFamilySpecificationCoreText.h in Headers */,
E42EE3A717576E5500EEE8CF /* FontGenericFamilies.h in Headers */,
+ 658436860AE01B7400E53743 /* FontLoadRequest.h in Headers */,
BC4A532F256057CD0028C592 /* FontLoadTimingOverride.h in Headers */,
0845680812B90DA600960A9F /* FontMetrics.h in Headers */,
B5320D6B122A24E9002D1440 /* FontPlatformData.h in Headers */,
Modified: trunk/Source/WebCore/css/CSSFontFace.cpp (275816 => 275817)
--- trunk/Source/WebCore/css/CSSFontFace.cpp 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/css/CSSFontFace.cpp 2021-04-12 09:26:42 UTC (rev 275817)
@@ -76,10 +76,9 @@
if (!item.isLocal()) {
const auto* settings = context ? &context->settingsValues() : nullptr;
bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled);
- if (allowDownloading && item.isSupportedFormat() && is<Document>(context)) {
- auto& document = downcast<Document>(*context);
- if (CachedFont* cachedFont = item.cachedFont(&document, foundSVGFont, isInitiatingElementInUserAgentShadowTree))
- source = makeUnique<CSSFontFaceSource>(fontFace, item.resource(), document.fontSelector(), *cachedFont);
+ if (allowDownloading && item.isSupportedFormat()) {
+ if (auto fontRequest = item.fontLoadRequest(context, foundSVGFont, isInitiatingElementInUserAgentShadowTree))
+ source = makeUnique<CSSFontFaceSource>(fontFace, item.resource(), *context->cssFontSelector(), makeUniqueRefFromNonNullUniquePtr(WTFMove(fontRequest)));
}
} else
source = (fontFaceElement ? makeUnique<CSSFontFaceSource>(fontFace, item.resource(), *fontFaceElement)
Modified: trunk/Source/WebCore/css/CSSFontFaceSource.cpp (275816 => 275817)
--- trunk/Source/WebCore/css/CSSFontFaceSource.cpp 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/css/CSSFontFaceSource.cpp 2021-04-12 09:26:42 UTC (rev 275817)
@@ -28,7 +28,7 @@
#include "CSSFontFace.h"
#include "CSSFontSelector.h"
-#include "CachedFont.h"
+#include "CachedFontLoadRequest.h"
#include "CachedSVGFont.h"
#include "Document.h"
#include "Font.h"
@@ -72,19 +72,19 @@
{
}
-CSSFontFaceSource::CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, CSSFontSelector& fontSelector, CachedFont& font)
+CSSFontFaceSource::CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, CSSFontSelector& fontSelector, UniqueRef<FontLoadRequest>&& request)
: m_familyNameOrURI(familyNameOrURI)
, m_face(owner)
, m_fontSelector(makeWeakPtr(fontSelector))
- , m_font(&font)
+ , m_fontRequest(request.moveToUniquePtr())
{
// This may synchronously call fontLoaded().
- m_font->addClient(*this);
+ m_fontRequest->setClient(this);
- if (status() == Status::Pending && m_font->isLoaded()) {
+ if (status() == Status::Pending && !m_fontRequest->isLoading()) {
setStatus(Status::Loading);
if (!shouldIgnoreFontLoadCompletions()) {
- if (m_font->errorOccurred())
+ if (m_fontRequest->errorOccurred())
setStatus(Status::Failure);
else
setStatus(Status::Success);
@@ -109,8 +109,8 @@
CSSFontFaceSource::~CSSFontFaceSource()
{
- if (m_font)
- m_font->removeClient(*this);
+ if (m_fontRequest)
+ m_fontRequest->setClient(nullptr);
}
bool CSSFontFaceSource::shouldIgnoreFontLoadCompletions() const
@@ -120,13 +120,13 @@
void CSSFontFaceSource::opportunisticallyStartFontDataURLLoading()
{
- if (status() == Status::Pending && m_font && m_font->url().protocolIsData() && m_familyNameOrURI.length() < MB)
+ if (status() == Status::Pending && m_fontRequest && m_fontRequest->url().protocolIsData() && m_familyNameOrURI.length() < MB)
load();
}
-void CSSFontFaceSource::fontLoaded(CachedFont& loadedFont)
+void CSSFontFaceSource::fontLoaded(FontLoadRequest& fontRequest)
{
- ASSERT_UNUSED(loadedFont, &loadedFont == m_font.get());
+ ASSERT_UNUSED(fontRequest, &fontRequest == m_fontRequest.get());
if (shouldIgnoreFontLoadCompletions())
return;
@@ -133,16 +133,16 @@
Ref<CSSFontFace> protectedFace(m_face);
- // If the font is in the cache, this will be synchronously called from CachedFont::addClient().
+ // If the font is in the cache, this will be synchronously called from FontLoadRequest::addClient().
if (m_status == Status::Pending)
setStatus(Status::Loading);
else if (m_status == Status::Failure) {
// This function may be called twice if loading was cancelled.
- ASSERT(m_font->errorOccurred());
+ ASSERT(m_fontRequest->errorOccurred());
return;
}
- if (m_font->errorOccurred() || !m_font->ensureCustomFontData(m_familyNameOrURI))
+ if (m_fontRequest->errorOccurred() || !m_fontRequest->ensureCustomFontData(m_familyNameOrURI))
setStatus(Status::Failure);
else
setStatus(Status::Success);
@@ -154,9 +154,10 @@
{
setStatus(Status::Loading);
- if (m_font) {
+ if (m_fontRequest) {
ASSERT(m_fontSelector);
- m_fontSelector->beginLoadingFontSoon(*m_font);
+ if (auto* context = m_fontSelector->scriptExecutionContext())
+ context->beginLoadingFontSoon(*m_fontRequest);
} else {
bool success = false;
if (m_hasSVGFontFaceElement) {
@@ -198,7 +199,7 @@
bool usesInDocumentSVGFont = m_hasSVGFontFaceElement;
- if (!m_font && !usesInDocumentSVGFont) {
+ if (!m_fontRequest && !usesInDocumentSVGFont) {
if (m_immediateSource) {
if (!m_immediateFontCustomPlatformData)
return nullptr;
@@ -210,12 +211,12 @@
return FontCache::singleton().fontForFamily(fontDescription, m_familyNameOrURI, &fontFaceFeatures, fontFaceCapabilities, true);
}
- if (m_font) {
- auto success = m_font->ensureCustomFontData(m_familyNameOrURI);
+ if (m_fontRequest) {
+ auto success = m_fontRequest->ensureCustomFontData(m_familyNameOrURI);
ASSERT_UNUSED(success, success);
ASSERT(status() == Status::Success);
- auto result = m_font->createFont(fontDescription, m_familyNameOrURI, syntheticBold, syntheticItalic, fontFaceFeatures, fontFaceCapabilities);
+ auto result = m_fontRequest->createFont(fontDescription, m_familyNameOrURI, syntheticBold, syntheticItalic, fontFaceFeatures, fontFaceCapabilities);
ASSERT(result);
return result;
}
@@ -232,7 +233,7 @@
bool CSSFontFaceSource::isSVGFontFaceSource() const
{
- return m_hasSVGFontFaceElement || is<CachedSVGFont>(m_font.get());
+ return m_hasSVGFontFaceElement || (is<CachedFontLoadRequest>(m_fontRequest.get()) && is<CachedSVGFont>(downcast<CachedFontLoadRequest>(m_fontRequest.get())->cachedFont()));
}
}
Modified: trunk/Source/WebCore/css/CSSFontFaceSource.h (275816 => 275817)
--- trunk/Source/WebCore/css/CSSFontFaceSource.h 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/css/CSSFontFaceSource.h 2021-04-12 09:26:42 UTC (rev 275817)
@@ -25,8 +25,7 @@
#pragma once
-#include "CachedFontClient.h"
-#include "CachedResourceHandle.h"
+#include "FontLoadRequest.h"
#include <_javascript_Core/ArrayBufferView.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/AtomString.h>
@@ -47,11 +46,11 @@
template <typename T> class FontTaggedSettings;
typedef FontTaggedSettings<int> FontFeatureSettings;
-class CSSFontFaceSource final : public CachedFontClient {
+class CSSFontFaceSource final : public FontLoadRequestClient {
WTF_MAKE_FAST_ALLOCATED;
public:
CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI);
- CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, CSSFontSelector&, CachedFont&);
+ CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, CSSFontSelector&, UniqueRef<FontLoadRequest>&&);
CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, SVGFontFaceElement&);
CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, Ref<JSC::ArrayBufferView>&&);
virtual ~CSSFontFaceSource();
@@ -76,8 +75,8 @@
void load(Document* = nullptr);
RefPtr<Font> font(const FontDescription&, bool syntheticBold, bool syntheticItalic, const FontFeatureSettings&, FontSelectionSpecifiedCapabilities);
- CachedFont* cachedFont() const { return m_font.get(); }
- bool requiresExternalResource() const { return m_font; }
+ FontLoadRequest* fontLoadRequest() const { return m_fontRequest.get(); }
+ bool requiresExternalResource() const { return m_fontRequest.get(); }
bool isSVGFontFaceSource() const;
@@ -84,7 +83,7 @@
private:
bool shouldIgnoreFontLoadCompletions() const;
- void fontLoaded(CachedFont&) override;
+ void fontLoaded(FontLoadRequest&) override;
void setStatus(Status);
@@ -91,7 +90,7 @@
AtomString m_familyNameOrURI; // URI for remote, built-in font name for local.
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.
+ std::unique_ptr<FontLoadRequest> m_fontRequest; // Also for remote fonts, a pointer to the resource request.
RefPtr<SharedBuffer> m_generatedOTFBuffer;
RefPtr<JSC::ArrayBufferView> m_immediateSource;
Modified: trunk/Source/WebCore/css/CSSFontFaceSrcValue.cpp (275816 => 275817)
--- trunk/Source/WebCore/css/CSSFontFaceSrcValue.cpp 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/css/CSSFontFaceSrcValue.cpp 2021-04-12 09:26:42 UTC (rev 275817)
@@ -29,10 +29,11 @@
#include "CachedResourceLoader.h"
#include "CachedResourceRequest.h"
#include "CachedResourceRequestInitiators.h"
-#include "Document.h"
#include "FontCustomPlatformData.h"
+#include "FontLoadRequest.h"
#include "Node.h"
#include "SVGFontFaceElement.h"
+#include "ScriptExecutionContext.h"
#include <wtf/text/StringBuilder.h>
namespace WebCore {
@@ -76,19 +77,16 @@
return handler(*m_cachedFont);
}
-CachedFont* CSSFontFaceSrcValue::cachedFont(Document* document, bool isSVG, bool isInitiatingElementInUserAgentShadowTree)
+std::unique_ptr<FontLoadRequest> CSSFontFaceSrcValue::fontLoadRequest(ScriptExecutionContext* context, bool isSVG, bool isInitiatingElementInUserAgentShadowTree)
{
if (m_cachedFont)
- return m_cachedFont.get();
+ return makeUnique<CachedFontLoadRequest>(*m_cachedFont);
- ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
- options.contentSecurityPolicyImposition = isInitiatingElementInUserAgentShadowTree ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
- options.loadedFromOpaqueSource = m_loadedFromOpaqueSource;
+ auto request = context->fontLoadRequest(m_resource, isSVG, isInitiatingElementInUserAgentShadowTree, m_loadedFromOpaqueSource);
+ if (is<CachedFontLoadRequest>(request.get()))
+ m_cachedFont = &downcast<CachedFontLoadRequest>(request.get())->cachedFont();
- CachedResourceRequest request(ResourceRequest(document->completeURL(m_resource)), options);
- request.setInitiator(cachedResourceRequestInitiators().css);
- m_cachedFont = document->cachedResourceLoader().requestFont(WTFMove(request), isSVG).value_or(nullptr);
- return m_cachedFont.get();
+ return request;
}
bool CSSFontFaceSrcValue::equals(const CSSFontFaceSrcValue& other) const
Modified: trunk/Source/WebCore/css/CSSFontFaceSrcValue.h (275816 => 275817)
--- trunk/Source/WebCore/css/CSSFontFaceSrcValue.h 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/css/CSSFontFaceSrcValue.h 2021-04-12 09:26:42 UTC (rev 275817)
@@ -34,8 +34,9 @@
namespace WebCore {
class CachedFont;
-class Document;
+class FontLoadRequest;
class SVGFontFaceElement;
+class ScriptExecutionContext;
class CSSFontFaceSrcValue final : public CSSValue {
public:
@@ -66,7 +67,7 @@
bool traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const;
- CachedFont* cachedFont(Document*, bool isSVG, bool isInitiatingElementInUserAgentShadowTree);
+ std::unique_ptr<FontLoadRequest> fontLoadRequest(ScriptExecutionContext*, bool isSVG, bool isInitiatingElementInUserAgentShadowTree);
bool equals(const CSSFontFaceSrcValue&) const;
Modified: trunk/Source/WebCore/css/CSSFontSelector.cpp (275816 => 275817)
--- trunk/Source/WebCore/css/CSSFontSelector.cpp 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/css/CSSFontSelector.cpp 2021-04-12 09:26:42 UTC (rev 275817)
@@ -68,7 +68,6 @@
, m_fontCache(makeRef(context.fontCache()))
, m_cssFontFaceSet(CSSFontFaceSet::create(this))
, m_fontModifiedObserver([this] { fontModified(); })
- , m_fontLoadingTimer(*this, &CSSFontSelector::fontLoadingTimerFired)
, m_uniqueId(++fontSelectorId)
, m_version(0)
{
@@ -93,7 +92,7 @@
{
LOG(Fonts, "CSSFontSelector %p dtor", this);
- stopLoadingAndClearFonts();
+ clearFonts();
m_fontCache->removeClient(*this);
}
@@ -336,94 +335,13 @@
return FontRanges { WTFMove(font) };
}
-void CSSFontSelector::stopLoadingAndClearFonts()
+void CSSFontSelector::clearFonts()
{
- if (m_isStopped) {
- ASSERT(!m_fontLoadingTimer.isActive());
- ASSERT(m_fontsToBeginLoading.isEmpty());
- return;
- }
-
m_isStopped = true;
- m_fontLoadingTimer.stop();
-
- if (is<Document>(m_context.get())) {
- auto& document = downcast<Document>(*m_context);
- CachedResourceLoader& cachedResourceLoader = document.cachedResourceLoader();
- for (auto& fontHandle : m_fontsToBeginLoading) {
- // Balances incrementRequestCount() in beginLoadingFontSoon().
- cachedResourceLoader.decrementRequestCount(*fontHandle);
- }
- m_fontsToBeginLoading.clear();
- }
-
m_cssFontFaceSet->clear();
m_clients.clear();
}
-void CSSFontSelector::beginLoadingFontSoon(CachedFont& font)
-{
- if (m_isStopped || !is<Document>(m_context.get()))
- return;
-
- auto& document = downcast<Document>(*m_context);
-
- m_fontsToBeginLoading.append(&font);
- // Increment the request count now, in order to prevent didFinishLoad from being dispatched
- // after this font has been requested but before it began loading. Balanced by
- // decrementRequestCount() in fontLoadingTimerFired() and in stopLoadingAndClearFonts().
- document.cachedResourceLoader().incrementRequestCount(font);
-
- if (!m_isFontLoadingSuspended && !m_fontLoadingTimer.isActive())
- m_fontLoadingTimer.startOneShot(0_s);
-}
-
-void CSSFontSelector::suspendFontLoadingTimer()
-{
- suspend(ReasonForSuspension::PageWillBeSuspended);
-}
-
-void CSSFontSelector::loadPendingFonts()
-{
- if (m_isFontLoadingSuspended || !is<Document>(m_context.get()))
- return;
-
- auto& document = downcast<Document>(*m_context);
-
- Vector<CachedResourceHandle<CachedFont>> fontsToBeginLoading;
- fontsToBeginLoading.swap(m_fontsToBeginLoading);
-
- // CSSFontSelector could get deleted via beginLoadIfNeeded() or loadDone() unless protected.
- Ref<CSSFontSelector> protectedThis(*this);
-
- CachedResourceLoader& cachedResourceLoader = document.cachedResourceLoader();
- for (auto& fontHandle : fontsToBeginLoading) {
- fontHandle->beginLoadIfNeeded(cachedResourceLoader);
- // Balances incrementRequestCount() in beginLoadingFontSoon().
- cachedResourceLoader.decrementRequestCount(*fontHandle);
- }
-}
-
-void CSSFontSelector::fontLoadingTimerFired()
-{
- if (!is<Document>(m_context.get()))
- return;
-
- auto& document = downcast<Document>(*m_context);
- Ref<CSSFontSelector> protectedThis(*this);
-
- loadPendingFonts();
-
- // FIXME: Use SubresourceLoader instead.
- // Call FrameLoader::loadDone before FrameLoader::subresourceLoadDone to match the order in SubresourceLoader::notifyDone.
- document.cachedResourceLoader().loadDone(LoadCompletionType::Finish);
- // Ensure that if the request count reaches zero, the frame loader will know about it.
- // New font loads may be triggered by layout after the document load is complete but before we have dispatched
- // didFinishLoading for the frame. Make sure the delegate is always dispatched by checking explicitly.
- if (document.frame())
- document.frame()->loader().checkLoadComplete();
-}
-
size_t CSSFontSelector::fallbackFontCount()
{
if (m_isStopped)
@@ -449,29 +367,4 @@
return font;
}
-void CSSFontSelector::stop()
-{
- m_fontLoadingTimer.stop();
}
-
-void CSSFontSelector::suspend(ReasonForSuspension)
-{
- if (m_isFontLoadingSuspended)
- return;
-
- m_isFontLoadingSuspended = true;
- m_fontLoadingTimer.stop();
-}
-
-void CSSFontSelector::resume()
-{
- if (!m_isFontLoadingSuspended)
- return;
-
- if (!m_fontsToBeginLoading.isEmpty())
- m_fontLoadingTimer.startOneShot(0_s);
-
- m_isFontLoadingSuspended = false;
-}
-
-}
Modified: trunk/Source/WebCore/css/CSSFontSelector.h (275816 => 275817)
--- trunk/Source/WebCore/css/CSSFontSelector.h 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/css/CSSFontSelector.h 2021-04-12 09:26:42 UTC (rev 275817)
@@ -64,7 +64,7 @@
size_t fallbackFontCount() final;
RefPtr<Font> fallbackFontAt(const FontDescription&, size_t) final;
- void stopLoadingAndClearFonts();
+ void clearFonts();
void emptyCaches();
void buildStarted();
void buildCompleted();
@@ -81,9 +81,6 @@
ScriptExecutionContext* scriptExecutionContext() const { return m_context.get(); }
- void beginLoadingFontSoon(CachedFont&);
- void suspendFontLoadingTimer();
-
FontFaceSet* fontFaceSetIfExists();
FontFaceSet& fontFaceSet();
@@ -110,12 +107,8 @@
void fontStyleUpdateNeeded(CSSFontFace&) final;
void fontModified();
- void fontLoadingTimerFired();
// ActiveDOMObject
- void stop() final;
- void suspend(ReasonForSuspension) final;
- void resume() final;
const char* activeDOMObjectName() const final { return "CSSFontSelector"_s; }
struct PendingFontFaceRule {
@@ -130,15 +123,11 @@
Ref<CSSFontFaceSet> m_cssFontFaceSet;
HashSet<FontSelectorClient*> m_clients;
- Vector<CachedResourceHandle<CachedFont>> m_fontsToBeginLoading;
HashSet<RefPtr<CSSFontFace>> m_cssConnectionsPossiblyToRemove;
HashSet<RefPtr<StyleRuleFontFace>> m_cssConnectionsEncounteredDuringBuild;
CSSFontFaceSet::FontModifiedObserver m_fontModifiedObserver;
- Timer m_fontLoadingTimer;
- bool m_isFontLoadingSuspended { false };
-
unsigned m_uniqueId;
unsigned m_version;
unsigned m_computingRootStyleFontCount { 0 };
Modified: trunk/Source/WebCore/dom/Document.cpp (275816 => 275817)
--- trunk/Source/WebCore/dom/Document.cpp 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/dom/Document.cpp 2021-04-12 09:26:42 UTC (rev 275817)
@@ -37,6 +37,7 @@
#include "CSSStyleDeclaration.h"
#include "CSSStyleSheet.h"
#include "CachedCSSStyleSheet.h"
+#include "CachedFontLoadRequest.h"
#include "CachedFrame.h"
#include "CachedResourceLoader.h"
#include "CanvasRenderingContext2D.h"
@@ -59,6 +60,7 @@
#include "DateComponents.h"
#include "DebugPageOverlays.h"
#include "DeprecatedGlobalSettings.h"
+#include "DocumentFontLoader.h"
#include "DocumentLoader.h"
#include "DocumentMarkerController.h"
#include "DocumentSharedObjectPool.h"
@@ -639,6 +641,7 @@
, m_visualUpdatesSuppressionTimer(*this, &Document::visualUpdatesSuppressionTimerFired)
, m_sharedObjectPoolClearTimer(*this, &Document::clearSharedObjectPool)
, m_fontSelector(CSSFontSelector::create(*this))
+ , m_fontLoader(makeUniqueRef<DocumentFontLoader>(*this))
, m_didAssociateFormControlsTimer(*this, &Document::didAssociateFormControlsTimerFired)
, m_cookieCacheExpiryTimer(*this, &Document::invalidateDOMCookieCache)
, m_socketProvider(page() ? &page()->socketProvider() : nullptr)
@@ -758,7 +761,7 @@
extensionStyleSheets().detachFromDocument();
styleScope().clearResolver(); // We need to destroy CSSFontSelector before destroying m_cachedResourceLoader.
- m_fontSelector->stopLoadingAndClearFonts();
+ m_fontLoader->stopLoadingAndClearFonts();
// It's possible for multiple Documents to end up referencing the same CachedResourceLoader (e.g., SVGImages
// load the initial empty document and the SVGDocument with the same DocumentLoader).
@@ -806,7 +809,7 @@
#endif
m_associatedFormControls.clear();
- m_fontSelector->stopLoadingAndClearFonts();
+ m_fontLoader->stopLoadingAndClearFonts();
detachParser();
@@ -2061,7 +2064,7 @@
m_inStyleRecalc = false;
- fontSelector().loadPendingFonts();
+ m_fontLoader->loadPendingFonts();
if (styleUpdate) {
updateRenderTree(WTFMove(styleUpdate));
@@ -2706,6 +2709,11 @@
#endif
}
+void Document::suspendFontLoading()
+{
+ m_fontLoader->suspendFontLoading();
+}
+
bool Document::shouldBypassMainWorldContentSecurityPolicy() const
{
// Bypass this policy when the world is known, and it not the normal world.
@@ -2991,6 +2999,19 @@
setReadyState(Loading);
}
+std::unique_ptr<FontLoadRequest> Document::fontLoadRequest(String& url, bool isSVG, bool isInitiatingElementInUserAgentShadowTree, LoadedFromOpaqueSource loadedFromOpaqueSource)
+{
+ auto* cachedFont = m_fontLoader->cachedFont(completeURL(url), isSVG, isInitiatingElementInUserAgentShadowTree, loadedFromOpaqueSource);
+ return cachedFont ? makeUnique<CachedFontLoadRequest>(*cachedFont) : nullptr;
+}
+
+void Document::beginLoadingFontSoon(FontLoadRequest& request)
+{
+ ASSERT(is<CachedFontLoadRequest>(request));
+ auto& font = downcast<CachedFontLoadRequest>(request).cachedFont();
+ m_fontLoader->beginLoadingFontSoon(font);
+}
+
HTMLBodyElement* Document::body() const
{
auto* element = documentElement();
@@ -5510,6 +5531,8 @@
m_visualUpdatesAllowed = false;
m_visualUpdatesSuppressionTimer.stop();
+ m_fontLoader->suspendFontLoading();
+
m_isSuspended = true;
}
@@ -5536,6 +5559,8 @@
m_visualUpdatesAllowed = true;
+ m_fontLoader->resumeFontLoading();
+
m_isSuspended = false;
#if ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/dom/Document.h (275816 => 275817)
--- trunk/Source/WebCore/dom/Document.h 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/dom/Document.h 2021-04-12 09:26:42 UTC (rev 275817)
@@ -122,6 +122,7 @@
class DeviceOrientationAndMotionAccessController;
class DeviceOrientationClient;
class DeviceOrientationController;
+class DocumentFontLoader;
class DocumentFragment;
class DocumentLoader;
class DocumentMarkerController;
@@ -137,6 +138,7 @@
class FloatQuad;
class FloatRect;
class FontFaceSet;
+class FontLoadRequest;
class FormController;
class Frame;
class FrameSelection;
@@ -627,6 +629,8 @@
void suspendDeviceMotionAndOrientationUpdates();
void resumeDeviceMotionAndOrientationUpdates();
+ void suspendFontLoading();
+
RenderView* renderView() const { return m_renderView.get(); }
bool renderTreeBeingDestroyed() const { return m_renderTreeBeingDestroyed; }
@@ -1641,6 +1645,8 @@
// ScriptExecutionContext
CSSFontSelector* cssFontSelector() final { return m_fontSelector.ptr(); }
+ std::unique_ptr<FontLoadRequest> fontLoadRequest(String&, bool, bool, LoadedFromOpaqueSource) final;
+ void beginLoadingFontSoon(FontLoadRequest&) final;
// FontSelectorClient
void fontsNeedUpdate(FontSelector&) final;
@@ -1974,6 +1980,7 @@
RefPtr<DocumentFragment> m_documentFragmentForInnerOuterHTML;
Ref<CSSFontSelector> m_fontSelector;
+ UniqueRef<DocumentFontLoader> m_fontLoader;
WeakHashSet<MediaProducer> m_audioProducers;
WeakPtr<SpeechRecognition> m_activeSpeechRecognition;
Added: trunk/Source/WebCore/dom/DocumentFontLoader.cpp (0 => 275817)
--- trunk/Source/WebCore/dom/DocumentFontLoader.cpp (rev 0)
+++ trunk/Source/WebCore/dom/DocumentFontLoader.cpp 2021-04-12 09:26:42 UTC (rev 275817)
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2021 Metrological Group B.V.
+ * Copyright (C) 2021 Igalia S.L.
+ * Copyright (C) 2007, 2008, 2011, 2013 Apple Inc. All rights reserved.
+ * (C) 2007, 2008 Nikolas Zimmermann <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DocumentFontLoader.h"
+
+#include "CachedFont.h"
+#include "CachedResourceRequest.h"
+#include "CachedResourceRequestInitiators.h"
+
+namespace WebCore {
+
+DocumentFontLoader::DocumentFontLoader(Document& document)
+ : m_document(document)
+ , m_fontLoadingTimer(*this, &DocumentFontLoader::fontLoadingTimerFired)
+{
+}
+
+DocumentFontLoader::~DocumentFontLoader()
+{
+ stopLoadingAndClearFonts();
+}
+
+CachedFont* DocumentFontLoader::cachedFont(URL&& url, bool isSVG, bool isInitiatingElementInUserAgentShadowTree, LoadedFromOpaqueSource loadedFromOpaqueSource)
+{
+ ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
+ options.contentSecurityPolicyImposition = isInitiatingElementInUserAgentShadowTree ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
+ options.loadedFromOpaqueSource = loadedFromOpaqueSource;
+
+ CachedResourceRequest request(ResourceRequest(WTFMove(url)), options);
+ request.setInitiator(cachedResourceRequestInitiators().css);
+ return m_document.cachedResourceLoader().requestFont(WTFMove(request), isSVG).value_or(nullptr).get();
+}
+
+void DocumentFontLoader::beginLoadingFontSoon(CachedFont& font)
+{
+ if (m_isStopped)
+ return;
+
+ m_fontsToBeginLoading.append(&font);
+ // Increment the request count now, in order to prevent didFinishLoad from being dispatched
+ // after this font has been requested but before it began loading. Balanced by
+ // decrementRequestCount() in fontLoadingTimerFired() and in stopLoadingAndClearFonts().
+ m_document.cachedResourceLoader().incrementRequestCount(font);
+
+ if (!m_isFontLoadingSuspended && !m_fontLoadingTimer.isActive())
+ m_fontLoadingTimer.startOneShot(0_s);
+}
+
+void DocumentFontLoader::loadPendingFonts()
+{
+ if (m_isFontLoadingSuspended)
+ return;
+
+ Vector<CachedResourceHandle<CachedFont>> fontsToBeginLoading;
+ fontsToBeginLoading.swap(m_fontsToBeginLoading);
+
+ auto& cachedResourceLoader = m_document.cachedResourceLoader();
+ for (auto& fontHandle : fontsToBeginLoading) {
+ fontHandle->beginLoadIfNeeded(cachedResourceLoader);
+ // Balances incrementRequestCount() in beginLoadingFontSoon().
+ cachedResourceLoader.decrementRequestCount(*fontHandle);
+ }
+}
+
+void DocumentFontLoader::fontLoadingTimerFired()
+{
+ loadPendingFonts();
+
+ // FIXME: Use SubresourceLoader instead.
+ // Call FrameLoader::loadDone before FrameLoader::subresourceLoadDone to match the order in SubresourceLoader::notifyDone.
+ m_document.cachedResourceLoader().loadDone(LoadCompletionType::Finish);
+ // Ensure that if the request count reaches zero, the frame loader will know about it.
+ // New font loads may be triggered by layout after the document load is complete but before we have dispatched
+ // didFinishLoading for the frame. Make sure the delegate is always dispatched by checking explicitly.
+ if (m_document.frame())
+ m_document.frame()->loader().checkLoadComplete();
+}
+
+void DocumentFontLoader::stopLoadingAndClearFonts()
+{
+ if (m_isStopped)
+ return;
+
+ m_fontLoadingTimer.stop();
+ auto& cachedResourceLoader = m_document.cachedResourceLoader();
+ for (auto& fontHandle : m_fontsToBeginLoading) {
+ // Balances incrementRequestCount() in beginLoadingFontSoon().
+ cachedResourceLoader.decrementRequestCount(*fontHandle);
+ }
+ m_fontsToBeginLoading.clear();
+ m_document.fontSelector().clearFonts();
+
+ m_isFontLoadingSuspended = true;
+ m_isStopped = true;
+}
+
+void DocumentFontLoader::suspendFontLoading()
+{
+ if (m_isFontLoadingSuspended)
+ return;
+
+ m_fontLoadingTimer.stop();
+ m_isFontLoadingSuspended = true;
+}
+
+void DocumentFontLoader::resumeFontLoading()
+{
+ if (!m_isFontLoadingSuspended || m_isStopped)
+ return;
+
+ m_isFontLoadingSuspended = false;
+ if (!m_fontsToBeginLoading.isEmpty())
+ m_fontLoadingTimer.startOneShot(0_s);
+}
+
+} // namespace WebCore
Added: trunk/Source/WebCore/dom/DocumentFontLoader.h (0 => 275817)
--- trunk/Source/WebCore/dom/DocumentFontLoader.h (rev 0)
+++ trunk/Source/WebCore/dom/DocumentFontLoader.h 2021-04-12 09:26:42 UTC (rev 275817)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2021 Metrological Group B.V.
+ * Copyright (C) 2021 Igalia S.L.
+ * Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "CachedResourceHandle.h"
+#include "Document.h"
+#include "Timer.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class CachedFont;
+
+class DocumentFontLoader {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ DocumentFontLoader(Document&);
+ ~DocumentFontLoader();
+
+ CachedFont* cachedFont(URL&&, bool, bool, LoadedFromOpaqueSource);
+ void beginLoadingFontSoon(CachedFont&);
+
+ void loadPendingFonts();
+ void stopLoadingAndClearFonts();
+
+ void suspendFontLoading();
+ void resumeFontLoading();
+
+private:
+ void fontLoadingTimerFired();
+
+ Document& m_document;
+ Timer m_fontLoadingTimer;
+ Vector<CachedResourceHandle<CachedFont>> m_fontsToBeginLoading;
+ bool m_isFontLoadingSuspended { false };
+ bool m_isStopped { false };
+};
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (275816 => 275817)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2021-04-12 09:26:42 UTC (rev 275817)
@@ -36,6 +36,7 @@
#include "Document.h"
#include "ErrorEvent.h"
#include "FontCache.h"
+#include "FontLoadRequest.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMWindow.h"
#include "JSWorkerGlobalScope.h"
@@ -232,6 +233,11 @@
return FontCache::singleton();
}
+std::unique_ptr<FontLoadRequest> ScriptExecutionContext::fontLoadRequest(String&, bool, bool, LoadedFromOpaqueSource)
+{
+ return nullptr;
+}
+
void ScriptExecutionContext::forEachActiveDOMObject(const Function<ShouldContinue(ActiveDOMObject&)>& apply) const
{
// It is not allowed to run arbitrary script or construct new ActiveDOMObjects while we are iterating over ActiveDOMObjects.
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (275816 => 275817)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.h 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h 2021-04-12 09:26:42 UTC (rev 275817)
@@ -30,6 +30,7 @@
#include "ActiveDOMObject.h"
#include "DOMTimer.h"
#include "RTCDataChannelRemoteHandlerConnection.h"
+#include "ResourceLoaderOptions.h"
#include "ScriptExecutionContextIdentifier.h"
#include "SecurityContext.h"
#include "ServiceWorkerTypes.h"
@@ -66,6 +67,7 @@
class EventLoopTaskGroup;
class EventTarget;
class FontCache;
+class FontLoadRequest;
class MessagePort;
class PublicURLManager;
class RejectedPromiseTracker;
@@ -165,6 +167,8 @@
virtual FontCache& fontCache();
virtual CSSFontSelector* cssFontSelector() { return nullptr; }
+ virtual std::unique_ptr<FontLoadRequest> fontLoadRequest(String& url, bool isSVG, bool isInitiatingElementInUserAgentShadowTree, LoadedFromOpaqueSource);
+ virtual void beginLoadingFontSoon(FontLoadRequest&) { }
void ref() { refScriptExecutionContext(); }
void deref() { derefScriptExecutionContext(); }
Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (275816 => 275817)
--- trunk/Source/WebCore/loader/DocumentLoader.cpp 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp 2021-04-12 09:26:42 UTC (rev 275817)
@@ -33,7 +33,6 @@
#include "ApplicationCacheHost.h"
#include "Archive.h"
#include "ArchiveResourceCollection.h"
-#include "CSSFontSelector.h"
#include "CachedPage.h"
#include "CachedRawResource.h"
#include "CachedResourceLoader.h"
@@ -338,7 +337,7 @@
cancelAll(m_multipartSubresourceLoaders);
if (auto* document = this->document())
- document->fontSelector().suspendFontLoadingTimer();
+ document->suspendFontLoading();
// Appcache uses ResourceHandle directly, DocumentLoader doesn't count these loads.
m_applicationCacheHost->stopLoadingInFrame(*m_frame);
Added: trunk/Source/WebCore/loader/FontLoadRequest.h (0 => 275817)
--- trunk/Source/WebCore/loader/FontLoadRequest.h (rev 0)
+++ trunk/Source/WebCore/loader/FontLoadRequest.h 2021-04-12 09:26:42 UTC (rev 275817)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2021 Metrological Group B.V.
+ * Copyright (C) 2021 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "FontTaggedSettings.h"
+#include <wtf/text/AtomString.h>
+
+namespace WebCore {
+
+class Font;
+class FontDescription;
+class FontLoadRequest;
+struct FontSelectionSpecifiedCapabilities;
+
+template <typename T> class FontTaggedSettings;
+using FontFeatureSettings = FontTaggedSettings<int>;
+
+class FontLoadRequestClient {
+public:
+ virtual ~FontLoadRequestClient() = default;
+ virtual void fontLoaded(FontLoadRequest&) { }
+};
+
+class FontLoadRequest {
+public:
+ virtual ~FontLoadRequest() = default;
+
+ virtual const URL& url() const = 0;
+ virtual bool isLoading() const = 0;
+ virtual bool errorOccurred() const = 0;
+
+ virtual bool ensureCustomFontData(const AtomString& remoteURI) = 0;
+ virtual RefPtr<Font> createFont(const FontDescription&, const AtomString& remoteURI, bool syntheticBold, bool syntheticItalic, const FontFeatureSettings&, FontSelectionSpecifiedCapabilities) = 0;
+
+ virtual void setClient(FontLoadRequestClient*) = 0;
+
+ virtual bool isCachedFontLoadRequest() const { return false; }
+};
+
+} // namespace WebCore
+
+#define SPECIALIZE_TYPE_TRAITS_FONTLOADREQUEST(ToValueTypeName, predicate) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(ToValueTypeName) \
+ static bool isType(const WebCore::FontLoadRequest& request) { return request.predicate; } \
+SPECIALIZE_TYPE_TRAITS_END()
Added: trunk/Source/WebCore/loader/cache/CachedFontLoadRequest.h (0 => 275817)
--- trunk/Source/WebCore/loader/cache/CachedFontLoadRequest.h (rev 0)
+++ trunk/Source/WebCore/loader/cache/CachedFontLoadRequest.h 2021-04-12 09:26:42 UTC (rev 275817)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2021 Metrological Group B.V.
+ * Copyright (C) 2021 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "CachedFont.h"
+#include "CachedFontClient.h"
+#include "CachedResourceHandle.h"
+#include "FontLoadRequest.h"
+
+namespace WebCore {
+
+class CachedFontLoadRequest final : public FontLoadRequest, public CachedFontClient {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ CachedFontLoadRequest(CachedFont& font)
+ : m_font(&font)
+ {
+ }
+
+ ~CachedFontLoadRequest()
+ {
+ if (m_fontLoadRequestClient)
+ m_font->removeClient(*this);
+ }
+
+ CachedFont& cachedFont() const { return *m_font; }
+
+private:
+ const URL& url() const final { return m_font->url(); }
+ bool isLoading() const final { return m_font->isLoading(); }
+ bool errorOccurred() const final { return m_font->errorOccurred(); }
+
+ bool ensureCustomFontData(const AtomString& remoteURI) final { return m_font->ensureCustomFontData(remoteURI); }
+ RefPtr<Font> createFont(const FontDescription& description, const AtomString& remoteURI, bool syntheticBold, bool syntheticItalic, const FontFeatureSettings& settings, FontSelectionSpecifiedCapabilities capabilities) final
+ {
+ return m_font->createFont(description, remoteURI, syntheticBold, syntheticItalic, settings, capabilities);
+ }
+
+ void setClient(FontLoadRequestClient* client) final
+ {
+ auto* oldClient = m_fontLoadRequestClient;
+ m_fontLoadRequestClient = client;
+
+ if (!client && oldClient)
+ m_font->removeClient(*this);
+ else if (client && !oldClient)
+ m_font->addClient(*this);
+ }
+
+ bool isCachedFontLoadRequest() const final { return true; }
+
+ void fontLoaded(CachedFont& font) final
+ {
+ ASSERT_UNUSED(font, &font == m_font.get());
+ if (m_fontLoadRequestClient)
+ m_fontLoadRequestClient->fontLoaded(*this);
+ }
+
+ CachedResourceHandle<CachedFont> m_font;
+ FontLoadRequestClient* m_fontLoadRequestClient { nullptr };
+};
+
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_FONTLOADREQUEST(WebCore::CachedFontLoadRequest, isCachedFontLoadRequest())
Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (275816 => 275817)
--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2021-04-12 08:13:16 UTC (rev 275816)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2021-04-12 09:26:42 UTC (rev 275817)
@@ -112,8 +112,6 @@
allWorkerGlobalScopeIdentifiers(locker).remove(contextIdentifier());
}
- if (m_cssFontSelector)
- m_cssFontSelector->stopLoadingAndClearFonts();
m_performance = nullptr;
m_crypto = nullptr;