/* * 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::DOMURL { class DOMURL : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(DOMURL, Bindings::PlatformObject); JS_DECLARE_ALLOCATOR(DOMURL); public: [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, URL::URL, JS::NonnullGCPtr query); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, String const& url, Optional const& base = {}); virtual ~DOMURL() override; static WebIDL::ExceptionOr create_object_url(JS::VM&, JS::NonnullGCPtr object); static WebIDL::ExceptionOr revoke_object_url(JS::VM&, StringView url); 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&); Optional const& fragment() const { return m_url.fragment(); } ByteString path_segment_at_index(size_t index) const { return m_url.path_segment_at_index(index); } void set_paths(Vector const& paths) { return m_url.set_paths(paths); } // 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(); } 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; Optional const& query() const { return m_url.query(); } void set_query(Badge, Optional query) { m_url.set_query(move(query)); } private: DOMURL(JS::Realm&, URL::URL, JS::NonnullGCPtr query); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; URL::URL m_url; JS::NonnullGCPtr m_query; }; HTML::Origin url_origin(URL::URL const&); bool host_is_domain(URL::Host const&); // https://url.spec.whatwg.org/#potentially-strip-trailing-spaces-from-an-opaque-path void strip_trailing_spaces_from_an_opaque_path(DOMURL& url); // https://url.spec.whatwg.org/#concept-url-parser URL::URL parse(StringView input, Optional const& base_url = {}); }