NavigationDestination.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. JS_DECLARE_ALLOCATOR(NavigationDestination);
  15. public:
  16. [[nodiscard]] static JS::NonnullGCPtr<NavigationDestination> create(JS::Realm&);
  17. WebIDL::ExceptionOr<String> url() const;
  18. String key() const;
  19. String id() const;
  20. i64 index() const;
  21. bool same_document() const;
  22. WebIDL::ExceptionOr<JS::Value> get_state();
  23. // Non-spec'd getter, not exposed to JS
  24. JS::GCPtr<NavigationHistoryEntry> navigation_history_entry() const { return m_entry; }
  25. // Setters are not available to JS, but expected in many spec algorithms
  26. void set_url(URL const& url) { m_url = url; }
  27. void set_entry(JS::GCPtr<NavigationHistoryEntry> entry) { m_entry = entry; }
  28. void set_state(SerializationRecord state) { m_state = move(state); }
  29. void set_is_same_document(bool b) { m_is_same_document = b; }
  30. virtual ~NavigationDestination() override;
  31. URL const& raw_url() const { return m_url; }
  32. private:
  33. NavigationDestination(JS::Realm&);
  34. virtual void initialize(JS::Realm&) override;
  35. virtual void visit_edges(JS::Cell::Visitor&) override;
  36. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-url
  37. URL m_url;
  38. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-url
  39. JS::GCPtr<NavigationHistoryEntry> m_entry;
  40. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-state
  41. SerializationRecord m_state;
  42. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-samedocument
  43. bool m_is_same_document { false };
  44. };
  45. }