Skip to content

Commit

Permalink
Cherry-pick 271213@main (b1f4d81). https://bugs.webkit.org/show_bug.c…
Browse files Browse the repository at this point in the history
…gi?id=265000

    FontFace with data: URI crashes Worker
    https://bugs.webkit.org/show_bug.cgi?id=265000
    rdar://118546120

    Reviewed by Alex Christensen.

    Make sure to reject the promise when font loading fails in a worker.
    Align implementation with spec on data URL font loading by allowing them.

    * LayoutTests/http/wpt/workers/font-loading-error.any-expected.txt: Added.
    * LayoutTests/http/wpt/workers/font-loading-error.any.html: Added.
    * LayoutTests/http/wpt/workers/font-loading-error.any.js: Added.
    (promise_test.async return):
    (promise_test):
    * LayoutTests/http/wpt/workers/font-loading-error.any.worker-expected.txt: Added.
    * LayoutTests/http/wpt/workers/font-loading-error.any.worker.html: Added.
    * Source/WebCore/dom/DocumentFontLoader.cpp:
    (WebCore::DocumentFontLoader::cachedFont):
    * Source/WebCore/workers/WorkerFontLoadRequest.cpp:
    (WebCore::WorkerFontLoadRequest::load):
    (WebCore::WorkerFontLoadRequest::didFail):

    Canonical link: https://commits.webkit.org/271213@main
  • Loading branch information
youennf authored and aperezdc committed Jan 26, 2024
1 parent 1df901e commit ab51672
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

PASS Data URL should not trigger CORS errors and if failing should reject the promise.

1 change: 1 addition & 0 deletions LayoutTests/http/wpt/workers/font-loading-error.any.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
5 changes: 5 additions & 0 deletions LayoutTests/http/wpt/workers/font-loading-error.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
promise_test(async () => {
return new FontFace("ABC", "url(data:font/woff2,abcd) format('woff2')").load().catch(e => {
assert_equals(e.name, "NetworkError");
});
}, "Data URL should not trigger CORS errors and if failing should reject the promise.");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

PASS Data URL should not trigger CORS errors and if failing should reject the promise.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
1 change: 1 addition & 0 deletions Source/WebCore/dom/DocumentFontLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ CachedFont* DocumentFontLoader::cachedFont(URL&& url, bool isSVG, bool isInitiat
ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
options.contentSecurityPolicyImposition = isInitiatingElementInUserAgentShadowTree ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
options.loadedFromOpaqueSource = loadedFromOpaqueSource;
options.sameOriginDataURLFlag = SameOriginDataURLFlag::Set;

CachedResourceRequest request(ResourceRequest(WTFMove(url)), options);
request.setInitiatorType(cachedResourceRequestInitiatorTypes().css);
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/workers/WorkerFontLoadRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void WorkerFontLoadRequest::load(WorkerGlobalScope& workerGlobalScope)
options.sendLoadCallbacks = SendCallbackPolicy::SendCallbacks;
options.contentSecurityPolicyEnforcement = m_context->shouldBypassMainWorldContentSecurityPolicy() ? ContentSecurityPolicyEnforcement::DoNotEnforce : ContentSecurityPolicyEnforcement::EnforceWorkerSrcDirective;
options.loadedFromOpaqueSource = m_loadedFromOpaqueSource;
options.sameOriginDataURLFlag = SameOriginDataURLFlag::Set;

options.serviceWorkersMode = ServiceWorkersMode::All;
#if ENABLE(SERVICE_WORKER)
Expand Down Expand Up @@ -138,6 +139,8 @@ void WorkerFontLoadRequest::didFinishLoading(ResourceLoaderIdentifier, const Net
void WorkerFontLoadRequest::didFail(const ResourceError&)
{
m_errorOccurred = true;
if (m_fontLoadRequestClient)
m_fontLoadRequestClient->fontLoaded(*this);
}

} // namespace WebCore

0 comments on commit ab51672

Please sign in to comment.