LibWeb: Implement Resource Timing

This commit is contained in:
Luke Wilde 2025-02-26 15:51:05 +00:00 committed by Andrew Kaster
commit 6d1f78198d
Notes: github-actions[bot] 2025-03-06 16:01:58 +00:00
21 changed files with 741 additions and 14 deletions

View file

@ -53,6 +53,7 @@
#include <LibWeb/MixedContent/AbstractOperations.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/ReferrerPolicy/AbstractOperations.h>
#include <LibWeb/ResourceTiming/PerformanceResourceTiming.h>
#include <LibWeb/SRI/SRI.h>
#include <LibWeb/SecureContexts/AbstractOperations.h>
#include <LibWeb/Streams/TransformStream.h>
@ -687,13 +688,11 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
body_info.content_type = MimeSniff::minimise_a_supported_mime_type(mime_type.value());
}
// FIXME: 8. If fetchParamss requests initiator type is not null, then mark resource timing given timingInfo,
// requests URL, requests initiator type, global, cacheState, bodyInfo, and responseStatus.
(void)timing_info;
(void)global;
(void)cache_state;
(void)body_info;
(void)response_status;
// 8. If fetchParamss requests initiator type is not null, then mark resource timing given timingInfo,
// requests URL, requests initiator type, global, cacheState, bodyInfo, and responseStatus.
if (fetch_params.request()->initiator_type().has_value()) {
ResourceTiming::PerformanceResourceTiming::mark_resource_timing(timing_info, fetch_params.request()->url().to_string(), Infrastructure::initiator_type_to_string(fetch_params.request()->initiator_type().value()), global, cache_state, body_info, response_status);
}
});
// 4. Let processResponseEndOfBodyTask be the following steps:

View file

@ -442,6 +442,55 @@ StringView request_mode_to_string(Request::Mode mode)
VERIFY_NOT_REACHED();
}
FlyString initiator_type_to_string(Request::InitiatorType initiator_type)
{
switch (initiator_type) {
case Request::InitiatorType::Audio:
return "audio"_fly_string;
case Request::InitiatorType::Beacon:
return "beacon"_fly_string;
case Request::InitiatorType::Body:
return "body"_fly_string;
case Request::InitiatorType::CSS:
return "css"_fly_string;
case Request::InitiatorType::EarlyHint:
return "early-hints"_fly_string;
case Request::InitiatorType::Embed:
return "embed"_fly_string;
case Request::InitiatorType::Fetch:
return "fetch"_fly_string;
case Request::InitiatorType::Font:
return "font"_fly_string;
case Request::InitiatorType::Frame:
return "frame"_fly_string;
case Request::InitiatorType::IFrame:
return "iframe"_fly_string;
case Request::InitiatorType::Image:
return "image"_fly_string;
case Request::InitiatorType::IMG:
return "img"_fly_string;
case Request::InitiatorType::Input:
return "input"_fly_string;
case Request::InitiatorType::Link:
return "link"_fly_string;
case Request::InitiatorType::Object:
return "object"_fly_string;
case Request::InitiatorType::Ping:
return "ping"_fly_string;
case Request::InitiatorType::Script:
return "script"_fly_string;
case Request::InitiatorType::Track:
return "track"_fly_string;
case Request::InitiatorType::Video:
return "video"_fly_string;
case Request::InitiatorType::XMLHttpRequest:
return "xmlhttprequest"_fly_string;
case Request::InitiatorType::Other:
return "other"_fly_string;
}
VERIFY_NOT_REACHED();
}
Optional<Request::Priority> request_priority_from_string(StringView string)
{
if (string.equals_ignoring_ascii_case("high"sv))

View file

@ -531,6 +531,7 @@ private:
StringView request_destination_to_string(Request::Destination);
StringView request_mode_to_string(Request::Mode);
FlyString initiator_type_to_string(Request::InitiatorType);
Optional<Request::Priority> request_priority_from_string(StringView);