1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:37:35 +00:00

LibWeb: Make Fetch::Infrastructure::{Request,Response} ref-counted

With the addition of the 'fetch params' struct, the single ownership
model we had so far falls apart completely.

Additionally, this works nicely for FilteredResponse's internal response
instead of risking a dangling reference.

Replacing the public constructor with a create() function also found a
few instances of a Request being stack-allocated!
This commit is contained in:
Linus Groh 2022-10-04 23:45:47 +01:00
parent 886ca9c7b6
commit 1c12f5c31d
14 changed files with 228 additions and 175 deletions

View file

@ -864,21 +864,21 @@ void BrowsingContext::remove()
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate
WebIDL::ExceptionOr<void> BrowsingContext::navigate(
Fetch::Infrastructure::Request resource,
NonnullRefPtr<Fetch::Infrastructure::Request> resource,
BrowsingContext& source_browsing_context,
bool exceptions_enabled,
HistoryHandlingBehavior history_handling,
Optional<PolicyContainer> history_policy_container,
String navigation_type,
Optional<String> navigation_id,
Function<void(NonnullOwnPtr<Fetch::Infrastructure::Response>)> process_response_end_of_body)
Function<void(NonnullRefPtr<Fetch::Infrastructure::Response>)> process_response_end_of_body)
{
// 1. If resource is a URL, then set resource to a new request whose URL is resource.
// NOTE: This function only accepts resources that are already a request, so this is irrelevant.
// 2. If resource is a request and historyHandling is "reload", then set resource's reload-navigation flag.
if (history_handling == HistoryHandlingBehavior::Reload)
resource.set_reload_navigation(true);
resource->set_reload_navigation(true);
// 3. If the source browsing context is not allowed to navigate browsingContext, then:
if (!source_browsing_context.is_allowed_to_navigate(*this)) {
@ -918,8 +918,8 @@ WebIDL::ExceptionOr<void> BrowsingContext::navigate(
// - resource is a request whose URL's scheme is "javascript"
if (history_handling == HistoryHandlingBehavior::Default
&& (still_on_its_initial_about_blank_document()
|| resource.url().equals(active_document()->url())
|| resource.url().scheme() == "javascript"sv)) {
|| resource->url().equals(active_document()->url())
|| resource->url().scheme() == "javascript"sv)) {
// then set historyHandling to "replace".
history_handling = HistoryHandlingBehavior::Replace;
}
@ -928,10 +928,10 @@ WebIDL::ExceptionOr<void> BrowsingContext::navigate(
// resource's URL equals browsingContext's active document's URL with exclude fragments set to true,
// and resource's URL's fragment is non-null, then:
if (history_handling != HistoryHandlingBehavior::Reload
&& resource.url().equals(active_document()->url(), AK::URL::ExcludeFragment::Yes)
&& !resource.url().fragment().is_null()) {
&& resource->url().equals(active_document()->url(), AK::URL::ExcludeFragment::Yes)
&& !resource->url().fragment().is_null()) {
// 1. Navigate to a fragment given browsingContext, resource's URL, historyHandling, and navigationId.
navigate_to_a_fragment(resource.url(), history_handling, *navigation_id);
navigate_to_a_fragment(resource->url(), history_handling, *navigation_id);
// 2. Return.
return {};
@ -982,7 +982,7 @@ WebIDL::ExceptionOr<void> BrowsingContext::navigate(
(void)process_response_end_of_body;
// AD-HOC:
loader().load(resource.url(), FrameLoader::Type::IFrame);
loader().load(resource->url(), FrameLoader::Type::IFrame);
return {};
}
@ -1039,18 +1039,18 @@ WebIDL::ExceptionOr<void> BrowsingContext::traverse_the_history(size_t entry_ind
VERIFY(history_handling == HistoryHandlingBehavior::Default);
// 2. Let request be a new request whose URL is entry's URL.
auto request = Fetch::Infrastructure::Request();
request.set_url(entry->url);
auto request = Fetch::Infrastructure::Request::create();
request->set_url(entry->url);
// 3. If explicitHistoryNavigation is true, then set request's history-navigation flag.
if (explicit_history_navigation)
request.set_history_navigation(true);
request->set_history_navigation(true);
// 4. Navigate the browsing context to request with historyHandling set to "entry update"
// and with historyPolicyContainer set to entry's policy container.
// The navigation must be done using the same source browsing context as was used the first time entry was created.
VERIFY(entry->original_source_browsing_context);
TRY(navigate(request, *entry->original_source_browsing_context, false, HistoryHandlingBehavior::EntryUpdate, entry->policy_container));
TRY(navigate(move(request), *entry->original_source_browsing_context, false, HistoryHandlingBehavior::EntryUpdate, entry->policy_container));
// 5. Return.
return {};

View file

@ -141,14 +141,14 @@ public:
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate
WebIDL::ExceptionOr<void> navigate(
Fetch::Infrastructure::Request resource,
NonnullRefPtr<Fetch::Infrastructure::Request> resource,
BrowsingContext& source_browsing_context,
bool exceptions_enabled = false,
HistoryHandlingBehavior history_handling = HistoryHandlingBehavior::Default,
Optional<PolicyContainer> history_policy_container = {},
String navigation_type = "other",
Optional<String> navigation_id = {},
Function<void(NonnullOwnPtr<Fetch::Infrastructure::Response>)> process_response_end_of_body = {});
Function<void(NonnullRefPtr<Fetch::Infrastructure::Response>)> process_response_end_of_body = {});
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate-fragid
WebIDL::ExceptionOr<void> navigate_to_a_fragment(AK::URL const&, HistoryHandlingBehavior, String navigation_id);

View file

@ -163,8 +163,8 @@ void BrowsingContextContainer::shared_attribute_processing_steps_for_iframe_and_
}
// 5. Let resource be a new request whose URL is url and whose referrer policy is the current state of element's referrerpolicy content attribute.
auto resource = Fetch::Infrastructure::Request();
resource.set_url(url);
auto resource = Fetch::Infrastructure::Request::create();
resource->set_url(url);
// FIXME: Set the referrer policy.
// AD-HOC:
@ -191,7 +191,7 @@ void BrowsingContextContainer::shared_attribute_processing_steps_for_iframe_and_
}
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#navigate-an-iframe-or-frame
void BrowsingContextContainer::navigate_an_iframe_or_frame(Fetch::Infrastructure::Request resource)
void BrowsingContextContainer::navigate_an_iframe_or_frame(NonnullRefPtr<Fetch::Infrastructure::Request> resource)
{
// 1. Let historyHandling be "default".
auto history_handling = HistoryHandlingBehavior::Default;

View file

@ -35,7 +35,7 @@ protected:
void shared_attribute_processing_steps_for_iframe_and_frame(bool initial_insertion);
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#navigate-an-iframe-or-frame
void navigate_an_iframe_or_frame(Fetch::Infrastructure::Request);
void navigate_an_iframe_or_frame(NonnullRefPtr<Fetch::Infrastructure::Request>);
void create_new_nested_browsing_context();

View file

@ -23,10 +23,10 @@ struct NavigationParams {
String id;
// null or a request that started the navigation
OwnPtr<Fetch::Infrastructure::Request> request;
RefPtr<Fetch::Infrastructure::Request> request;
// a response that ultimately was navigated to (potentially a network error)
NonnullOwnPtr<Fetch::Infrastructure::Response> response;
NonnullRefPtr<Fetch::Infrastructure::Response> response;
// an origin to use for the new Document
Origin origin;