URL.h 1.8 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/String.h>
  9. #include <AK/URL.h>
  10. #include <LibWeb/Bindings/Wrappable.h>
  11. #include <LibWeb/DOM/ExceptionOr.h>
  12. #include <LibWeb/URL/URLSearchParams.h>
  13. namespace Web::URL {
  14. class URL : public Bindings::Wrappable
  15. , public RefCounted<URL>
  16. , public Weakable<URL> {
  17. public:
  18. using WrapperType = Bindings::URLWrapper;
  19. static NonnullRefPtr<URL> create(AK::URL url, NonnullRefPtr<URLSearchParams> query)
  20. {
  21. return adopt_ref(*new URL(move(url), move(query)));
  22. }
  23. static DOM::ExceptionOr<NonnullRefPtr<URL>> create_with_global_object(Bindings::WindowObject&, const String& url, const String& base);
  24. String href() const;
  25. DOM::ExceptionOr<void> set_href(String const&);
  26. String origin() const;
  27. String protocol() const;
  28. void set_protocol(String const&);
  29. String username() const;
  30. void set_username(String const&);
  31. String password() const;
  32. void set_password(String const&);
  33. String host() const;
  34. void set_host(String const&);
  35. String hostname() const;
  36. void set_hostname(String const&);
  37. String port() const;
  38. void set_port(String const&);
  39. String pathname() const;
  40. void set_pathname(String const&);
  41. String search() const;
  42. void set_search(String const&);
  43. URLSearchParams const* search_params() const;
  44. String hash() const;
  45. void set_hash(String const&);
  46. String to_json() const;
  47. void set_query(Badge<URLSearchParams>, String query) { m_url.set_query(move(query)); }
  48. private:
  49. explicit URL(AK::URL url, NonnullRefPtr<URLSearchParams> query)
  50. : m_url(move(url))
  51. , m_query(move(query)) {};
  52. AK::URL m_url;
  53. NonnullRefPtr<URLSearchParams> m_query;
  54. };
  55. }