NavigationDestination.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. private:
  31. NavigationDestination(JS::Realm&);
  32. virtual void initialize(JS::Realm&) override;
  33. virtual void visit_edges(JS::Cell::Visitor&) override;
  34. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-url
  35. AK::URL m_url;
  36. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-url
  37. JS::GCPtr<NavigationHistoryEntry> m_entry;
  38. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-state
  39. SerializationRecord m_state;
  40. // https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationdestination-samedocument
  41. bool m_is_same_document { false };
  42. };
  43. }