From fef331a03f60359961f84b4d892575b441e1ba7d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 13 Oct 2022 19:20:27 +0200 Subject: LibWeb: Implement 'fetch timing info' struct --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../Fetch/Infrastructure/FetchTimingInfo.cpp | 37 +++++++ .../LibWeb/Fetch/Infrastructure/FetchTimingInfo.h | 122 +++++++++++++++++++++ Userland/Libraries/LibWeb/Forward.h | 1 + 4 files changed, 161 insertions(+) create mode 100644 Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.cpp create mode 100644 Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.h (limited to 'Userland') diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 7a298890c7..aa41f6ffa9 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -125,6 +125,7 @@ set(SOURCES Fetch/Headers.cpp Fetch/HeadersIterator.cpp Fetch/Infrastructure/ConnectionTimingInfo.cpp + Fetch/Infrastructure/FetchTimingInfo.cpp Fetch/Infrastructure/HTTP.cpp Fetch/Infrastructure/HTTP/Bodies.cpp Fetch/Infrastructure/HTTP/Headers.cpp diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.cpp new file mode 100644 index 0000000000..0e4a43adda --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::Fetch::Infrastructure { + +FetchTimingInfo::FetchTimingInfo() = default; + +JS::NonnullGCPtr FetchTimingInfo::create(JS::VM& vm) +{ + return { *vm.heap().allocate_without_realm() }; +} + +void FetchTimingInfo::visit_edges(JS::Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_final_connection_timing_info); +} + +// https://fetch.spec.whatwg.org/#create-an-opaque-timing-info +JS::NonnullGCPtr create_opaque_timing_info(JS::VM& vm, FetchTimingInfo const& timing_info) +{ + // To create an opaque timing info, given a fetch timing info timingInfo, return a new fetch timing info whose + // start time and post-redirect start time are timingInfo’s start time. + auto new_timing_info = FetchTimingInfo::create(vm); + new_timing_info->set_start_time(timing_info.start_time()); + new_timing_info->set_post_redirect_start_time(timing_info.start_time()); + return new_timing_info; +} + +} diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.h new file mode 100644 index 0000000000..1a66a366dc --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchTimingInfo.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace Web::Fetch::Infrastructure { + +// https://fetch.spec.whatwg.org/#fetch-timing-info +class FetchTimingInfo : public JS::Cell { + JS_CELL(FetchTimingInfo, JS::Cell); + +public: + [[nodiscard]] static JS::NonnullGCPtr create(JS::VM&); + + [[nodiscard]] HighResolutionTime::DOMHighResTimeStamp start_time() const { return m_start_time; } + void set_start_time(HighResolutionTime::DOMHighResTimeStamp start_time) { m_start_time = start_time; } + + [[nodiscard]] HighResolutionTime::DOMHighResTimeStamp redirect_start_time() const { return m_redirect_start_time; } + void set_redirect_start_time(HighResolutionTime::DOMHighResTimeStamp redirect_start_time) { m_redirect_start_time = redirect_start_time; } + + [[nodiscard]] HighResolutionTime::DOMHighResTimeStamp redirect_end_time() const { return m_redirect_end_time; } + void set_redirect_end_time(HighResolutionTime::DOMHighResTimeStamp redirect_end_time) { m_redirect_end_time = redirect_end_time; } + + [[nodiscard]] HighResolutionTime::DOMHighResTimeStamp post_redirect_start_time() const { return m_post_redirect_start_time; } + void set_post_redirect_start_time(HighResolutionTime::DOMHighResTimeStamp post_redirect_start_time) { m_post_redirect_start_time = post_redirect_start_time; } + + [[nodiscard]] HighResolutionTime::DOMHighResTimeStamp final_service_worker_start_time() const { return m_final_service_worker_start_time; } + void set_final_service_worker_start_time(HighResolutionTime::DOMHighResTimeStamp final_service_worker_start_time) { m_final_service_worker_start_time = final_service_worker_start_time; } + + [[nodiscard]] HighResolutionTime::DOMHighResTimeStamp final_network_request_start_time() const { return m_final_network_request_start_time; } + void set_final_network_request_start_time(HighResolutionTime::DOMHighResTimeStamp final_network_request_start_time) { m_final_network_request_start_time = final_network_request_start_time; } + + [[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 end_time() const { return m_end_time; } + void set_end_time(HighResolutionTime::DOMHighResTimeStamp end_time) { m_end_time = end_time; } + + [[nodiscard]] JS::GCPtr final_connection_timing_info() const { return m_final_connection_timing_info; } + void set_final_connection_timing_info(JS::GCPtr final_connection_timing_info) { m_final_connection_timing_info = final_connection_timing_info; } + + [[nodiscard]] Vector& server_timing_headers() { return m_server_timing_headers; } + [[nodiscard]] Vector const& server_timing_headers() const { return m_server_timing_headers; } + void set_server_timing_headers(Vector server_timing_headers) { m_server_timing_headers = move(server_timing_headers); } + + [[nodiscard]] bool render_blocking() const { return m_render_blocking; } + void set_render_blocking(bool render_blocking) { m_render_blocking = render_blocking; } + +private: + FetchTimingInfo(); + + virtual void visit_edges(JS::Cell::Visitor&) override; + + // https://fetch.spec.whatwg.org/#fetch-timing-info-start-time + // start time (default 0) + // A DOMHighResTimeStamp. + HighResolutionTime::DOMHighResTimeStamp m_start_time { 0 }; + + // https://fetch.spec.whatwg.org/#fetch-timing-info-redirect-start-time + // redirect start time (default 0) + // A DOMHighResTimeStamp. + HighResolutionTime::DOMHighResTimeStamp m_redirect_start_time { 0 }; + + // https://fetch.spec.whatwg.org/#fetch-timing-info-redirect-end-time + // redirect end time (default 0) + // A DOMHighResTimeStamp. + HighResolutionTime::DOMHighResTimeStamp m_redirect_end_time { 0 }; + + // https://fetch.spec.whatwg.org/#fetch-timing-info-post-redirect-start-time + // post-redirect start time (default 0) + // A DOMHighResTimeStamp. + HighResolutionTime::DOMHighResTimeStamp m_post_redirect_start_time { 0 }; + + // https://fetch.spec.whatwg.org/#fetch-timing-info-final-service-worker-start-time + // final service worker start time (default 0) + // A DOMHighResTimeStamp. + HighResolutionTime::DOMHighResTimeStamp m_final_service_worker_start_time { 0 }; + + // https://fetch.spec.whatwg.org/#fetch-timing-info-final-network-request-start-time + // final network-request start time (default 0) + // A DOMHighResTimeStamp. + HighResolutionTime::DOMHighResTimeStamp m_final_network_request_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. + HighResolutionTime::DOMHighResTimeStamp m_final_network_response_start_time { 0 }; + + // https://fetch.spec.whatwg.org/#fetch-timing-info-end-time + // end time (default 0) + // A DOMHighResTimeStamp. + HighResolutionTime::DOMHighResTimeStamp m_end_time { 0 }; + + // https://fetch.spec.whatwg.org/#fetch-timing-info-final-connection-timing-info + // final connection timing info (default null) + // Null or a connection timing info. + JS::GCPtr m_final_connection_timing_info; + + // https://fetch.spec.whatwg.org/#fetch-timing-info-server-timing-headers + // server-timing headers (default « ») + // A list of strings. + Vector m_server_timing_headers; + + // https://fetch.spec.whatwg.org/#fetch-timing-info-render-blocking + // render-blocking (default false) + // A boolean. + bool m_render_blocking { false }; +}; + +JS::NonnullGCPtr create_opaque_timing_info(JS::VM&, FetchTimingInfo const& timing_info); + +} diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 61ca3c1291..e8c9d84af0 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -193,6 +193,7 @@ namespace Web::Fetch::Infrastructure { class Body; struct BodyWithType; class ConnectionTimingInfo; +class FetchTimingInfo; struct Header; class HeaderList; class Request; -- cgit v1.2.3