Skip to content

Truly independent web browser

LibWeb: Keep a fetch's task destination on its fetch controller

Luke Wilde4b34650b5b00
diff --git a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp
index a14f94f4ecf..9229a2655d0 100644
--- a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp
@@ -224,7 +224,7 @@ void BodyStreamPullSource::on_pull_wake()
run_pull_task();
});
if (m_fetch_params) {
- Infrastructure::queue_fetch_task(m_fetch_params->task_destination(), steps);
+ Infrastructure::queue_fetch_task(m_fetch_params->controller()->task_destination(), steps);
return;
}
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
index 287fc080bf3..d4314a8c13b 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -324,7 +324,7 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:
// response consume body is processResponseConsumeBody, process response end-of-body is processResponseEndOfBody,
// task destination is taskDestination, and cross-origin isolated capability is crossOriginIsolatedCapability.
auto fetch_params = Infrastructure::FetchParams::create(request, algorithms, timing_info, current_loader_config());
- fetch_params->set_task_destination(task_destination);
+ fetch_params->controller()->set_task_destination(task_destination);
fetch_params->set_cross_origin_isolated_capability(cross_origin_isolated_capability);
fetch_params->set_has_response_body_transfer_lease(create_response_body_transfer_lease == CreateResponseBodyTransferLease::Yes);
@@ -918,7 +918,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
// 4. Fully read response’s body given processBody and processBodyError.
auto body_view = create_body_view(realm, *response, &fetch_params);
- body_view->fully_read(realm, process_body, process_body_error, fetch_params.task_destination());
+ body_view->fully_read(realm, process_body, process_body_error, fetch_params.controller()->task_destination());
}
// 24. Otherwise, run fetch response handover given fetchParams and response.
else {
@@ -1094,7 +1094,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
// entry for a preloaded resource and its consumer.
// AD-HOC: The global object of a client another process hosts is in that process, so the fetch reports its
// timing to the global object of the realm that started it.
- auto const* task_destination_global_object = fetch_params.task_destination().get_pointer<GC::Ref<JS::Object>>();
+ auto const* task_destination_global_object = fetch_params.controller()->task_destination().get_pointer<GC::Ref<JS::Object>>();
if (task_destination_global_object != nullptr && fetch_params.request()->initiator_type().has_value() && !fetch_params.preload_reports_timing()) {
auto client = resolve_fetch_client(fetch_params.request());
auto client_global_is_task_destination = client.has_value()
@@ -1129,13 +1129,13 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
});
// 4. Queue a fetch task to run processResponseEndOfBodyTask with fetchParams’s task destination.
- Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), move(process_response_end_of_body_task));
+ Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.controller()->task_destination(), move(process_response_end_of_body_task));
};
// 5. If fetchParams’s process response is non-null, then queue a fetch task to run fetchParams’s process response
// given response, with fetchParams’s task destination.
if (fetch_params.controller()->algorithms()->process_response()) {
- Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), GC::create_function(GC::Heap::the(), [&fetch_params, response_view]() {
+ Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.controller()->task_destination(), GC::create_function(GC::Heap::the(), [&fetch_params, response_view]() {
fetch_params.controller()->algorithms()->process_response()(response_view);
}));
}
@@ -1263,7 +1263,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
process_response_end_of_body();
});
auto discard_error = GC::create_function(GC::Heap::the(), [](JS::Value) { });
- body_view->incrementally_read(realm, discard_chunk, end_of_body, discard_error, fetch_params.task_destination());
+ body_view->incrementally_read(realm, discard_chunk, end_of_body, discard_error, fetch_params.controller()->task_destination());
break;
}
case Engine::BodyIntent::SyncAccumulate:
@@ -1312,7 +1312,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
if (read_body_in_parallel) {
(algorithms->process_response_consume_body())(response_view, Empty {});
} else {
- Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), GC::create_function(GC::Heap::the(), [algorithms, response_view]() {
+ Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.controller()->task_destination(), GC::create_function(GC::Heap::the(), [algorithms, response_view]() {
// NB: We have to provide fully_read a callback which accepts a ByteBuffer. Since that's not
// nullable, we just invoke process_response_consume_body with a null value manually here.
(algorithms->process_response_consume_body())(response_view, Empty {});
@@ -1352,7 +1352,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
}
}
} else {
- body_view->fully_read(realm, process_body, process_body_error, fetch_params.task_destination());
+ body_view->fully_read(realm, process_body, process_body_error, fetch_params.controller()->task_destination());
}
}
}
@@ -2978,7 +2978,7 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(
// fetchParams’s process request end-of-body and fetchParams’s task destination.
if (request->body().has<Empty>()) {
if (fetch_params.controller()->algorithms()->process_request_end_of_body()) {
- Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), GC::create_function(GC::Heap::the(), [&fetch_params]() {
+ Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.controller()->task_destination(), GC::create_function(GC::Heap::the(), [&fetch_params]() {
fetch_params.controller()->algorithms()->process_request_end_of_body()();
}));
}
@@ -3035,18 +3035,18 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(
// fetch() acquired for its stream.
if (auto const& source = body->source(); source.has_value()) {
if (auto length = source->size(); length > 0) {
- Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), GC::create_function(GC::Heap::the(), [process_body_chunk, length] {
+ Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.controller()->task_destination(), GC::create_function(GC::Heap::the(), [process_body_chunk, length] {
process_body_chunk(length);
}));
}
- Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), process_end_of_body);
+ Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.controller()->task_destination(), process_end_of_body);
} else if (auto const& request_body_reader = fetch_params.controller()->algorithms()->request_body_reader(); request_body_reader.has_value()) {
// FIXME: Send the bytes read here to RequestServer, which only receives a body's source.
auto process_body_chunk_bytes = GC::create_function(GC::Heap::the(), [process_body_chunk](ByteBuffer bytes) {
process_body_chunk(bytes.size());
});
HTML::TemporaryExecutionContext const execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
- request_body_reader->body->incrementally_read_loop(request_body_reader->reader, fetch_params.task_destination(), process_body_chunk_bytes, process_end_of_body, process_body_error);
+ request_body_reader->body->incrementally_read_loop(request_body_reader->reader, fetch_params.controller()->task_destination(), process_body_chunk_bytes, process_end_of_body, process_body_error);
}
}
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
index 8a1ead5a3f1..50d88c35524 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
@@ -46,6 +46,7 @@ void FetchController::visit_edges(JS::Cell::Visitor& visitor)
visitor.visit(m_next_manual_redirect_steps);
visitor.visit(m_fetch_params);
visitor.visit(m_algorithms);
+ visitor.visit(m_task_destination);
visitor.visit(m_pending_preloaded_response);
visitor.visit(m_stop_steps);
visitor.visit(m_pending_responses);
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h
index 9558a462d39..9395a6488c4 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h
@@ -18,6 +18,7 @@
#include <LibWeb/Fetch/Engine/FetchBodyDeliveryGate.h>
#include <LibWeb/Fetch/Engine/FetchByteChannel.h>
#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>
+#include <LibWeb/Fetch/Infrastructure/Task.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/EventLoop/Task.h>
#include <LibWeb/HTML/StructuredSerializeTypes.h>
@@ -70,6 +71,9 @@ public:
void set_algorithms(Badge<FetchParams>, GC::Ref<FetchAlgorithms const> algorithms) { m_algorithms = algorithms; }
[[nodiscard]] GC::Ref<FetchAlgorithms const> algorithms() const;
+ [[nodiscard]] TaskDestination const& task_destination() const { return m_task_destination; }
+ void set_task_destination(TaskDestination task_destination) { m_task_destination = move(task_destination); }
+
// AD-HOC: Whether this fetch's response has arrived: as headers from the network, or at main fetch. From then on,
// its body delivery is queued as event-loop tasks, and its response processing captures its task
// destination as it was then — so re-targeting the fetch no longer reaches either.
@@ -153,6 +157,13 @@ private:
// Null or an algorithm.
GC::Ptr<FetchAlgorithms const> m_algorithms;
+ // AD-HOC: The fetch params' task destination is kept on their controller, which every copy of the fetch params
+ // shares.
+ // https://fetch.spec.whatwg.org/#fetch-params-task-destination
+ // task destination (default null)
+ // Null, a global object, or a parallel queue.
+ TaskDestination m_task_destination;
+
bool m_response_arrived { false };
// NB: Assumes one waiting consumer for a pending preloaded response.
// Widen this if preload handoff ever supports multiple consumers.
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp
index 35a70e57fbb..3352a92b17e 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp
@@ -27,7 +27,6 @@ FetchParams::FetchParams(NonnullRefPtr<Request> request, GC::Ref<FetchAlgorithms
FetchParams::FetchParams(FetchParams const& params)
: m_request(params.m_request)
, 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)
, m_timing_info(params.m_timing_info)
@@ -53,7 +52,6 @@ void FetchParams::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_controller);
- visitor.visit(m_task_destination);
}
// https://fetch.spec.whatwg.org/#fetch-params-aborted
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h
index 01a2a21fd97..8ba0adc83cd 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h
@@ -16,7 +16,6 @@
#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
-#include <LibWeb/Fetch/Infrastructure/Task.h>
#include <LibWebCommon/FileAPI/SerializedBlobURLEntry.h>
#include <LibWebCommon/Loader/LoaderConfigSnapshot.h>
@@ -44,10 +43,6 @@ public:
[[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); }
-
[[nodiscard]] HTML::CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability() const { return m_cross_origin_isolated_capability; }
void set_cross_origin_isolated_capability(HTML::CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability) { m_cross_origin_isolated_capability = cross_origin_isolated_capability; }
@@ -80,11 +75,6 @@ private:
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.
- TaskDestination m_task_destination;
-
// https://fetch.spec.whatwg.org/#fetch-params-cross-origin-isolated-capability
// cross-origin isolated capability (default false)
// A boolean.
diff --git a/Libraries/LibWeb/HTML/PreloadEntry.cpp b/Libraries/LibWeb/HTML/PreloadEntry.cpp
index e3e53005fff..846e002d5b7 100644
--- a/Libraries/LibWeb/HTML/PreloadEntry.cpp
+++ b/Libraries/LibWeb/HTML/PreloadEntry.cpp
@@ -127,10 +127,9 @@ bool consume_a_preloaded_resource(
// reuses a resource for a sync request (Resource::CanReuse), and WebKit's sync load bypasses its cache
// and preloads (DocumentThreadableLoader::loadRequest).
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());
+ entry->controller->set_task_destination(ParallelQueue::create());
+ if (auto fetch_params = entry->controller->fetch_params())
fetch_params->set_body_intent(consumer_body_intent);
- }
}
}
// 10. Otherwise, call onResponseAvailable with entry's response.