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>
|
2025-03-15 15:38:09 +13:00
|
|
|
* Copyright (c) 2024-2025, 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>
|
2025-07-19 19:35:33 -07:00
|
|
|
#include <LibWeb/Export.h>
|
2025-08-18 00:37:34 +02:00
|
|
|
#include <LibWeb/FileAPI/BlobURLStore.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);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(DOMURL);
|
2021-09-14 00:10:22 +03:00
|
|
|
|
2022-09-04 14:04:42 +02:00
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] static GC::Ref<DOMURL> create(JS::Realm&, URL::URL, GC::Ref<URLSearchParams> query);
|
|
|
|
static WebIDL::ExceptionOr<GC::Ref<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
|
|
|
|
2025-08-18 00:37:34 +02:00
|
|
|
static WebIDL::ExceptionOr<Utf16String> create_object_url(JS::VM&, FileAPI::BlobURLEntry::Object object);
|
2024-12-03 22:31:33 +13:00
|
|
|
static void revoke_object_url(JS::VM&, StringView url);
|
2023-08-01 18:49:32 -04:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
static GC::Ptr<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 = {});
|
|
|
|
|
2024-12-03 22:31:33 +13:00
|
|
|
String href() const;
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<void> set_href(String const&);
|
2021-09-14 00:13:32 +03:00
|
|
|
|
2024-11-23 20:10:34 +13:00
|
|
|
String origin() const;
|
2021-09-14 00:18:25 +03:00
|
|
|
|
2025-01-22 17:17:16 +13:00
|
|
|
String protocol() const;
|
|
|
|
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
|
|
|
|
2025-01-22 17:17:16 +13:00
|
|
|
String host() const;
|
2023-03-01 20:10:01 +01:00
|
|
|
void set_host(String const&);
|
2021-09-14 00:21:29 +03:00
|
|
|
|
2025-01-22 17:17:16 +13:00
|
|
|
String hostname() const;
|
2023-03-01 20:10:01 +01:00
|
|
|
void set_hostname(String const&);
|
2021-09-14 00:21:29 +03:00
|
|
|
|
2025-01-22 17:17:16 +13:00
|
|
|
String port() const;
|
2023-03-01 20:10:01 +01:00
|
|
|
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
|
|
|
|
2025-03-07 19:08:44 +13:00
|
|
|
bool has_an_opaque_path() const { return m_url.has_an_opaque_path(); }
|
2023-09-10 16:50:29 -07:00
|
|
|
|
2025-01-22 17:17:16 +13:00
|
|
|
String search() const;
|
2024-08-11 00:24:54 +12:00
|
|
|
void set_search(String const&);
|
2021-09-14 00:21:51 +03:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<URLSearchParams const> search_params() const;
|
2021-09-14 00:15:41 +03:00
|
|
|
|
2025-01-22 17:17:16 +13:00
|
|
|
String hash() const;
|
2023-03-01 20:10:01 +01:00
|
|
|
void set_hash(String const&);
|
2021-09-14 00:21:51 +03:00
|
|
|
|
2024-12-03 22:31:33 +13:00
|
|
|
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-11-15 04:01:23 +13:00
|
|
|
DOMURL(JS::Realm&, URL::URL, GC::Ref<URLSearchParams> query);
|
2022-09-04 14:04:42 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
static GC::Ref<DOMURL> initialize_a_url(JS::Realm&, URL::URL const&);
|
2024-05-13 16:09:58 +12:00
|
|
|
|
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;
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<URLSearchParams> m_query;
|
2021-09-14 00:10:22 +03:00
|
|
|
};
|
|
|
|
|
2023-07-15 14:24:58 +12:00
|
|
|
// https://url.spec.whatwg.org/#concept-url-parser
|
2025-07-19 19:35:33 -07:00
|
|
|
WEB_API Optional<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
|
|
|
}
|