TraversableNavigable.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Vector.h>
  8. #include <LibWeb/HTML/Navigable.h>
  9. #include <LibWeb/HTML/VisibilityState.h>
  10. namespace Web::HTML {
  11. // https://html.spec.whatwg.org/multipage/document-sequences.html#traversable-navigable
  12. class TraversableNavigable final : public Navigable {
  13. JS_CELL(TraversableNavigable, Navigable);
  14. public:
  15. static WebIDL::ExceptionOr<JS::NonnullGCPtr<TraversableNavigable>> create_a_new_top_level_traversable(Page&, JS::GCPtr<BrowsingContext> opener, String target_name);
  16. static WebIDL::ExceptionOr<JS::NonnullGCPtr<TraversableNavigable>> create_a_fresh_top_level_traversable(Page&, AK::URL const& initial_navigation_url, Variant<Empty, String, POSTResource> = Empty {});
  17. virtual ~TraversableNavigable() override;
  18. bool is_top_level_traversable() const;
  19. int current_session_history_step() const { return m_current_session_history_step; };
  20. Vector<JS::NonnullGCPtr<SessionHistoryEntry>>& session_history_entries() { return m_session_history_entries; };
  21. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> const& session_history_entries() const { return m_session_history_entries; };
  22. bool running_nested_apply_history_step() const { return m_running_nested_apply_history_step; };
  23. VisibilityState system_visibility_state() const { return m_system_visibility_state; };
  24. struct HistoryObjectLengthAndIndex {
  25. size_t script_history_length;
  26. size_t script_history_index;
  27. };
  28. HistoryObjectLengthAndIndex get_the_history_object_length_and_index(int) const;
  29. void apply_the_history_step(int step, Optional<SourceSnapshotParams> = {});
  30. int get_the_used_step(int step) const;
  31. Vector<JS::Handle<Navigable>> get_all_navigables_whose_current_session_history_entry_will_change_or_reload(int) const;
  32. Vector<int> get_all_used_history_steps() const;
  33. void clear_the_forward_session_history();
  34. void traverse_the_history_by_delta(int delta);
  35. private:
  36. TraversableNavigable();
  37. virtual void visit_edges(Cell::Visitor&) override;
  38. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-current-session-history-step
  39. int m_current_session_history_step { 0 };
  40. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-entries
  41. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> m_session_history_entries;
  42. // FIXME: https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-traversal-queue
  43. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-running-nested-apply-history-step
  44. bool m_running_nested_apply_history_step { false };
  45. // https://html.spec.whatwg.org/multipage/document-sequences.html#system-visibility-state
  46. VisibilityState m_system_visibility_state { VisibilityState::Visible };
  47. };
  48. }