URL.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. * Copyright (c) 2021, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/DeprecatedString.h>
  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. WebIDL::ExceptionOr<String> href() const;
  21. WebIDL::ExceptionOr<void> set_href(String const&);
  22. WebIDL::ExceptionOr<String> origin() const;
  23. WebIDL::ExceptionOr<String> protocol() const;
  24. WebIDL::ExceptionOr<void> set_protocol(String const&);
  25. WebIDL::ExceptionOr<String> username() const;
  26. void set_username(String const&);
  27. WebIDL::ExceptionOr<String> password() const;
  28. void set_password(String const&);
  29. WebIDL::ExceptionOr<String> host() const;
  30. void set_host(String const&);
  31. WebIDL::ExceptionOr<String> hostname() const;
  32. void set_hostname(String const&);
  33. WebIDL::ExceptionOr<String> port() const;
  34. void set_port(String const&);
  35. WebIDL::ExceptionOr<String> pathname() const;
  36. void set_pathname(String const&);
  37. WebIDL::ExceptionOr<String> search() const;
  38. WebIDL::ExceptionOr<void> set_search(String const&);
  39. URLSearchParams const* search_params() const;
  40. WebIDL::ExceptionOr<String> hash() const;
  41. void set_hash(String const&);
  42. WebIDL::ExceptionOr<String> to_json() const;
  43. void set_query(Badge<URLSearchParams>, String query) { m_url.set_query(query.to_deprecated_string()); }
  44. private:
  45. URL(JS::Realm&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query);
  46. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  47. virtual void visit_edges(Cell::Visitor&) override;
  48. AK::URL m_url;
  49. JS::NonnullGCPtr<URLSearchParams> m_query;
  50. };
  51. HTML::Origin url_origin(AK::URL const&);
  52. bool host_is_domain(StringView host);
  53. }