Skip to content

Commit 6057719

Browse files
trflynn89awesomekling
authored andcommitted
LibWeb: Use fetch to retrieve all HTMLLinkElement resources
HTMLLinkElement is the final user of Resource/ResourceClient (used for preloads and icons). This ports these link types to use fetch according to the spec. Preloads were particularly goofy because they would be stored in the ResourceLoader's ad-hoc cache. But this cache was never consulted for organic loads, thus were never used. There is more work to be done to use these preloads within fetch, but for now they at least are stored in fetch's HTTP cache for re-use.
1 parent c61fa1d commit 6057719

File tree

4 files changed

+582
-140
lines changed

4 files changed

+582
-140
lines changed

Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,7 @@ void Request::set_url(URL::URL url)
9090
// https://fetch.spec.whatwg.org/#request-destination-script-like
9191
bool Request::destination_is_script_like() const
9292
{
93-
// A request’s destination is script-like if it is "audioworklet", "paintworklet", "script", "serviceworker", "sharedworker", or "worker".
94-
static constexpr Array script_like_destinations = {
95-
Destination::AudioWorklet,
96-
Destination::PaintWorklet,
97-
Destination::Script,
98-
Destination::ServiceWorker,
99-
Destination::SharedWorker,
100-
Destination::Worker,
101-
};
102-
return any_of(script_like_destinations, [this](auto destination) {
103-
return m_destination == destination;
104-
});
93+
return m_destination.has_value() && Infrastructure::destination_is_script_like(*m_destination);
10594
}
10695

10796
// https://fetch.spec.whatwg.org/#subresource-request
@@ -452,6 +441,76 @@ StringView request_destination_to_string(Request::Destination destination)
452441
VERIFY_NOT_REACHED();
453442
}
454443

444+
// https://fetch.spec.whatwg.org/#concept-potential-destination-translate
445+
Optional<Request::Destination> translate_potential_destination(StringView potential_destination)
446+
{
447+
// 1. If potentialDestination is "fetch", then return the empty string.
448+
if (potential_destination == "fetch"sv)
449+
return {};
450+
451+
// 2. Assert: potentialDestination is a destination.
452+
// 3. Return potentialDestination.
453+
if (potential_destination == "audio"sv)
454+
return Request::Destination::Audio;
455+
if (potential_destination == "audioworklet"sv)
456+
return Request::Destination::AudioWorklet;
457+
if (potential_destination == "document"sv)
458+
return Request::Destination::Document;
459+
if (potential_destination == "embed"sv)
460+
return Request::Destination::Embed;
461+
if (potential_destination == "font"sv)
462+
return Request::Destination::Font;
463+
if (potential_destination == "frame"sv)
464+
return Request::Destination::Frame;
465+
if (potential_destination == "iframe"sv)
466+
return Request::Destination::IFrame;
467+
if (potential_destination == "image"sv)
468+
return Request::Destination::Image;
469+
if (potential_destination == "json"sv)
470+
return Request::Destination::JSON;
471+
if (potential_destination == "manifest"sv)
472+
return Request::Destination::Manifest;
473+
if (potential_destination == "object"sv)
474+
return Request::Destination::Object;
475+
if (potential_destination == "paintworklet"sv)
476+
return Request::Destination::PaintWorklet;
477+
if (potential_destination == "report"sv)
478+
return Request::Destination::Report;
479+
if (potential_destination == "script"sv)
480+
return Request::Destination::Script;
481+
if (potential_destination == "serviceworker"sv)
482+
return Request::Destination::ServiceWorker;
483+
if (potential_destination == "sharedworker"sv)
484+
return Request::Destination::SharedWorker;
485+
if (potential_destination == "style"sv)
486+
return Request::Destination::Style;
487+
if (potential_destination == "track"sv)
488+
return Request::Destination::Track;
489+
if (potential_destination == "video"sv)
490+
return Request::Destination::Video;
491+
if (potential_destination == "webidentity"sv)
492+
return Request::Destination::WebIdentity;
493+
if (potential_destination == "worker"sv)
494+
return Request::Destination::Worker;
495+
if (potential_destination == "xslt"sv)
496+
return Request::Destination::XSLT;
497+
VERIFY_NOT_REACHED();
498+
}
499+
500+
// https://fetch.spec.whatwg.org/#request-destination-script-like
501+
bool destination_is_script_like(Request::Destination destination)
502+
{
503+
// A request’s destination is script-like if it is "audioworklet", "paintworklet", "script", "serviceworker",
504+
// "sharedworker", or "worker".
505+
return first_is_one_of(destination,
506+
Request::Destination::AudioWorklet,
507+
Request::Destination::PaintWorklet,
508+
Request::Destination::Script,
509+
Request::Destination::ServiceWorker,
510+
Request::Destination::SharedWorker,
511+
Request::Destination::Worker);
512+
}
513+
455514
StringView request_mode_to_string(Request::Mode mode)
456515
{
457516
switch (mode) {

Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ class WEB_API Request final : public JS::Cell {
537537
};
538538

539539
WEB_API StringView request_destination_to_string(Request::Destination);
540+
Optional<Request::Destination> translate_potential_destination(StringView potential_destination);
541+
bool destination_is_script_like(Request::Destination);
542+
540543
WEB_API StringView request_mode_to_string(Request::Mode);
541544
WEB_API FlyString initiator_type_to_string(Request::InitiatorType);
542545

0 commit comments

Comments
 (0)