NavigationDestination.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/URL.h>
  8. #include <LibWeb/Bindings/PlatformObject.h>
  9. #include <LibWeb/HTML/StructuredSerialize.h>
  10. namespace Web::HTML {
  11. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigationdestination
  12. class NavigationDestination : public Bindings::PlatformObject {
  13. WEB_PLATFORM_OBJECT(NavigationDestination, Bindings::PlatformObject);
  14. public:
  15. [[nodiscard]] static JS::NonnullGCPtr<NavigationDestination> create(JS::Realm&);
  16. WebIDL::ExceptionOr<String> url() const;
  17. String key() const;
  18. String id() const;
  19. i64 index() const;
  20. bool same_document() const;
  21. WebIDL::ExceptionOr<JS::Value> get_state();
  22. // Non-spec'd getter, not exposed to JS
  23. JS::GCPtr<NavigationHistoryEntry> navigation_history_entry() const { return m_entry; }
  24. // Setters are not available to JS, but expected in many spec algorithms
  25. void set_url(AK::URL const& url) { m_url = url; }
  26. void set_entry(JS::GCPtr<NavigationHistoryEntry> entry) { m_entry = entry; }
  27. void set_state(SerializationRecord state) { m_state = move(state); }
  28. void set_is_same_document(bool b) { m_is_same_document = b; }
  29. virtual ~NavigationDestination() override;
  30. AK::URL const& raw_url() const { return m_url; }
  31. private:
  32. NavigationDestination(JS::Realm&);
  33. virtual void initialize(JS::Realm&) override;
  34. virtual void visit_edges(JS::Cell::Visitor&) override;
  35. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-url
  36. AK::URL m_url;
  37. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-url
  38. JS::GCPtr<NavigationHistoryEntry> m_entry;
  39. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-state
  40. SerializationRecord m_state;
  41. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-samedocument
  42. bool m_is_same_document { false };
  43. };
  44. }