2021-09-13 00:33:23 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
2023-04-11 14:57:34 +02:00
|
|
|
* Copyright (c) 2023, networkException <networkexception@serenityos.org>
|
2024-05-13 16:09:58 +12:00
|
|
|
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
2021-09-13 00:33:23 +03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
#include <LibURL/URL.h>
|
2022-09-04 14:04:42 +02:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2024-02-11 19:48:56 +13:00
|
|
|
#include <LibWeb/DOMURL/URLSearchParams.h>
|
2022-09-25 17:03:42 +01:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2021-09-14 00:10:22 +03:00
|
|
|
|
2024-02-11 19:48:56 +13:00
|
|
|
namespace Web::DOMURL {
|
2021-09-14 00:10:22 +03:00
|
|
|
|
2024-02-11 19:48:56 +13:00
|
|
|
class DOMURL : public Bindings::PlatformObject {
|
|
|
|
WEB_PLATFORM_OBJECT(DOMURL, Bindings::PlatformObject);
|
|
|
|
JS_DECLARE_ALLOCATOR(DOMURL);
|
2021-09-14 00:10:22 +03:00
|
|
|
|
2022-09-04 14:04:42 +02:00
|
|
|
public:
|
2024-03-18 16:22:27 +13:00
|
|
|
[[nodiscard]] static JS::NonnullGCPtr<DOMURL> create(JS::Realm&, URL::URL, JS::NonnullGCPtr<URLSearchParams> query);
|
2024-02-11 19:48:56 +13:00
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMURL>> construct_impl(JS::Realm&, String const& url, Optional<String> const& base = {});
|
2021-09-14 00:10:22 +03:00
|
|
|
|
2024-02-11 19:48:56 +13:00
|
|
|
virtual ~DOMURL() override;
|
2021-09-14 00:10:22 +03:00
|
|
|
|
2023-08-01 18:49:32 -04:00
|
|
|
static WebIDL::ExceptionOr<String> create_object_url(JS::VM&, JS::NonnullGCPtr<FileAPI::Blob> object);
|
|
|
|
static WebIDL::ExceptionOr<void> revoke_object_url(JS::VM&, StringView url);
|
|
|
|
|
2024-05-13 16:10:19 +12:00
|
|
|
static JS::GCPtr<DOMURL> parse_for_bindings(JS::VM&, String const& url, Optional<String> const& base = {});
|
2023-04-11 14:57:34 +02:00
|
|
|
static bool can_parse(JS::VM&, String const& url, Optional<String> const& base = {});
|
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> href() const;
|
|
|
|
WebIDL::ExceptionOr<void> set_href(String const&);
|
2021-09-14 00:13:32 +03:00
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> origin() const;
|
2021-09-14 00:18:25 +03:00
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> protocol() const;
|
|
|
|
WebIDL::ExceptionOr<void> set_protocol(String const&);
|
2021-09-14 00:21:51 +03:00
|
|
|
|
2024-08-04 22:02:02 +12:00
|
|
|
String const& username() const;
|
2023-03-01 20:10:01 +01:00
|
|
|
void set_username(String const&);
|
2021-09-14 00:18:25 +03:00
|
|
|
|
2024-08-04 22:02:02 +12:00
|
|
|
String const& password() const;
|
2023-03-01 20:10:01 +01:00
|
|
|
void set_password(String const&);
|
2021-09-14 00:18:25 +03:00
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> host() const;
|
|
|
|
void set_host(String const&);
|
2021-09-14 00:21:29 +03:00
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> hostname() const;
|
|
|
|
void set_hostname(String const&);
|
2021-09-14 00:21:29 +03:00
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> port() const;
|
|
|
|
void set_port(String const&);
|
2021-09-14 00:21:29 +03:00
|
|
|
|
2024-08-05 16:55:39 +12:00
|
|
|
String pathname() const;
|
2023-03-01 20:10:01 +01:00
|
|
|
void set_pathname(String const&);
|
2021-09-14 00:21:51 +03:00
|
|
|
|
2023-09-10 16:50:29 -07:00
|
|
|
Optional<String> const& fragment() const { return m_url.fragment(); }
|
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString path_segment_at_index(size_t index) const { return m_url.path_segment_at_index(index); }
|
2023-09-10 16:50:29 -07:00
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
void set_paths(Vector<ByteString> const& paths) { return m_url.set_paths(paths); }
|
2023-09-10 16:50:29 -07:00
|
|
|
|
|
|
|
// FIXME: Reimplement this to meet the definition in https://url.spec.whatwg.org/#url-opaque-path once we modernize URL to meet the spec.
|
|
|
|
bool cannot_be_a_base_url() const { return m_url.cannot_be_a_base_url(); }
|
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> search() const;
|
|
|
|
WebIDL::ExceptionOr<void> set_search(String const&);
|
2021-09-14 00:21:51 +03:00
|
|
|
|
2023-04-12 23:20:27 +02:00
|
|
|
JS::NonnullGCPtr<URLSearchParams const> search_params() const;
|
2021-09-14 00:15:41 +03:00
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> hash() const;
|
|
|
|
void set_hash(String const&);
|
2021-09-14 00:21:51 +03:00
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> to_json() const;
|
2021-09-14 00:13:32 +03:00
|
|
|
|
2023-09-10 16:50:29 -07:00
|
|
|
Optional<String> const& query() const { return m_url.query(); }
|
2023-08-12 19:28:19 +12:00
|
|
|
void set_query(Badge<URLSearchParams>, Optional<String> query) { m_url.set_query(move(query)); }
|
2021-09-14 00:10:22 +03:00
|
|
|
|
|
|
|
private:
|
2024-03-18 16:22:27 +13:00
|
|
|
DOMURL(JS::Realm&, URL::URL, JS::NonnullGCPtr<URLSearchParams> query);
|
2022-09-04 14:04:42 +02:00
|
|
|
|
2024-05-13 16:09:58 +12:00
|
|
|
static JS::NonnullGCPtr<DOMURL> initialize_a_url(JS::Realm&, URL::URL const&);
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-09-04 14:04:42 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2021-09-14 00:10:22 +03:00
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
URL::URL m_url;
|
2022-09-04 14:04:42 +02:00
|
|
|
JS::NonnullGCPtr<URLSearchParams> m_query;
|
2021-09-14 00:10:22 +03:00
|
|
|
};
|
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
HTML::Origin url_origin(URL::URL const&);
|
2024-02-11 20:15:39 +13:00
|
|
|
bool host_is_domain(URL::Host const&);
|
2022-10-13 18:25:00 +02:00
|
|
|
|
2023-09-10 16:50:29 -07:00
|
|
|
// https://url.spec.whatwg.org/#potentially-strip-trailing-spaces-from-an-opaque-path
|
2024-02-11 19:48:56 +13:00
|
|
|
void strip_trailing_spaces_from_an_opaque_path(DOMURL& url);
|
2023-09-10 16:50:29 -07:00
|
|
|
|
2023-07-15 14:24:58 +12:00
|
|
|
// https://url.spec.whatwg.org/#concept-url-parser
|
2024-08-05 21:47:45 +01:00
|
|
|
URL::URL parse(StringView input, Optional<URL::URL> const& base_url = {}, Optional<StringView> encoding = {});
|
2023-07-15 14:24:58 +12:00
|
|
|
|
2021-09-13 00:33:23 +03:00
|
|
|
}
|