From ba31547fa08638f0f879a3a4a69a48d14ac6641b Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 13 Oct 2022 19:23:43 +0200 Subject: [PATCH] LibWeb: Implement container class for fetch algorithms --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../Fetch/Infrastructure/FetchAlgorithms.cpp | 28 +++++++++ .../Fetch/Infrastructure/FetchAlgorithms.h | 58 +++++++++++++++++++ Userland/Libraries/LibWeb/Forward.h | 1 + 4 files changed, 88 insertions(+) create mode 100644 Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp create mode 100644 Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index fb948db3aa..15fa404dee 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/FetchAlgorithms.cpp Fetch/Infrastructure/FetchController.cpp Fetch/Infrastructure/FetchTimingInfo.cpp Fetch/Infrastructure/HTTP.cpp diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp new file mode 100644 index 0000000000..22e0ebe5a6 --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::Fetch::Infrastructure { + +JS::NonnullGCPtr FetchAlgorithms::create(JS::VM& vm, Input input) +{ + return { *vm.heap().allocate_without_realm(move(input)) }; +} + +FetchAlgorithms::FetchAlgorithms(Input input) + : m_process_request_body_chunk_length(move(input.process_request_body_chunk_length)) + , m_process_request_end_of_body(move(input.process_request_end_of_body)) + , m_process_early_hints_response(move(input.process_early_hints_response)) + , m_process_response(move(input.process_response)) + , m_process_response_end_of_body(move(input.process_response_end_of_body)) + , m_process_response_consume_body(move(input.process_response_consume_body)) +{ +} + +} diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h new file mode 100644 index 0000000000..a0583869f0 --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Web::Fetch::Infrastructure { + +// https://fetch.spec.whatwg.org/#fetch-elsewhere-fetch +class FetchAlgorithms : public JS::Cell { + JS_CELL(FetchAlgorithms, JS::Cell); + +public: + struct ConsumeBodyFailureTag { }; + using ProcessRequestBodyChunkLengthFunction = JS::SafeFunction; + using ProcessRequestEndOfBodyFunction = JS::SafeFunction; + using ProcessEarlyHintsResponseFunction = JS::SafeFunction)>; + using ProcessResponseFunction = JS::SafeFunction)>; + using ProcessResponseEndOfBodyFunction = JS::SafeFunction)>; + using ProcessResponseConsumeBodyFunction = JS::SafeFunction, Variant)>; + + struct Input { + Optional process_request_body_chunk_length; + Optional process_request_end_of_body; + Optional process_early_hints_response; + Optional process_response; + Optional process_response_end_of_body; + Optional process_response_consume_body; + }; + + [[nodiscard]] static JS::NonnullGCPtr create(JS::VM&, Input); + + Optional const& process_request_body_chunk_length() const { return m_process_request_body_chunk_length; } + Optional const& process_request_end_of_body() const { return m_process_request_end_of_body; } + Optional const& process_early_hints_response() const { return m_process_early_hints_response; } + Optional const& process_response() const { return m_process_response; } + Optional const& process_response_end_of_body() const { return m_process_response_end_of_body; } + Optional const& process_response_consume_body() const { return m_process_response_consume_body; } + +private: + explicit FetchAlgorithms(Input); + + Optional m_process_request_body_chunk_length; + Optional m_process_request_end_of_body; + Optional m_process_early_hints_response; + Optional m_process_response; + Optional m_process_response_end_of_body; + Optional m_process_response_consume_body; +}; + +} diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 1413bd0c14..cafdf2dc79 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 FetchAlgorithms; class FetchController; class FetchTimingInfo; struct Header;