mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibWeb/Fetch: Update timing info with the timings received from RS
This commit is contained in:
parent
618697ef13
commit
23c84e62a5
Notes:
github-actions[bot]
2025-03-06 16:02:04 +00:00
Author: https://github.com/Lubrsi
Commit: 23c84e62a5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3704
Reviewed-by: https://github.com/ADKaster ✅
4 changed files with 77 additions and 4 deletions
|
@ -650,7 +650,10 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
|
|||
return;
|
||||
|
||||
// 2. Set timingInfo’s end time to the relative high resolution time given unsafeEndTime and global.
|
||||
timing_info->set_end_time(HighResolutionTime::relative_high_resolution_time(unsafe_end_time, global));
|
||||
// Spec Issue: Using relative time here is incorrect, as end time is converted to relative time by Resource Timing,
|
||||
// causing it to take a relative time of an already relative time, effectively make it always a negative
|
||||
// value approximately the value of the time origin.
|
||||
timing_info->set_end_time(unsafe_end_time);
|
||||
|
||||
// 3. Let cacheState be response’s cache state.
|
||||
auto cache_state = response.cache_state();
|
||||
|
@ -2270,6 +2273,9 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> nonstandard_resource_loader_file_o
|
|||
{
|
||||
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'non-standard HTTP-network fetch' with: fetch_params @ {}", &fetch_params);
|
||||
|
||||
auto fetch_timing_info = fetch_params.timing_info();
|
||||
auto cross_origin_isolated_capability = fetch_params.cross_origin_isolated_capability();
|
||||
|
||||
auto& vm = realm.vm();
|
||||
|
||||
(void)include_credentials;
|
||||
|
@ -2401,6 +2407,7 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> nonstandard_resource_loader_file_o
|
|||
});
|
||||
|
||||
auto on_complete = GC::create_function(vm.heap(), [&vm, &realm, pending_response, stream](bool success, Requests::RequestTimingInfo const&, Optional<StringView> error_message) {
|
||||
dbgln("FIXME: Implement on_complete timing info for unbuffered requests");
|
||||
HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
|
||||
// 16.1.1.2. Otherwise, if the bytes transmission for response’s message body is done normally and stream is readable,
|
||||
|
@ -2423,7 +2430,7 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> nonstandard_resource_loader_file_o
|
|||
|
||||
ResourceLoader::the().load_unbuffered(load_request, on_headers_received, on_data_received, on_complete);
|
||||
} else {
|
||||
auto on_load_success = GC::create_function(vm.heap(), [&realm, &vm, request, pending_response](ReadonlyBytes data, Requests::RequestTimingInfo const&, HTTP::HeaderMap const& response_headers, Optional<u32> status_code, Optional<String> const& reason_phrase) {
|
||||
auto on_load_success = GC::create_function(vm.heap(), [&realm, &vm, request, pending_response, fetch_timing_info, cross_origin_isolated_capability](ReadonlyBytes data, Requests::RequestTimingInfo const& timing_info, HTTP::HeaderMap const& response_headers, Optional<u32> status_code, Optional<String> const& reason_phrase) {
|
||||
(void)request;
|
||||
dbgln_if(WEB_FETCH_DEBUG, "Fetch: ResourceLoader load for '{}' complete", request->url());
|
||||
if constexpr (WEB_FETCH_DEBUG)
|
||||
|
@ -2432,6 +2439,10 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> nonstandard_resource_loader_file_o
|
|||
auto response = Infrastructure::Response::create(vm);
|
||||
response->set_status(status_code.value_or(200));
|
||||
response->set_body(move(body));
|
||||
auto body_info = response->body_info();
|
||||
body_info.encoded_size = timing_info.encoded_body_size;
|
||||
body_info.decoded_size = data.size();
|
||||
response->set_body_info(body_info);
|
||||
for (auto const& [name, value] : response_headers.headers()) {
|
||||
auto header = Infrastructure::Header::from_latin1_pair(name, value);
|
||||
response->header_list()->append(move(header));
|
||||
|
@ -2440,10 +2451,12 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> nonstandard_resource_loader_file_o
|
|||
if (reason_phrase.has_value())
|
||||
response->set_status_message(MUST(ByteBuffer::copy(reason_phrase.value().bytes())));
|
||||
|
||||
fetch_timing_info->update_final_timings(timing_info, cross_origin_isolated_capability);
|
||||
|
||||
pending_response->resolve(response);
|
||||
});
|
||||
|
||||
auto on_load_error = GC::create_function(vm.heap(), [&realm, &vm, request, pending_response](ByteString const& error, Requests::RequestTimingInfo const&, Optional<u32> status_code, Optional<String> const& reason_phrase, ReadonlyBytes data, HTTP::HeaderMap const& response_headers) {
|
||||
auto on_load_error = GC::create_function(vm.heap(), [&realm, &vm, request, pending_response, fetch_timing_info, cross_origin_isolated_capability](ByteString const& error, Requests::RequestTimingInfo const& timing_info, Optional<u32> status_code, Optional<String> const& reason_phrase, ReadonlyBytes data, HTTP::HeaderMap const& response_headers) {
|
||||
(void)request;
|
||||
dbgln_if(WEB_FETCH_DEBUG, "Fetch: ResourceLoader load for '{}' failed: {} (status {})", request->url(), error, status_code.value_or(0));
|
||||
if constexpr (WEB_FETCH_DEBUG)
|
||||
|
@ -2457,6 +2470,10 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> nonstandard_resource_loader_file_o
|
|||
response->set_status(status_code.value_or(400));
|
||||
auto [body, _] = TRY_OR_IGNORE(extract_body(realm, data));
|
||||
response->set_body(move(body));
|
||||
auto body_info = response->body_info();
|
||||
body_info.encoded_size = timing_info.encoded_body_size;
|
||||
body_info.decoded_size = data.size();
|
||||
response->set_body_info(body_info);
|
||||
for (auto const& [name, value] : response_headers.headers()) {
|
||||
auto header = Infrastructure::Header::from_latin1_pair(name, value);
|
||||
response->header_list()->append(move(header));
|
||||
|
@ -2465,6 +2482,9 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> nonstandard_resource_loader_file_o
|
|||
if (reason_phrase.has_value())
|
||||
response->set_status_message(MUST(ByteBuffer::copy(reason_phrase.value().bytes())));
|
||||
}
|
||||
|
||||
fetch_timing_info->update_final_timings(timing_info, cross_origin_isolated_capability);
|
||||
|
||||
pending_response->resolve(response);
|
||||
});
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <LibWeb/HighResolutionTime/DOMHighResTimeStamp.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
@ -42,7 +43,7 @@ struct ConnectionTimingInfo {
|
|||
// https://fetch.spec.whatwg.org/#connection-timing-info-alpn-negotiated-protocol
|
||||
// ALPN negotiated protocol (default the empty byte sequence)
|
||||
// A byte sequence.
|
||||
ByteBuffer alpn_negotiated_protocol;
|
||||
FlyString alpn_negotiated_protocol;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
#include <LibGC/Heap.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibRequests/RequestTimingInfo.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>
|
||||
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
||||
|
@ -35,4 +37,41 @@ GC::Ref<FetchTimingInfo> create_opaque_timing_info(JS::VM& vm, FetchTimingInfo c
|
|||
return new_timing_info;
|
||||
}
|
||||
|
||||
void FetchTimingInfo::update_final_timings(Requests::RequestTimingInfo const& final_timings, HTML::CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability)
|
||||
{
|
||||
bool has_cross_origin_isolated_capability = cross_origin_isolated_capability == HTML::CanUseCrossOriginIsolatedAPIs::Yes;
|
||||
|
||||
auto domain_lookup_start_time_milliseconds = m_start_time + (static_cast<HighResolutionTime::DOMHighResTimeStamp>(final_timings.domain_lookup_start_microseconds) / 1000.0);
|
||||
auto coarsened_domain_lookup_start_time = HighResolutionTime::coarsen_time(domain_lookup_start_time_milliseconds, has_cross_origin_isolated_capability);
|
||||
|
||||
auto domain_lookup_end_time_milliseconds = m_start_time + (static_cast<HighResolutionTime::DOMHighResTimeStamp>(final_timings.domain_lookup_end_microseconds) / 1000.0);
|
||||
auto coarsened_domain_lookup_end_time = HighResolutionTime::coarsen_time(domain_lookup_end_time_milliseconds, has_cross_origin_isolated_capability);
|
||||
|
||||
auto connect_start_time_milliseconds = m_start_time + (static_cast<HighResolutionTime::DOMHighResTimeStamp>(final_timings.connect_start_microseconds) / 1000.0);
|
||||
auto coarsened_connection_start_time = HighResolutionTime::coarsen_time(connect_start_time_milliseconds, has_cross_origin_isolated_capability);
|
||||
|
||||
auto connect_end_time_milliseconds = m_start_time + (static_cast<HighResolutionTime::DOMHighResTimeStamp>(final_timings.connect_end_microseconds) / 1000.0);
|
||||
auto coarsened_connection_end_time = HighResolutionTime::coarsen_time(connect_end_time_milliseconds, has_cross_origin_isolated_capability);
|
||||
|
||||
auto secure_connect_start_time_milliseconds = m_start_time + (static_cast<HighResolutionTime::DOMHighResTimeStamp>(final_timings.secure_connect_start_microseconds) / 1000.0);
|
||||
auto coarsened_secure_connection_start_time = HighResolutionTime::coarsen_time(secure_connect_start_time_milliseconds, has_cross_origin_isolated_capability);
|
||||
|
||||
m_final_connection_timing_info = ConnectionTimingInfo {
|
||||
.domain_lookup_start_time = coarsened_domain_lookup_start_time,
|
||||
.domain_lookup_end_time = coarsened_domain_lookup_end_time,
|
||||
.connection_start_time = coarsened_connection_start_time,
|
||||
.connection_end_time = coarsened_connection_end_time,
|
||||
.secure_connection_start_time = coarsened_secure_connection_start_time,
|
||||
.alpn_negotiated_protocol = alpn_http_version_to_fly_string(final_timings.http_version_alpn_identifier),
|
||||
};
|
||||
|
||||
auto request_start_time_milliseconds = m_start_time + (static_cast<HighResolutionTime::DOMHighResTimeStamp>(final_timings.request_start_microseconds) / 1000.0);
|
||||
auto coarsened_request_start_time = HighResolutionTime::coarsen_time(request_start_time_milliseconds, has_cross_origin_isolated_capability);
|
||||
m_final_network_request_start_time = coarsened_request_start_time;
|
||||
|
||||
auto response_start_time_milliseconds = m_start_time + (static_cast<HighResolutionTime::DOMHighResTimeStamp>(final_timings.response_start_microseconds) / 1000.0);
|
||||
auto coarsened_response_start_time = HighResolutionTime::coarsen_time(response_start_time_milliseconds, has_cross_origin_isolated_capability);
|
||||
m_final_network_response_start_time = coarsened_response_start_time;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,10 +8,13 @@
|
|||
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGC/CellAllocator.h>
|
||||
#include <LibGC/Ptr.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibRequests/Forward.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/ConnectionTimingInfo.h>
|
||||
#include <LibWeb/HTML/Scripting/SerializedEnvironmentSettingsObject.h>
|
||||
#include <LibWeb/HighResolutionTime/DOMHighResTimeStamp.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
@ -45,6 +48,9 @@ public:
|
|||
[[nodiscard]] HighResolutionTime::DOMHighResTimeStamp final_network_response_start_time() const { return m_final_network_response_start_time; }
|
||||
void set_final_network_response_start_time(HighResolutionTime::DOMHighResTimeStamp final_network_response_start_time) { m_final_network_response_start_time = final_network_response_start_time; }
|
||||
|
||||
[[nodiscard]] HighResolutionTime::DOMHighResTimeStamp first_interim_network_response_start_time() const { return m_first_interim_network_response_start_time; }
|
||||
void set_first_interim_network_response_start_time(HighResolutionTime::DOMHighResTimeStamp first_interim_network_response_start_time) { m_first_interim_network_response_start_time = first_interim_network_response_start_time; }
|
||||
|
||||
[[nodiscard]] HighResolutionTime::DOMHighResTimeStamp end_time() const { return m_end_time; }
|
||||
void set_end_time(HighResolutionTime::DOMHighResTimeStamp end_time) { m_end_time = end_time; }
|
||||
|
||||
|
@ -58,6 +64,8 @@ public:
|
|||
[[nodiscard]] bool render_blocking() const { return m_render_blocking; }
|
||||
void set_render_blocking(bool render_blocking) { m_render_blocking = render_blocking; }
|
||||
|
||||
void update_final_timings(Requests::RequestTimingInfo const& final_timings, HTML::CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability);
|
||||
|
||||
private:
|
||||
FetchTimingInfo();
|
||||
|
||||
|
@ -93,6 +101,11 @@ private:
|
|||
// A DOMHighResTimeStamp.
|
||||
HighResolutionTime::DOMHighResTimeStamp m_final_network_request_start_time { 0 };
|
||||
|
||||
// https://fetch.spec.whatwg.org/#fetch-timing-info-first-interim-network-response-start-time
|
||||
// first interim network-response start time (default 0)
|
||||
// A DOMHighResTimeStamp.
|
||||
HighResolutionTime::DOMHighResTimeStamp m_first_interim_network_response_start_time { 0 };
|
||||
|
||||
// https://fetch.spec.whatwg.org/#fetch-timing-info-final-network-response-start-time
|
||||
// final network-response start time (default 0)
|
||||
// A DOMHighResTimeStamp.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue