mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +00:00
AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of the system, as LibCore depends on LibURL. This change has two main benefits: * Moving AK back more towards being an agnostic library that can be used between the kernel and userspace. URL has never really fit that description - and is not used in the kernel. * URL _should_ depend on LibUnicode, as it needs punnycode support. However, it's not really possible to do this inside of AK as it can't depend on any external library. This change brings us a little closer to being able to do that, but unfortunately we aren't there quite yet, as the code generators depend on LibCore.
This commit is contained in:
parent
21bfa001b1
commit
e800605ad3
Notes:
sideshowbarker
2024-07-17 04:41:05 +09:00
Author: https://github.com/shannonbooth
Commit: e800605ad3
Pull-request: https://github.com/SerenityOS/serenity/pull/23443
Issue: https://github.com/SerenityOS/serenity/issues/22884
Reviewed-by: https://github.com/trflynn89
403 changed files with 1336 additions and 1305 deletions
|
@ -44,7 +44,7 @@ JS::NonnullGCPtr<Request> Request::create(JS::VM& vm)
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-request-url
|
||||
URL& Request::url()
|
||||
URL::URL& Request::url()
|
||||
{
|
||||
// A request has an associated URL (a URL).
|
||||
// NOTE: Implementations are encouraged to make this a pointer to the first URL in request’s URL list. It is provided as a distinct field solely for the convenience of other standards hooking into Fetch.
|
||||
|
@ -53,13 +53,13 @@ URL& Request::url()
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-request-url
|
||||
URL const& Request::url() const
|
||||
URL::URL const& Request::url() const
|
||||
{
|
||||
return const_cast<Request&>(*this).url();
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-request-current-url
|
||||
URL& Request::current_url()
|
||||
URL::URL& Request::current_url()
|
||||
{
|
||||
// A request has an associated current URL. It is a pointer to the last URL in request’s URL list.
|
||||
VERIFY(!m_url_list.is_empty());
|
||||
|
@ -67,12 +67,12 @@ URL& Request::current_url()
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-request-current-url
|
||||
URL const& Request::current_url() const
|
||||
URL::URL const& Request::current_url() const
|
||||
{
|
||||
return const_cast<Request&>(*this).current_url();
|
||||
}
|
||||
|
||||
void Request::set_url(URL url)
|
||||
void Request::set_url(URL::URL url)
|
||||
{
|
||||
// Sometimes setting the URL and URL list are done as two distinct steps in the spec,
|
||||
// but since we know the URL is always the URL list's first item and doesn't change later
|
||||
|
@ -163,7 +163,7 @@ bool Request::has_redirect_tainted_origin() const
|
|||
// A request request has a redirect-tainted origin if these steps return true:
|
||||
|
||||
// 1. Let lastURL be null.
|
||||
Optional<URL const&> last_url;
|
||||
Optional<URL::URL const&> last_url;
|
||||
|
||||
// 2. For each url of request’s URL list:
|
||||
for (auto const& url : m_url_list) {
|
||||
|
|
|
@ -12,12 +12,12 @@
|
|||
#include <AK/Forward.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/URL.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Headers.h>
|
||||
#include <LibWeb/HTML/Origin.h>
|
||||
|
@ -164,7 +164,7 @@ public:
|
|||
using BodyType = Variant<Empty, ByteBuffer, JS::NonnullGCPtr<Body>>;
|
||||
using OriginType = Variant<Origin, HTML::Origin>;
|
||||
using PolicyContainerType = Variant<PolicyContainer, HTML::PolicyContainer>;
|
||||
using ReferrerType = Variant<Referrer, URL>;
|
||||
using ReferrerType = Variant<Referrer, URL::URL>;
|
||||
using ReservedClientType = Variant<Empty, HTML::Environment*, JS::GCPtr<HTML::EnvironmentSettingsObject>>;
|
||||
using WindowType = Variant<Window, JS::GCPtr<HTML::EnvironmentSettingsObject>>;
|
||||
|
||||
|
@ -263,9 +263,9 @@ public:
|
|||
[[nodiscard]] bool render_blocking() const { return m_render_blocking; }
|
||||
void set_render_blocking(bool render_blocking) { m_render_blocking = render_blocking; }
|
||||
|
||||
[[nodiscard]] Vector<URL> const& url_list() const { return m_url_list; }
|
||||
[[nodiscard]] Vector<URL>& url_list() { return m_url_list; }
|
||||
void set_url_list(Vector<URL> url_list) { m_url_list = move(url_list); }
|
||||
[[nodiscard]] Vector<URL::URL> const& url_list() const { return m_url_list; }
|
||||
[[nodiscard]] Vector<URL::URL>& url_list() { return m_url_list; }
|
||||
void set_url_list(Vector<URL::URL> url_list) { m_url_list = move(url_list); }
|
||||
|
||||
[[nodiscard]] u8 redirect_count() const { return m_redirect_count; }
|
||||
void set_redirect_count(u8 redirect_count) { m_redirect_count = redirect_count; }
|
||||
|
@ -288,11 +288,11 @@ public:
|
|||
[[nodiscard]] bool timing_allow_failed() const { return m_timing_allow_failed; }
|
||||
void set_timing_allow_failed(bool timing_allow_failed) { m_timing_allow_failed = timing_allow_failed; }
|
||||
|
||||
[[nodiscard]] URL& url();
|
||||
[[nodiscard]] URL const& url() const;
|
||||
[[nodiscard]] URL& current_url();
|
||||
[[nodiscard]] URL const& current_url() const;
|
||||
void set_url(URL url);
|
||||
[[nodiscard]] URL::URL& url();
|
||||
[[nodiscard]] URL::URL const& url() const;
|
||||
[[nodiscard]] URL::URL& current_url();
|
||||
[[nodiscard]] URL::URL const& current_url() const;
|
||||
void set_url(URL::URL url);
|
||||
|
||||
[[nodiscard]] bool destination_is_script_like() const;
|
||||
|
||||
|
@ -487,7 +487,7 @@ private:
|
|||
// https://fetch.spec.whatwg.org/#concept-request-url-list
|
||||
// A request has an associated URL list (a list of one or more URLs). Unless stated otherwise, it is a list
|
||||
// containing a copy of request’s URL.
|
||||
Vector<URL> m_url_list;
|
||||
Vector<URL::URL> m_url_list;
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-request-redirect-count
|
||||
// A request has an associated redirect count. Unless stated otherwise, it is zero.
|
||||
|
|
|
@ -104,7 +104,7 @@ bool Response::is_network_error() const
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-response-url
|
||||
Optional<URL const&> Response::url() const
|
||||
Optional<URL::URL const&> Response::url() const
|
||||
{
|
||||
// A response has an associated URL. It is a pointer to the last URL in response’s URL list and null if response’s URL list is empty.
|
||||
// NOTE: We have to use the virtual getter here to not bypass filtered responses.
|
||||
|
@ -114,23 +114,23 @@ Optional<URL const&> Response::url() const
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-response-location-url
|
||||
ErrorOr<Optional<URL>> Response::location_url(Optional<String> const& request_fragment) const
|
||||
ErrorOr<Optional<URL::URL>> Response::location_url(Optional<String> const& request_fragment) const
|
||||
{
|
||||
// The location URL of a response response, given null or an ASCII string requestFragment, is the value returned by the following steps. They return null, failure, or a URL.
|
||||
|
||||
// 1. If response’s status is not a redirect status, then return null.
|
||||
// NOTE: We have to use the virtual getter here to not bypass filtered responses.
|
||||
if (!is_redirect_status(status()))
|
||||
return Optional<URL> {};
|
||||
return Optional<URL::URL> {};
|
||||
|
||||
// 2. Let location be the result of extracting header list values given `Location` and response’s header list.
|
||||
auto location_values_or_failure = TRY(extract_header_list_values("Location"sv.bytes(), m_header_list));
|
||||
if (location_values_or_failure.has<Infrastructure::ExtractHeaderParseFailure>() || location_values_or_failure.has<Empty>())
|
||||
return Optional<URL> {};
|
||||
return Optional<URL::URL> {};
|
||||
|
||||
auto const& location_values = location_values_or_failure.get<Vector<ByteBuffer>>();
|
||||
if (location_values.size() != 1)
|
||||
return Optional<URL> {};
|
||||
return Optional<URL::URL> {};
|
||||
|
||||
// 3. If location is a header value, then set location to the result of parsing location with response’s URL.
|
||||
auto location = DOMURL::parse(location_values.first(), url());
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
#include <AK/Error.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/URL.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Headers.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Statuses.h>
|
||||
|
@ -65,9 +65,9 @@ public:
|
|||
[[nodiscard]] virtual bool aborted() const { return m_aborted; }
|
||||
void set_aborted(bool aborted) { m_aborted = aborted; }
|
||||
|
||||
[[nodiscard]] virtual Vector<URL> const& url_list() const { return m_url_list; }
|
||||
[[nodiscard]] virtual Vector<URL>& url_list() { return m_url_list; }
|
||||
void set_url_list(Vector<URL> url_list) { m_url_list = move(url_list); }
|
||||
[[nodiscard]] virtual Vector<URL::URL> const& url_list() const { return m_url_list; }
|
||||
[[nodiscard]] virtual Vector<URL::URL>& url_list() { return m_url_list; }
|
||||
void set_url_list(Vector<URL::URL> url_list) { m_url_list = move(url_list); }
|
||||
|
||||
[[nodiscard]] virtual Status status() const { return m_status; }
|
||||
void set_status(Status status) { m_status = status; }
|
||||
|
@ -106,8 +106,8 @@ public:
|
|||
[[nodiscard]] bool is_aborted_network_error() const;
|
||||
[[nodiscard]] bool is_network_error() const;
|
||||
|
||||
[[nodiscard]] Optional<URL const&> url() const;
|
||||
[[nodiscard]] ErrorOr<Optional<URL>> location_url(Optional<String> const& request_fragment) const;
|
||||
[[nodiscard]] Optional<URL::URL const&> url() const;
|
||||
[[nodiscard]] ErrorOr<Optional<URL::URL>> location_url(Optional<String> const& request_fragment) const;
|
||||
|
||||
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> clone(JS::Realm&) const;
|
||||
|
||||
|
@ -134,7 +134,7 @@ private:
|
|||
|
||||
// https://fetch.spec.whatwg.org/#concept-response-url-list
|
||||
// A response has an associated URL list (a list of zero or more URLs). Unless stated otherwise, it is the empty list.
|
||||
Vector<URL> m_url_list;
|
||||
Vector<URL::URL> m_url_list;
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-response-status
|
||||
// A response has an associated status, which is a status. Unless stated otherwise it is 200.
|
||||
|
@ -197,8 +197,8 @@ public:
|
|||
|
||||
[[nodiscard]] virtual Type type() const override { return m_internal_response->type(); }
|
||||
[[nodiscard]] virtual bool aborted() const override { return m_internal_response->aborted(); }
|
||||
[[nodiscard]] virtual Vector<URL> const& url_list() const override { return m_internal_response->url_list(); }
|
||||
[[nodiscard]] virtual Vector<URL>& url_list() override { return m_internal_response->url_list(); }
|
||||
[[nodiscard]] virtual Vector<URL::URL> const& url_list() const override { return m_internal_response->url_list(); }
|
||||
[[nodiscard]] virtual Vector<URL::URL>& url_list() override { return m_internal_response->url_list(); }
|
||||
[[nodiscard]] virtual Status status() const override { return m_internal_response->status(); }
|
||||
[[nodiscard]] virtual ReadonlyBytes status_message() const override { return m_internal_response->status_message(); }
|
||||
[[nodiscard]] virtual JS::NonnullGCPtr<HeaderList> header_list() const override { return m_internal_response->header_list(); }
|
||||
|
@ -268,8 +268,8 @@ public:
|
|||
[[nodiscard]] static JS::NonnullGCPtr<OpaqueFilteredResponse> create(JS::VM&, JS::NonnullGCPtr<Response>);
|
||||
|
||||
[[nodiscard]] virtual Type type() const override { return Type::Opaque; }
|
||||
[[nodiscard]] virtual Vector<URL> const& url_list() const override { return m_url_list; }
|
||||
[[nodiscard]] virtual Vector<URL>& url_list() override { return m_url_list; }
|
||||
[[nodiscard]] virtual Vector<URL::URL> const& url_list() const override { return m_url_list; }
|
||||
[[nodiscard]] virtual Vector<URL::URL>& url_list() override { return m_url_list; }
|
||||
[[nodiscard]] virtual Status status() const override { return 0; }
|
||||
[[nodiscard]] virtual ReadonlyBytes status_message() const override { return {}; }
|
||||
[[nodiscard]] virtual JS::NonnullGCPtr<HeaderList> header_list() const override { return m_header_list; }
|
||||
|
@ -281,7 +281,7 @@ private:
|
|||
|
||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||
|
||||
Vector<URL> m_url_list;
|
||||
Vector<URL::URL> m_url_list;
|
||||
JS::NonnullGCPtr<HeaderList> m_header_list;
|
||||
JS::GCPtr<Body> m_body;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue