Truly independent web browser
LibWeb: Keep a fetch's body intent on its fetch params
Luke Wilde84974f347f65
diff --git a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cppindex 7e5bdb306f5..a14f94f4ecf 100644--- a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp@@ -241,7 +241,7 @@ void BodyStreamPullSource::push_while_paused(){if (m_detached || m_pending_pull_promise || m_push_ticket.has_value() || !HTML::main_thread_event_loop().execution_paused())return;- if (!m_fetch_params || m_fetch_params->algorithms()->body_intent() != Engine::BodyIntent::SyncAccumulate)+ if (!m_fetch_params || m_fetch_params->body_intent() != Engine::BodyIntent::SyncAccumulate)return;m_push_ticket = arm_waiter(Engine::FetchByteChannel::BufferedAtLeast { 1 });}diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cppindex cb7e0d6dd50..7829d50a610 100644--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp@@ -386,7 +386,7 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:request.credentials_mode(),request.integrity_metadata(),on_preloaded_response_available,- fetch_params->algorithms()->body_intent(),+ fetch_params->body_intent(),preload_reports_timing);fetch_params->set_preload_reports_timing(preload_reports_timing);@@ -1167,7 +1167,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams constauto algorithms = fetch_params.algorithms();- auto body_intent = algorithms->body_intent();+ auto body_intent = fetch_params.body_intent();// AD-HOC: A fetch whose body intent is SyncAccumulate is a sync XHR send()// (https://xhr.spec.whatwg.org/#the-send()-method, step 12) — or a preload fetch that "consume a preloadeddiff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cppindex 2452a54a90e..9d5c4ad0767 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp@@ -33,19 +33,6 @@ GC::Ref<FetchAlgorithms> FetchAlgorithms::create(Input input)move(input.request_body_reader));}-GC::Ref<FetchAlgorithms> FetchAlgorithms::with_body_intent(Engine::BodyIntent body_intent) const-{- return GC::Heap::the().allocate<FetchAlgorithms>(- body_intent,- m_process_request_body_chunk_length,- m_process_request_end_of_body,- m_process_early_hints_response,- m_process_response,- m_process_response_end_of_body,- m_process_response_consume_body,- m_request_body_reader);-}-FetchAlgorithms::FetchAlgorithms(Engine::BodyIntent body_intent,ProcessRequestBodyChunkLengthHeapFunction process_request_body_chunk_length,diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.hindex c7149ef0db0..e3e026b5be5 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h@@ -63,7 +63,6 @@ public:};[[nodiscard]] static GC::Ref<FetchAlgorithms> create(Input);- [[nodiscard]] GC::Ref<FetchAlgorithms> with_body_intent(Engine::BodyIntent) const;Engine::BodyIntent body_intent() const { return m_body_intent; }Optional<RequestBodyReader> const& request_body_reader() const { return m_request_body_reader; }diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cppindex 30d8e168533..8c158a178f0 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp@@ -193,7 +193,8 @@ void FetchController::stop_fetch()if (m_fetch_params) {// NB: Nobody reads a stopped fetch's body.- auto fetch_algorithms = FetchAlgorithms::create(FetchAlgorithms::Input { Engine::BodyIntent::DrainAndDiscard });+ m_fetch_params->set_body_intent(Engine::BodyIntent::DrainAndDiscard);+ auto fetch_algorithms = FetchAlgorithms::create(FetchAlgorithms::Input { m_fetch_params->body_intent() });m_fetch_params->set_algorithms(fetch_algorithms);}diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cppindex d9181930b6a..d9ae0411a14 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp@@ -16,6 +16,7 @@ GC_DEFINE_ALLOCATOR(FetchParams);FetchParams::FetchParams(NonnullRefPtr<Request> request, GC::Ref<FetchAlgorithms const> algorithms, GC::Ref<FetchController> controller, NonnullRefPtr<FetchTimingInfo> timing_info, NonnullRefPtr<LoaderConfigSnapshot const> loader_config): m_request(move(request)), m_algorithms(algorithms)+ , m_body_intent(algorithms->body_intent()), m_controller(controller), m_timing_info(move(timing_info)), m_loader_config(move(loader_config))@@ -26,6 +27,7 @@ FetchParams::FetchParams(NonnullRefPtr<Request> request, GC::Ref<FetchAlgorithmsFetchParams::FetchParams(FetchParams const& params): m_request(params.m_request), m_algorithms(params.m_algorithms)+ , m_body_intent(params.m_body_intent), m_task_destination(params.m_task_destination), m_cross_origin_isolated_capability(params.m_cross_origin_isolated_capability), m_controller(params.m_controller)diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.hindex 616dd05d1a0..8c93f172eb6 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h@@ -44,6 +44,9 @@ public:[[nodiscard]] GC::Ref<FetchAlgorithms const> algorithms() const { return m_algorithms; }void set_algorithms(GC::Ref<FetchAlgorithms const> algorithms) { m_algorithms = algorithms; }+ [[nodiscard]] Engine::BodyIntent body_intent() const { return m_body_intent; }+ void set_body_intent(Engine::BodyIntent body_intent) { m_body_intent = body_intent; }+[[nodiscard]] TaskDestination& task_destination() { return m_task_destination; }[[nodiscard]] TaskDestination const& task_destination() const { return m_task_destination; }void set_task_destination(TaskDestination task_destination) { m_task_destination = move(task_destination); }@@ -93,6 +96,8 @@ private:// Null or an algorithm.GC::Ref<FetchAlgorithms const> m_algorithms;+ Engine::BodyIntent m_body_intent;+// https://fetch.spec.whatwg.org/#fetch-params-task-destination// task destination (default null)// Null, a global object, or a parallel queue.diff --git a/Libraries/LibWeb/HTML/PreloadEntry.cpp b/Libraries/LibWeb/HTML/PreloadEntry.cppindex fa1d6b90364..e3e53005fff 100644--- a/Libraries/LibWeb/HTML/PreloadEntry.cpp+++ b/Libraries/LibWeb/HTML/PreloadEntry.cpp@@ -129,7 +129,7 @@ bool consume_a_preloaded_resource(if (consumer_body_intent == Fetch::Engine::BodyIntent::SyncAccumulate && entry->controller) {if (auto fetch_params = entry->controller->fetch_params()) {fetch_params->set_task_destination(ParallelQueue::create());- fetch_params->set_algorithms(fetch_params->algorithms()->with_body_intent(consumer_body_intent));+ fetch_params->set_body_intent(consumer_body_intent);}}}