Skip to content
Browse files
Fire error event when link preload fails synchronously.

Reviewed by Youenn Fablet.

This fires an error event when fetch fails before scheduling with the
Network process when preloading a resource specified by a link element.

The code path for firing error events in case of a network error is to return
a CachedResource with an error state to a LinkPreloadResourceClient. The client
then calls the LinkLoader with the resource and the loader in turn has the
HTMLLinkElement fire an event depending on the state of the resource returned.

This code path never executes when we block due to CSP since we do not get to the
point of scheduling the load with the Network process or even creating the
LinkPreloadResourceClient. This change detects that condition and has the HTMLLinkElement
fire an error event.

See the spec for The fetch and process the linked resource steps here:

In particular, we are supposed to return a "network error" when blocking due to
CSP and so we should fire an error event:

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/content-security-policy/font-src/font-mismatch-blocked.sub-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/content-security-policy/font-src/font-none-blocked.sub-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/content-security-policy/reporting/report-preload-and-consume.https-expected.txt:

* Source/WebCore/loader/LinkLoader.cpp:
* Source/WebCore/loader/LinkLoader.h:

Canonical link:
  • Loading branch information
rreno committed Oct 19, 2022
1 parent a7b9e4e commit 6bab27e2e35e1637493df40e8d4c296586b23f73
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
@@ -1039,8 +1039,6 @@ imported/w3c/web-platform-tests/content-security-policy/svg/including.sub.svg [

# Skip Content Security Policy tests that time out
imported/w3c/web-platform-tests/content-security-policy/child-src/child-src-cross-origin-load.sub.html [ Skip ]
imported/w3c/web-platform-tests/content-security-policy/font-src/font-mismatch-blocked.sub.html [ Skip ]
imported/w3c/web-platform-tests/content-security-policy/font-src/font-none-blocked.sub.html [ Skip ]
imported/w3c/web-platform-tests/content-security-policy/frame-ancestors/frame-ancestors-nested-cross-in-cross-none-block.html [ Skip ]
imported/w3c/web-platform-tests/content-security-policy/frame-ancestors/frame-ancestors-nested-cross-in-cross-self-block.html [ Skip ]
imported/w3c/web-platform-tests/content-security-policy/frame-ancestors/frame-ancestors-nested-cross-in-cross-star-allow.html [ Skip ]
@@ -1,5 +1,3 @@

Harness Error (TIMEOUT), message = null

TIMEOUT Test font does not load if it does not match font-src. Test timed out
PASS Test font does not load if it does not match font-src.

@@ -1,5 +1,3 @@

Harness Error (TIMEOUT), message = null

TIMEOUT Test font does not load if it does not match font-src. Test timed out
PASS Test font does not load if it does not match font-src.

@@ -1,3 +1,3 @@

FAIL Reporting endpoints received credentials. assert_equals: expected 2 but got 1
PASS Reporting endpoints received credentials.

@@ -84,6 +84,11 @@ void LinkLoader::triggerEvents(const CachedResource& resource)

void LinkLoader::triggerError()

void LinkLoader::notifyFinished(CachedResource& resource, const NetworkLoadMetrics&)
ASSERT_UNUSED(resource, m_cachedLinkResource.get() == &resource);
@@ -321,6 +326,9 @@ std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preloadIfNeeded(const Lin

if (cachedLinkResource && loader)
return createLinkPreloadResourceClient(*cachedLinkResource, *loader, document);

if (loader)
return nullptr;

@@ -70,6 +70,7 @@ class LinkLoader : public CachedResourceClient {
static bool isSupportedType(CachedResource::Type, const String& mimeType, Document&);

void triggerEvents(const CachedResource&);
void triggerError();
void cancelLoad();


0 comments on commit 6bab27e

Please sign in to comment.