2021-09-12 18:33:23 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
2023-04-11 09:57:34 -03:00
|
|
|
* Copyright (c) 2023, networkException <networkexception@serenityos.org>
|
2025-03-14 23:38:09 -03:00
|
|
|
* Copyright (c) 2024-2025, Shannon Booth <shannon@serenityos.org>
|
2021-09-12 18:33:23 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-03-18 00:22:27 -03:00
|
|
|
#include <LibURL/URL.h>
|
2022-09-04 09:04:42 -03:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2024-02-11 03:48:56 -03:00
|
|
|
#include <LibWeb/DOMURL/URLSearchParams.h>
|
2025-07-19 23:35:33 -03:00
|
|
|
#include <LibWeb/Export.h>
|
2025-08-17 19:37:34 -03:00
|
|
|
#include <LibWeb/FileAPI/BlobURLStore.h>
|
2022-09-25 13:03:42 -03:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2021-09-13 18:10:22 -03:00
|
|
|
|
2024-02-11 03:48:56 -03:00
|
|
|
namespace Web::DOMURL {
|
2021-09-13 18:10:22 -03:00
|
|
|
|
2024-02-11 03:48:56 -03:00
|
|
|
class DOMURL : public Bindings::PlatformObject {
|
2025-07-18 00:46:17 -03:00
|
|
|
// NOTE: This is 'URL' in the IDL, but we call it DOMURL to avoid name conflicts with LibURL.
|
|
|
|
|
WEB_PLATFORM_OBJECT(URL, Bindings::PlatformObject);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(DOMURL);
|
2021-09-13 18:10:22 -03:00
|
|
|
|
2022-09-04 09:04:42 -03:00
|
|
|
public:
|
2024-11-14 12:01:23 -03: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-13 18:10:22 -03:00
|
|
|
|
2024-02-11 03:48:56 -03:00
|
|
|
virtual ~DOMURL() override;
|
2021-09-13 18:10:22 -03:00
|
|
|
|
2025-08-17 19:37:34 -03:00
|
|
|
static WebIDL::ExceptionOr<Utf16String> create_object_url(JS::VM&, FileAPI::BlobURLEntry::Object object);
|
2024-12-03 06:31:33 -03:00
|
|
|
static void revoke_object_url(JS::VM&, StringView url);
|
2023-08-01 19:49:32 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
static GC::Ptr<DOMURL> parse_for_bindings(JS::VM&, String const& url, Optional<String> const& base = {});
|
2023-04-11 09:57:34 -03:00
|
|
|
static bool can_parse(JS::VM&, String const& url, Optional<String> const& base = {});
|
|
|
|
|
|
2024-12-03 06:31:33 -03:00
|
|
|
String href() const;
|
2023-03-01 16:10:01 -03:00
|
|
|
WebIDL::ExceptionOr<void> set_href(String const&);
|
2021-09-13 18:13:32 -03:00
|
|
|
|
2024-11-23 04:10:34 -03:00
|
|
|
String origin() const;
|
2021-09-13 18:18:25 -03:00
|
|
|
|
2025-01-22 01:17:16 -03:00
|
|
|
String protocol() const;
|
|
|
|
|
void set_protocol(String const&);
|
2021-09-13 18:21:51 -03:00
|
|
|
|
2024-08-04 07:02:02 -03:00
|
|
|
String const& username() const;
|
2023-03-01 16:10:01 -03:00
|
|
|
void set_username(String const&);
|
2021-09-13 18:18:25 -03:00
|
|
|
|
2024-08-04 07:02:02 -03:00
|
|
|
String const& password() const;
|
2023-03-01 16:10:01 -03:00
|
|
|
void set_password(String const&);
|
2021-09-13 18:18:25 -03:00
|
|
|
|
2025-01-22 01:17:16 -03:00
|
|
|
String host() const;
|
2023-03-01 16:10:01 -03:00
|
|
|
void set_host(String const&);
|
2021-09-13 18:21:29 -03:00
|
|
|
|
2025-01-22 01:17:16 -03:00
|
|
|
String hostname() const;
|
2023-03-01 16:10:01 -03:00
|
|
|
void set_hostname(String const&);
|
2021-09-13 18:21:29 -03:00
|
|
|
|
2025-01-22 01:17:16 -03:00
|
|
|
String port() const;
|
2023-03-01 16:10:01 -03:00
|
|
|
void set_port(String const&);
|
2021-09-13 18:21:29 -03:00
|
|
|
|
2024-08-05 01:55:39 -03:00
|
|
|
String pathname() const;
|
2023-03-01 16:10:01 -03:00
|
|
|
void set_pathname(String const&);
|
2021-09-13 18:21:51 -03:00
|
|
|
|
2023-09-10 20:50:29 -03:00
|
|
|
Optional<String> const& fragment() const { return m_url.fragment(); }
|
|
|
|
|
|
2023-12-16 11:19:34 -03:00
|
|
|
ByteString path_segment_at_index(size_t index) const { return m_url.path_segment_at_index(index); }
|
2023-09-10 20:50:29 -03:00
|
|
|
|
2023-12-16 11:19:34 -03:00
|
|
|
void set_paths(Vector<ByteString> const& paths) { return m_url.set_paths(paths); }
|
2023-09-10 20:50:29 -03:00
|
|
|
|
2025-03-07 03:08:44 -03:00
|
|
|
bool has_an_opaque_path() const { return m_url.has_an_opaque_path(); }
|
2023-09-10 20:50:29 -03:00
|
|
|
|
2025-01-22 01:17:16 -03:00
|
|
|
String search() const;
|
2024-08-10 09:24:54 -03:00
|
|
|
void set_search(String const&);
|
2021-09-13 18:21:51 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<URLSearchParams const> search_params() const;
|
2021-09-13 18:15:41 -03:00
|
|
|
|
2025-01-22 01:17:16 -03:00
|
|
|
String hash() const;
|
2023-03-01 16:10:01 -03:00
|
|
|
void set_hash(String const&);
|
2021-09-13 18:21:51 -03:00
|
|
|
|
2024-12-03 06:31:33 -03:00
|
|
|
String to_json() const;
|
2021-09-13 18:13:32 -03:00
|
|
|
|
2023-09-10 20:50:29 -03:00
|
|
|
Optional<String> const& query() const { return m_url.query(); }
|
2023-08-12 04:28:19 -03:00
|
|
|
void set_query(Badge<URLSearchParams>, Optional<String> query) { m_url.set_query(move(query)); }
|
2021-09-13 18:10:22 -03:00
|
|
|
|
2025-12-07 10:19:54 -03:00
|
|
|
virtual Optional<URL::Origin> extract_an_origin() const override;
|
|
|
|
|
|
2021-09-13 18:10:22 -03:00
|
|
|
private:
|
2024-11-14 12:01:23 -03:00
|
|
|
DOMURL(JS::Realm&, URL::URL, GC::Ref<URLSearchParams> query);
|
2022-09-04 09:04:42 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
static GC::Ref<DOMURL> initialize_a_url(JS::Realm&, URL::URL const&);
|
2024-05-13 01:09:58 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-09-04 09:04:42 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2021-09-13 18:10:22 -03:00
|
|
|
|
2024-03-18 00:22:27 -03:00
|
|
|
URL::URL m_url;
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<URLSearchParams> m_query;
|
2021-09-13 18:10:22 -03:00
|
|
|
};
|
|
|
|
|
|
2023-07-14 23:24:58 -03:00
|
|
|
// https://url.spec.whatwg.org/#concept-url-parser
|
2025-07-19 23:35:33 -03:00
|
|
|
WEB_API Optional<URL::URL> parse(StringView input, Optional<URL::URL const&> base_url = {}, Optional<StringView> encoding = {});
|
2023-07-14 23:24:58 -03:00
|
|
|
|
2021-09-12 18:33:23 -03:00
|
|
|
}
|