URL.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. URLSearchParams const* search_params() const;
  27. String to_json() const;
  28. void set_query(Badge<URLSearchParams>, String query) { m_url.set_query(move(query)); }
  29. private:
  30. explicit URL(AK::URL url, NonnullRefPtr<URLSearchParams> query)
  31. : m_url(move(url))
  32. , m_query(move(query)) {};
  33. AK::URL m_url;
  34. NonnullRefPtr<URLSearchParams> m_query;
  35. };
  36. }