/* * Copyright (c) 2021, Idan Horowitz * Copyright (c) 2021, the SerenityOS developers. * Copyright (c) 2023, networkException * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::URL { class URL : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(URL, Bindings::PlatformObject); public: static WebIDL::ExceptionOr> create(JS::Realm&, AK::URL url, JS::NonnullGCPtr query); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, String const& url, Optional const& base = {}); virtual ~URL() override; static bool can_parse(JS::VM&, String const& url, Optional const& base = {}); WebIDL::ExceptionOr href() const; WebIDL::ExceptionOr set_href(String const&); WebIDL::ExceptionOr origin() const; WebIDL::ExceptionOr protocol() const; WebIDL::ExceptionOr set_protocol(String const&); WebIDL::ExceptionOr username() const; void set_username(String const&); WebIDL::ExceptionOr password() const; void set_password(String const&); WebIDL::ExceptionOr host() const; void set_host(String const&); WebIDL::ExceptionOr hostname() const; void set_hostname(String const&); WebIDL::ExceptionOr port() const; void set_port(String const&); WebIDL::ExceptionOr pathname() const; void set_pathname(String const&); WebIDL::ExceptionOr search() const; WebIDL::ExceptionOr set_search(String const&); JS::NonnullGCPtr search_params() const; WebIDL::ExceptionOr hash() const; void set_hash(String const&); WebIDL::ExceptionOr to_json() const; void set_query(Badge, String query) { m_url.set_query(query.to_deprecated_string(), AK::URL::ApplyPercentEncoding::Yes); } private: URL(JS::Realm&, AK::URL, JS::NonnullGCPtr query); virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; AK::URL m_url; JS::NonnullGCPtr m_query; }; HTML::Origin url_origin(AK::URL const&); bool host_is_domain(StringView host); }