Skip to content

Truly independent web browser

LibWeb: Make fetch Response reference-counted instead of GC-allocated

Luke Wilde3febd1641432
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp
index 5ac01c116fb..2e0e5f42168 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp
+++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp
@@ -665,7 +665,7 @@ MatchResult does_request_match_source_list(NonnullRefPtr<Fetch::Infrastructure::
}
// https://w3c.github.io/webappsec-csp/#match-response-to-source-list
-MatchResult does_response_match_source_list(GC::Ref<Fetch::Infrastructure::Response const> response, NonnullRefPtr<Fetch::Infrastructure::Request const> request, Vector<Utf16String> const& source_list, Policy const& policy)
+MatchResult does_response_match_source_list(NonnullRefPtr<Fetch::Infrastructure::Response const> response, NonnullRefPtr<Fetch::Infrastructure::Request const> request, Vector<Utf16String> const& source_list, Policy const& policy)
{
// Given a request request, and a source list source list, and a policy policy, this algorithm returns the result
// of executing § 6.7.2.7 Does url match source list in origin with redirect count? on response’s url, source list,
@@ -799,7 +799,7 @@ Directive::Result script_directives_pre_request_check(NonnullRefPtr<Fetch::Infra
}
// https://w3c.github.io/webappsec-csp/#script-post-request
-Directive::Result script_directives_post_request_check(NonnullRefPtr<Fetch::Infrastructure::Request const> request, GC::Ref<Fetch::Infrastructure::Response const> response, Directive const& directive, Policy const& policy)
+Directive::Result script_directives_post_request_check(NonnullRefPtr<Fetch::Infrastructure::Request const> request, NonnullRefPtr<Fetch::Infrastructure::Response const> response, Directive const& directive, Policy const& policy)
{
// 1. If request’s destination is script-like:
if (request->destination_is_script_like()) {
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.h b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.h
index 6db55a4d6bf..a890c5fadbb 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.h
+++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.h
@@ -34,10 +34,10 @@ MatchResult does_url_match_expression_in_origin_with_redirect_count(URL::URL con
MatchResult does_url_match_source_list_in_origin_with_redirect_count(URL::URL const& url, Vector<Utf16String> const& source_list, URL::Origin const& origin, u8 redirect_count);
MatchResult does_request_match_source_list(NonnullRefPtr<Fetch::Infrastructure::Request const> request, Vector<Utf16String> const& source_list, Policy const& policy);
-MatchResult does_response_match_source_list(GC::Ref<Fetch::Infrastructure::Response const> response, NonnullRefPtr<Fetch::Infrastructure::Request const> request, Vector<Utf16String> const& source_list, Policy const& policy);
+MatchResult does_response_match_source_list(NonnullRefPtr<Fetch::Infrastructure::Response const> response, NonnullRefPtr<Fetch::Infrastructure::Request const> request, Vector<Utf16String> const& source_list, Policy const& policy);
MatchResult does_nonce_match_source_list(Utf16View nonce, Vector<Utf16String> const& source_list);
Directive::Result script_directives_pre_request_check(NonnullRefPtr<Fetch::Infrastructure::Request const> request, Directive const& directive, Policy const& policy);
-Directive::Result script_directives_post_request_check(NonnullRefPtr<Fetch::Infrastructure::Request const> request, GC::Ref<Fetch::Infrastructure::Response const> response, Directive const& directive, Policy const& policy);
+Directive::Result script_directives_post_request_check(NonnullRefPtr<Fetch::Infrastructure::Request const> request, NonnullRefPtr<Fetch::Infrastructure::Response const> response, Directive const& directive, Policy const& policy);
}
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
index 3c162fcbb94..cb7e0d6dd50 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -230,7 +230,7 @@ static RefPtr<HTTP::MemoryCache> determine_the_http_cache_partition(Infrastructu
return HTTPCache::the().get(*partition);
}
-static GC::Ptr<Infrastructure::Response> select_response_from_cache(HTTP::MemoryCache& http_cache, Infrastructure::Request const& request)
+static RefPtr<Infrastructure::Response> select_response_from_cache(HTTP::MemoryCache& http_cache, Infrastructure::Request const& request)
{
if (!g_http_memory_cache_enabled)
return {};
@@ -362,7 +362,7 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:
// 2. Let onPreloadedResponseAvailable be an algorithm that runs the following step given a response
// response: set fetchParams’s preloaded response candidate to response.
- auto on_preloaded_response_available = GC::create_function(GC::Heap::the(), [fetch_params](GC::Ref<Infrastructure::Response> response) {
+ auto on_preloaded_response_available = GC::create_function(GC::Heap::the(), [fetch_params](NonnullRefPtr<Infrastructure::Response> response) {
fetch_params->set_preloaded_response_candidate(response);
// NB: main fetch may already be parked on this preload result.
@@ -566,7 +566,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
WebDriver::BiDi::initialize_network_request(*request);
// 2. Let response be null.
- GC::Ptr<Infrastructure::Response> response;
+ RefPtr<Infrastructure::Response> response;
// 3. If request’s local-URLs-only flag is set and request’s current URL is not local, then set response to a
// network error.
@@ -652,10 +652,10 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
}
// 2. Assert: fetchParams’s preloaded response candidate is a response.
- VERIFY(fetch_params.preloaded_response_candidate().has<GC::Ref<Infrastructure::Response>>());
+ VERIFY(fetch_params.preloaded_response_candidate().has<NonnullRefPtr<Infrastructure::Response>>());
// 3. Return fetchParams’s preloaded response candidate.
- return PendingResponse::create(fetch_params, fetch_params.preloaded_response_candidate().get<GC::Ref<Infrastructure::Response>>());
+ return PendingResponse::create(fetch_params, fetch_params.preloaded_response_candidate().get<NonnullRefPtr<Infrastructure::Response>>());
}
// -> request’s current URL’s origin is same origin with request’s origin, and request’s response tainting is "basic"
@@ -729,7 +729,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
// 2. Let corsWithPreflightResponse be the result of running HTTP fetch given fetchParams and true.
auto cors_with_preflight_response = http_fetch(realm, fetch_params, MakeCORSPreflight::Yes);
- cors_with_preflight_response->when_loaded([request, returned_pending_response](GC::Ref<Infrastructure::Response> cors_with_preflight_response) {
+ cors_with_preflight_response->when_loaded([request, returned_pending_response](NonnullRefPtr<Infrastructure::Response> cors_with_preflight_response) {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'main fetch' cors_with_preflight_response load callback");
// 3. If corsWithPreflightResponse is a network error, then clear cache entries using request.
if (cors_with_preflight_response->is_network_error()) {
@@ -770,7 +770,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
if (!response) {
pending_response = get_response->function()();
}
- pending_response->when_loaded([&realm, &fetch_params, request, response, response_was_null = !response](GC::Ref<Infrastructure::Response> resolved_response) mutable {
+ pending_response->when_loaded([&realm, &fetch_params, request, response, response_was_null = !response](NonnullRefPtr<Infrastructure::Response> resolved_response) mutable {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'main fetch' pending_response load callback");
// AD-HOC: From here on, response processing captures fetchParams's task destination as it schedules work
@@ -807,7 +807,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
// 2. Set response to the following filtered response with response as its internal response, depending
// on request’s response tainting:
- response = [&]() -> GC::Ref<Infrastructure::Response> {
+ response = [&]() -> NonnullRefPtr<Infrastructure::Response> {
switch (request->response_tainting()) {
// -> "basic"
case Infrastructure::Request::ResponseTainting::Basic:
@@ -830,7 +830,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
// 15. Let internalResponse be response, if response is a network error, and response’s internal response
// otherwise.
auto internal_response = response->is_network_error()
- ? GC::Ref { *response }
+ ? NonnullRefPtr { *response }
: static_cast<Infrastructure::FilteredResponse&>(*response).internal_response();
// 16. If internalResponse’s URL list is empty, then set it to a clone of request’s URL list.
@@ -1022,12 +1022,12 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
// within processResponseConsumeBody. So we ensure report_timing_steps is set on error too, which allows
// reportTiming to work without asserting, and still produces useful timing data for failed fetches.
auto timing_reported = RefCountedFlag::create(false);
- auto setup_report_timing_steps = [&response, &fetch_params, timing_info, timing_reported] {
+ auto setup_report_timing_steps = [response = response_view->record(), &fetch_params, timing_info, timing_reported] {
// 1. Let unsafeEndTime be the unsafe shared current time.
auto unsafe_end_time = HighResolutionTime::unsafe_shared_current_time();
// 2. Set fetchParams’s controller’s report timing steps to the following steps given a global object global:
- fetch_params.controller()->set_report_timing_steps([&response, &fetch_params, timing_info, unsafe_end_time, timing_reported](JS::Object& global) mutable {
+ fetch_params.controller()->set_report_timing_steps([response, &fetch_params, timing_info, unsafe_end_time, timing_reported](JS::Object& global) mutable {
// NB: Network completion and consuming the response body can both request a timing report.
if (timing_reported->value())
return;
@@ -1045,16 +1045,16 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
timing_info->set_end_time(unsafe_end_time);
// 3. Let cacheState be response’s cache state.
- auto cache_state = response.cache_state();
+ auto cache_state = response->cache_state();
// 4. Let bodyInfo be response’s body info.
- auto body_info = response.body_info();
+ auto body_info = response->body_info();
// 5. If response’s timing allow passed flag is not set, then set timingInfo to the result of creating an
// opaque timing info for timingInfo, set bodyInfo to a new response body info, and set cacheState to
// the empty string.
// NOTE: This covers the case of response being a network error.
- if (!response.timing_allow_passed()) {
+ if (!response->timing_allow_passed()) {
timing_info = Infrastructure::create_opaque_timing_info(timing_info);
body_info = Infrastructure::Response::BodyInfo {};
cache_state = {};
@@ -1064,12 +1064,12 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
auto response_status = 0;
// 7. If fetchParams’s request’s mode is not "navigate" or response’s redirect taint is "same-origin":
- if (fetch_params.request()->mode() != Infrastructure::Request::Mode::Navigate || response.redirect_taint() == Infrastructure::RedirectTaint::SameOrigin) {
+ if (fetch_params.request()->mode() != Infrastructure::Request::Mode::Navigate || response->redirect_taint() == Infrastructure::RedirectTaint::SameOrigin) {
// 1. Set responseStatus to response’s status.
- response_status = response.status();
+ response_status = response->status();
// 2. Let mimeType be the result of extracting a MIME type from response’s header list.
- auto mime_type = Infrastructure::extract_mime_type(response.header_list());
+ auto mime_type = Infrastructure::extract_mime_type(response->header_list());
// 3. If mimeType is non-null, then set bodyInfo’s content type to the result of minimizing a supported MIME type given mimeType.
if (mime_type.has_value())
@@ -1140,7 +1140,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
}
// 6. Let internalResponse be response, if response is a network error; otherwise response’s internal response.
- auto internal_response = response.is_network_error() ? GC::Ref { response } : response.unsafe_response();
+ auto internal_response = response.is_network_error() ? NonnullRefPtr { response } : response.unsafe_response();
// AD-HOC: Report a body's timing once the network has delivered it. Fetch reports it from the flush of the
// transform the body is piped through, which backpressure on an unread body can hold back.
@@ -1276,15 +1276,15 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
if (algorithms->process_response_consume_body()) {
// 1. Let processBody given nullOrBytes be this step: run fetchParams’s process response consume body given
// response and nullOrBytes.
- auto process_body = GC::create_function(GC::Heap::the(), [algorithms, &response, response_view](ByteBuffer bytes) {
- if (auto body = response.body(); body.has_value()) {
+ auto process_body = GC::create_function(GC::Heap::the(), [algorithms, response = response_view->record(), response_view](ByteBuffer bytes) {
+ if (auto body = response->body(); body.has_value()) {
if (auto source = body->source(); source.has_value()) {
(algorithms->process_response_consume_body())(response_view, *source);
return;
}
}
// A body the transport delivered as slices of one mapping keeps that mapping instead of the bytes read.
- if (auto const& network_transport = response.network_transport(); network_transport.has_value()) {
+ if (auto const& network_transport = response->network_transport(); network_transport.has_value()) {
if (auto whole_body = network_transport->body_channel->whole_body(); whole_body.has_value()) {
(algorithms->process_response_consume_body())(response_view, whole_body.release_value());
return;
@@ -1643,8 +1643,8 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam
auto request = fetch_params.request();
// 2. Let response and internalResponse be null.
- GC::Ptr<Infrastructure::Response> response;
- GC::Ptr<Infrastructure::Response> internal_response;
+ RefPtr<Infrastructure::Response> response;
+ RefPtr<Infrastructure::Response> internal_response;
// 3. If request’s service-workers mode is "all", then:
if (request->service_workers_mode() == Infrastructure::Request::ServiceWorkersMode::All) {
@@ -1682,8 +1682,8 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam
// 3. Set internalResponse to response, if response is not a filtered response; otherwise to response’s
// internal response.
internal_response = !is<Infrastructure::FilteredResponse>(*response)
- ? GC::Ref { *response }
- : static_cast<Infrastructure::FilteredResponse const&>(*response).internal_response();
+ ? NonnullRefPtr { *response }
+ : static_cast<Infrastructure::FilteredResponse&>(*response).internal_response();
// 4. If one of the following is true
if (
@@ -1749,7 +1749,7 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam
if (pending_preflight_response) {
pending_actual_response = PendingResponse::create(fetch_params);
- pending_preflight_response->when_loaded([returned_pending_response, pending_actual_response, fetch_main_content](GC::Ref<Infrastructure::Response> preflight_response) {
+ pending_preflight_response->when_loaded([returned_pending_response, pending_actual_response, fetch_main_content](NonnullRefPtr<Infrastructure::Response> preflight_response) {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'HTTP fetch' pending_preflight_response load callback");
// 2. If preflightResponse is a network error, then return preflightResponse.
@@ -1759,7 +1759,7 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam
}
auto pending_main_content_response = fetch_main_content->function()();
- pending_main_content_response->when_loaded([pending_actual_response](GC::Ref<Infrastructure::Response> main_content_response) {
+ pending_main_content_response->when_loaded([pending_actual_response](NonnullRefPtr<Infrastructure::Response> main_content_response) {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'HTTP fetch' pending_main_content_response load callback");
pending_actual_response->resolve(main_content_response);
});
@@ -1771,7 +1771,7 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam
pending_actual_response = PendingResponse::create(fetch_params, Infrastructure::Response::create());
}
- pending_actual_response->when_loaded([&realm, &fetch_params, request, response, internal_response, returned_pending_response, response_was_null = !response](GC::Ref<Infrastructure::Response> resolved_actual_response) mutable {
+ pending_actual_response->when_loaded([&realm, &fetch_params, request, response, internal_response, returned_pending_response, response_was_null = !response](NonnullRefPtr<Infrastructure::Response> resolved_actual_response) mutable {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'HTTP fetch' pending_actual_response load callback");
if (response_was_null) {
response = internal_response = resolved_actual_response;
@@ -1855,7 +1855,7 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam
}
if (inner_pending_response) {
- inner_pending_response->when_loaded([returned_pending_response](GC::Ref<Infrastructure::Response> response) {
+ inner_pending_response->when_loaded([returned_pending_response](NonnullRefPtr<Infrastructure::Response> response) {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'HTTP fetch' inner_pending_response load callback");
returned_pending_response->resolve(response);
});
@@ -1880,7 +1880,7 @@ GC::Ptr<PendingResponse> http_redirect_fetch(JS::Realm& realm, Infrastructure::F
// 2. Let internalResponse be response, if response is not a filtered response; otherwise response’s internal
// response.
auto internal_response = !is<Infrastructure::FilteredResponse>(response)
- ? GC::Ref { response }
+ ? NonnullRefPtr<Infrastructure::Response const> { response }
: static_cast<Infrastructure::FilteredResponse const&>(response).internal_response();
// 3. Let locationURL be internalResponse’s location URL given request’s current URL’s fragment.
@@ -2022,7 +2022,7 @@ enum class AuthenticationHandled {
};
// https://fetch.spec.whatwg.org/#concept-http-network-or-cache-fetch
-static void process_http_network_or_cache_response(JS::Object& global_object, Infrastructure::FetchParams const& fetch_params, NonnullRefPtr<Infrastructure::Request> http_request, GC::Ref<Infrastructure::Response> response, GC::Ref<PendingResponse> returned_pending_response, IsAuthenticationFetch is_authentication_fetch, IsNewConnectionFetch is_new_connection_fetch, HTTP::Cookie::IncludeCredentials include_credentials, AuthenticationHandled authentication_handled = AuthenticationHandled::No)
+static void process_http_network_or_cache_response(JS::Object& global_object, Infrastructure::FetchParams const& fetch_params, NonnullRefPtr<Infrastructure::Request> http_request, NonnullRefPtr<Infrastructure::Response> response, GC::Ref<PendingResponse> returned_pending_response, IsAuthenticationFetch is_authentication_fetch, IsNewConnectionFetch is_new_connection_fetch, HTTP::Cookie::IncludeCredentials include_credentials, AuthenticationHandled authentication_handled = AuthenticationHandled::No)
{
auto& realm = HTML::relevant_realm(global_object);
auto request = fetch_params.request();
@@ -2092,7 +2092,7 @@ static void process_http_network_or_cache_response(JS::Object& global_object, In
if (WebDriver::BiDi::g_network_events_enabled && authentication_handled == AuthenticationHandled::No) {
auto intercepts = WebDriver::BiDi::get_network_intercepts(fetch_params, "authRequired"sv);
if (!intercepts.is_empty()) {
- WebDriver::BiDi::block_network_request(fetch_params, response, "authRequired"_string, move(intercepts), WebDriver::BiDi::NetworkContinuation::create(realm.heap(), [&realm, &fetch_params, http_request, returned_pending_response, is_authentication_fetch, is_new_connection_fetch, include_credentials](WebDriver::BiDi::NetworkContinuationAction action, GC::Ptr<Infrastructure::Response> continued_response) {
+ WebDriver::BiDi::block_network_request(fetch_params, response, "authRequired"_string, move(intercepts), WebDriver::BiDi::NetworkContinuation::create(realm.heap(), [&realm, &fetch_params, http_request, returned_pending_response, is_authentication_fetch, is_new_connection_fetch, include_credentials](WebDriver::BiDi::NetworkContinuationAction action, RefPtr<Infrastructure::Response> continued_response) {
if (action == WebDriver::BiDi::NetworkContinuationAction::ProvideCredentials) {
stop_discarded_response_body(*fetch_params.controller(), *continued_response);
auto pending_response = http_network_or_cache_fetch(realm, fetch_params, IsAuthenticationFetch::Yes);
@@ -2123,7 +2123,7 @@ static void process_http_network_or_cache_response(JS::Object& global_object, In
inner_pending_response = http_network_or_cache_fetch(realm, fetch_params, IsAuthenticationFetch::Yes);
}
- inner_pending_response->when_loaded([&realm, &fetch_params, request, returned_pending_response, is_authentication_fetch, is_new_connection_fetch](GC::Ref<Infrastructure::Response> response) {
+ inner_pending_response->when_loaded([&realm, &fetch_params, request, returned_pending_response, is_authentication_fetch, is_new_connection_fetch](NonnullRefPtr<Infrastructure::Response> response) {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'HTTP network-or-cache fetch' inner_pending_response load callback");
// 15. If response’s status is 407, then:
if (response->status() == 407) {
@@ -2173,7 +2173,7 @@ static void process_http_network_or_cache_response(JS::Object& global_object, In
inner_pending_response = http_network_or_cache_fetch(realm, fetch_params, is_authentication_fetch, IsNewConnectionFetch::Yes);
}
- inner_pending_response->when_loaded([returned_pending_response, is_authentication_fetch](GC::Ref<Infrastructure::Response> response) {
+ inner_pending_response->when_loaded([returned_pending_response, is_authentication_fetch](NonnullRefPtr<Infrastructure::Response> response) {
// 17. If isAuthenticationFetch is true, then create an authentication entry for request and the given
// realm.
if (is_authentication_fetch == IsAuthenticationFetch::Yes) {
@@ -2186,7 +2186,7 @@ static void process_http_network_or_cache_response(JS::Object& global_object, In
}
// https://fetch.spec.whatwg.org/#concept-http-network-or-cache-fetch
-static GC::Ref<PendingResponse> continue_http_network_or_cache_fetch(JS::Object& global_object, Infrastructure::FetchParams const& fetch_params, GC::Ref<Infrastructure::FetchParams const> http_fetch_params, GC::Ptr<Infrastructure::Response> response, GC::Ptr<Infrastructure::Response> stored_response, RefPtr<HTTP::MemoryCache> http_cache, IsAuthenticationFetch is_authentication_fetch, IsNewConnectionFetch is_new_connection_fetch, HTTP::Cookie::IncludeCredentials include_credentials)
+static GC::Ref<PendingResponse> continue_http_network_or_cache_fetch(JS::Object& global_object, Infrastructure::FetchParams const& fetch_params, GC::Ref<Infrastructure::FetchParams const> http_fetch_params, RefPtr<Infrastructure::Response> response, RefPtr<Infrastructure::Response> stored_response, RefPtr<HTTP::MemoryCache> http_cache, IsAuthenticationFetch is_authentication_fetch, IsNewConnectionFetch is_new_connection_fetch, HTTP::Cookie::IncludeCredentials include_credentials)
{
auto& realm = HTML::relevant_realm(global_object);
auto request = fetch_params.request();
@@ -2213,7 +2213,7 @@ static GC::Ref<PendingResponse> continue_http_network_or_cache_fetch(JS::Object&
auto returned_pending_response = PendingResponse::create(fetch_params);
- pending_forward_response->when_loaded([&realm, &fetch_params, response, stored_response, http_request, http_fetch_params, returned_pending_response, is_authentication_fetch, is_new_connection_fetch, include_credentials, response_was_null = !response, http_cache](GC::Ref<Infrastructure::Response> resolved_forward_response) mutable {
+ pending_forward_response->when_loaded([&realm, &fetch_params, response, stored_response, http_request, http_fetch_params, returned_pending_response, is_authentication_fetch, is_new_connection_fetch, include_credentials, response_was_null = !response, http_cache](NonnullRefPtr<Infrastructure::Response> resolved_forward_response) mutable {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'HTTP-network-or-cache fetch' pending_forward_response load callback");
if (response_was_null) {
auto forward_response = resolved_forward_response;
@@ -2260,7 +2260,7 @@ static GC::Ref<PendingResponse> continue_http_network_or_cache_fetch(JS::Object&
WebDriver::BiDi::synchronize_network_request(*fetch_params.request(), *http_request);
auto intercepts = WebDriver::BiDi::get_network_intercepts(*http_fetch_params, "responseStarted"sv);
if (!response->is_network_error() && !intercepts.is_empty()) {
- WebDriver::BiDi::block_network_request(*http_fetch_params, response, "responseStarted"_string, move(intercepts), WebDriver::BiDi::NetworkContinuation::create(realm.heap(), [&realm, &fetch_params, http_request, returned_pending_response, is_authentication_fetch, is_new_connection_fetch, include_credentials](WebDriver::BiDi::NetworkContinuationAction, GC::Ptr<Infrastructure::Response> continued_response) {
+ WebDriver::BiDi::block_network_request(*http_fetch_params, response, "responseStarted"_string, move(intercepts), WebDriver::BiDi::NetworkContinuation::create(realm.heap(), [&realm, &fetch_params, http_request, returned_pending_response, is_authentication_fetch, is_new_connection_fetch, include_credentials](WebDriver::BiDi::NetworkContinuationAction, RefPtr<Infrastructure::Response> continued_response) {
process_http_network_or_cache_response(realm.global_object(), fetch_params, *http_request, *continued_response, returned_pending_response, is_authentication_fetch, is_new_connection_fetch, include_credentials);
}));
return;
@@ -2297,10 +2297,10 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
RefPtr<Infrastructure::Request> http_request;
// 4. Let response be null.
- GC::Ptr<Infrastructure::Response> response;
+ RefPtr<Infrastructure::Response> response;
// 5. Let storedResponse be null.
- GC::Ptr<Infrastructure::Response> stored_response;
+ RefPtr<Infrastructure::Response> stored_response;
// 6. Let httpCache be null.
RefPtr<HTTP::MemoryCache> http_cache;
@@ -2590,7 +2590,7 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
auto intercepts = WebDriver::BiDi::get_network_intercepts(*http_fetch_params, "beforeRequestSent"sv);
if (!intercepts.is_empty()) {
auto returned_pending_response = PendingResponse::create(fetch_params);
- WebDriver::BiDi::block_network_request(*http_fetch_params, nullptr, "beforeRequestSent"_string, move(intercepts), WebDriver::BiDi::NetworkContinuation::create(realm.heap(), [&realm, &fetch_params, http_fetch_params, response, stored_response, http_cache, is_authentication_fetch, is_new_connection_fetch, include_credentials, returned_pending_response](WebDriver::BiDi::NetworkContinuationAction action, GC::Ptr<Infrastructure::Response> continued_response) {
+ WebDriver::BiDi::block_network_request(*http_fetch_params, nullptr, "beforeRequestSent"_string, move(intercepts), WebDriver::BiDi::NetworkContinuation::create(realm.heap(), [&realm, &fetch_params, http_fetch_params, response, stored_response, http_cache, is_authentication_fetch, is_new_connection_fetch, include_credentials, returned_pending_response](WebDriver::BiDi::NetworkContinuationAction action, RefPtr<Infrastructure::Response> continued_response) {
// AD-HOC: The fetch can be canceled while its request is blocked.
if (fetch_params.is_canceled()) {
returned_pending_response->resolve(Infrastructure::Response::appropriate_network_error(fetch_params));
@@ -3106,7 +3106,7 @@ GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm& realm, Infrastructure::
auto preflight_response = http_network_or_cache_fetch(realm, preflight_fetch_params);
- preflight_response->when_loaded([request = fetch_params.request(), returned_pending_response, preflight_controller = preflight_fetch_params->controller()](GC::Ref<Infrastructure::Response> response) {
+ preflight_response->when_loaded([request = fetch_params.request(), returned_pending_response, preflight_controller = preflight_fetch_params->controller()](NonnullRefPtr<Infrastructure::Response> response) {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'CORS-preflight fetch' preflight_response load callback");
if (WebDriver::BiDi::g_network_events_enabled) {
diff --git a/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp b/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp
index 6ddd3a998a6..36c56c96d09 100644
--- a/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp
@@ -28,9 +28,9 @@ NetworkBodyPump::NetworkBodyPump(GC::Ptr<Infrastructure::FetchParams const> fetc
NetworkBodyPump::~NetworkBodyPump() = default;
-void NetworkBodyPump::set_response(GC::Ref<Infrastructure::Response> response)
+void NetworkBodyPump::set_response(NonnullRefPtr<Infrastructure::Response> response)
{
- m_response = response;
+ m_response = move(response);
if (m_network_complete)
update_response_body_info();
}
@@ -47,7 +47,6 @@ void NetworkBodyPump::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_fetch_params);
- visitor.visit(m_response);
}
// This implements the transmission steps of HTTP-network fetch.
diff --git a/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.h b/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.h
index 23322592994..6fadb86dc5d 100644
--- a/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.h
+++ b/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.h
@@ -29,7 +29,8 @@ class NetworkBodyPump final : public JS::Cell {
public:
virtual ~NetworkBodyPump() override;
- void set_response(GC::Ref<Fetch::Infrastructure::Response>);
+ // The pump records the body's sizes in the response once the body completes.
+ void set_response(NonnullRefPtr<Fetch::Infrastructure::Response>);
void handle_network_data(Requests::ResponseData);
void handle_network_complete(Optional<u64> encoded_body_size = {});
@@ -48,7 +49,7 @@ private:
void update_response_body_info();
GC::Ptr<Infrastructure::FetchParams const> m_fetch_params;
- GC::Ptr<Fetch::Infrastructure::Response> m_response;
+ RefPtr<Fetch::Infrastructure::Response> m_response;
NonnullRefPtr<Engine::FetchByteChannel> m_channel;
NonnullRefPtr<Engine::FetchBodyDeliveryGate> m_delivery_gate;
diff --git a/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cpp b/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cpp
index 69ac8c895b5..896c75bc7a5 100644
--- a/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cpp
@@ -20,14 +20,14 @@ GC::Ref<PendingResponse> PendingResponse::create(Infrastructure::FetchParams con
return GC::Heap::the().allocate<PendingResponse>(fetch_params.controller());
}
-GC::Ref<PendingResponse> PendingResponse::create(Infrastructure::FetchParams const& fetch_params, GC::Ref<Infrastructure::Response> response)
+GC::Ref<PendingResponse> PendingResponse::create(Infrastructure::FetchParams const& fetch_params, NonnullRefPtr<Infrastructure::Response> response)
{
- return GC::Heap::the().allocate<PendingResponse>(fetch_params.controller(), response);
+ return GC::Heap::the().allocate<PendingResponse>(fetch_params.controller(), move(response));
}
-PendingResponse::PendingResponse(GC::Ref<Infrastructure::FetchController> fetch_controller, GC::Ptr<Infrastructure::Response> response)
+PendingResponse::PendingResponse(GC::Ref<Infrastructure::FetchController> fetch_controller, RefPtr<Infrastructure::Response> response)
: m_fetch_controller(fetch_controller)
- , m_response(response)
+ , m_response(move(response))
{
m_fetch_controller->add_pending_response({}, *this);
}
@@ -37,7 +37,6 @@ void PendingResponse::visit_edges(JS::Cell::Visitor& visitor)
Base::visit_edges(visitor);
visitor.visit(m_callback);
visitor.visit(m_fetch_controller);
- visitor.visit(m_response);
}
void PendingResponse::when_loaded(Callback callback)
@@ -48,10 +47,10 @@ void PendingResponse::when_loaded(Callback callback)
run_callback();
}
-void PendingResponse::resolve(GC::Ref<Infrastructure::Response> response)
+void PendingResponse::resolve(NonnullRefPtr<Infrastructure::Response> response)
{
VERIFY(!m_response);
- m_response = response;
+ m_response = move(response);
if (m_callback)
run_callback();
}
diff --git a/Libraries/LibWeb/Fetch/Fetching/PendingResponse.h b/Libraries/LibWeb/Fetch/Fetching/PendingResponse.h
index d7f4dfb8229..3d33b4463ce 100644
--- a/Libraries/LibWeb/Fetch/Fetching/PendingResponse.h
+++ b/Libraries/LibWeb/Fetch/Fetching/PendingResponse.h
@@ -22,25 +22,25 @@ class PendingResponse : public JS::Cell {
GC_DECLARE_ALLOCATOR(PendingResponse);
public:
- using Callback = Function<void(GC::Ref<Infrastructure::Response>)>;
+ using Callback = Function<void(NonnullRefPtr<Infrastructure::Response>)>;
[[nodiscard]] static GC::Ref<PendingResponse> create(Infrastructure::FetchParams const&);
- [[nodiscard]] static GC::Ref<PendingResponse> create(Infrastructure::FetchParams const&, GC::Ref<Infrastructure::Response>);
+ [[nodiscard]] static GC::Ref<PendingResponse> create(Infrastructure::FetchParams const&, NonnullRefPtr<Infrastructure::Response>);
void when_loaded(Callback);
- void resolve(GC::Ref<Infrastructure::Response>);
+ void resolve(NonnullRefPtr<Infrastructure::Response>);
bool is_resolved() const { return m_response != nullptr; }
private:
- PendingResponse(GC::Ref<Infrastructure::FetchController>, GC::Ptr<Infrastructure::Response> = {});
+ PendingResponse(GC::Ref<Infrastructure::FetchController>, RefPtr<Infrastructure::Response> = {});
virtual void visit_edges(JS::Cell::Visitor&) override;
void run_callback();
- GC::Ptr<GC::Function<void(GC::Ref<Infrastructure::Response>)>> m_callback;
+ GC::Ptr<GC::Function<void(NonnullRefPtr<Infrastructure::Response>)>> m_callback;
GC::Ref<Infrastructure::FetchController> m_fetch_controller;
- GC::Ptr<Infrastructure::Response> m_response;
+ RefPtr<Infrastructure::Response> m_response;
};
}
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp
index 666aafe77e8..d9181930b6a 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp
@@ -54,7 +54,6 @@ void FetchParams::visit_edges(JS::Cell::Visitor& visitor)
visitor.visit(m_algorithms);
visitor.visit(m_controller);
visitor.visit(m_task_destination);
- visitor.visit(m_preloaded_response_candidate);
}
// 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 e5d0b4c27d9..616dd05d1a0 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h
@@ -15,6 +15,7 @@
#include <LibWeb/Fetch/Infrastructure/FetchController.h>
#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>
@@ -28,7 +29,7 @@ class WEB_API FetchParams : public JS::Cell {
public:
struct PreloadedResponseCandidatePendingTag { };
- using PreloadedResponseCandidate = Variant<Empty, PreloadedResponseCandidatePendingTag, GC::Ref<Response>>;
+ using PreloadedResponseCandidate = Variant<Empty, PreloadedResponseCandidatePendingTag, NonnullRefPtr<Response>>;
[[nodiscard]] static GC::Ref<FetchParams> create(NonnullRefPtr<Request>, GC::Ref<FetchAlgorithms const>, NonnullRefPtr<FetchTimingInfo>, NonnullRefPtr<LoaderConfigSnapshot const>);
[[nodiscard]] static GC::Ref<FetchParams> copy(FetchParams const&);
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.cpp
index 95c3c992320..22f0c47b50f 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.cpp
@@ -11,13 +11,13 @@ namespace Web::Fetch::Infrastructure {
GC_DEFINE_ALLOCATOR(ResponseView);
-GC::Ref<ResponseView> ResponseView::create(GC::Ref<Response> record, GC::Ptr<Body> body_view)
+GC::Ref<ResponseView> ResponseView::create(NonnullRefPtr<Response const> record, GC::Ptr<Body> body_view)
{
VERIFY(record->unsafe_response()->body().has_value() == (body_view != nullptr));
- return GC::Heap::the().allocate<ResponseView>(record, body_view);
+ return GC::Heap::the().allocate<ResponseView>(move(record), body_view);
}
-GC::Ref<ResponseView> ResponseView::create(JS::Realm& realm, GC::Ref<Response> record)
+GC::Ref<ResponseView> ResponseView::create(JS::Realm& realm, NonnullRefPtr<Response const> record)
{
auto body = record->unsafe_response()->body();
if (!body.has_value())
@@ -35,8 +35,8 @@ GC::Ref<ResponseView> ResponseView::aborted_network_error()
return create(Response::aborted_network_error(), nullptr);
}
-ResponseView::ResponseView(GC::Ref<Response> record, GC::Ptr<Body> body_view)
- : m_record(record)
+ResponseView::ResponseView(NonnullRefPtr<Response const> record, GC::Ptr<Body> body_view)
+ : m_record(move(record))
, m_body_view(body_view)
{
}
@@ -44,7 +44,6 @@ ResponseView::ResponseView(GC::Ref<Response> record, GC::Ptr<Body> body_view)
void ResponseView::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
- visitor.visit(m_record);
visitor.visit(m_body_view);
}
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h
index 4a695298eb7..f3b603e02ac 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h
@@ -20,13 +20,13 @@ class WEB_API ResponseView final : public JS::Cell {
public:
// body_view is the view of the body of record's unsafe response.
- [[nodiscard]] static GC::Ref<ResponseView> create(GC::Ref<Response> record, GC::Ptr<Body> body_view);
+ [[nodiscard]] static GC::Ref<ResponseView> create(NonnullRefPtr<Response const> record, GC::Ptr<Body> body_view);
// The body of record's unsafe response is null or bytes.
- [[nodiscard]] static GC::Ref<ResponseView> create(JS::Realm&, GC::Ref<Response> record);
+ [[nodiscard]] static GC::Ref<ResponseView> create(JS::Realm&, NonnullRefPtr<Response const> record);
[[nodiscard]] static GC::Ref<ResponseView> network_error(String message);
[[nodiscard]] static GC::Ref<ResponseView> aborted_network_error();
- [[nodiscard]] GC::Ref<Response> record() const { return m_record; }
+ [[nodiscard]] NonnullRefPtr<Response const> const& record() const { return m_record; }
[[nodiscard]] Response::Type type() const { return m_record->type(); }
[[nodiscard]] bool aborted() const { return m_record->aborted(); }
@@ -65,11 +65,11 @@ public:
[[nodiscard]] Vector<Core::ImmutableBytes> release_body_for_transfer() const { return m_record->release_body_for_transfer(); }
private:
- ResponseView(GC::Ref<Response>, GC::Ptr<Body>);
+ ResponseView(NonnullRefPtr<Response const>, GC::Ptr<Body>);
virtual void visit_edges(Visitor&) override;
- GC::Ref<Response> m_record;
+ NonnullRefPtr<Response const> m_record;
GC::Ptr<Body> m_body_view;
};
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp
index 29a7a356a67..7546baac332 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp
@@ -6,9 +6,6 @@
#include <AK/Debug.h>
#include <AK/TypeCasts.h>
-#include <LibGC/Heap.h>
-#include <LibJS/Runtime/Completion.h>
-#include <LibJS/Runtime/VM.h>
#include <LibWeb/DOMURL/DOMURL.h>
#include <LibWeb/Fetch/Infrastructure/FetchParams.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
@@ -18,20 +15,9 @@
namespace Web::Fetch::Infrastructure {
-GC_DEFINE_ALLOCATOR(Response);
-GC_DEFINE_ALLOCATOR(BasicFilteredResponse);
-GC_DEFINE_ALLOCATOR(CORSFilteredResponse);
-GC_DEFINE_ALLOCATOR(OpaqueFilteredResponse);
-GC_DEFINE_ALLOCATOR(OpaqueRedirectFilteredResponse);
-
-GC::Ref<Response> Response::create()
-{
- return GC::Heap::the().allocate<Response>(HTTP::HeaderList::create());
-}
-
-GC::Ref<Response> Response::create(JS::VM&)
+NonnullRefPtr<Response> Response::create()
{
- return create();
+ return adopt_ref(*new Response(HTTP::HeaderList::create()));
}
Response::Response(NonnullRefPtr<HTTP::HeaderList> header_list)
@@ -44,14 +30,14 @@ Response::Response(NonnullRefPtr<HTTP::HeaderList> header_list)
// A network error is a response whose status is always 0, status message is always
// the empty byte sequence, header list is always empty, and body is always null.
-GC::Ref<Response> Response::aborted_network_error()
+NonnullRefPtr<Response> Response::aborted_network_error()
{
auto response = network_error("Fetch has been aborted"_string);
response->set_aborted(true);
return response;
}
-GC::Ref<Response> Response::network_error(String message)
+NonnullRefPtr<Response> Response::network_error(String message)
{
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Creating network error response with message: {}", message);
auto response = Response::create();
@@ -62,13 +48,8 @@ GC::Ref<Response> Response::network_error(String message)
return response;
}
-GC::Ref<Response> Response::network_error(JS::VM&, String message)
-{
- return network_error(move(message));
-}
-
// https://fetch.spec.whatwg.org/#appropriate-network-error
-GC::Ref<Response> Response::appropriate_network_error(FetchParams const& fetch_params)
+NonnullRefPtr<Response> Response::appropriate_network_error(FetchParams const& fetch_params)
{
// 1. Assert: fetchParams is canceled.
VERIFY(fetch_params.is_canceled());
@@ -180,7 +161,7 @@ ErrorOr<Optional<URL::URL>> Response::location_url(Optional<StringView> request_
}
// https://fetch.spec.whatwg.org/#concept-response-clone
-GC::Ref<Response> Response::clone() const
+NonnullRefPtr<Response> Response::clone() const
{
// To clone a response response, run these steps:
// 1. If response is a filtered response, then return a new identical filtered response whose internal response is a clone of response’s internal response.
@@ -235,9 +216,17 @@ GC::Ref<Response> Response::clone() const
}
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#unsafe-response
-GC::Ref<Response> Response::unsafe_response()
+NonnullRefPtr<Response const> Response::unsafe_response() const
{
// A response's unsafe response is its internal response if it has one, and the response itself otherwise.
+ if (is<FilteredResponse>(this))
+ return static_cast<FilteredResponse const&>(*this).internal_response();
+
+ return *this;
+}
+
+NonnullRefPtr<Response> Response::unsafe_response()
+{
if (is<FilteredResponse>(this))
return static_cast<FilteredResponse&>(*this).internal_response();
@@ -265,9 +254,9 @@ bool Response::is_cors_cross_origin() const
return type() == Type::Opaque || type() == Type::OpaqueRedirect;
}
-FilteredResponse::FilteredResponse(GC::Ref<Response> internal_response, NonnullRefPtr<HTTP::HeaderList> header_list)
+FilteredResponse::FilteredResponse(NonnullRefPtr<Response> internal_response, NonnullRefPtr<HTTP::HeaderList> header_list)
: Response(move(header_list))
- , m_internal_response(internal_response)
+ , m_internal_response(move(internal_response))
{
}
@@ -275,13 +264,7 @@ FilteredResponse::~FilteredResponse()
{
}
-void FilteredResponse::visit_edges(JS::Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_internal_response);
-}
-
-GC::Ref<BasicFilteredResponse> BasicFilteredResponse::create(GC::Ref<Response> internal_response)
+NonnullRefPtr<BasicFilteredResponse> BasicFilteredResponse::create(NonnullRefPtr<Response> internal_response)
{
// A basic filtered response is a filtered response whose type is "basic" and header list excludes
// any headers in internal response’s header list whose name is a forbidden response-header name.
@@ -292,16 +275,16 @@ GC::Ref<BasicFilteredResponse> BasicFilteredResponse::create(GC::Ref<Response> i
header_list->append(header);
}
- return GC::Heap::the().allocate<BasicFilteredResponse>(internal_response, move(header_list));
+ return adopt_ref(*new BasicFilteredResponse(move(internal_response), move(header_list)));
}
-BasicFilteredResponse::BasicFilteredResponse(GC::Ref<Response> internal_response, NonnullRefPtr<HTTP::HeaderList> header_list)
- : FilteredResponse(internal_response, header_list)
+BasicFilteredResponse::BasicFilteredResponse(NonnullRefPtr<Response> internal_response, NonnullRefPtr<HTTP::HeaderList> header_list)
+ : FilteredResponse(move(internal_response), header_list)
, m_header_list(move(header_list))
{
}
-GC::Ref<CORSFilteredResponse> CORSFilteredResponse::create(GC::Ref<Response> internal_response)
+NonnullRefPtr<CORSFilteredResponse> CORSFilteredResponse::create(NonnullRefPtr<Response> internal_response)
{
// A CORS filtered response is a filtered response whose type is "cors" and header list excludes
// any headers in internal response’s header list whose name is not a CORS-safelisted response-header
@@ -318,37 +301,37 @@ GC::Ref<CORSFilteredResponse> CORSFilteredResponse::create(GC::Ref<Response> int
header_list->append(header);
}
- return GC::Heap::the().allocate<CORSFilteredResponse>(internal_response, header_list);
+ return adopt_ref(*new CORSFilteredResponse(move(internal_response), move(header_list)));
}
-CORSFilteredResponse::CORSFilteredResponse(GC::Ref<Response> internal_response, NonnullRefPtr<HTTP::HeaderList> header_list)
- : FilteredResponse(internal_response, header_list)
+CORSFilteredResponse::CORSFilteredResponse(NonnullRefPtr<Response> internal_response, NonnullRefPtr<HTTP::HeaderList> header_list)
+ : FilteredResponse(move(internal_response), header_list)
, m_header_list(move(header_list))
{
}
-GC::Ref<OpaqueFilteredResponse> OpaqueFilteredResponse::create(GC::Ref<Response> internal_response)
+NonnullRefPtr<OpaqueFilteredResponse> OpaqueFilteredResponse::create(NonnullRefPtr<Response> internal_response)
{
// An opaque filtered response is a filtered response whose type is "opaque", URL list is the empty list,
// status is 0, status message is the empty byte sequence, header list is empty, and body is null.
- return GC::Heap::the().allocate<OpaqueFilteredResponse>(internal_response, HTTP::HeaderList::create());
+ return adopt_ref(*new OpaqueFilteredResponse(move(internal_response), HTTP::HeaderList::create()));
}
-OpaqueFilteredResponse::OpaqueFilteredResponse(GC::Ref<Response> internal_response, NonnullRefPtr<HTTP::HeaderList> header_list)
- : FilteredResponse(internal_response, header_list)
+OpaqueFilteredResponse::OpaqueFilteredResponse(NonnullRefPtr<Response> internal_response, NonnullRefPtr<HTTP::HeaderList> header_list)
+ : FilteredResponse(move(internal_response), header_list)
, m_header_list(move(header_list))
{
}
-GC::Ref<OpaqueRedirectFilteredResponse> OpaqueRedirectFilteredResponse::create(GC::Ref<Response> internal_response)
+NonnullRefPtr<OpaqueRedirectFilteredResponse> OpaqueRedirectFilteredResponse::create(NonnullRefPtr<Response> internal_response)
{
// An opaque-redirect filtered response is a filtered response whose type is "opaqueredirect",
// status is 0, status message is the empty byte sequence, header list is empty, and body is null.
- return GC::Heap::the().allocate<OpaqueRedirectFilteredResponse>(internal_response, HTTP::HeaderList::create());
+ return adopt_ref(*new OpaqueRedirectFilteredResponse(move(internal_response), HTTP::HeaderList::create()));
}
-OpaqueRedirectFilteredResponse::OpaqueRedirectFilteredResponse(GC::Ref<Response> internal_response, NonnullRefPtr<HTTP::HeaderList> header_list)
- : FilteredResponse(internal_response, header_list)
+OpaqueRedirectFilteredResponse::OpaqueRedirectFilteredResponse(NonnullRefPtr<Response> internal_response, NonnullRefPtr<HTTP::HeaderList> header_list)
+ : FilteredResponse(move(internal_response), header_list)
, m_header_list(move(header_list))
{
}
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h
index 41708dbcafa..1e8ef850025 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h
@@ -9,15 +9,14 @@
#include <AK/ByteString.h>
#include <AK/Error.h>
#include <AK/Forward.h>
+#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
+#include <AK/RefCounted.h>
#include <AK/Time.h>
#include <AK/Utf16String.h>
#include <AK/Vector.h>
#include <LibCore/ImmutableBytes.h>
-#include <LibGC/Ptr.h>
#include <LibHTTP/HeaderList.h>
-#include <LibJS/Forward.h>
-#include <LibJS/Heap/Cell.h>
#include <LibURL/URL.h>
#include <LibWeb/Export.h>
#include <LibWeb/Fetch/Engine/FetchBodyDeliveryGate.h>
@@ -30,10 +29,7 @@
namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#concept-response
-class WEB_API Response : public JS::Cell {
- GC_CELL(Response, JS::Cell);
- GC_DECLARE_ALLOCATOR(Response);
-
+class WEB_API Response : public RefCounted<Response> {
public:
using CacheState = ResponseCacheState;
@@ -67,12 +63,10 @@ public:
NonnullRefPtr<Engine::FetchByteChannel> body_channel;
};
- [[nodiscard]] static GC::Ref<Response> create();
- [[nodiscard]] static GC::Ref<Response> create(JS::VM&);
- [[nodiscard]] static GC::Ref<Response> aborted_network_error();
- [[nodiscard]] static GC::Ref<Response> network_error(String message);
- [[nodiscard]] static GC::Ref<Response> network_error(JS::VM&, String message);
- [[nodiscard]] static GC::Ref<Response> appropriate_network_error(FetchParams const&);
+ [[nodiscard]] static NonnullRefPtr<Response> create();
+ [[nodiscard]] static NonnullRefPtr<Response> aborted_network_error();
+ [[nodiscard]] static NonnullRefPtr<Response> network_error(String message);
+ [[nodiscard]] static NonnullRefPtr<Response> appropriate_network_error(FetchParams const&);
virtual ~Response() = default;
@@ -135,9 +129,10 @@ public:
[[nodiscard]] Optional<URL::URL const&> url() const;
[[nodiscard]] ErrorOr<Optional<URL::URL>> location_url(Optional<StringView> request_fragment) const;
- [[nodiscard]] GC::Ref<Response> clone() const;
+ [[nodiscard]] NonnullRefPtr<Response> clone() const;
- [[nodiscard]] GC::Ref<Response> unsafe_response();
+ [[nodiscard]] NonnullRefPtr<Response const> unsafe_response() const;
+ [[nodiscard]] NonnullRefPtr<Response> unsafe_response();
[[nodiscard]] bool is_cors_same_origin() const;
[[nodiscard]] bool is_cors_cross_origin() const;
@@ -239,10 +234,8 @@ public:
// https://fetch.spec.whatwg.org/#concept-filtered-response
class FilteredResponse : public Response {
- GC_CELL(FilteredResponse, Response);
-
public:
- FilteredResponse(GC::Ref<Response>, NonnullRefPtr<HTTP::HeaderList>);
+ FilteredResponse(NonnullRefPtr<Response>, NonnullRefPtr<HTTP::HeaderList>);
virtual ~FilteredResponse() = 0;
[[nodiscard]] virtual Type type() const override { return m_internal_response->type(); }
@@ -296,57 +289,46 @@ public:
virtual void resume_body_delivery_up_to(size_t byte_count) const override { m_internal_response->resume_body_delivery_up_to(byte_count); }
virtual Vector<Core::ImmutableBytes> release_body_for_transfer() const override { return m_internal_response->release_body_for_transfer(); }
- [[nodiscard]] GC::Ref<Response> internal_response() const { return m_internal_response; }
-
-protected:
- virtual void visit_edges(JS::Cell::Visitor&) override;
+ [[nodiscard]] NonnullRefPtr<Response const> internal_response() const { return m_internal_response; }
+ [[nodiscard]] NonnullRefPtr<Response> internal_response() { return m_internal_response; }
private:
// https://fetch.spec.whatwg.org/#concept-internal-response
- GC::Ref<Response> m_internal_response;
+ NonnullRefPtr<Response> m_internal_response;
};
// https://fetch.spec.whatwg.org/#concept-filtered-response-basic
class WEB_API BasicFilteredResponse final : public FilteredResponse {
- GC_CELL(BasicFilteredResponse, FilteredResponse);
- GC_DECLARE_ALLOCATOR(BasicFilteredResponse);
-
public:
- [[nodiscard]] static GC::Ref<BasicFilteredResponse> create(GC::Ref<Response>);
+ [[nodiscard]] static NonnullRefPtr<BasicFilteredResponse> create(NonnullRefPtr<Response>);
[[nodiscard]] virtual Type type() const override { return Type::Basic; }
virtual NonnullRefPtr<HTTP::HeaderList> const& header_list() const override { return m_header_list; }
private:
- BasicFilteredResponse(GC::Ref<Response>, NonnullRefPtr<HTTP::HeaderList>);
+ BasicFilteredResponse(NonnullRefPtr<Response>, NonnullRefPtr<HTTP::HeaderList>);
NonnullRefPtr<HTTP::HeaderList> m_header_list;
};
// https://fetch.spec.whatwg.org/#concept-filtered-response-cors
class WEB_API CORSFilteredResponse final : public FilteredResponse {
- GC_CELL(CORSFilteredResponse, FilteredResponse);
- GC_DECLARE_ALLOCATOR(CORSFilteredResponse);
-
public:
- [[nodiscard]] static GC::Ref<CORSFilteredResponse> create(GC::Ref<Response>);
+ [[nodiscard]] static NonnullRefPtr<CORSFilteredResponse> create(NonnullRefPtr<Response>);
[[nodiscard]] virtual Type type() const override { return Type::CORS; }
virtual NonnullRefPtr<HTTP::HeaderList> const& header_list() const override { return m_header_list; }
private:
- CORSFilteredResponse(GC::Ref<Response>, NonnullRefPtr<HTTP::HeaderList>);
+ CORSFilteredResponse(NonnullRefPtr<Response>, NonnullRefPtr<HTTP::HeaderList>);
NonnullRefPtr<HTTP::HeaderList> m_header_list;
};
// https://fetch.spec.whatwg.org/#concept-filtered-response-opaque
class WEB_API OpaqueFilteredResponse final : public FilteredResponse {
- GC_CELL(OpaqueFilteredResponse, FilteredResponse);
- GC_DECLARE_ALLOCATOR(OpaqueFilteredResponse);
-
public:
- [[nodiscard]] static GC::Ref<OpaqueFilteredResponse> create(GC::Ref<Response>);
+ [[nodiscard]] static NonnullRefPtr<OpaqueFilteredResponse> create(NonnullRefPtr<Response>);
[[nodiscard]] virtual Type type() const override { return Type::Opaque; }
[[nodiscard]] virtual Vector<URL::URL> const& url_list() const override { return m_url_list; }
@@ -357,7 +339,7 @@ public:
[[nodiscard]] virtual Optional<ResponseBody const&> body() const override { return {}; }
private:
- OpaqueFilteredResponse(GC::Ref<Response>, NonnullRefPtr<HTTP::HeaderList>);
+ OpaqueFilteredResponse(NonnullRefPtr<Response>, NonnullRefPtr<HTTP::HeaderList>);
Vector<URL::URL> m_url_list;
ByteString const m_method;
@@ -366,11 +348,8 @@ private:
// https://fetch.spec.whatwg.org/#concept-filtered-response-opaque-redirect
class WEB_API OpaqueRedirectFilteredResponse final : public FilteredResponse {
- GC_CELL(OpaqueRedirectFilteredResponse, FilteredResponse);
- GC_DECLARE_ALLOCATOR(OpaqueRedirectFilteredResponse);
-
public:
- [[nodiscard]] static GC::Ref<OpaqueRedirectFilteredResponse> create(GC::Ref<Response>);
+ [[nodiscard]] static NonnullRefPtr<OpaqueRedirectFilteredResponse> create(NonnullRefPtr<Response>);
[[nodiscard]] virtual Type type() const override { return Type::OpaqueRedirect; }
[[nodiscard]] virtual Status status() const override { return 0; }
@@ -379,7 +358,7 @@ public:
[[nodiscard]] virtual Optional<ResponseBody const&> body() const override { return {}; }
private:
- OpaqueRedirectFilteredResponse(GC::Ref<Response>, NonnullRefPtr<HTTP::HeaderList>);
+ OpaqueRedirectFilteredResponse(NonnullRefPtr<Response>, NonnullRefPtr<HTTP::HeaderList>);
ByteString const m_method;
NonnullRefPtr<HTTP::HeaderList> m_header_list;
diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
index c2d9c915e1d..c0c5b840d2d 100644
--- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
@@ -1033,7 +1033,9 @@ void HTMLLinkElement::preload(LinkProcessingOptions& options, Function<void(Fetc
fetch_algorithms_input.process_response_consume_body = [options = GC::Ref { options }, process_response = move(process_response), entry, report_timing](GC::Ref<Fetch::Infrastructure::ResponseView> response_view, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) {
// FIXME: If the response is CORS cross-origin, we must use its internal response to query any of its data. See:
// https://github.com/whatwg/html/issues/9355
- auto response = response_view->record()->unsafe_response();
+ // NB: Step 1 sets the body of a clone of response, so the response fetch delivered never changes. Nothing can
+ // observe the difference.
+ auto response = response_view->record()->unsafe_response()->clone();
// 1. If bodyBytes is a byte sequence, then set response's body to bodyBytes as a body.
if (auto* byte_sequence = body_bytes.get_pointer<Core::ImmutableBytes>())
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index c46ed05b45a..f907d1ae79b 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -2146,7 +2146,7 @@ static GC::Ref<NavigationParams> create_navigation_params_from_a_srcdoc_resource
// URL: about:srcdoc
// header list: (`Content-Type`, `text/html`)
// body: the UTF-8 encoding of documentResource, as a body
- auto response = Fetch::Infrastructure::Response::create(vm);
+ auto response = Fetch::Infrastructure::Response::create();
response->url_list().append(URL::about_srcdoc());
response->header_list()->append({ "Content-Type"sv, "text/html"sv });
auto document_resource_utf8 = MUST(document_resource.get<Utf16String>().utf16_view().to_utf8());
@@ -4052,7 +4052,7 @@ GC::Ptr<DOM::Document> LocalNavigable::evaluate_javascript_url(URL::URL const& u
// header list: «(`Content-Type`, `text/html;charset=utf-8`)»
// body: the UTF-8 encoding of result, as a body
auto result_utf8 = MUST(result->to_utf8());
- auto response = Fetch::Infrastructure::Response::create(vm);
+ auto response = Fetch::Infrastructure::Response::create();
response->url_list().append(active_document()->url());
response->header_list()->append({ "Content-Type"sv, "text/html;charset=utf-8"sv });
response->set_body(Fetch::Infrastructure::byte_sequence_as_response_body(result_utf8.bytes()));
diff --git a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
index bc643545dc4..c27797add8e 100644
--- a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
+++ b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
@@ -254,8 +254,8 @@ static Function<void(Optional<StringView>)> network_navigation_response_observer
{
auto observed_navigable = network_response.has_value() ? GC::Weak<LocalNavigable> { navigable } : GC::Weak<LocalNavigable> {};
- // NB: The body pump traces response. Observing its navigable must not keep the navigable alive.
- return [response = GC::Ptr { &response }, observed_navigable = move(observed_navigable), timing_info = move(timing_info), network_response = move(network_response), network_response_state = move(network_response_state)](Optional<StringView> error) {
+ // NB: Observing its navigable must not keep the navigable alive.
+ return [response = NonnullRefPtr { response }, observed_navigable = move(observed_navigable), timing_info = move(timing_info), network_response = move(network_response), network_response_state = move(network_response_state)](Optional<StringView> error) {
if (!network_response.has_value() || !observed_navigable || network_response_state->owner != NavigationResponseNetworkEventState::Owner::Renderer)
return;
network_response_state->owner = NavigationResponseNetworkEventState::Owner::Completed;
@@ -266,8 +266,8 @@ static Function<void(Optional<StringView>)> network_navigation_response_observer
static ErrorOr<GC::Ref<Fetch::Infrastructure::ResponseView>> create_navigation_response_from_descriptor(JS::Realm& realm, LocalNavigable& navigable, NavigationResponseDescriptor descriptor, RefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, RefPtr<NavigationResponseNetworkEventState> network_response_state)
{
auto response = descriptor.network_error_message.has_value()
- ? Fetch::Infrastructure::Response::network_error(realm.vm(), move(*descriptor.network_error_message))
- : Fetch::Infrastructure::Response::create(realm.vm());
+ ? Fetch::Infrastructure::Response::network_error(move(*descriptor.network_error_message))
+ : Fetch::Infrastructure::Response::create();
response->set_url_list(move(descriptor.url_list));
response->set_status(descriptor.status);
response->set_status_message(move(descriptor.status_message));
diff --git a/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp
index 266802d7e1c..f5519905ab5 100644
--- a/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp
+++ b/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp
@@ -174,10 +174,11 @@ void issue_speculative_fetch(JS::Realm& realm, DOM::Document& document, URL::URL
return;
// NB: Keep the filtered response, which main fetch uses as is. Unfiltered, it would be treated as same-origin.
- internal_response->set_body(Fetch::Infrastructure::ResponseBody::from_bytes(*byte_sequence));
+ auto preloaded_response = response->clone();
+ preloaded_response->unsafe_response()->set_body(Fetch::Infrastructure::ResponseBody::from_bytes(*byte_sequence));
auto entry = PreloadEntry::create();
- entry->response = response;
+ entry->response = move(preloaded_response);
entry->is_speculative = true;
document->map_of_preloaded_resources().set(key, entry);
};
diff --git a/Libraries/LibWeb/HTML/PreloadEntry.cpp b/Libraries/LibWeb/HTML/PreloadEntry.cpp
index e01ca2b10bf..fa1d6b90364 100644
--- a/Libraries/LibWeb/HTML/PreloadEntry.cpp
+++ b/Libraries/LibWeb/HTML/PreloadEntry.cpp
@@ -24,7 +24,6 @@ GC::Ref<PreloadEntry> PreloadEntry::create()
void PreloadEntry::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
- visitor.visit(response);
visitor.visit(on_response_available);
visitor.visit(controller);
}
@@ -61,7 +60,7 @@ bool consume_a_preloaded_resource(
Fetch::Infrastructure::Request::Mode mode,
Fetch::Infrastructure::Request::CredentialsMode credentials_mode,
Utf16View integrity_metadata,
- GC::Ref<GC::Function<void(GC::Ref<Fetch::Infrastructure::Response>)>> on_response_available,
+ GC::Ref<GC::Function<void(NonnullRefPtr<Fetch::Infrastructure::Response>)>> on_response_available,
Fetch::Engine::BodyIntent consumer_body_intent,
bool& preload_reports_timing)
{
diff --git a/Libraries/LibWeb/HTML/PreloadEntry.h b/Libraries/LibWeb/HTML/PreloadEntry.h
index 5cd745b6006..e73a7d51a1c 100644
--- a/Libraries/LibWeb/HTML/PreloadEntry.h
+++ b/Libraries/LibWeb/HTML/PreloadEntry.h
@@ -62,13 +62,13 @@ public:
// response
// Null or a response
- GC::Ptr<Fetch::Infrastructure::Response> response;
+ RefPtr<Fetch::Infrastructure::Response> response;
// on response available
// Null, or an algorithm accepting a response or null
// The callback is always invoked with a non-null response — either entry's resolved response,
// or the response delivered by the preload's fetch.
- GC::Ptr<GC::Function<void(GC::Ref<Fetch::Infrastructure::Response>)>> on_response_available;
+ GC::Ptr<GC::Function<void(NonnullRefPtr<Fetch::Infrastructure::Response>)>> on_response_available;
// AD-HOC: The controller of the fetch loading this entry. A sync XHR consumer, whose event loop is paused while it's
// blocked, re-targets that fetch thru this, so it delivers its response without the event loop as well; see
@@ -87,7 +87,7 @@ bool consume_a_preloaded_resource(
Fetch::Infrastructure::Request::Mode mode,
Fetch::Infrastructure::Request::CredentialsMode credentials_mode,
Utf16View integrity_metadata,
- GC::Ref<GC::Function<void(GC::Ref<Fetch::Infrastructure::Response>)>> on_response_available,
+ GC::Ref<GC::Function<void(NonnullRefPtr<Fetch::Infrastructure::Response>)>> on_response_available,
Fetch::Engine::BodyIntent consumer_body_intent,
bool& preload_reports_timing);
diff --git a/Libraries/LibWeb/MixedContent/AbstractOperations.cpp b/Libraries/LibWeb/MixedContent/AbstractOperations.cpp
index 2a19c4ec3ac..b162a2b8343 100644
--- a/Libraries/LibWeb/MixedContent/AbstractOperations.cpp
+++ b/Libraries/LibWeb/MixedContent/AbstractOperations.cpp
@@ -124,7 +124,7 @@ Fetch::Infrastructure::RequestOrResponseBlocking should_fetching_request_be_bloc
}
// https://w3c.github.io/webappsec-mixed-content/#should-block-response
-Web::Fetch::Infrastructure::RequestOrResponseBlocking should_response_to_request_be_blocked_as_mixed_content(Fetch::Infrastructure::Request& request, GC::Ref<Fetch::Infrastructure::Response>& response)
+Web::Fetch::Infrastructure::RequestOrResponseBlocking should_response_to_request_be_blocked_as_mixed_content(Fetch::Infrastructure::Request& request, Fetch::Infrastructure::Response const& response)
{
// 1. Return allowed if one or more of the following conditions are met:
if (
@@ -132,7 +132,7 @@ Web::Fetch::Infrastructure::RequestOrResponseBlocking should_response_to_request
does_client_prohibit_mixed_security_contexts(request) == ProhibitsMixedSecurityContexts::DoesNotRestrictMixedSecurityContexts
// 2. response’s url is a potentially trustworthy URL.
- || (response->url().has_value() && SecureContexts::is_url_potentially_trustworthy(response->url().value()) == SecureContexts::Trustworthiness::PotentiallyTrustworthy)
+ || (response.url().has_value() && SecureContexts::is_url_potentially_trustworthy(response.url().value()) == SecureContexts::Trustworthiness::PotentiallyTrustworthy)
// FIXME: 3. The user agent has been instructed to allow mixed content, as described in § 7.2 User Controls).
|| false
diff --git a/Libraries/LibWeb/MixedContent/AbstractOperations.h b/Libraries/LibWeb/MixedContent/AbstractOperations.h
index 8417ad156c3..41df35ebdc9 100644
--- a/Libraries/LibWeb/MixedContent/AbstractOperations.h
+++ b/Libraries/LibWeb/MixedContent/AbstractOperations.h
@@ -20,6 +20,6 @@ ProhibitsMixedSecurityContexts does_settings_prohibit_mixed_security_contexts(HT
WEB_API Fetch::Infrastructure::RequestOrResponseBlocking should_fetching_request_be_blocked_as_mixed_content(Fetch::Infrastructure::Request&);
-WEB_API Fetch::Infrastructure::RequestOrResponseBlocking should_response_to_request_be_blocked_as_mixed_content(Fetch::Infrastructure::Request&, GC::Ref<Fetch::Infrastructure::Response>&);
+WEB_API Fetch::Infrastructure::RequestOrResponseBlocking should_response_to_request_be_blocked_as_mixed_content(Fetch::Infrastructure::Request&, Fetch::Infrastructure::Response const&);
}
diff --git a/Libraries/LibWeb/WebDriver/BiDi/Network.cpp b/Libraries/LibWeb/WebDriver/BiDi/Network.cpp
index 64370f3b092..f5560b4f5e6 100644
--- a/Libraries/LibWeb/WebDriver/BiDi/Network.cpp
+++ b/Libraries/LibWeb/WebDriver/BiDi/Network.cpp
@@ -50,11 +50,10 @@ void NetworkContinuation::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(fetch_params);
- visitor.visit(response);
visitor.visit_possible_values(m_callback.raw_capture_range());
}
-void NetworkContinuation::invoke(NetworkContinuationAction action, GC::Ptr<Response> response)
+void NetworkContinuation::invoke(NetworkContinuationAction action, RefPtr<Response> response)
{
m_callback(action, response);
m_callback = nullptr;
@@ -109,7 +108,7 @@ static void stop_response_transport(FetchParams const& fetch_params, Response co
fetch_params.controller()->stop_body_transport();
}
-static void resume_blocked_request(String id, NetworkContinuationAction action, GC::Ptr<Fetch::Infrastructure::Response> response)
+static void resume_blocked_request(String id, NetworkContinuationAction action, RefPtr<Fetch::Infrastructure::Response> response)
{
auto it = blocked_requests().find(id);
if (it == blocked_requests().end())
@@ -522,7 +521,7 @@ static JsonObject process_a_network_event(HTML::Navigable const& navigable, Requ
return params;
}
-void block_network_request(FetchParams const& fetch_params, GC::Ptr<Fetch::Infrastructure::Response> response, String phase, JsonArray intercepts, GC::Ref<NetworkContinuation> continuation, RefPtr<Fetch::Infrastructure::Request> original_request)
+void block_network_request(FetchParams const& fetch_params, RefPtr<Fetch::Infrastructure::Response> response, String phase, JsonArray intercepts, GC::Ref<NetworkContinuation> continuation, RefPtr<Fetch::Infrastructure::Request> original_request)
{
auto request = fetch_params.request();
// NB: Cancellation runs through the controller's original parameters, rather than a prepared HTTP clone.
diff --git a/Libraries/LibWeb/WebDriver/BiDi/Network.h b/Libraries/LibWeb/WebDriver/BiDi/Network.h
index ead459b83ce..185247c2cfd 100644
--- a/Libraries/LibWeb/WebDriver/BiDi/Network.h
+++ b/Libraries/LibWeb/WebDriver/BiDi/Network.h
@@ -44,9 +44,9 @@ class NetworkContinuation final : public JS::Cell {
GC_DECLARE_ALLOCATOR(NetworkContinuation);
public:
- using Callback = Function<void(NetworkContinuationAction, GC::Ptr<Fetch::Infrastructure::Response>)>;
+ using Callback = Function<void(NetworkContinuationAction, RefPtr<Fetch::Infrastructure::Response>)>;
static GC::Ref<NetworkContinuation> create(GC::Heap&, Callback);
- void invoke(NetworkContinuationAction, GC::Ptr<Fetch::Infrastructure::Response>);
+ void invoke(NetworkContinuationAction, RefPtr<Fetch::Infrastructure::Response>);
void clear_blocked_state();
String request_id;
@@ -54,7 +54,7 @@ public:
JsonArray intercepts;
GC::Ptr<Fetch::Infrastructure::FetchParams const> fetch_params;
RefPtr<Fetch::Infrastructure::Request> original_request;
- GC::Ptr<Fetch::Infrastructure::Response> response;
+ RefPtr<Fetch::Infrastructure::Response> response;
private:
explicit NetworkContinuation(Callback);
@@ -97,7 +97,7 @@ void apply_network_cache_behavior(Fetch::Infrastructure::Request&);
void apply_network_extra_headers(Fetch::Infrastructure::Request&);
void apply_network_request_header_overrides(Fetch::Infrastructure::Request&);
JsonArray get_network_intercepts(Fetch::Infrastructure::FetchParams const&, StringView phase);
-void block_network_request(Fetch::Infrastructure::FetchParams const&, GC::Ptr<Fetch::Infrastructure::Response>, String phase, JsonArray intercepts, GC::Ref<NetworkContinuation>, RefPtr<Fetch::Infrastructure::Request> original_request = nullptr);
+void block_network_request(Fetch::Infrastructure::FetchParams const&, RefPtr<Fetch::Infrastructure::Response>, String phase, JsonArray intercepts, GC::Ref<NetworkContinuation>, RefPtr<Fetch::Infrastructure::Request> original_request = nullptr);
WEB_API Response continue_network_request(StringView method, JsonObject const&);
void initialize_network_request(Fetch::Infrastructure::Request&, GC::Ptr<HTML::Navigable> = nullptr, Optional<Utf16String> const& navigation = {});
diff --git a/Tests/LibWeb/TestDownloadReader.cpp b/Tests/LibWeb/TestDownloadReader.cpp
index de07a769808..380765231a7 100644
--- a/Tests/LibWeb/TestDownloadReader.cpp
+++ b/Tests/LibWeb/TestDownloadReader.cpp
@@ -83,7 +83,7 @@ TEST_CASE(download_reader_is_registered_with_page_client)
auto traversable = Web::HTML::LocalTraversableNavigable::create_a_new_top_level_traversable(page, nullptr, {});
page->set_top_level_traversable(traversable);
- auto response = Web::Fetch::Infrastructure::Response::create(vm);
+ auto response = Web::Fetch::Infrastructure::Response::create();
response->set_body(Web::Fetch::Infrastructure::byte_sequence_as_response_body("download contents"sv.bytes()));
traversable->handle_as_a_download(Web::Fetch::Infrastructure::ResponseView::create(*realm, response), URL::about_blank(), nullptr, "download.txt", {});
diff --git a/Tests/LibWeb/TestFetchResponse.cpp b/Tests/LibWeb/TestFetchResponse.cpp
index 7f5fc055855..49ceb8580f7 100644
--- a/Tests/LibWeb/TestFetchResponse.cpp
+++ b/Tests/LibWeb/TestFetchResponse.cpp
@@ -19,13 +19,10 @@
namespace {
class TransferTrackingResponse final : public Web::Fetch::Infrastructure::Response {
- GC_CELL(TransferTrackingResponse, Web::Fetch::Infrastructure::Response);
- GC_DECLARE_ALLOCATOR(TransferTrackingResponse);
-
public:
- static GC::Ref<TransferTrackingResponse> create(JS::VM& vm)
+ static NonnullRefPtr<TransferTrackingResponse> create()
{
- return vm.heap().allocate<TransferTrackingResponse>();
+ return adopt_ref(*new TransferTrackingResponse);
}
bool transfer_lease_was_released() const { return m_transfer_lease_was_released; }
@@ -40,14 +37,10 @@ private:
mutable bool m_transfer_lease_was_released { false };
};
-GC_DEFINE_ALLOCATOR(TransferTrackingResponse);
-
}
TEST_CASE(javascript_bytecode_cache_memory_cache_request_headers_are_cloned)
{
- auto vm = JS::VM::create();
-
auto request_headers = HTTP::HeaderList::create({
{ "User-Agent"sv, "Ladybird"sv },
});
@@ -77,7 +70,7 @@ TEST_CASE(http_redirect_fetch_releases_intermediate_response_transfer_lease)
auto algorithms = Web::Fetch::Infrastructure::FetchAlgorithms::create(Web::Fetch::Infrastructure::FetchAlgorithms::Input { Web::Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent });
auto fetch_params = Web::Fetch::Infrastructure::FetchParams::create(request, algorithms, Web::Fetch::Infrastructure::FetchTimingInfo::create(), Web::current_loader_config());
- auto response = TransferTrackingResponse::create(*vm);
+ auto response = TransferTrackingResponse::create();
response->set_status(302);
response->set_header_list(HTTP::HeaderList::create({ { "Location"sv, "/redirected"sv } }));