URL.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. * Copyright (c) 2021, the SerenityOS developers.
  4. * Copyright (c) 2023, networkException <networkexception@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/URL.h>
  10. #include <LibWeb/Bindings/PlatformObject.h>
  11. #include <LibWeb/URL/URLSearchParams.h>
  12. #include <LibWeb/WebIDL/ExceptionOr.h>
  13. namespace Web::URL {
  14. class URL : public Bindings::PlatformObject {
  15. WEB_PLATFORM_OBJECT(URL, Bindings::PlatformObject);
  16. public:
  17. static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> create(JS::Realm&, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query);
  18. static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> construct_impl(JS::Realm&, String const& url, Optional<String> const& base = {});
  19. virtual ~URL() override;
  20. static bool can_parse(JS::VM&, String const& url, Optional<String> const& base = {});
  21. WebIDL::ExceptionOr<String> href() const;
  22. WebIDL::ExceptionOr<void> set_href(String const&);
  23. WebIDL::ExceptionOr<String> origin() const;
  24. WebIDL::ExceptionOr<String> protocol() const;
  25. WebIDL::ExceptionOr<void> set_protocol(String const&);
  26. WebIDL::ExceptionOr<String> username() const;
  27. void set_username(String const&);
  28. WebIDL::ExceptionOr<String> password() const;
  29. void set_password(String const&);
  30. WebIDL::ExceptionOr<String> host() const;
  31. void set_host(String const&);
  32. WebIDL::ExceptionOr<String> hostname() const;
  33. void set_hostname(String const&);
  34. WebIDL::ExceptionOr<String> port() const;
  35. void set_port(String const&);
  36. WebIDL::ExceptionOr<String> pathname() const;
  37. void set_pathname(String const&);
  38. WebIDL::ExceptionOr<String> search() const;
  39. WebIDL::ExceptionOr<void> set_search(String const&);
  40. JS::NonnullGCPtr<URLSearchParams const> search_params() const;
  41. WebIDL::ExceptionOr<String> hash() const;
  42. void set_hash(String const&);
  43. WebIDL::ExceptionOr<String> to_json() const;
  44. void set_query(Badge<URLSearchParams>, String query) { m_url.set_query(query.to_deprecated_string(), AK::URL::ApplyPercentEncoding::Yes); }
  45. private:
  46. URL(JS::Realm&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query);
  47. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  48. virtual void visit_edges(Cell::Visitor&) override;
  49. AK::URL m_url;
  50. JS::NonnullGCPtr<URLSearchParams> m_query;
  51. };
  52. HTML::Origin url_origin(AK::URL const&);
  53. bool host_is_domain(StringView host);
  54. }