Skip to content

Truly independent web browser

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

Luke Wildee996671fbec3
diff --git a/Libraries/LibWeb/CSS/Fetch.cpp b/Libraries/LibWeb/CSS/Fetch.cpp
index 7320f934944..245788d43e1 100644
--- a/Libraries/LibWeb/CSS/Fetch.cpp
+++ b/Libraries/LibWeb/CSS/Fetch.cpp
@@ -83,7 +83,7 @@ Optional<::URL::URL> resolve_a_style_resource_url(StyleResourceURL const& url_va
}
// https://drafts.csswg.org/css-values-4/#fetch-a-style-resource
-static GC::Ptr<Fetch::Infrastructure::Request> fetch_a_style_resource_impl(StyleResourceURL const& url_value, RuleOrDeclaration css_rule_or_declaration, Fetch::Infrastructure::Request::Destination destination, CorsMode cors_mode)
+static RefPtr<Fetch::Infrastructure::Request> fetch_a_style_resource_impl(StyleResourceURL const& url_value, RuleOrDeclaration css_rule_or_declaration, Fetch::Infrastructure::Request::Destination destination, CorsMode cors_mode)
{
// 1. Let parsedUrl be the result of resolving urlValue given cssRuleOrDeclaration. If that failed, return.
auto parsed_url = resolve_a_style_resource_url(url_value, css_rule_or_declaration);
@@ -187,7 +187,7 @@ GC::Ptr<HTML::SharedResourceRequest> fetch_an_external_image_for_a_stylesheet(St
}
// https://drafts.csswg.org/css-values-5/#apply-request-modifiers-from-url-value
-void apply_request_modifiers_from_url_value(URL const& url, GC::Ref<Fetch::Infrastructure::Request> request)
+void apply_request_modifiers_from_url_value(URL const& url, NonnullRefPtr<Fetch::Infrastructure::Request> request)
{
// To apply request modifiers from URL value given a request req and a <url> url, call the URL request modifier
// steps for url’s <request-url-modifier>s in sequence given req.
diff --git a/Libraries/LibWeb/CSS/Fetch.h b/Libraries/LibWeb/CSS/Fetch.h
index 1dd3f9a43ba..c74967df464 100644
--- a/Libraries/LibWeb/CSS/Fetch.h
+++ b/Libraries/LibWeb/CSS/Fetch.h
@@ -52,6 +52,6 @@ GC::Ptr<Fetch::Infrastructure::FetchController> fetch_a_style_resource(StyleReso
GC::Ptr<HTML::SharedResourceRequest> fetch_an_external_image_for_a_stylesheet(StyleResourceURL const&, RuleOrDeclaration, DOM::Document&);
// https://drafts.csswg.org/css-values-5/#apply-request-modifiers-from-url-value
-void apply_request_modifiers_from_url_value(URL const&, GC::Ref<Fetch::Infrastructure::Request>);
+void apply_request_modifiers_from_url_value(URL const&, NonnullRefPtr<Fetch::Infrastructure::Request>);
}
diff --git a/Libraries/LibWeb/CSS/URL.cpp b/Libraries/LibWeb/CSS/URL.cpp
index d027348a3d7..e279aee53c6 100644
--- a/Libraries/LibWeb/CSS/URL.cpp
+++ b/Libraries/LibWeb/CSS/URL.cpp
@@ -81,7 +81,7 @@ RequestURLModifier::RequestURLModifier(Type type, Value value)
{
}
-void RequestURLModifier::modify_request(GC::Ref<Fetch::Infrastructure::Request> request) const
+void RequestURLModifier::modify_request(NonnullRefPtr<Fetch::Infrastructure::Request> request) const
{
switch (m_type) {
case Type::CrossOrigin: {
diff --git a/Libraries/LibWeb/CSS/URL.h b/Libraries/LibWeb/CSS/URL.h
index a924d1e9b47..3655fa90006 100644
--- a/Libraries/LibWeb/CSS/URL.h
+++ b/Libraries/LibWeb/CSS/URL.h
@@ -31,7 +31,7 @@ public:
static RequestURLModifier create_referrer_policy(ReferrerPolicyModifierValue);
~RequestURLModifier() = default;
- void modify_request(GC::Ref<Fetch::Infrastructure::Request>) const;
+ void modify_request(NonnullRefPtr<Fetch::Infrastructure::Request>) const;
Type type() const { return m_type; }
using Value = Variant<CrossOriginModifierValue, ReferrerPolicyModifierValue, Utf16FlyString>;
Value const& value() const { return m_value; }
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp
index 36062bcadf8..d9a76314ccf 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp
+++ b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp
@@ -44,7 +44,7 @@ static bool may_report_violations_for(GC::Ptr<HTML::EnvironmentSettingsObject co
return !snapshot || snapshot->report_violation();
}
-ViolationReporter violation_reporter_for_request(JS::Realm& realm, GC::Ref<Fetch::Infrastructure::Request> request)
+ViolationReporter violation_reporter_for_request(JS::Realm& realm, NonnullRefPtr<Fetch::Infrastructure::Request> request)
{
return [&realm, request](NonnullRefPtr<Policy const> policy) {
if (!may_report_violations_for(Fetch::Fetching::resolve_client(request)))
@@ -55,7 +55,7 @@ ViolationReporter violation_reporter_for_request(JS::Realm& realm, GC::Ref<Fetch
}
// https://w3c.github.io/webappsec-csp/#should-block-navigation-request
-Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_content_security_policy(GC::Ref<Fetch::Infrastructure::Request> navigation_request, Directives::Directive::NavigationType navigation_type)
+Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_content_security_policy(NonnullRefPtr<Fetch::Infrastructure::Request> navigation_request, Directives::Directive::NavigationType navigation_type)
{
// 1. Let result be "Allowed".
auto result = Directives::Directive::Result::Allowed;
@@ -145,7 +145,7 @@ Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_co
// https://w3c.github.io/webappsec-csp/#should-block-navigation-response
Directives::Directive::Result should_navigation_response_to_navigation_request_of_type_in_target_be_blocked_by_content_security_policy(
- GC::Ptr<Fetch::Infrastructure::Request> navigation_request,
+ RefPtr<Fetch::Infrastructure::Request> navigation_request,
GC::Ref<Fetch::Infrastructure::Response> navigation_response,
PolicyList const& response_csp_list,
Directives::Directive::NavigationType navigation_type,
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.h b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.h
index d8e7e043425..60580ae8185 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.h
+++ b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.h
@@ -14,11 +14,11 @@
namespace Web::ContentSecurityPolicy {
-[[nodiscard]] ViolationReporter violation_reporter_for_request(JS::Realm&, GC::Ref<Fetch::Infrastructure::Request>);
+[[nodiscard]] ViolationReporter violation_reporter_for_request(JS::Realm&, NonnullRefPtr<Fetch::Infrastructure::Request>);
-Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_content_security_policy(GC::Ref<Fetch::Infrastructure::Request> navigation_request, Directives::Directive::NavigationType navigation_type);
+Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_content_security_policy(NonnullRefPtr<Fetch::Infrastructure::Request> navigation_request, Directives::Directive::NavigationType navigation_type);
Directives::Directive::Result should_navigation_response_to_navigation_request_of_type_in_target_be_blocked_by_content_security_policy(
- GC::Ptr<Fetch::Infrastructure::Request> navigation_request,
+ RefPtr<Fetch::Infrastructure::Request> navigation_request,
GC::Ref<Fetch::Infrastructure::Response> navigation_response,
ContentSecurityPolicy::PolicyList const& response_csp_list,
Directives::Directive::NavigationType navigation_type,
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp
index ee5e29d1f9f..5ac01c116fb 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp
+++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp
@@ -80,7 +80,7 @@ static Utf16View substring_view(Utf16View view, size_t start)
}
// https://w3c.github.io/webappsec-csp/#effective-directive-for-a-request
-Optional<Utf16FlyString> get_the_effective_directive_for_request(GC::Ref<Fetch::Infrastructure::Request const> request)
+Optional<Utf16FlyString> get_the_effective_directive_for_request(NonnullRefPtr<Fetch::Infrastructure::Request const> request)
{
// Each fetch directive controls a specific destination of request. Given a request request, the following algorithm
// returns either null or the name of the request’s effective directive:
@@ -654,7 +654,7 @@ MatchResult does_url_match_source_list_in_origin_with_redirect_count(URL::URL co
}
// https://w3c.github.io/webappsec-csp/#match-request-to-source-list
-MatchResult does_request_match_source_list(GC::Ref<Fetch::Infrastructure::Request const> request, Vector<Utf16String> const& source_list, Policy const& policy)
+MatchResult does_request_match_source_list(NonnullRefPtr<Fetch::Infrastructure::Request const> request, Vector<Utf16String> const& source_list, Policy const& policy)
{
// Given a request request, 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 request’s current url, source
@@ -665,7 +665,7 @@ MatchResult does_request_match_source_list(GC::Ref<Fetch::Infrastructure::Reques
}
// https://w3c.github.io/webappsec-csp/#match-response-to-source-list
-MatchResult does_response_match_source_list(GC::Ref<Fetch::Infrastructure::Response const> response, GC::Ref<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)
{
// 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,
@@ -757,7 +757,7 @@ static MatchResult does_integrity_metadata_match_source_list(Utf16View integrity
}
// https://w3c.github.io/webappsec-csp/#script-pre-request
-Directive::Result script_directives_pre_request_check(GC::Ref<Fetch::Infrastructure::Request const> request, Directive const& directive, Policy const& policy)
+Directive::Result script_directives_pre_request_check(NonnullRefPtr<Fetch::Infrastructure::Request const> request, Directive const& directive, Policy const& policy)
{
// 1. If request’s destination is script-like:
if (request->destination_is_script_like()) {
@@ -799,7 +799,7 @@ Directive::Result script_directives_pre_request_check(GC::Ref<Fetch::Infrastruct
}
// https://w3c.github.io/webappsec-csp/#script-post-request
-Directive::Result script_directives_post_request_check(GC::Ref<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, GC::Ref<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 64b6fbeb857..6db55a4d6bf 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.h
+++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.h
@@ -26,18 +26,18 @@ enum class [[nodiscard]] MatchResult {
Matches,
};
-[[nodiscard]] Optional<Utf16FlyString> get_the_effective_directive_for_request(GC::Ref<Fetch::Infrastructure::Request const> request);
+[[nodiscard]] Optional<Utf16FlyString> get_the_effective_directive_for_request(NonnullRefPtr<Fetch::Infrastructure::Request const> request);
[[nodiscard]] Vector<Utf16FlyString> get_fetch_directive_fallback_list(Optional<Utf16FlyString> directive_name);
ShouldExecute should_fetch_directive_execute(Optional<Utf16FlyString> effective_directive_name, Utf16FlyString const& directive_name, Policy const& policy);
MatchResult does_url_match_expression_in_origin_with_redirect_count(URL::URL const& url, Utf16View expression, URL::Origin const& origin, u8 redirect_count);
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(GC::Ref<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, GC::Ref<Fetch::Infrastructure::Request const> request, Vector<Utf16String> const& source_list, Policy const& policy);
+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_nonce_match_source_list(Utf16View nonce, Vector<Utf16String> const& source_list);
-Directive::Result script_directives_pre_request_check(GC::Ref<Fetch::Infrastructure::Request const> request, Directive const& directive, Policy const& policy);
-Directive::Result script_directives_post_request_check(GC::Ref<Fetch::Infrastructure::Request const> request, GC::Ref<Fetch::Infrastructure::Response const> response, Directive const& directive, Policy const& policy);
+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);
}
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp b/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp
index a59d70bb6a7..0df076ad55c 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp
+++ b/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp
@@ -93,7 +93,7 @@ GC::Ref<Violation> Violation::create_a_violation_object_for_global_policy_and_di
}
// https://w3c.github.io/webappsec-csp/#create-violation-for-request
-GC::Ref<Violation> Violation::create_a_violation_object_for_request_and_policy(GC::Ref<Fetch::Infrastructure::Request> request, NonnullRefPtr<Policy const> policy)
+GC::Ref<Violation> Violation::create_a_violation_object_for_request_and_policy(NonnullRefPtr<Fetch::Infrastructure::Request> request, NonnullRefPtr<Policy const> policy)
{
// 1. Let directive be the result of executing § 6.8.1 Get the effective directive for request on request.
auto directive = Directives::get_the_effective_directive_for_request(request);
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Violation.h b/Libraries/LibWeb/ContentSecurityPolicy/Violation.h
index 1713eac1c54..0a395654576 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/Violation.h
+++ b/Libraries/LibWeb/ContentSecurityPolicy/Violation.h
@@ -42,7 +42,7 @@ public:
virtual ~Violation() = default;
[[nodiscard]] static GC::Ref<Violation> create_a_violation_object_for_global_policy_and_directive(GC::Ptr<JS::Object> global_object, NonnullRefPtr<Policy const> policy, String directive);
- [[nodiscard]] static GC::Ref<Violation> create_a_violation_object_for_request_and_policy(GC::Ref<Fetch::Infrastructure::Request> request, NonnullRefPtr<Policy const>);
+ [[nodiscard]] static GC::Ref<Violation> create_a_violation_object_for_request_and_policy(NonnullRefPtr<Fetch::Infrastructure::Request> request, NonnullRefPtr<Policy const>);
// https://w3c.github.io/webappsec-csp/#violation-url
[[nodiscard]] URL::URL url() const;
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
index 7543516088e..5e4b770d8d9 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -612,7 +612,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
if (auto pending_preloaded_response = controller->pending_preloaded_response())
return *pending_preloaded_response;
- auto pending_preloaded_response = PendingResponse::create(request);
+ auto pending_preloaded_response = PendingResponse::create(fetch_params);
controller->set_pending_preloaded_response(pending_preloaded_response);
return pending_preloaded_response;
}
@@ -621,7 +621,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
VERIFY(fetch_params.preloaded_response_candidate().has<GC::Ref<Infrastructure::Response>>());
// 3. Return fetchParams’s preloaded response candidate.
- return PendingResponse::create(request, fetch_params.preloaded_response_candidate().get<GC::Ref<Infrastructure::Response>>());
+ return PendingResponse::create(fetch_params, fetch_params.preloaded_response_candidate().get<GC::Ref<Infrastructure::Response>>());
}
// -> request’s current URL’s origin is same origin with request’s origin, and request’s response tainting is "basic"
@@ -653,14 +653,14 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
// -> request’s mode is "same-origin"
if (request->mode() == Infrastructure::Request::Mode::SameOrigin) {
// Return a network error.
- return PendingResponse::create(request, Infrastructure::Response::network_error("Request with 'same-origin' mode must have same URL and request origin"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Request with 'same-origin' mode must have same URL and request origin"_string));
}
// -> request’s mode is "no-cors"
if (request->mode() == Infrastructure::Request::Mode::NoCORS) {
// 1. If request’s redirect mode is not "follow", then return a network error.
if (request->redirect_mode() != Infrastructure::Request::RedirectMode::Follow)
- return PendingResponse::create(request, Infrastructure::Response::network_error("Request with 'no-cors' mode must have redirect mode set to 'follow'"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Request with 'no-cors' mode must have redirect mode set to 'follow'"_string));
// 2. Set request’s response tainting to "opaque".
request->set_response_tainting(Infrastructure::Request::ResponseTainting::Opaque);
@@ -677,7 +677,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
VERIFY(request->mode() == Infrastructure::Request::Mode::CORS);
// Return a network error.
- return PendingResponse::create(request, Infrastructure::Response::network_error("Request with 'cors' mode must have URL with HTTP or HTTPS scheme"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Request with 'cors' mode must have URL with HTTP or HTTPS scheme"_string));
}
// -> request’s use-CORS-preflight flag is set
@@ -691,7 +691,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
// 1. Set request’s response tainting to "cors".
request->set_response_tainting(Infrastructure::Request::ResponseTainting::CORS);
- auto returned_pending_response = PendingResponse::create(request);
+ auto returned_pending_response = PendingResponse::create(fetch_params);
// 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);
@@ -722,7 +722,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
// matching statement:
auto pending_response = !response
? get_response->function()()
- : PendingResponse::create(request, *response);
+ : PendingResponse::create(fetch_params, *response);
// 13. If recursive is true, then return response.
return pending_response;
@@ -732,7 +732,7 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(GC::Heap::the(), [&realm, &fetch_params, request, response, get_response] {
// 12. If response is null, then set response to the result of running the steps corresponding to the first
// matching statement:
- auto pending_response = PendingResponse::create(request, Infrastructure::Response::create());
+ auto pending_response = PendingResponse::create(fetch_params, Infrastructure::Response::create());
if (!response) {
pending_response = get_response->function()();
}
@@ -1299,7 +1299,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
// 1. If fetchParams is canceled, then return the appropriate network error for fetchParams.
if (fetch_params.is_canceled())
- return PendingResponse::create(fetch_params.request(), Infrastructure::Response::appropriate_network_error(fetch_params));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::appropriate_network_error(fetch_params));
// 2. Let request be fetchParams’s request.
auto request = fetch_params.request();
@@ -1318,7 +1318,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
response->header_list()->append({ "Content-Type"sv, "text/html;charset=utf-8"sv });
response->set_body(Infrastructure::byte_sequence_as_body(realm, ""sv.bytes()));
- return PendingResponse::create(request, response);
+ return PendingResponse::create(fetch_params, response);
}
// FIXME: This is actually wrong, see note above.
@@ -1331,7 +1331,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
// 2. If request’s method is not `GET` or blobURLEntry is null, then return a network error. [FILEAPI]
if (request->method() != "GET"sv || !blob_url_entry.has_value())
- return PendingResponse::create(request, Infrastructure::Response::network_error("Request has an invalid 'blob:' URL"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Request has an invalid 'blob:' URL"_string));
// 3. Let requestEnvironment be the result of determining the environment given request.
auto request_environment = determine_the_environment(request);
@@ -1380,11 +1380,11 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
// 8. If blob is not a Blob object, then return a network error.
if (!maybe_blob_object.has_value())
- return PendingResponse::create(request, Infrastructure::Response::network_error("Failed to obtain a Blob object from 'blob:' URL"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Failed to obtain a Blob object from 'blob:' URL"_string));
auto const* blob_object = maybe_blob_object.value().get_pointer<FileAPI::SerializedBlobURLEntry::Blob>();
if (!blob_object)
- return PendingResponse::create(request, Infrastructure::Response::network_error("Failed to obtain a Blob object from 'blob:' URL"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Failed to obtain a Blob object from 'blob:' URL"_string));
auto const blob = FileAPI::Blob::create(blob_object->data, Utf16String::from_utf8(blob_object->type));
// 9. Let response be a new response.
@@ -1430,7 +1430,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
// 4. If rangeValue is failure, then return a network error.
if (!maybe_range_value.has_value())
- return PendingResponse::create(request, Infrastructure::Response::network_error("Failed to parse single range header value"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Failed to parse single range header value"_string));
// 5. Let (rangeStart, rangeEnd) be rangeValue.
auto& [range_start, range_end] = maybe_range_value.value();
@@ -1449,7 +1449,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
else {
// 1. If rangeStart is greater than or equal to fullLength, then return a network error.
if (*range_start >= full_length)
- return PendingResponse::create(request, Infrastructure::Response::network_error("rangeStart is greater than or equal to fullLength"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("rangeStart is greater than or equal to fullLength"_string));
// 2. If rangeEnd is null or rangeEnd is greater than or equal to fullLength, then set rangeEnd to fullLength − 1.
if (!range_end.has_value() || *range_end >= full_length)
@@ -1493,7 +1493,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
}
// 15. Return response.
- return PendingResponse::create(request, response);
+ return PendingResponse::create(fetch_params, response);
}
// -> "data"
else if (request->current_url().scheme() == "data"sv) {
@@ -1502,7 +1502,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
// 2. If dataURLStruct is failure, then return a network error.
if (data_url_struct.is_error())
- return PendingResponse::create(request, Infrastructure::Response::network_error("Failed to process 'data:' URL"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Failed to process 'data:' URL"_string));
// 3. Let mimeType be dataURLStruct’s MIME type, serialized.
auto const& mime_type = data_url_struct.value().mime_type.serialized();
@@ -1516,7 +1516,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
response->header_list()->append(move(header));
response->set_body(Infrastructure::byte_sequence_as_body(realm, data_url_struct.value().body));
- return PendingResponse::create(request, response);
+ return PendingResponse::create(fetch_params, response);
}
// -> "file"
// AD-HOC: "resource"
@@ -1524,7 +1524,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
// For now, unfortunate as it is, file: URLs are left as an exercise for the reader.
// When in doubt, return a network error.
- auto error = PendingResponse::create(request, Infrastructure::Response::network_error("Request with 'file:' or 'resource:' URL blocked"_string));
+ auto error = PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Request with 'file:' or 'resource:' URL blocked"_string));
auto const* origin = request->origin().get_pointer<URL::Origin>();
if (!origin)
@@ -1566,7 +1566,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
auto message = request->current_url().scheme() == "about"sv
? "Request has invalid 'about:' URL, only 'about:blank' can be fetched"_string
: "Request URL has invalid scheme, must be one of 'about', 'blob', 'data', 'file', 'http', or 'https'"_string;
- return PendingResponse::create(request, Infrastructure::Response::network_error(move(message)));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error(move(message)));
}
// https://fetch.spec.whatwg.org/#concept-http-fetch
@@ -1634,14 +1634,14 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam
// - request’s redirect mode is not "follow" and response’s URL list has more than one item.
|| (request->redirect_mode() != Infrastructure::Request::RedirectMode::Follow && response->url_list().size() > 1)) {
// then return a network error.
- return PendingResponse::create(request, Infrastructure::Response::network_error("Invalid request/response state combination"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Invalid request/response state combination"_string));
}
}
}
GC::Ptr<PendingResponse> pending_actual_response;
- auto returned_pending_response = PendingResponse::create(request);
+ auto returned_pending_response = PendingResponse::create(fetch_params);
// 4. If response is null, then:
if (!response) {
@@ -1663,7 +1663,7 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam
if (make_cors_preflight == MakeCORSPreflight::Yes && (method_needs_preflight || headers_need_preflight)) {
// 1. Let preflightResponse be the result of running CORS-preflight fetch given request.
- pending_preflight_response = cors_preflight_fetch(realm, request);
+ pending_preflight_response = cors_preflight_fetch(realm, fetch_params);
// NOTE: Step 2 is performed in pending_preflight_response's load callback below.
}
@@ -1684,7 +1684,7 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam
});
if (pending_preflight_response) {
- pending_actual_response = PendingResponse::create(request);
+ 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) {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'HTTP fetch' pending_preflight_response load callback");
@@ -1704,7 +1704,7 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam
pending_actual_response = fetch_main_content->function()();
}
} else {
- pending_actual_response = PendingResponse::create(request, Infrastructure::Response::create());
+ 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 {
@@ -1824,7 +1824,7 @@ GC::Ptr<PendingResponse> http_redirect_fetch(JS::Realm& realm, Infrastructure::F
// 4. If locationURL is null, then return response.
if (!location_url_or_error.is_error() && !location_url_or_error.value().has_value())
- return PendingResponse::create(request, response);
+ return PendingResponse::create(fetch_params, response);
// AD-HOC: Navigation responses have a RequestServer transfer lease so they can move through the UI process.
// This response will be discarded in favor of either a network error or the redirect response, so
@@ -1833,17 +1833,17 @@ GC::Ptr<PendingResponse> http_redirect_fetch(JS::Realm& realm, Infrastructure::F
// 5. If locationURL is failure, then return a network error.
if (location_url_or_error.is_error())
- return PendingResponse::create(request, Infrastructure::Response::network_error("Request redirect URL is invalid"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Request redirect URL is invalid"_string));
auto location_url = location_url_or_error.release_value().release_value();
// 6. If locationURL’s scheme is not an HTTP(S) scheme, then return a network error.
if (!Infrastructure::is_http_or_https_scheme(location_url.scheme()))
- return PendingResponse::create(request, Infrastructure::Response::network_error("Request redirect URL must have HTTP or HTTPS scheme"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Request redirect URL must have HTTP or HTTPS scheme"_string));
// 7. If request’s redirect count is 20, then return a network error.
if (request->redirect_count() == 20)
- return PendingResponse::create(request, Infrastructure::Response::network_error("Request has reached maximum redirect count of 20"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Request has reached maximum redirect count of 20"_string));
// 8. Increase request’s redirect count by 1.
request->set_redirect_count(request->redirect_count() + 1);
@@ -1854,20 +1854,20 @@ GC::Ptr<PendingResponse> http_redirect_fetch(JS::Realm& realm, Infrastructure::F
&& location_url.includes_credentials()
&& request->origin().has<URL::Origin>()
&& !request->origin().get<URL::Origin>().is_same_origin(location_url.origin())) {
- return PendingResponse::create(request, Infrastructure::Response::network_error("Request with 'cors' mode and different URL and request origin must not include credentials in redirect URL"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Request with 'cors' mode and different URL and request origin must not include credentials in redirect URL"_string));
}
// 10. If request’s response tainting is "cors" and locationURL includes credentials, then return a network error.
// NOTE: This catches a cross-origin resource redirecting to a same-origin URL.
if (request->response_tainting() == Infrastructure::Request::ResponseTainting::CORS && location_url.includes_credentials())
- return PendingResponse::create(request, Infrastructure::Response::network_error("Request with 'cors' response tainting must not include credentials in redirect URL"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Request with 'cors' response tainting must not include credentials in redirect URL"_string));
// 11. If internalResponse’s status is not 303, request’s body is non-null, and request’s body’s source is null, then
// return a network error.
if (internal_response->status() != 303
&& !request->body().has<Empty>()
&& !request->body().get<Infrastructure::FetchBody>().source().has_value()) {
- return PendingResponse::create(request, Infrastructure::Response::network_error("Request has body but no body source"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Request has body but no body source"_string));
}
// 12. If one of the following is true
@@ -1964,7 +1964,7 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
GC::Ptr<Infrastructure::FetchParams const> http_fetch_params;
// 3. Let httpRequest be null.
- GC::Ptr<Infrastructure::Request> http_request;
+ RefPtr<Infrastructure::Request> http_request;
// 4. Let response be null.
GC::Ptr<Infrastructure::Response> response;
@@ -2070,7 +2070,7 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
// 5. If the sum of contentLength and inflightKeepaliveBytes is greater than 64 kibibytes, then return a network error.
if ((content_length.value() + inflight_keep_alive_bytes) > keepalive_maximum_size)
- return PendingResponse::create(request, Infrastructure::Response::network_error("Keepalive request exceeded maximum allowed size of 64 KiB"_string));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::network_error("Keepalive request exceeded maximum allowed size of 64 KiB"_string));
// NOTE: The above limit ensures that requests that are allowed to outlive the environment settings object
// and contain a body, have a bounded size and are not allowed to stay alive indefinitely.
@@ -2248,7 +2248,7 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
// 9. If aborted, then return the appropriate network error for fetchParams.
if (aborted)
- return PendingResponse::create(request, Infrastructure::Response::appropriate_network_error(fetch_params));
+ return PendingResponse::create(fetch_params, Infrastructure::Response::appropriate_network_error(fetch_params));
GC::Ptr<PendingResponse> pending_forward_response;
@@ -2262,14 +2262,14 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
// and isNewConnectionFetch.
pending_forward_response = nonstandard_resource_loader_file_or_http_network_fetch(realm, *http_fetch_params, include_credentials, is_new_connection_fetch, http_cache);
} else {
- pending_forward_response = PendingResponse::create(request, Infrastructure::Response::create());
+ pending_forward_response = PendingResponse::create(fetch_params, Infrastructure::Response::create());
}
// AD-HOC: If the controller is already in the non-spec Stopped state, we should cancel the network request immediately.
if (http_fetch_params->controller()->state() == Infrastructure::FetchController::State::Stopped)
http_fetch_params->controller()->stop_fetch();
- auto returned_pending_response = PendingResponse::create(request);
+ auto returned_pending_response = PendingResponse::create(fetch_params);
pending_forward_response->when_loaded([&realm, &fetch_params, request, 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 {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'HTTP-network-or-cache fetch' pending_forward_response load callback");
@@ -2322,7 +2322,7 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
// 13. Set response’s request-includes-credentials to includeCredentials.
response->set_request_includes_credentials(include_credentials == HTTP::Cookie::IncludeCredentials::Yes);
- auto inner_pending_response = PendingResponse::create(request, *response);
+ auto inner_pending_response = PendingResponse::create(fetch_params, *response);
// 14. If response’s status is 401, httpRequest’s response tainting is not "cors", includeCredentials is true,
// and request’s traversable for user prompts is a traversable navigable:
@@ -2420,7 +2420,7 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
// (Doing this without step 4 would potentially lead to an infinite request cycle.)
}
- auto inner_pending_response = PendingResponse::create(request, *response);
+ auto inner_pending_response = PendingResponse::create(fetch_params, *response);
// 16. If all of the following are true
if (
@@ -2551,7 +2551,7 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(
load_request.set_body(MUST(source->copy_to_byte_buffer()));
}
- auto pending_response = PendingResponse::create(request);
+ auto pending_response = PendingResponse::create(fetch_params);
if constexpr (WEB_FETCH_DEBUG) {
dbgln("Fetch: Invoking ResourceLoader");
@@ -2823,8 +2823,10 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(
}
// https://fetch.spec.whatwg.org/#cors-preflight-fetch-0
-GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm& realm, Infrastructure::Request& request)
+// NB: request is given as its fetch params.
+GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm& realm, Infrastructure::FetchParams const& fetch_params)
{
+ auto& request = *fetch_params.request();
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'CORS-preflight fetch' with request @ {}", &request);
// 1. Let preflight be a new request whose method is `OPTIONS`, URL list is a clone of request’s URL list, initiator is
@@ -2868,13 +2870,13 @@ GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm& realm, Infrastructure::
// 6. Let response be the result of running HTTP-network-or-cache fetch given a new fetch params whose request is preflight.
// FIXME: The spec doesn't say anything about timing_info here, but FetchParams requires a non-null FetchTimingInfo object.
auto timing_info = Infrastructure::FetchTimingInfo::create();
- auto fetch_params = Infrastructure::FetchParams::create(preflight, Infrastructure::FetchAlgorithms::create(Infrastructure::FetchAlgorithms::Input { Engine::BodyIntent::DrainAndDiscard }), timing_info);
+ auto preflight_fetch_params = Infrastructure::FetchParams::create(preflight, Infrastructure::FetchAlgorithms::create(Infrastructure::FetchAlgorithms::Input { Engine::BodyIntent::DrainAndDiscard }), timing_info);
- auto returned_pending_response = PendingResponse::create(request);
+ auto returned_pending_response = PendingResponse::create(fetch_params);
- auto preflight_response = http_network_or_cache_fetch(realm, fetch_params);
+ auto preflight_response = http_network_or_cache_fetch(realm, preflight_fetch_params);
- preflight_response->when_loaded([&request, returned_pending_response, preflight_controller = 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()](GC::Ref<Infrastructure::Response> response) {
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'CORS-preflight fetch' preflight_response load callback");
if (WebDriver::BiDi::g_network_events_enabled) {
@@ -2890,7 +2892,7 @@ GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm& realm, Infrastructure::
// 7. If a CORS check for request and response returns success and response’s status is an ok status, then:
// NOTE: The CORS check is done on request rather than preflight to ensure the correct credentials mode is used.
- if (cors_check(request, response) && Infrastructure::is_ok_status(response->status())) {
+ if (cors_check(*request, response) && Infrastructure::is_ok_status(response->status())) {
// 1. Let methods be the result of extracting header list values given `Access-Control-Allow-Methods` and response’s header list.
auto methods_or_failure = response->header_list()->extract_header_list_values("Access-Control-Allow-Methods"sv);
@@ -2920,26 +2922,26 @@ GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm& realm, Infrastructure::
// 4. If methods is null and request’s use-CORS-preflight flag is set, then set methods to a new list containing request’s method.
// NOTE: This ensures that a CORS-preflight fetch that happened due to request’s use-CORS-preflight flag being set is cached.
- if (methods.is_empty() && request.use_cors_preflight())
- methods = { request.method() };
+ if (methods.is_empty() && request->use_cors_preflight())
+ methods = { request->method() };
// 5. If request’s method is not in methods, request’s method is not a CORS-safelisted method, and request’s credentials mode
// is "include" or methods does not contain `*`, then return a network error.
- if (!methods.contains_slow(request.method()) && !HTTP::is_cors_safelisted_method(request.method())) {
- if (request.credentials_mode() == Infrastructure::Request::CredentialsMode::Include) {
- returned_pending_response->resolve(Infrastructure::Response::network_error(TRY_OR_IGNORE(String::formatted("Non-CORS-safelisted method '{}' not found in the CORS-preflight response's Access-Control-Allow-Methods header (the header may be missing). '*' is not allowed as the main request includes credentials.", request.method()))));
+ if (!methods.contains_slow(request->method()) && !HTTP::is_cors_safelisted_method(request->method())) {
+ if (request->credentials_mode() == Infrastructure::Request::CredentialsMode::Include) {
+ returned_pending_response->resolve(Infrastructure::Response::network_error(TRY_OR_IGNORE(String::formatted("Non-CORS-safelisted method '{}' not found in the CORS-preflight response's Access-Control-Allow-Methods header (the header may be missing). '*' is not allowed as the main request includes credentials.", request->method()))));
return;
}
if (!methods.contains_slow("*"sv)) {
- returned_pending_response->resolve(Infrastructure::Response::network_error(TRY_OR_IGNORE(String::formatted("Non-CORS-safelisted method '{}' not found in the CORS-preflight response's Access-Control-Allow-Methods header and there was no '*' entry. The header may be missing.", request.method()))));
+ returned_pending_response->resolve(Infrastructure::Response::network_error(TRY_OR_IGNORE(String::formatted("Non-CORS-safelisted method '{}' not found in the CORS-preflight response's Access-Control-Allow-Methods header and there was no '*' entry. The header may be missing.", request->method()))));
return;
}
}
// 6. If one of request’s header list’s names is a CORS non-wildcard request-header name and is not a byte-case-insensitive match
// for an item in headerNames, then return a network error.
- for (auto const& header : *request.header_list()) {
+ for (auto const& header : *request->header_list()) {
if (Infrastructure::is_cors_non_wildcard_request_header_name(header.name)) {
bool is_in_header_names = false;
@@ -2960,7 +2962,7 @@ GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm& realm, Infrastructure::
// 7. For each unsafeName of the CORS-unsafe request-header names with request’s header list, if unsafeName is not a
// byte-case-insensitive match for an item in headerNames and request’s credentials mode is "include" or headerNames
// does not contain `*`, return a network error.
- auto unsafe_names = Infrastructure::get_cors_unsafe_header_names(request.header_list());
+ auto unsafe_names = Infrastructure::get_cors_unsafe_header_names(request->header_list());
for (auto const& unsafe_name : unsafe_names) {
bool is_in_header_names = false;
@@ -2972,7 +2974,7 @@ GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm& realm, Infrastructure::
}
if (!is_in_header_names) {
- if (request.credentials_mode() == Infrastructure::Request::CredentialsMode::Include) {
+ if (request->credentials_mode() == Infrastructure::Request::CredentialsMode::Include) {
returned_pending_response->resolve(Infrastructure::Response::network_error(TRY_OR_IGNORE(String::formatted("CORS-unsafe request-header '{}' not found in the CORS-preflight response's Access-Control-Allow-Headers header (the header may be missing). '*' is not allowed as the main request includes credentials.", unsafe_name))));
return;
}
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.h b/Libraries/LibWeb/Fetch/Fetching/Fetching.h
index 3804da16dca..6409068cd12 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.h
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.h
@@ -54,7 +54,7 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm&, Infrastructure::FetchParams cons
WEB_API GC::Ptr<PendingResponse> http_redirect_fetch(JS::Realm&, Infrastructure::FetchParams const&, Infrastructure::Response&);
GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm&, Infrastructure::FetchParams const&, IsAuthenticationFetch is_authentication_fetch = IsAuthenticationFetch::No, IsNewConnectionFetch is_new_connection_fetch = IsNewConnectionFetch::No);
GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(JS::Realm&, Infrastructure::FetchParams const&, HTTP::Cookie::IncludeCredentials include_credentials = HTTP::Cookie::IncludeCredentials::No, IsNewConnectionFetch is_new_connection_fetch = IsNewConnectionFetch::No, RefPtr<HTTP::MemoryCache> = {});
-GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm&, Infrastructure::Request&);
+GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm&, Infrastructure::FetchParams const&);
void set_sec_fetch_dest_header(Infrastructure::Request&);
void set_sec_fetch_mode_header(Infrastructure::Request&);
void set_sec_fetch_site_header(Infrastructure::Request&);
diff --git a/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cpp b/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cpp
index 087e98066de..69ac8c895b5 100644
--- a/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/PendingResponse.cpp
@@ -7,35 +7,36 @@
#include <LibGC/Heap.h>
#include <LibJS/Runtime/VM.h>
#include <LibWeb/Fetch/Fetching/PendingResponse.h>
-#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
+#include <LibWeb/Fetch/Infrastructure/FetchController.h>
+#include <LibWeb/Fetch/Infrastructure/FetchParams.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
namespace Web::Fetch::Fetching {
GC_DEFINE_ALLOCATOR(PendingResponse);
-GC::Ref<PendingResponse> PendingResponse::create(GC::Ref<Infrastructure::Request> request)
+GC::Ref<PendingResponse> PendingResponse::create(Infrastructure::FetchParams const& fetch_params)
{
- return GC::Heap::the().allocate<PendingResponse>(request);
+ return GC::Heap::the().allocate<PendingResponse>(fetch_params.controller());
}
-GC::Ref<PendingResponse> PendingResponse::create(GC::Ref<Infrastructure::Request> request, GC::Ref<Infrastructure::Response> response)
+GC::Ref<PendingResponse> PendingResponse::create(Infrastructure::FetchParams const& fetch_params, GC::Ref<Infrastructure::Response> response)
{
- return GC::Heap::the().allocate<PendingResponse>(request, response);
+ return GC::Heap::the().allocate<PendingResponse>(fetch_params.controller(), response);
}
-PendingResponse::PendingResponse(GC::Ref<Infrastructure::Request> request, GC::Ptr<Infrastructure::Response> response)
- : m_request(request)
+PendingResponse::PendingResponse(GC::Ref<Infrastructure::FetchController> fetch_controller, GC::Ptr<Infrastructure::Response> response)
+ : m_fetch_controller(fetch_controller)
, m_response(response)
{
- m_request->add_pending_response({}, *this);
+ m_fetch_controller->add_pending_response({}, *this);
}
void PendingResponse::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_callback);
- visitor.visit(m_request);
+ visitor.visit(m_fetch_controller);
visitor.visit(m_response);
}
@@ -68,7 +69,7 @@ void PendingResponse::run_callback()
// conservatively.
auto callback = exchange(m_callback, nullptr);
callback->function()(*m_response);
- m_request->remove_pending_response({}, *this);
+ m_fetch_controller->remove_pending_response({}, *this);
}));
}
diff --git a/Libraries/LibWeb/Fetch/Fetching/PendingResponse.h b/Libraries/LibWeb/Fetch/Fetching/PendingResponse.h
index ae00bb10ac6..d7f4dfb8229 100644
--- a/Libraries/LibWeb/Fetch/Fetching/PendingResponse.h
+++ b/Libraries/LibWeb/Fetch/Fetching/PendingResponse.h
@@ -24,22 +24,22 @@ class PendingResponse : public JS::Cell {
public:
using Callback = Function<void(GC::Ref<Infrastructure::Response>)>;
- [[nodiscard]] static GC::Ref<PendingResponse> create(GC::Ref<Infrastructure::Request>);
- [[nodiscard]] static GC::Ref<PendingResponse> create(GC::Ref<Infrastructure::Request>, GC::Ref<Infrastructure::Response>);
+ [[nodiscard]] static GC::Ref<PendingResponse> create(Infrastructure::FetchParams const&);
+ [[nodiscard]] static GC::Ref<PendingResponse> create(Infrastructure::FetchParams const&, GC::Ref<Infrastructure::Response>);
void when_loaded(Callback);
void resolve(GC::Ref<Infrastructure::Response>);
bool is_resolved() const { return m_response != nullptr; }
private:
- PendingResponse(GC::Ref<Infrastructure::Request>, GC::Ptr<Infrastructure::Response> = {});
+ PendingResponse(GC::Ref<Infrastructure::FetchController>, GC::Ptr<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::Ref<Infrastructure::Request> m_request;
+ GC::Ref<Infrastructure::FetchController> m_fetch_controller;
GC::Ptr<Infrastructure::Response> m_response;
};
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
index 4096a456ee6..b870ffac1d7 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
@@ -44,6 +44,7 @@ void FetchController::visit_edges(JS::Cell::Visitor& visitor)
visitor.visit(m_fetch_params);
visitor.visit(m_pending_preloaded_response);
visitor.visit(m_stop_steps);
+ visitor.visit(m_pending_responses);
}
void FetchController::set_pending_request(RefPtr<Requests::Request> const& request)
@@ -217,6 +218,17 @@ void FetchController::fetch_task_complete(u64 fetch_task_id)
m_ongoing_fetch_tasks.remove(fetch_task_id);
}
+void FetchController::add_pending_response(Badge<Fetching::PendingResponse>, GC::Ref<Fetching::PendingResponse> pending_response)
+{
+ VERIFY(!m_pending_responses.contains_slow(pending_response));
+ m_pending_responses.append(pending_response);
+}
+
+void FetchController::remove_pending_response(Badge<Fetching::PendingResponse>, GC::Ref<Fetching::PendingResponse> pending_response)
+{
+ m_pending_responses.remove_first_matching([&](auto entry) { return entry == pending_response; });
+}
+
GC_DEFINE_ALLOCATOR(FetchControllerHolder);
FetchControllerHolder::FetchControllerHolder() = default;
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h
index 9342347c77f..b05f1687fd6 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h
@@ -87,6 +87,9 @@ public:
void fetch_task_queued(u64 fetch_task_id, HTML::TaskID event_id);
void fetch_task_complete(u64 fetch_task_id);
+ void add_pending_response(Badge<Fetching::PendingResponse>, GC::Ref<Fetching::PendingResponse>);
+ void remove_pending_response(Badge<Fetching::PendingResponse>, GC::Ref<Fetching::PendingResponse>);
+
private:
FetchController();
@@ -134,6 +137,9 @@ private:
// AD-HOC: Run when the fetch is stopped, for whatever was waiting on its response.
GC::Ptr<GC::Function<void()>> m_stop_steps;
+
+ // The pending responses of this fetch whose callbacks have yet to run.
+ Vector<GC::Ref<Fetching::PendingResponse>> m_pending_responses;
};
class FetchControllerHolder : public JS::Cell {
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp
index 95f76a4710a..9741e2e5c39 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp
@@ -13,8 +13,8 @@ namespace Web::Fetch::Infrastructure {
GC_DEFINE_ALLOCATOR(FetchParams);
-FetchParams::FetchParams(GC::Ref<Request> request, GC::Ref<FetchAlgorithms const> algorithms, GC::Ref<FetchController> controller, NonnullRefPtr<FetchTimingInfo> timing_info)
- : m_request(request)
+FetchParams::FetchParams(NonnullRefPtr<Request> request, GC::Ref<FetchAlgorithms const> algorithms, GC::Ref<FetchController> controller, NonnullRefPtr<FetchTimingInfo> timing_info)
+ : m_request(move(request))
, m_algorithms(algorithms)
, m_controller(controller)
, m_timing_info(move(timing_info))
@@ -35,10 +35,10 @@ FetchParams::FetchParams(FetchParams const& params)
{
}
-GC::Ref<FetchParams> FetchParams::create(GC::Ref<Request> request, GC::Ref<FetchAlgorithms const> algorithms, NonnullRefPtr<FetchTimingInfo> timing_info)
+GC::Ref<FetchParams> FetchParams::create(NonnullRefPtr<Request> request, GC::Ref<FetchAlgorithms const> algorithms, NonnullRefPtr<FetchTimingInfo> timing_info)
{
auto controller = Infrastructure::FetchController::create();
- return GC::Heap::the().allocate<FetchParams>(request, algorithms, controller, move(timing_info));
+ return GC::Heap::the().allocate<FetchParams>(move(request), algorithms, controller, move(timing_info));
}
GC::Ref<FetchParams> FetchParams::copy(FetchParams const& params)
@@ -49,7 +49,6 @@ GC::Ref<FetchParams> FetchParams::copy(FetchParams const& params)
void FetchParams::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
- visitor.visit(m_request);
visitor.visit(m_algorithms);
visitor.visit(m_controller);
visitor.visit(m_task_destination);
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h
index 386e94d889c..3a978a9166a 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h
@@ -29,11 +29,11 @@ public:
struct PreloadedResponseCandidatePendingTag { };
using PreloadedResponseCandidate = Variant<Empty, PreloadedResponseCandidatePendingTag, GC::Ref<Response>>;
- [[nodiscard]] static GC::Ref<FetchParams> create(GC::Ref<Request>, GC::Ref<FetchAlgorithms const>, NonnullRefPtr<FetchTimingInfo>);
+ [[nodiscard]] static GC::Ref<FetchParams> create(NonnullRefPtr<Request>, GC::Ref<FetchAlgorithms const>, NonnullRefPtr<FetchTimingInfo>);
[[nodiscard]] static GC::Ref<FetchParams> copy(FetchParams const&);
- [[nodiscard]] GC::Ref<Request> request() const { return m_request; }
- void set_request(GC::Ref<Request> request) { m_request = request; }
+ [[nodiscard]] NonnullRefPtr<Request> request() const { return m_request; }
+ void set_request(NonnullRefPtr<Request> request) { m_request = move(request); }
[[nodiscard]] GC::Ref<FetchController> controller() const { return m_controller; }
[[nodiscard]] NonnullRefPtr<FetchTimingInfo> timing_info() const { return m_timing_info; }
@@ -64,7 +64,7 @@ public:
void set_blob_url_entry(Optional<FileAPI::SerializedBlobURLEntry> blob_url_entry) { m_blob_url_entry = move(blob_url_entry); }
private:
- FetchParams(GC::Ref<Request>, GC::Ref<FetchAlgorithms const>, GC::Ref<FetchController>, NonnullRefPtr<FetchTimingInfo>);
+ FetchParams(NonnullRefPtr<Request>, GC::Ref<FetchAlgorithms const>, GC::Ref<FetchController>, NonnullRefPtr<FetchTimingInfo>);
FetchParams(FetchParams const&);
virtual void visit_edges(JS::Cell::Visitor&) override;
@@ -72,7 +72,7 @@ private:
// https://fetch.spec.whatwg.org/#fetch-params-request
// request
// A request.
- GC::Ref<Request> m_request;
+ NonnullRefPtr<Request> m_request;
// https://fetch.spec.whatwg.org/#fetch-params-process-request-body
// process request body chunk length (default null)
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.cpp
index 9bd20b2c9e5..6b697b41eb0 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.cpp
@@ -12,23 +12,13 @@ namespace Web::Fetch::Infrastructure {
GC_DEFINE_ALLOCATOR(FetchRecord);
-GC::Ref<FetchRecord> FetchRecord::create(GC::Ref<Infrastructure::Request> request)
-{
- return GC::Heap::the().allocate<FetchRecord>(request);
-}
-
-GC::Ref<FetchRecord> FetchRecord::create(GC::Ref<Infrastructure::Request> request, GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller)
+GC::Ref<FetchRecord> FetchRecord::create(NonnullRefPtr<Infrastructure::Request> request, GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller)
{
return GC::Heap::the().allocate<FetchRecord>(request, fetch_controller);
}
-FetchRecord::FetchRecord(GC::Ref<Infrastructure::Request> request)
- : m_request(request)
-{
-}
-
-FetchRecord::FetchRecord(GC::Ref<Infrastructure::Request> request, GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller)
- : m_request(request)
+FetchRecord::FetchRecord(NonnullRefPtr<Infrastructure::Request> request, GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller)
+ : m_request(move(request))
, m_fetch_controller(fetch_controller)
{
}
@@ -36,7 +26,6 @@ FetchRecord::FetchRecord(GC::Ref<Infrastructure::Request> request, GC::Ptr<Fetch
void FetchRecord::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
- visitor.visit(m_request);
visitor.visit(m_fetch_controller);
}
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.h
index a7464e999f2..43894c74315 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.h
@@ -17,25 +17,22 @@ class WEB_API FetchRecord final : public JS::Cell {
GC_DECLARE_ALLOCATOR(FetchRecord);
public:
- [[nodiscard]] static GC::Ref<FetchRecord> create(GC::Ref<Infrastructure::Request>);
- [[nodiscard]] static GC::Ref<FetchRecord> create(GC::Ref<Infrastructure::Request>, GC::Ptr<FetchController>);
+ [[nodiscard]] static GC::Ref<FetchRecord> create(NonnullRefPtr<Infrastructure::Request>, GC::Ptr<FetchController>);
- [[nodiscard]] GC::Ref<Infrastructure::Request> request() const { return m_request; }
- void set_request(GC::Ref<Infrastructure::Request> request) { m_request = request; }
+ [[nodiscard]] Infrastructure::Request& request() const { return *m_request; }
[[nodiscard]] GC::Ptr<FetchController> fetch_controller() const { return m_fetch_controller; }
void set_fetch_controller(GC::Ptr<FetchController> fetch_controller) { m_fetch_controller = fetch_controller; }
private:
- explicit FetchRecord(GC::Ref<Infrastructure::Request>);
- FetchRecord(GC::Ref<Infrastructure::Request>, GC::Ptr<FetchController>);
+ FetchRecord(NonnullRefPtr<Infrastructure::Request>, GC::Ptr<FetchController>);
virtual void visit_edges(Visitor&) override;
virtual void finalize() override;
// https://fetch.spec.whatwg.org/#concept-request
// A fetch record has an associated request (a request)
- GC::Ref<Infrastructure::Request> m_request;
+ NonnullRefPtr<Infrastructure::Request> m_request;
// https://fetch.spec.whatwg.org/#fetch-controller
// A fetch record has an associated controller (a fetch controller or null)
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp
index 524236b243b..100d87e1b65 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp
@@ -6,14 +6,11 @@
#include <AK/Array.h>
#include <AK/CharacterTypes.h>
-#include <LibGC/Heap.h>
-#include <LibJS/Runtime/Realm.h>
#include <LibTextCodec/Encoder.h>
#include <LibWeb/ContentSecurityPolicy/Directives/Names.h>
#include <LibWeb/ContentSecurityPolicy/PolicyList.h>
#include <LibWeb/ContentSecurityPolicy/Violation.h>
#include <LibWeb/DOMURL/DOMURL.h>
-#include <LibWeb/Fetch/Fetching/PendingResponse.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
#include <LibWeb/HTML/LocalTraversableNavigable.h>
@@ -22,16 +19,9 @@
namespace Web::Fetch::Infrastructure {
-GC_DEFINE_ALLOCATOR(Request);
-
-GC::Ref<Request> Request::create()
-{
- return GC::Heap::the().allocate<Request>(HTTP::HeaderList::create());
-}
-
-GC::Ref<Request> Request::create(JS::VM&)
+NonnullRefPtr<Request> Request::create()
{
- return create();
+ return adopt_ref(*new Request(HTTP::HeaderList::create()));
}
Request::Request(NonnullRefPtr<HTTP::HeaderList> header_list)
@@ -40,22 +30,16 @@ Request::Request(NonnullRefPtr<HTTP::HeaderList> header_list)
{
}
-void Request::visit_edges(JS::Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_reserved_client);
- visitor.visit(m_pending_responses);
- visitor.visit(m_webdriver_bidi_network_request);
-}
+Request::~Request() = default;
-GC::Ptr<WebDriver::BiDi::NetworkRequest> Request::webdriver_bidi_network_request() const
+RefPtr<WebDriver::BiDi::NetworkRequest> Request::webdriver_bidi_network_request() const
{
return m_webdriver_bidi_network_request;
}
-void Request::set_webdriver_bidi_network_request(GC::Ptr<WebDriver::BiDi::NetworkRequest> state)
+void Request::set_webdriver_bidi_network_request(RefPtr<WebDriver::BiDi::NetworkRequest> state)
{
- m_webdriver_bidi_network_request = state;
+ m_webdriver_bidi_network_request = move(state);
}
// https://fetch.spec.whatwg.org/#concept-request-url
@@ -221,7 +205,7 @@ ByteString Request::byte_serialize_origin() const
}
// https://fetch.spec.whatwg.org/#concept-request-clone
-GC::Ref<Request> Request::clone() const
+NonnullRefPtr<Request> Request::clone() const
{
// To clone a request request, run these steps:
// 1. Let newRequest be a copy of request, except for its body.
@@ -232,7 +216,6 @@ GC::Ref<Request> Request::clone() const
new_request->header_list()->append(header);
new_request->set_unsafe_request(m_unsafe_request);
new_request->set_client(m_client);
- new_request->set_reserved_client(m_reserved_client);
new_request->set_client_snapshot(m_client_snapshot);
new_request->set_reserved_client_snapshot(m_reserved_client_snapshot);
new_request->set_replaces_client_id(m_replaces_client_id);
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h
index 0369842ff3d..d6ba2bc7e20 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h
@@ -11,18 +11,17 @@
#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/String.h>
#include <AK/Time.h>
#include <AK/Utf16String.h>
#include <AK/Utf16View.h>
#include <AK/Variant.h>
#include <AK/Vector.h>
-#include <LibGC/Ptr.h>
#include <LibHTTP/Cache/CacheMode.h>
#include <LibHTTP/HeaderList.h>
-#include <LibJS/Forward.h>
-#include <LibJS/Heap/Cell.h>
#include <LibURL/Origin.h>
#include <LibURL/URL.h>
#include <LibWeb/Export.h>
@@ -47,10 +46,7 @@ namespace Web::Fetch::Infrastructure {
class Response;
// https://fetch.spec.whatwg.org/#concept-request
-class WEB_API Request final : public JS::Cell {
- GC_CELL(Request, JS::Cell);
- GC_DECLARE_ALLOCATOR(Request);
-
+class WEB_API Request final : public RefCounted<Request> {
public:
enum class CredentialsMode {
Omit,
@@ -171,11 +167,10 @@ public:
using OriginType = Variant<Origin, URL::Origin>;
using PolicyContainerType = Variant<PolicyContainer, NonnullRefPtr<HTML::PolicyContainer const>>;
using ReferrerType = RequestReferrerType;
- using ReservedClientType = GC::Ptr<HTML::Environment>;
using TraversableForUserPromptsType = Variant<TraversableForUserPrompts, HTML::CrossProcessId>;
- [[nodiscard]] static GC::Ref<Request> create();
- [[nodiscard]] static GC::Ref<Request> create(JS::VM&);
+ [[nodiscard]] static NonnullRefPtr<Request> create();
+ ~Request();
[[nodiscard]] ByteString const& method() const { return m_method; }
void set_method(ByteString method) { m_method = move(method); }
@@ -201,10 +196,6 @@ public:
[[nodiscard]] Optional<HTML::EnvironmentSettingsObjectAddress> client() const { return m_client; }
void set_client(Optional<HTML::EnvironmentSettingsObjectAddress> client) { m_client = client; }
- [[nodiscard]] ReservedClientType const& reserved_client() const { return m_reserved_client; }
- [[nodiscard]] ReservedClientType& reserved_client() { return m_reserved_client; }
- void set_reserved_client(ReservedClientType reserved_client) { m_reserved_client = move(reserved_client); }
-
[[nodiscard]] RefPtr<ClientContextSnapshot const> const& client_snapshot() const { return m_client_snapshot; }
void set_client_snapshot(RefPtr<ClientContextSnapshot const> client_snapshot) { m_client_snapshot = move(client_snapshot); }
@@ -346,35 +337,21 @@ public:
[[nodiscard]] String serialize_origin() const;
[[nodiscard]] ByteString byte_serialize_origin() const;
- [[nodiscard]] GC::Ref<Request> clone() const;
+ [[nodiscard]] NonnullRefPtr<Request> clone() const;
void add_range_header(u64 first, Optional<u64> const& last);
void add_origin_header();
[[nodiscard]] bool cross_origin_embedder_policy_allows_credentials() const;
- // Non-standard
- void add_pending_response(Badge<Fetching::PendingResponse>, GC::Ref<Fetching::PendingResponse> pending_response)
- {
- VERIFY(!m_pending_responses.contains_slow(pending_response));
- m_pending_responses.append(pending_response);
- }
-
- void remove_pending_response(Badge<Fetching::PendingResponse>, GC::Ref<Fetching::PendingResponse> pending_response)
- {
- m_pending_responses.remove_first_matching([&](auto gc_ptr) { return gc_ptr == pending_response; });
- }
-
UnixDateTime request_time() const { return m_request_time; }
- GC::Ptr<WebDriver::BiDi::NetworkRequest> webdriver_bidi_network_request() const;
- void set_webdriver_bidi_network_request(GC::Ptr<WebDriver::BiDi::NetworkRequest>);
+ RefPtr<WebDriver::BiDi::NetworkRequest> webdriver_bidi_network_request() const;
+ void set_webdriver_bidi_network_request(RefPtr<WebDriver::BiDi::NetworkRequest>);
private:
explicit Request(NonnullRefPtr<HTTP::HeaderList>);
- virtual void visit_edges(JS::Cell::Visitor&) override;
-
// https://fetch.spec.whatwg.org/#concept-request-method
// A request has an associated method (a method). Unless stated otherwise it is `GET`.
ByteString m_method { "GET"sv };
@@ -399,13 +376,13 @@ private:
// A request has an associated client (null or an environment settings object).
Optional<HTML::EnvironmentSettingsObjectAddress> m_client;
+ // What fetching reads from the client, null when the client is.
+ RefPtr<ClientContextSnapshot const> m_client_snapshot;
+
// https://fetch.spec.whatwg.org/#concept-request-reserved-client
// A request has an associated reserved client (null, an environment, or an environment settings object). Unless
// stated otherwise it is null.
- ReservedClientType m_reserved_client;
-
- // What fetching reads from the client and the reserved client, null when the respective one is.
- RefPtr<ClientContextSnapshot const> m_client_snapshot;
+ // NB: The reserved client is held as a snapshot of what fetching reads from it.
RefPtr<ReservedClientContextSnapshot const> m_reserved_client_snapshot;
// https://fetch.spec.whatwg.org/#concept-request-replaces-client-id
@@ -588,9 +565,8 @@ private:
Vector<Vector<String>> m_navigation_timing_allow_values_list;
// Non-standard
- Vector<GC::Ref<Fetching::PendingResponse>> m_pending_responses;
UnixDateTime m_request_time;
- GC::Ptr<WebDriver::BiDi::NetworkRequest> m_webdriver_bidi_network_request;
+ RefPtr<WebDriver::BiDi::NetworkRequest> m_webdriver_bidi_network_request;
};
WEB_API StringView request_destination_to_string(Request::Destination);
diff --git a/Libraries/LibWeb/Fetch/Request.cpp b/Libraries/LibWeb/Fetch/Request.cpp
index ab45e3287fa..226ed775e35 100644
--- a/Libraries/LibWeb/Fetch/Request.cpp
+++ b/Libraries/LibWeb/Fetch/Request.cpp
@@ -206,7 +206,7 @@ static bool is_empty(Bindings::RequestInit const& request_init)
GC_DEFINE_ALLOCATOR(Request);
-Request::Request(GC::Ref<Infrastructure::Request> request)
+Request::Request(NonnullRefPtr<Infrastructure::Request> request)
: m_request(request)
{
}
@@ -216,7 +216,6 @@ Request::~Request() = default;
void Request::visit_edges(GC::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
- visitor.visit(m_request);
visitor.visit(m_body);
visitor.visit(m_headers);
visitor.visit(m_signal);
@@ -256,12 +255,12 @@ GC::Ptr<Infrastructure::Body> Request::body_impl()
}
// https://fetch.spec.whatwg.org/#request-create
-GC::Ref<Request> Request::create(GC::Ref<Infrastructure::Request> request)
+GC::Ref<Request> Request::create(NonnullRefPtr<Infrastructure::Request> request)
{
return GC::Heap::the().allocate<Request>(request);
}
-GC::Ref<Request> Request::create(GC::Ref<Infrastructure::Request> request, Headers::Guard guard, GC::Ref<DOM::AbortSignal> signal)
+GC::Ref<Request> Request::create(NonnullRefPtr<Infrastructure::Request> request, Headers::Guard guard, GC::Ref<DOM::AbortSignal> signal)
{
// 1. Let requestObject be a new Request object with realm.
// 2. Set requestObject’s request to request.
@@ -291,7 +290,7 @@ WebIDL::ExceptionOr<GC::Ref<Request>> Request::create_with_settings(HTML::Enviro
auto request_object = create(Infrastructure::Request::create());
// 1. Let request be null.
- GC::Ptr<Infrastructure::Request> input_request;
+ RefPtr<Infrastructure::Request> input_request;
// 2. Let fallbackMode be null.
Optional<Infrastructure::Request::Mode> fallback_mode;
diff --git a/Libraries/LibWeb/Fetch/Request.h b/Libraries/LibWeb/Fetch/Request.h
index d3f1d6cf8c7..4c5e6f42003 100644
--- a/Libraries/LibWeb/Fetch/Request.h
+++ b/Libraries/LibWeb/Fetch/Request.h
@@ -32,8 +32,8 @@ class Request final
GC_DECLARE_ALLOCATOR(Request);
public:
- [[nodiscard]] static GC::Ref<Request> create(GC::Ref<Infrastructure::Request>);
- [[nodiscard]] static GC::Ref<Request> create(GC::Ref<Infrastructure::Request>, Headers::Guard, GC::Ref<DOM::AbortSignal>);
+ [[nodiscard]] static GC::Ref<Request> create(NonnullRefPtr<Infrastructure::Request>);
+ [[nodiscard]] static GC::Ref<Request> create(NonnullRefPtr<Infrastructure::Request>, Headers::Guard, GC::Ref<DOM::AbortSignal>);
static WebIDL::ExceptionOr<GC::Ref<Request>> create_for_constructor(JS::Object&, RequestInfo const& input, Bindings::RequestInit const& init = {});
static WebIDL::ExceptionOr<GC::Ref<Request>> create_with_settings(HTML::EnvironmentSettingsObject&, RequestInfo const& input, Bindings::RequestInit const& init = {});
@@ -50,7 +50,7 @@ public:
using BodyMixin::json;
using BodyMixin::text;
- [[nodiscard]] GC::Ref<Infrastructure::Request> request() const { return m_request; }
+ [[nodiscard]] NonnullRefPtr<Infrastructure::Request> request() const { return m_request; }
// JS API functions
[[nodiscard]] String method() const;
@@ -72,13 +72,13 @@ public:
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<Request>> clone(JS::Realm&) const;
private:
- explicit Request(GC::Ref<Infrastructure::Request>);
+ explicit Request(NonnullRefPtr<Infrastructure::Request>);
virtual void visit_edges(GC::Cell::Visitor&) override;
// https://fetch.spec.whatwg.org/#concept-request-request
// A Request object has an associated request (a request).
- GC::Ref<Infrastructure::Request> m_request;
+ NonnullRefPtr<Infrastructure::Request> m_request;
// The body of this's request, with its stream.
GC::Ptr<Infrastructure::Body> m_body;
diff --git a/Libraries/LibWeb/HTML/EventSource.cpp b/Libraries/LibWeb/HTML/EventSource.cpp
index a721e0dc7a0..7c4a166de79 100644
--- a/Libraries/LibWeb/HTML/EventSource.cpp
+++ b/Libraries/LibWeb/HTML/EventSource.cpp
@@ -226,7 +226,6 @@ void EventSource::finalize()
void EventSource::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
- visitor.visit(m_request);
visitor.visit(m_fetch_algorithms);
visitor.visit(m_fetch_controller);
visitor.visit(m_reconnection_timer);
@@ -358,7 +357,7 @@ void EventSource::reestablish_the_connection()
return;
// 2. Let request be the EventSource object's request.
- GC::Ref request { *m_request };
+ NonnullRefPtr request { *m_request };
// 3. If the EventSource object's last event ID string is not the empty string, then:
if (!m_last_event_id.is_empty()) {
diff --git a/Libraries/LibWeb/HTML/EventSource.h b/Libraries/LibWeb/HTML/EventSource.h
index 357f97f7193..8036c1ca6d7 100644
--- a/Libraries/LibWeb/HTML/EventSource.h
+++ b/Libraries/LibWeb/HTML/EventSource.h
@@ -89,7 +89,7 @@ private:
URL::URL m_url;
// https://html.spec.whatwg.org/multipage/server-sent-events.html#concept-event-stream-request
- GC::Ptr<Fetch::Infrastructure::Request> m_request;
+ RefPtr<Fetch::Infrastructure::Request> m_request;
// https://html.spec.whatwg.org/multipage/server-sent-events.html#concept-event-stream-reconnection-time
AK::Duration m_reconnection_time { AK::Duration::from_seconds(3) };
diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
index 4e88085d42e..a5aebd478b2 100644
--- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
@@ -436,7 +436,7 @@ GC::Ref<HTMLLinkElement::LinkProcessingOptions> HTMLLinkElement::create_link_opt
}
// https://html.spec.whatwg.org/multipage/semantics.html#create-a-link-request
-GC::Ptr<Fetch::Infrastructure::Request> HTMLLinkElement::create_link_request(HTMLLinkElement::LinkProcessingOptions const& options)
+RefPtr<Fetch::Infrastructure::Request> HTMLLinkElement::create_link_request(HTMLLinkElement::LinkProcessingOptions const& options)
{
// 1. Assert: options's href is not the empty string.
VERIFY(!options.href.is_empty());
diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.h b/Libraries/LibWeb/HTML/HTMLLinkElement.h
index 1dc2e564db9..286db1de82b 100644
--- a/Libraries/LibWeb/HTML/HTMLLinkElement.h
+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.h
@@ -171,7 +171,7 @@ private:
virtual bool is_implicitly_potentially_render_blocking() const override;
GC::Ref<LinkProcessingOptions> create_link_options();
- static GC::Ptr<Fetch::Infrastructure::Request> create_link_request(LinkProcessingOptions const&);
+ static RefPtr<Fetch::Infrastructure::Request> create_link_request(LinkProcessingOptions const&);
static bool apply_link_options_from_parsed_header_attributes(LinkProcessingOptions&, HTTP::Link const&);
void fetch_and_process_linked_resource();
diff --git a/Libraries/LibWeb/HTML/ImageRequest.cpp b/Libraries/LibWeb/HTML/ImageRequest.cpp
index 271bcaff0a8..a397d3b63a6 100644
--- a/Libraries/LibWeb/HTML/ImageRequest.cpp
+++ b/Libraries/LibWeb/HTML/ImageRequest.cpp
@@ -120,7 +120,7 @@ void ImageRequest::prepare_for_presentation(HTMLImageElement&)
// FIXME: 9. Update req's img element's presentation appropriately.
}
-void ImageRequest::fetch_image(GC::Ref<Fetch::Infrastructure::Request> request)
+void ImageRequest::fetch_image(NonnullRefPtr<Fetch::Infrastructure::Request> request)
{
VERIFY(m_shared_resource_request);
if (m_shared_resource_request->needs_fetching())
diff --git a/Libraries/LibWeb/HTML/ImageRequest.h b/Libraries/LibWeb/HTML/ImageRequest.h
index 732356aa1a5..e90a606b925 100644
--- a/Libraries/LibWeb/HTML/ImageRequest.h
+++ b/Libraries/LibWeb/HTML/ImageRequest.h
@@ -57,7 +57,7 @@ public:
// https://html.spec.whatwg.org/multipage/images.html#prepare-an-image-for-presentation
void prepare_for_presentation(HTMLImageElement&);
- void fetch_image(GC::Ref<Fetch::Infrastructure::Request>);
+ void fetch_image(NonnullRefPtr<Fetch::Infrastructure::Request>);
void add_callbacks(Function<void()> on_finish, Function<void()> on_fail, Function<void()> on_stop = {});
GC::Ptr<SharedResourceRequest const> shared_resource_request() const { return m_shared_resource_request; }
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index bf2ae1edeb4..3aa13a21544 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -126,7 +126,7 @@ struct NavigationParamsFetchStateHolder : public JS::Cell {
GC_CELL(NavigationParamsFetchStateHolder, JS::Cell);
GC_DECLARE_ALLOCATOR(NavigationParamsFetchStateHolder);
- NavigationParamsFetchStateHolder(OpenerPolicyEnforcementResult&& coop_enforcement_result, URL::URL current_url, GC::Ref<Fetch::Infrastructure::Request> request,
+ NavigationParamsFetchStateHolder(OpenerPolicyEnforcementResult&& coop_enforcement_result, URL::URL current_url, NonnullRefPtr<Fetch::Infrastructure::Request> request,
Optional<URL::Origin> initiator_origin,
Variant<SerializedPolicyContainer, DocumentState::Client> history_policy_container,
Optional<URL::URL> about_base_url,
@@ -166,7 +166,11 @@ struct NavigationParamsFetchStateHolder : public JS::Cell {
URL::URL current_url;
GC::Ptr<GC::Function<void(DOM::Document&)>> commit_early_hints;
- GC::Ref<Fetch::Infrastructure::Request> request;
+ NonnullRefPtr<Fetch::Infrastructure::Request> request;
+
+ // The reserved client of request, whose snapshot request holds.
+ GC::Ptr<Environment> reserved_client;
+
GC::Ptr<LocalNavigable> navigable;
ContentSecurityPolicy::Directives::Directive::NavigationType csp_navigation_type;
Bindings::NavigationTimingType navigation_timing_type { Bindings::NavigationTimingType::Navigate };
@@ -208,7 +212,7 @@ struct NavigationParamsFetchStateHolder : public JS::Cell {
visitor.visit(response);
visitor.visit(fetch_controller);
visitor.visit(commit_early_hints);
- visitor.visit(request);
+ visitor.visit(reserved_client);
visitor.visit(navigable);
visitor.visit(source_snapshot_params);
visitor.visit(continuation_steps);
@@ -2238,12 +2242,12 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigation
// calling the top level completion steps and then returning.
// 1. If request's reserved client is not null and currentURL's origin is not the same as request's reserved client's creation URL's origin, then:
- if (state_holder->request->reserved_client() && !state_holder->current_url.origin().is_same_origin(state_holder->request->reserved_client()->creation_url.origin())) {
+ if (state_holder->reserved_client && !state_holder->current_url.origin().is_same_origin(state_holder->reserved_client->creation_url.origin())) {
// 1. Run the environment discarding steps for request's reserved client.
- state_holder->request->reserved_client()->discard_environment();
+ state_holder->reserved_client->discard_environment();
// 2. Set request's reserved client to null.
- state_holder->request->set_reserved_client(nullptr);
+ state_holder->reserved_client = nullptr;
state_holder->request->set_reserved_client_snapshot(nullptr);
// 3. Set commitEarlyHints to null.
@@ -2251,7 +2255,7 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigation
}
// 2. If request's reserved client is null, then:
- if (!state_holder->request->reserved_client()) {
+ if (!state_holder->reserved_client) {
// 1. Let topLevelCreationURL be currentURL.
Optional<URL::URL> top_level_creation_url = state_holder->current_url;
@@ -2285,9 +2289,8 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigation
// creation URL is currentURL,
// top-level creation URL is topLevelCreationURL,
// and top-level origin is topLevelOrigin.
- auto reserved_client = realm.create<Environment>(EnvironmentId::generate(), state_holder->current_url, top_level_creation_url, top_level_origin, state_holder->navigable->active_browsing_context());
- state_holder->request->set_reserved_client(reserved_client);
- state_holder->request->set_reserved_client_snapshot(Fetch::Fetching::snapshot_reserved_client_context(reserved_client));
+ state_holder->reserved_client = realm.create<Environment>(EnvironmentId::generate(), state_holder->current_url, top_level_creation_url, top_level_origin, state_holder->navigable->active_browsing_context());
+ state_holder->request->set_reserved_client_snapshot(Fetch::Fetching::snapshot_reserved_client_context(*state_holder->reserved_client));
}
// 3. If the result of should navigation request of type be blocked by Content Security Policy? given request and cspNavigationType is "Blocked", then set response to a network error and break. [CSP]
@@ -2380,7 +2383,7 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigation
}
// 9. Set responsePolicyContainer to the result of creating a policy container from a fetch response given response and request's reserved client.
- state_holder->response_policy_container = create_a_policy_container_from_a_fetch_response(*state_holder->response, state_holder->request->reserved_client());
+ state_holder->response_policy_container = create_a_policy_container_from_a_fetch_response(*state_holder->response, state_holder->reserved_client);
// 10. Set finalSandboxFlags to the union of targetSnapshotParams's sandboxing flags and responsePolicyContainer's CSP list's CSP-derived sandboxing flags.
state_holder->final_sandbox_flags = state_holder->target_snapshot_params.sandboxing_flags | state_holder->response_policy_container->csp_list.csp_derived_sandboxing_flags();
@@ -2394,7 +2397,7 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigation
if (!state_holder->response->is_network_error() && state_holder->navigable->is_top_level_traversable()) {
// 1. Set responseCOOP to the result of obtaining an opener policy given response and request's reserved client.
// AD-HOC: We don't yet set up environments in all cases. Without one, responseCOOP stays a new opener policy.
- if (auto const& reserved_client = state_holder->request->reserved_client())
+ if (auto const& reserved_client = state_holder->reserved_client)
state_holder->response_coop = obtain_an_opener_policy(*state_holder->response->header_list(), is_non_secure_context(*reserved_client));
// 2. Set coopEnforcementResult to the result of enforcing the response's opener policy given navigable's active browsing context,
@@ -2518,7 +2521,6 @@ static void create_navigation_params_by_fetching(
Bindings::NavigationTimingType navigation_timing_type,
GC::Ref<GC::Function<void(GC::Ref<InternalNavigationResult>)>> completion_steps)
{
- auto& vm = navigable->vm();
VERIFY(navigable->active_window());
auto& realm = navigable->active_window()->principal_realm();
auto& active_document = *navigable->active_document();
@@ -2541,7 +2543,7 @@ static void create_navigation_params_by_fetching(
// referrer: entry's document state's request referrer
// referrer policy: entry's document state's request referrer policy
// policy container: sourceSnapshotParams's source policy container
- auto request = Fetch::Infrastructure::Request::create(vm);
+ auto request = Fetch::Infrastructure::Request::create();
request->set_url(entry.url);
if (source_snapshot_params->fetch_client)
request->set_client(source_snapshot_params->fetch_client->address());
@@ -2843,7 +2845,7 @@ static void create_navigation_params_by_fetching(
state_holder->fetch_controller,
state_holder->commit_early_hints,
state_holder->coop_enforcement_result,
- state_holder->request->reserved_client(),
+ state_holder->reserved_client,
*state_holder->response_origin,
result_policy_container,
state_holder->final_sandbox_flags,
@@ -3475,7 +3477,7 @@ void LocalNavigable::navigate_to_a_javascript_url_from_ui_process(URL::URL const
// 1. Let request be a new request whose URL is url and whose policy container is sourceSnapshotParams's source
// policy container.
auto source_snapshot_params = create_source_snapshot_params_from_navigation_source_snapshot(relevant_realm(*window), source_snapshot);
- auto request = Fetch::Infrastructure::Request::create(vm());
+ auto request = Fetch::Infrastructure::Request::create();
request->set_url(url);
request->set_policy_container(source_snapshot_params->source_policy_container);
@@ -3662,7 +3664,7 @@ void LocalNavigable::begin_navigation(PreparedNavigation navigation)
// policy container: sourceSnapshotParams's source policy container
// NB: This is a synthetic request, needed because the Content Security Policy check in navigate to a javascript:
// URL operates on a request. It will never hit the network.
- auto request = Fetch::Infrastructure::Request::create(vm);
+ auto request = Fetch::Infrastructure::Request::create();
request->set_url(url);
if (source_snapshot_params->fetch_client)
request->set_client(source_snapshot_params->fetch_client->address());
@@ -4129,7 +4131,7 @@ GC::Ptr<DOM::Document> LocalNavigable::evaluate_javascript_url(URL::URL const& u
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate-to-a-javascript:-url
-void LocalNavigable::navigate_to_a_javascript_url(GC::Ref<Fetch::Infrastructure::Request> request, HistoryHandlingBehavior history_handling, URL::Origin const& initiator_origin, UserNavigationInvolvement user_involvement, ContentSecurityPolicy::Directives::Directive::NavigationType csp_navigation_type, InitialInsertion initial_insertion, Utf16String navigation_id)
+void LocalNavigable::navigate_to_a_javascript_url(NonnullRefPtr<Fetch::Infrastructure::Request> request, HistoryHandlingBehavior history_handling, URL::Origin const& initiator_origin, UserNavigationInvolvement user_involvement, ContentSecurityPolicy::Directives::Directive::NavigationType csp_navigation_type, InitialInsertion initial_insertion, Utf16String navigation_id)
{
// AD-HOC: These return paths do not run finalize_a_cross_document_navigation(). Clear a child navigable's
// load-event delay and tell the UI that the admitted navigation produced no document.
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index 60d7db4d957..da31ae7ff8e 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -469,7 +469,7 @@ private:
void park_navigation_for_population(Utf16String navigation_id, Optional<PreparedNavigation>);
void clear_parked_navigations();
Optional<NavigationParkedForPopulation> take_navigation_parked_for_population(Utf16String const& navigation_id);
- void navigate_to_a_javascript_url(GC::Ref<Fetch::Infrastructure::Request>, HistoryHandlingBehavior, URL::Origin const& initiator_origin, UserNavigationInvolvement, ContentSecurityPolicy::Directives::Directive::NavigationType csp_navigation_type, InitialInsertion, Utf16String navigation_id);
+ void navigate_to_a_javascript_url(NonnullRefPtr<Fetch::Infrastructure::Request>, HistoryHandlingBehavior, URL::Origin const& initiator_origin, UserNavigationInvolvement, ContentSecurityPolicy::Directives::Directive::NavigationType csp_navigation_type, InitialInsertion, Utf16String navigation_id);
void reset_cursor_blink_cycle();
diff --git a/Libraries/LibWeb/HTML/NavigationParams.cpp b/Libraries/LibWeb/HTML/NavigationParams.cpp
index 9b3d3834dc8..81faa63f59f 100644
--- a/Libraries/LibWeb/HTML/NavigationParams.cpp
+++ b/Libraries/LibWeb/HTML/NavigationParams.cpp
@@ -21,7 +21,6 @@ void NavigationParams::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(navigable);
- visitor.visit(request);
visitor.visit(response);
visitor.visit(fetch_controller);
visitor.visit(commit_early_hints);
diff --git a/Libraries/LibWeb/HTML/NavigationParams.h b/Libraries/LibWeb/HTML/NavigationParams.h
index cd0a1497a48..33cd20a86b9 100644
--- a/Libraries/LibWeb/HTML/NavigationParams.h
+++ b/Libraries/LibWeb/HTML/NavigationParams.h
@@ -53,7 +53,7 @@ struct NavigationParams : GC::Cell {
GC::Ptr<LocalNavigable> navigable;
// null or a request that started the navigation
- GC::Ptr<Fetch::Infrastructure::Request> request;
+ RefPtr<Fetch::Infrastructure::Request> request;
// a response that ultimately was navigated to (potentially a network error)
GC::Ptr<Fetch::Infrastructure::Response> response;
@@ -93,7 +93,7 @@ struct NavigationParams : GC::Cell {
OpenerPolicyEnforcementResult coop_enforcement_result;
// null or an environment reserved for the new Document
- Fetch::Infrastructure::Request::ReservedClientType reserved_environment;
+ GC::Ptr<Environment> reserved_environment;
// an origin to use for the new Document
URL::Origin origin;
@@ -125,12 +125,12 @@ protected:
NavigationParams(
Optional<Utf16String> id,
GC::Ptr<LocalNavigable> navigable,
- GC::Ptr<Fetch::Infrastructure::Request> request,
+ RefPtr<Fetch::Infrastructure::Request> request,
GC::Ptr<Fetch::Infrastructure::Response> response,
GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller,
GC::Ptr<GC::Function<void(DOM::Document&)>> commit_early_hints,
OpenerPolicyEnforcementResult coop_enforcement_result,
- Fetch::Infrastructure::Request::ReservedClientType reserved_environment,
+ GC::Ptr<Environment> reserved_environment,
URL::Origin origin,
RefPtr<PolicyContainer> policy_container,
SandboxingFlagSet final_sandboxing_flag_set,
diff --git a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
index c62bad40667..0f7a82a85ff 100644
--- a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
+++ b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
@@ -232,12 +232,12 @@ void create_navigation_params_descriptor(JS::Realm& realm, NavigationParamsVaria
GC::Ref { realm.global_object() });
}
-static GC::Ptr<Fetch::Infrastructure::Request> create_navigation_request_from_descriptor(JS::Realm& realm, LocalNavigable& navigable, Optional<NavigationRequestDescriptor> const& descriptor)
+static RefPtr<Fetch::Infrastructure::Request> create_navigation_request_from_descriptor(LocalNavigable& navigable, Optional<NavigationRequestDescriptor> const& descriptor)
{
if (!descriptor.has_value())
return nullptr;
- auto request = Fetch::Infrastructure::Request::create(realm.vm());
+ auto request = Fetch::Infrastructure::Request::create();
request->set_url_list(descriptor->url_list);
request->set_method(descriptor->method);
if (!descriptor->client_is_null)
@@ -386,7 +386,7 @@ ErrorOr<NavigationParamsVariant> create_navigation_params_from_descriptor(JS::Re
auto params = descriptor.get<NavigationParamsDescriptor>();
VERIFY(params.navigable_id == navigable.id());
- auto request = create_navigation_request_from_descriptor(realm, navigable, params.request);
+ auto request = create_navigation_request_from_descriptor(navigable, params.request);
RefPtr<Fetch::Infrastructure::FetchTimingInfo> fetch_timing_info;
if (params.fetch_timing_info.has_value())
fetch_timing_info = create_navigation_fetch_timing_info_from_descriptor(*params.fetch_timing_info);
diff --git a/Libraries/LibWeb/HTML/PotentialCORSRequest.cpp b/Libraries/LibWeb/HTML/PotentialCORSRequest.cpp
index 3352d01b255..5a9d1c72e25 100644
--- a/Libraries/LibWeb/HTML/PotentialCORSRequest.cpp
+++ b/Libraries/LibWeb/HTML/PotentialCORSRequest.cpp
@@ -10,7 +10,7 @@
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#create-a-potential-cors-request
-GC::Ref<Fetch::Infrastructure::Request>
+NonnullRefPtr<Fetch::Infrastructure::Request>
create_potential_CORS_request(URL::URL const& url, Optional<Fetch::Infrastructure::Request::Destination> destination, CORSSettingAttribute cors_attribute_state, SameOriginFallbackFlag same_origin_fallback_flag)
{
// 1. Let mode be "no-cors" if corsAttributeState is No CORS, and "cors" otherwise.
diff --git a/Libraries/LibWeb/HTML/PotentialCORSRequest.h b/Libraries/LibWeb/HTML/PotentialCORSRequest.h
index b9772143a8c..efc4bee69cd 100644
--- a/Libraries/LibWeb/HTML/PotentialCORSRequest.h
+++ b/Libraries/LibWeb/HTML/PotentialCORSRequest.h
@@ -19,6 +19,6 @@ enum class SameOriginFallbackFlag {
Yes,
};
-[[nodiscard]] WEB_API GC::Ref<Fetch::Infrastructure::Request> create_potential_CORS_request(URL::URL const&, Optional<Fetch::Infrastructure::Request::Destination>, CORSSettingAttribute, SameOriginFallbackFlag = SameOriginFallbackFlag::No);
+[[nodiscard]] WEB_API NonnullRefPtr<Fetch::Infrastructure::Request> create_potential_CORS_request(URL::URL const&, Optional<Fetch::Infrastructure::Request::Destination>, CORSSettingAttribute, SameOriginFallbackFlag = SameOriginFallbackFlag::No);
}
diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Libraries/LibWeb/HTML/Scripting/Environments.cpp
index 17a011c15b4..5aa7e640328 100644
--- a/Libraries/LibWeb/HTML/Scripting/Environments.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/Environments.cpp
@@ -102,7 +102,7 @@ void EnvironmentSettingsObject::visit_edges(Cell::Visitor& visitor)
// it's finalized.
for (auto& fetch_record : m_fetch_group) {
auto controller = fetch_record.fetch_controller();
- if (fetch_record.request()->done())
+ if (fetch_record.request().done())
continue;
if (controller && controller->state() != Fetch::Infrastructure::FetchController::State::Ongoing)
continue;
diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
index 8d6669a8c24..e6fb74fde45 100644
--- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
@@ -346,7 +346,7 @@ OnFetchScriptComplete create_on_fetch_script_complete(GC::Heap& heap, Function<v
return GC::create_function(heap, move(function));
}
-PerformTheFetchHook create_perform_the_fetch_hook(GC::Heap& heap, Function<WebIDL::ExceptionOr<void>(GC::Ref<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function)
+PerformTheFetchHook create_perform_the_fetch_hook(GC::Heap& heap, Function<WebIDL::ExceptionOr<void>(NonnullRefPtr<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function)
{
return GC::create_function(heap, move(function));
}
diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.h b/Libraries/LibWeb/HTML/Scripting/Fetching.h
index 20d74894753..bb60f7c0c27 100644
--- a/Libraries/LibWeb/HTML/Scripting/Fetching.h
+++ b/Libraries/LibWeb/HTML/Scripting/Fetching.h
@@ -25,10 +25,10 @@ enum class TopLevelModule {
};
using OnFetchScriptComplete = GC::Ref<GC::Function<void(GC::Ptr<Script>)>>;
-using PerformTheFetchHook = GC::Ptr<GC::Function<WebIDL::ExceptionOr<void>(GC::Ref<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)>>;
+using PerformTheFetchHook = GC::Ptr<GC::Function<WebIDL::ExceptionOr<void>(NonnullRefPtr<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)>>;
WEB_API OnFetchScriptComplete create_on_fetch_script_complete(GC::Heap& heap, Function<void(GC::Ptr<Script>)> function);
-WEB_API PerformTheFetchHook create_perform_the_fetch_hook(GC::Heap& heap, Function<WebIDL::ExceptionOr<void>(GC::Ref<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function);
+WEB_API PerformTheFetchHook create_perform_the_fetch_hook(GC::Heap& heap, Function<WebIDL::ExceptionOr<void>(NonnullRefPtr<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function);
class FetchContext : public JS::Cell {
GC_CELL(FetchContext, JS::Cell);
diff --git a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp b/Libraries/LibWeb/HTML/SharedResourceRequest.cpp
index 65ed536fd54..2d04df074c2 100644
--- a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp
+++ b/Libraries/LibWeb/HTML/SharedResourceRequest.cpp
@@ -133,7 +133,7 @@ void SharedResourceRequest::set_fetch_controller(GC::Ptr<Fetch::Infrastructure::
m_fetch_controller = move(fetch_controller);
}
-void SharedResourceRequest::fetch_resource(GC::Ref<Fetch::Infrastructure::Request> request)
+void SharedResourceRequest::fetch_resource(NonnullRefPtr<Fetch::Infrastructure::Request> request)
{
auto& realm = HTML::relevant_realm(*m_document);
VERIFY(needs_fetching());
diff --git a/Libraries/LibWeb/HTML/SharedResourceRequest.h b/Libraries/LibWeb/HTML/SharedResourceRequest.h
index 0313d07abcf..5d977babc24 100644
--- a/Libraries/LibWeb/HTML/SharedResourceRequest.h
+++ b/Libraries/LibWeb/HTML/SharedResourceRequest.h
@@ -49,7 +49,7 @@ public:
[[nodiscard]] GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller();
void set_fetch_controller(GC::Ptr<Fetch::Infrastructure::FetchController>);
- void fetch_resource(GC::Ref<Fetch::Infrastructure::Request>);
+ void fetch_resource(NonnullRefPtr<Fetch::Infrastructure::Request>);
void add_callbacks(Function<void()> on_finish, Function<void()> on_fail, Function<void()> on_stop = {});
diff --git a/Libraries/LibWeb/SRI/IntegrityPolicy.cpp b/Libraries/LibWeb/SRI/IntegrityPolicy.cpp
index 43e43180b04..d250f2aeb13 100644
--- a/Libraries/LibWeb/SRI/IntegrityPolicy.cpp
+++ b/Libraries/LibWeb/SRI/IntegrityPolicy.cpp
@@ -13,7 +13,7 @@
namespace Web::SRI {
// https://w3c.github.io/webappsec-subresource-integrity/#should-request-be-blocked-by-integrity-policy
-ContentSecurityPolicy::Directives::Directive::Result should_request_be_blocked_by_integrity_policy(GC::Ref<Fetch::Infrastructure::Request> request)
+ContentSecurityPolicy::Directives::Directive::Result should_request_be_blocked_by_integrity_policy(NonnullRefPtr<Fetch::Infrastructure::Request> request)
{
VERIFY(request->policy_container().has<NonnullRefPtr<HTML::PolicyContainer const>>());
diff --git a/Libraries/LibWeb/SRI/IntegrityPolicy.h b/Libraries/LibWeb/SRI/IntegrityPolicy.h
index a1716de9e73..954c9059664 100644
--- a/Libraries/LibWeb/SRI/IntegrityPolicy.h
+++ b/Libraries/LibWeb/SRI/IntegrityPolicy.h
@@ -25,6 +25,6 @@ struct IntegrityPolicy {
};
// https://w3c.github.io/webappsec-subresource-integrity/#should-request-be-blocked-by-integrity-policy
-ContentSecurityPolicy::Directives::Directive::Result should_request_be_blocked_by_integrity_policy(GC::Ref<Fetch::Infrastructure::Request>);
+ContentSecurityPolicy::Directives::Directive::Result should_request_be_blocked_by_integrity_policy(NonnullRefPtr<Fetch::Infrastructure::Request>);
}
diff --git a/Libraries/LibWeb/SVG/SVGUseElement.cpp b/Libraries/LibWeb/SVG/SVGUseElement.cpp
index 7b3b38b222c..ddadbe50f69 100644
--- a/Libraries/LibWeb/SVG/SVGUseElement.cpp
+++ b/Libraries/LibWeb/SVG/SVGUseElement.cpp
@@ -13,6 +13,7 @@
#include <LibWeb/DOM/ElementFactory.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/ShadowRoot.h>
+#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/HTML/PotentialCORSRequest.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/SharedResourceRequest.h>
diff --git a/Libraries/LibWeb/ServiceWorker/Cache.cpp b/Libraries/LibWeb/ServiceWorker/Cache.cpp
index 17e870c559e..ad9e84cfc13 100644
--- a/Libraries/LibWeb/ServiceWorker/Cache.cpp
+++ b/Libraries/LibWeb/ServiceWorker/Cache.cpp
@@ -40,11 +40,11 @@ static void resolve_cache_response_list(JS::Realm& realm, WebIDL::Promise& promi
WebIDL::resolve_promise(promise, JS::Array::create_from(realm, response_list->elements()));
}
-static void resolve_cache_request_list(JS::Realm& realm, WebIDL::Promise& promise, GC::Ref<GC::HeapVector<GC::Ref<Fetch::Infrastructure::Request>>> requests)
+static void resolve_cache_request_list(JS::Realm& realm, WebIDL::Promise& promise, Vector<NonnullRefPtr<Fetch::Infrastructure::Request>> const& requests)
{
auto request_list = GC::Heap::the().allocate<GC::HeapVector<JS::Value>>();
- for (auto request : requests->elements())
+ for (auto const& request : requests)
request_list->elements().append(Bindings::wrap(Bindings::host_defined_wrapper_world(realm), realm, Fetch::Request::create(request, Fetch::Headers::Guard::Immutable, DOM::AbortSignal::create())));
WebIDL::resolve_promise(promise, JS::Array::create_from(realm, request_list->elements()));
@@ -108,7 +108,7 @@ void Cache::match(JS::Realm& realm, Fetch::RequestInfo request, CacheQueryOption
void Cache::match_all(JS::Realm& realm, Optional<Fetch::RequestInfo> request, CacheQueryOptions options, GC::Ref<WebIDL::Promise> promise)
{
// 1. Let r be null.
- GC::Ptr<Fetch::Infrastructure::Request> inner_request;
+ RefPtr<Fetch::Infrastructure::Request> inner_request;
bool completed_synchronously = false;
// 2. If the optional argument request is not omitted, then:
@@ -231,7 +231,7 @@ void Cache::add_all(JS::Realm& realm, ReadonlySpan<Fetch::RequestInfo> requests,
auto response_promises = GC::Heap::the().allocate<GC::HeapVector<GC::Ref<WebIDL::Promise>>>();
// 2. Let requestList be an empty list.
- auto request_list = GC::Heap::the().allocate<GC::HeapVector<GC::Ref<Fetch::Infrastructure::Request>>>();
+ Vector<NonnullRefPtr<Fetch::Infrastructure::Request>> request_list;
// 3. For each request whose type is Request in requests:
for (auto const& request_info : requests) {
@@ -280,7 +280,7 @@ void Cache::add_all(JS::Realm& realm, ReadonlySpan<Fetch::RequestInfo> requests,
inner_request->set_service_workers_mode(Fetch::Infrastructure::Request::ServiceWorkersMode::None);
// 4. Add r to requestList.
- request_list->elements().append(inner_request);
+ request_list.append(inner_request);
// 5. Let responsePromise be a new promise.
auto response_promise = WebIDL::create_promise(realm);
@@ -360,7 +360,7 @@ void Cache::add_all(JS::Realm& realm, ReadonlySpan<Fetch::RequestInfo> requests,
// 7. Return the result of reacting to p with a fulfillment handler that, when called with argument responses, performs the following substeps:
WebIDL::react_to_promise(wait_for_responses_promise,
- GC::create_function(GC::Heap::the(), [this, &realm, request_list, promise](JS::Value result) -> WebIDL::ExceptionOr<JS::Value> {
+ GC::create_function(GC::Heap::the(), [this, &realm, request_list = move(request_list), promise](JS::Value result) -> WebIDL::ExceptionOr<JS::Value> {
HTML::TemporaryExecutionContext context { realm };
auto& responses = result.as<JS::Array>();
@@ -378,7 +378,7 @@ void Cache::add_all(JS::Realm& realm, ReadonlySpan<Fetch::RequestInfo> requests,
// 2. Set operation’s type to "put".
CacheBatchOperation::Type::Put,
// 3. Set operation’s request to requestList[index].
- request_list->elements()[index],
+ request_list[index],
// 4. Set operation’s response to response.
response);
@@ -426,7 +426,7 @@ void Cache::add_all(JS::Realm& realm, ReadonlySpan<Fetch::RequestInfo> requests,
void Cache::put(JS::Realm& realm, Fetch::RequestInfo request, GC::Ref<Fetch::Response> response, GC::Ref<WebIDL::Promise> promise)
{
// 1. Let innerRequest be null.
- GC::Ptr<Fetch::Infrastructure::Request> inner_request;
+ RefPtr<Fetch::Infrastructure::Request> inner_request;
auto request_result = request.visit(
// 2. If request is a Request object, then set innerRequest to request’s request.
@@ -572,7 +572,7 @@ void Cache::put(JS::Realm& realm, Fetch::RequestInfo request, GC::Ref<Fetch::Res
void Cache::delete_(JS::Realm& realm, Fetch::RequestInfo request, CacheQueryOptions options, GC::Ref<WebIDL::Promise> promise)
{
// 1. Let r be null.
- GC::Ptr<Fetch::Infrastructure::Request> inner_request;
+ RefPtr<Fetch::Infrastructure::Request> inner_request;
bool completed_synchronously = false;
auto result = request.visit(
@@ -662,7 +662,7 @@ void Cache::delete_(JS::Realm& realm, Fetch::RequestInfo request, CacheQueryOpti
void Cache::keys(JS::Realm& realm, Optional<Fetch::RequestInfo> request, CacheQueryOptions options, GC::Ref<WebIDL::Promise> promise)
{
// 1. Let r be null.
- GC::Ptr<Fetch::Infrastructure::Request> inner_request;
+ RefPtr<Fetch::Infrastructure::Request> inner_request;
bool completed_synchronously = false;
// 2. If the optional argument request is not omitted, then:
@@ -710,14 +710,14 @@ void Cache::keys(JS::Realm& realm, Optional<Fetch::RequestInfo> request, CacheQu
// 5. Run these substeps in parallel:
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(GC::Heap::the(), [this, &realm, inner_request, promise, request = move(request), options]() {
// 1. Let requests be an empty list.
- auto requests = GC::Heap::the().allocate<GC::HeapVector<GC::Ref<Fetch::Infrastructure::Request>>>();
+ Vector<NonnullRefPtr<Fetch::Infrastructure::Request>> requests;
// 2. If the optional argument request is omitted, then:
if (!request.has_value()) {
// 1. For each requestResponse of the relevant request response list:
for (auto& request_response : m_request_response_list->elements()) {
// 1. Add requestResponse’s request to requests.
- requests->elements().append(request_response->request);
+ requests.append(request_response->request);
}
}
// 3. Else:
@@ -728,7 +728,7 @@ void Cache::keys(JS::Realm& realm, Optional<Fetch::RequestInfo> request, CacheQu
// 2. For each requestResponse of requestResponses:
for (auto request_response : request_responses->elements()) {
// 1. Add requestResponse’s request to requests.
- requests->elements().append(request_response->request);
+ requests.append(request_response->request);
}
}
@@ -738,7 +738,7 @@ void Cache::keys(JS::Realm& realm, Optional<Fetch::RequestInfo> request, CacheQu
HTML::Task::Source::DOMManipulation,
HTML::relevant_settings_object(promise->promise()).responsible_event_loop(),
{},
- GC::create_function(GC::Heap::the(), [&realm, promise, requests]() {
+ GC::create_function(GC::Heap::the(), [&realm, promise, requests = move(requests)]() {
HTML::TemporaryExecutionContext context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
resolve_cache_request_list(realm, promise, requests);
@@ -748,8 +748,8 @@ void Cache::keys(JS::Realm& realm, Optional<Fetch::RequestInfo> request, CacheQu
// https://w3c.github.io/ServiceWorker/#request-matches-cached-item-algorithm
static bool request_matches_cached_item(
- GC::Ref<Fetch::Infrastructure::Request> request_query,
- GC::Ref<Fetch::Infrastructure::Request> request,
+ NonnullRefPtr<Fetch::Infrastructure::Request> request_query,
+ NonnullRefPtr<Fetch::Infrastructure::Request> request,
GC::Ptr<Fetch::Infrastructure::Response> response,
CacheQueryOptions options)
{
@@ -799,7 +799,7 @@ static bool request_matches_cached_item(
}
// https://w3c.github.io/ServiceWorker/#query-cache-algorithm
-GC::Ref<RequestResponseList> Cache::query_cache(JS::Realm& realm, GC::Ref<Fetch::Infrastructure::Request> request_query, CacheQueryOptions options, GC::Ptr<RequestResponseList> target_storage, CloneCache clone_cache)
+GC::Ref<RequestResponseList> Cache::query_cache(JS::Realm& realm, NonnullRefPtr<Fetch::Infrastructure::Request> request_query, CacheQueryOptions options, GC::Ptr<RequestResponseList> target_storage, CloneCache clone_cache)
{
// 1. Let resultList be an empty list.
auto result_list = GC::Heap::the().allocate<RequestResponseList>();
@@ -964,7 +964,6 @@ WebIDL::ExceptionOr<bool> Cache::batch_cache_operations(JS::Realm& realm, GC::Re
void CacheBatchOperation::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
- visitor.visit(request);
visitor.visit(response);
}
diff --git a/Libraries/LibWeb/ServiceWorker/Cache.h b/Libraries/LibWeb/ServiceWorker/Cache.h
index 78be96305ee..ef372ab522f 100644
--- a/Libraries/LibWeb/ServiceWorker/Cache.h
+++ b/Libraries/LibWeb/ServiceWorker/Cache.h
@@ -29,7 +29,7 @@ struct CacheBatchOperation : public GC::Cell {
Put,
};
- CacheBatchOperation(Type type, GC::Ref<Fetch::Infrastructure::Request> request, GC::Ptr<Fetch::Infrastructure::Response> response = {}, CacheQueryOptions options = {})
+ CacheBatchOperation(Type type, NonnullRefPtr<Fetch::Infrastructure::Request> request, GC::Ptr<Fetch::Infrastructure::Response> response = {}, CacheQueryOptions options = {})
: type(type)
, request(request)
, response(response)
@@ -40,7 +40,7 @@ struct CacheBatchOperation : public GC::Cell {
virtual void visit_edges(Visitor&) override;
Type type;
- GC::Ref<Fetch::Infrastructure::Request> request;
+ NonnullRefPtr<Fetch::Infrastructure::Request> request;
GC::Ptr<Fetch::Infrastructure::Response> response;
CacheQueryOptions options;
};
@@ -68,7 +68,7 @@ private:
No,
Yes,
};
- GC::Ref<RequestResponseList> query_cache(JS::Realm&, GC::Ref<Fetch::Infrastructure::Request> request_query, CacheQueryOptions options = {}, GC::Ptr<RequestResponseList> = {}, CloneCache = Cache::CloneCache::Yes);
+ GC::Ref<RequestResponseList> query_cache(JS::Realm&, NonnullRefPtr<Fetch::Infrastructure::Request> request_query, CacheQueryOptions options = {}, GC::Ptr<RequestResponseList> = {}, CloneCache = Cache::CloneCache::Yes);
WebIDL::ExceptionOr<bool> batch_cache_operations(JS::Realm&, GC::Ref<GC::HeapVector<GC::Ref<CacheBatchOperation>>>);
GC::Ref<RequestResponseList> m_request_response_list;
diff --git a/Libraries/LibWeb/ServiceWorker/Job.cpp b/Libraries/LibWeb/ServiceWorker/Job.cpp
index 05b8782e0f2..d92efc7cae9 100644
--- a/Libraries/LibWeb/ServiceWorker/Job.cpp
+++ b/Libraries/LibWeb/ServiceWorker/Job.cpp
@@ -216,7 +216,7 @@ static void update(JS::VM& vm, GC::Ref<Job> job)
// - Soft-Update has no client
// To perform the fetch hook given request, run the following steps:
- auto perform_the_fetch_hook_function = [&registration = *registration, job, newest_worker, state](GC::Ref<Fetch::Infrastructure::Request> request, HTML::TopLevelModule top_level, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction process_custom_fetch_response) -> WebIDL::ExceptionOr<void> {
+ auto perform_the_fetch_hook_function = [&registration = *registration, job, newest_worker, state](NonnullRefPtr<Fetch::Infrastructure::Request> request, HTML::TopLevelModule top_level, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction process_custom_fetch_response) -> WebIDL::ExceptionOr<void> {
// FIXME: Soft-Update has no client
auto& realm = job->client->realm();
diff --git a/Libraries/LibWeb/ServiceWorker/NameToCacheMap.cpp b/Libraries/LibWeb/ServiceWorker/NameToCacheMap.cpp
index 93f1cacab8c..46ad9ed9c7e 100644
--- a/Libraries/LibWeb/ServiceWorker/NameToCacheMap.cpp
+++ b/Libraries/LibWeb/ServiceWorker/NameToCacheMap.cpp
@@ -12,10 +12,15 @@ namespace Web::ServiceWorker {
GC_DEFINE_ALLOCATOR(RequestResponse);
+RequestResponse::RequestResponse(NonnullRefPtr<Fetch::Infrastructure::Request> request, GC::Ref<Fetch::Infrastructure::Response> response)
+ : request(move(request))
+ , response(response)
+{
+}
+
void RequestResponse::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
- visitor.visit(request);
visitor.visit(response);
}
diff --git a/Libraries/LibWeb/ServiceWorker/NameToCacheMap.h b/Libraries/LibWeb/ServiceWorker/NameToCacheMap.h
index e6940854414..f9cc30d26c0 100644
--- a/Libraries/LibWeb/ServiceWorker/NameToCacheMap.h
+++ b/Libraries/LibWeb/ServiceWorker/NameToCacheMap.h
@@ -19,15 +19,11 @@ struct RequestResponse : public GC::Cell {
GC_CELL(RequestResponse, GC::Cell);
GC_DECLARE_ALLOCATOR(RequestResponse);
- RequestResponse(GC::Ref<Fetch::Infrastructure::Request> request, GC::Ref<Fetch::Infrastructure::Response> response)
- : request(request)
- , response(response)
- {
- }
+ RequestResponse(NonnullRefPtr<Fetch::Infrastructure::Request>, GC::Ref<Fetch::Infrastructure::Response>);
virtual void visit_edges(Visitor&) override;
- GC::Ref<Fetch::Infrastructure::Request> request;
+ NonnullRefPtr<Fetch::Infrastructure::Request> request;
GC::Ref<Fetch::Infrastructure::Response> response;
};
diff --git a/Libraries/LibWeb/WebDriver/BiDi/Network.cpp b/Libraries/LibWeb/WebDriver/BiDi/Network.cpp
index a382e50d05c..9a8fec978ac 100644
--- a/Libraries/LibWeb/WebDriver/BiDi/Network.cpp
+++ b/Libraries/LibWeb/WebDriver/BiDi/Network.cpp
@@ -10,7 +10,6 @@
#include <AK/Random.h>
#include <AK/StringBuilder.h>
#include <AK/Time.h>
-#include <LibGC/Heap.h>
#include <LibRequests/Request.h>
#include <LibWeb/Fetch/Infrastructure/ClientContextSnapshot.h>
#include <LibWeb/Fetch/Infrastructure/FetchParams.h>
@@ -26,8 +25,6 @@ namespace Web::WebDriver::BiDi {
using namespace Fetch::Infrastructure;
-GC_DEFINE_ALLOCATOR(NetworkRequest);
-
bool g_network_events_enabled { false };
NetworkRequest::NetworkRequest()
@@ -39,7 +36,7 @@ void initialize_network_request(Request& request, GC::Ptr<HTML::Navigable> navig
{
if (!g_network_events_enabled || request.webdriver_bidi_network_request())
return;
- auto state = GC::Heap::the().allocate<NetworkRequest>();
+ auto state = NetworkRequest::create();
if (navigable)
state->navigable_id = navigable->id();
else if (auto const& client = request.client_snapshot())
diff --git a/Libraries/LibWeb/WebDriver/BiDi/Network.h b/Libraries/LibWeb/WebDriver/BiDi/Network.h
index 2351e86ff24..9b15470a9ec 100644
--- a/Libraries/LibWeb/WebDriver/BiDi/Network.h
+++ b/Libraries/LibWeb/WebDriver/BiDi/Network.h
@@ -10,9 +10,10 @@
#include <AK/HashTable.h>
#include <AK/JsonObject.h>
#include <AK/Optional.h>
+#include <AK/RefCounted.h>
#include <AK/String.h>
#include <AK/Utf16String.h>
-#include <LibJS/Heap/Cell.h>
+#include <LibGC/Ptr.h>
#include <LibWeb/Forward.h>
#include <LibWebCommon/HTML/CrossProcessId.h>
@@ -20,11 +21,12 @@ namespace Web::WebDriver::BiDi {
// https://w3c.github.io/webdriver-bidi/#request-id
// NB: Fetch's internal request clones and redirects share this identity.
-class NetworkRequest final : public JS::Cell {
- GC_CELL(NetworkRequest, JS::Cell);
- GC_DECLARE_ALLOCATOR(NetworkRequest);
+class NetworkRequest final : public RefCounted<NetworkRequest> {
+ AK_ALLOC_WITH_KMALLOC;
public:
+ static NonnullRefPtr<NetworkRequest> create() { return adopt_ref(*new NetworkRequest); }
+
String id;
// The navigable the request's events go to.
Optional<HTML::CrossProcessId> navigable_id;
diff --git a/Libraries/LibWeb/WebSockets/WebSocket.cpp b/Libraries/LibWeb/WebSockets/WebSocket.cpp
index 815a027d93a..dd5cd39bc1d 100644
--- a/Libraries/LibWeb/WebSockets/WebSocket.cpp
+++ b/Libraries/LibWeb/WebSockets/WebSocket.cpp
@@ -185,7 +185,7 @@ ErrorOr<void> WebSocket::establish_web_socket_connection(URL::URL const& url_rec
// 2. Let request be a new request, whose URL is requestURL, client is client, service-workers mode is "none",
// referrer is "no-referrer", mode is "websocket", credentials mode is "include", cache mode is "no-store", and
// redirect mode is "error".
- auto request = Fetch::Infrastructure::Request::create(client.vm());
+ auto request = Fetch::Infrastructure::Request::create();
request->set_url(move(request_url));
request->set_client(client.address());
request->set_service_workers_mode(Fetch::Infrastructure::Request::ServiceWorkersMode::None);
diff --git a/Meta/Linters/check_libweb_realm_mentions.py b/Meta/Linters/check_libweb_realm_mentions.py
index 9b9699eadc8..9a29c936dc2 100755
--- a/Meta/Linters/check_libweb_realm_mentions.py
+++ b/Meta/Linters/check_libweb_realm_mentions.py
@@ -43,8 +43,8 @@ ALLOWED_REALM_MENTIONS = {
"Crypto": (8, 383, "WebCrypto algorithms still use realms for buffer/key/promise materialization"),
"DOM": (10, 33, "DOM abort plumbing and node helpers still have callback/materialization realm use"),
"Fetch": (
- 23,
- 63,
+ 22,
+ 62,
"Fetch bodies, headers, requests, responses, and controllers still materialize JS values/streams; "
"the body receiver's delivery and close tasks carry the realm its stream is enqueued and closed in; "
"BodyStreamPullSource materializes stream pulls and errors on the consumer side, in its stream's realm",
@@ -52,7 +52,7 @@ ALLOWED_REALM_MENTIONS = {
"FileAPI": (4, 11, "File/Blob/FileReader algorithms still create streams, buffers, and events in selected realms"),
"HTML": (
64,
- 200,
+ 199,
"HTML algorithms still contain structured serialization, including posted-message preparation, canvas, navigation transfer/reconstruction, worker/worklet, and event realm use, and cross-origin Window/Location property functions are created in the current realm; RemoteWindow mirrors Window's postMessage",
),
"IndexedDB": (
diff --git a/Services/WebWorker/WorkerHost.cpp b/Services/WebWorker/WorkerHost.cpp
index fe617b1ef3d..a0eb3db5881 100644
--- a/Services/WebWorker/WorkerHost.cpp
+++ b/Services/WebWorker/WorkerHost.cpp
@@ -154,7 +154,7 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes
: Web::Fetch::Infrastructure::Request::Destination::Worker;
// In both cases, let performFetch be the following perform the fetch hook given request, isTopLevel, and processCustomFetchResponse:
- auto perform_fetch_function = [inside_settings, outside_settings, worker_global_scope, is_shared](GC::Ref<Web::Fetch::Infrastructure::Request> request, Web::HTML::TopLevelModule is_top_level, Web::Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction process_custom_fetch_response) -> Web::WebIDL::ExceptionOr<void> {
+ auto perform_fetch_function = [inside_settings, outside_settings, worker_global_scope, is_shared](NonnullRefPtr<Web::Fetch::Infrastructure::Request> request, Web::HTML::TopLevelModule is_top_level, Web::Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction process_custom_fetch_response) -> Web::WebIDL::ExceptionOr<void> {
auto& realm = inside_settings->realm();
Web::Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Web::Fetch::Engine::BodyIntent::ConsumeForCallback };
@@ -168,7 +168,6 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes
}
// 2. Set request's reserved client to inside settings.
- request->set_reserved_client(GC::Ptr<Web::HTML::EnvironmentSettingsObject>(inside_settings));
request->set_reserved_client_snapshot(Web::Fetch::Fetching::snapshot_reserved_client_context(*inside_settings));
// NB: We need to store the process custom fetch response function on the heap here, because we're storing it
diff --git a/Tests/LibWeb/TestFetchResponse.cpp b/Tests/LibWeb/TestFetchResponse.cpp
index 0e510e72cb4..223030fec55 100644
--- a/Tests/LibWeb/TestFetchResponse.cpp
+++ b/Tests/LibWeb/TestFetchResponse.cpp
@@ -72,7 +72,7 @@ TEST_CASE(http_redirect_fetch_releases_intermediate_response_transfer_lease)
auto request_url = URL::Parser::basic_parse("https://example.test/start"sv);
VERIFY(request_url.has_value());
- auto request = Web::Fetch::Infrastructure::Request::create(*vm);
+ auto request = Web::Fetch::Infrastructure::Request::create();
request->set_url_list({ request_url.release_value() });
request->set_redirect_count(20);