We should replace all direct uses of ResourceLoader with Fetch. This is because using ResourceLoader bypasses many features that Fetch handles:
All security mechanisms (CORS-preflight, Mixed Content, Content Security Policy, bad ports, Sec-Fetch-* headers, Referrer Policy, etc.)
Service Workers (not yet implemented)
Caching
Redirects
Blob URLs
Resource Timing (not yet implemented, required for #226 )
Referrers
More that I can't think as of writing.
These are the usages I could find:
HTMLLinkElement
// FIXME: Follow spec for fetching and processing these attributes as well
if (m_relationship & Relationship::Preload) {
// FIXME: Respect the "as" attribute.
LoadRequest request;
request.set_url (document ().parse_url (get_attribute_value (HTML::AttributeNames::href)));
set_resource (ResourceLoader::the ().load_resource (Resource::Type::Generic, request));
} else if (m_relationship & Relationship::DNSPrefetch) {
ResourceLoader::the ().prefetch_dns (document ().parse_url (get_attribute_value (HTML::AttributeNames::href)));
} else if (m_relationship & Relationship::Preconnect) {
ResourceLoader::the ().preconnect (document ().parse_url (get_attribute_value (HTML::AttributeNames::href)));
} else if (m_relationship & Relationship::Icon) {
auto favicon_url = document ().parse_url (href ());
auto favicon_request = LoadRequest::create_for_url_on_page (favicon_url, &document ().page ());
set_resource (ResourceLoader::the ().load_resource (Resource::Type::Generic, favicon_request));
}
Font Loading in StyleComputer.cpp
// HACK: We're crudely computing the referer value and shoving it into the
// request until fetch infrastructure is used here.
auto referrer_url = ReferrerPolicy::strip_url_for_use_as_referrer (m_style_computer.document ().url ());
if (referrer_url.has_value () && !request.headers ().contains (" Referer" ))
request.set_header (" Referer" , referrer_url->serialize ());
set_resource (ResourceLoader::the ().load_resource (Resource::Type::Generic, request));
CSSImportRule
dbgln_if (CSS_LOADER_DEBUG, " CSSImportRule: Loading import URL: {}" , m_url);
auto request = LoadRequest::create_for_url_on_page (m_url, &document.page ());
// NOTE: Mark this rule as delaying the document load event *before* calling set_resource()
// as it may trigger a synchronous resource_did_load() callback.
m_document_load_event_delayer.emplace (document);
set_resource (ResourceLoader::the ().load_resource (Resource::Type::Generic, request));
HTMLObjectElement
// 4. Let request be a new request whose URL is the resulting URL record, client is the element's node document's relevant settings object, destination is "object", credentials mode is "include", mode is "navigate", and whose use-URL-credentials flag is set.
auto request = LoadRequest::create_for_url_on_page (url, &document ().page ());
// 5. Fetch request, with processResponseEndOfBody given response res set to finalize and report timing with res, the element's node document's relevant global object, and "object".
// Fetching the resource must delay the load event of the element's node document until the task that is queued by the networking task source once the resource has been fetched (defined next) has been run.
set_resource (ResourceLoader::the ().load_resource (Resource::Type::Generic, request));
With these replaced, we could remove load_resource
and potentially badge load
and load_unbuffered
to only be called from Fetch.