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>
|
2021-09-13 00:33:23 +03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-09-14 00:10:22 +03:00
|
|
|
#include <AK/URL.h>
|
2022-09-04 14:04:42 +02:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2021-09-14 00:10:22 +03:00
|
|
|
#include <LibWeb/URL/URLSearchParams.h>
|
2022-09-25 17:03:42 +01:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2021-09-14 00:10:22 +03:00
|
|
|
|
2021-09-13 00:33:23 +03:00
|
|
|
namespace Web::URL {
|
2021-09-14 00:10:22 +03:00
|
|
|
|
2022-09-04 14:04:42 +02:00
|
|
|
class URL : public Bindings::PlatformObject {
|
|
|
|
WEB_PLATFORM_OBJECT(URL, Bindings::PlatformObject);
|
2021-09-14 00:10:22 +03:00
|
|
|
|
2022-09-04 14:04:42 +02:00
|
|
|
public:
|
2023-02-14 20:01:04 +01:00
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> create(JS::Realm&, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query);
|
2023-03-01 20:10:01 +01:00
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> construct_impl(JS::Realm&, String const& url, Optional<String> const& base = {});
|
2021-09-14 00:10:22 +03:00
|
|
|
|
2022-09-04 14:04:42 +02:00
|
|
|
virtual ~URL() 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);
|
|
|
|
|
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
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> username() const;
|
|
|
|
void set_username(String const&);
|
2021-09-14 00:18:25 +03:00
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> password() const;
|
|
|
|
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
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
WebIDL::ExceptionOr<String> pathname() const;
|
|
|
|
void set_pathname(String const&);
|
2021-09-14 00:21:51 +03:00
|
|
|
|
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-08-06 16:32:44 +12:00
|
|
|
void set_query(Badge<URLSearchParams>, StringView query) { m_url.set_query(query); }
|
2021-09-14 00:10:22 +03:00
|
|
|
|
|
|
|
private:
|
LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
2022-09-25 18:11:21 -06:00
|
|
|
URL(JS::Realm&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query);
|
2022-09-04 14:04:42 +02:00
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
virtual JS::ThrowCompletionOr<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
|
|
|
|
|
|
|
AK::URL m_url;
|
2022-09-04 14:04:42 +02:00
|
|
|
JS::NonnullGCPtr<URLSearchParams> m_query;
|
2021-09-14 00:10:22 +03:00
|
|
|
};
|
|
|
|
|
2022-10-13 18:25:00 +02:00
|
|
|
HTML::Origin url_origin(AK::URL const&);
|
2023-07-29 10:01:20 +12:00
|
|
|
bool host_is_domain(AK::URL::Host const&);
|
2022-10-13 18:25:00 +02:00
|
|
|
|
2023-07-15 14:24:58 +12:00
|
|
|
// https://url.spec.whatwg.org/#concept-url-parser
|
|
|
|
AK::URL parse(StringView input, Optional<AK::URL> const& base_url = {});
|
|
|
|
|
2021-09-13 00:33:23 +03:00
|
|
|
}
|