TraversableNavigable.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/SessionHistoryTraversalQueue.h>
  10. #include <LibWeb/HTML/VisibilityState.h>
  11. namespace Web::HTML {
  12. // https://html.spec.whatwg.org/multipage/document-sequences.html#traversable-navigable
  13. class TraversableNavigable final : public Navigable {
  14. JS_CELL(TraversableNavigable, Navigable);
  15. public:
  16. static WebIDL::ExceptionOr<JS::NonnullGCPtr<TraversableNavigable>> create_a_new_top_level_traversable(Page&, JS::GCPtr<BrowsingContext> opener, String target_name);
  17. static WebIDL::ExceptionOr<JS::NonnullGCPtr<TraversableNavigable>> create_a_fresh_top_level_traversable(Page&, AK::URL const& initial_navigation_url, Variant<Empty, String, POSTResource> = Empty {});
  18. virtual ~TraversableNavigable() override;
  19. bool is_top_level_traversable() const;
  20. int current_session_history_step() const { return m_current_session_history_step; }
  21. Vector<JS::NonnullGCPtr<SessionHistoryEntry>>& session_history_entries() { return m_session_history_entries; }
  22. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> const& session_history_entries() const { return m_session_history_entries; }
  23. bool running_nested_apply_history_step() const { return m_running_nested_apply_history_step; }
  24. VisibilityState system_visibility_state() const { return m_system_visibility_state; }
  25. struct HistoryObjectLengthAndIndex {
  26. size_t script_history_length;
  27. size_t script_history_index;
  28. };
  29. HistoryObjectLengthAndIndex get_the_history_object_length_and_index(int) const;
  30. void apply_the_history_step(int step, Optional<SourceSnapshotParams> = {});
  31. void apply_pending_history_changes();
  32. int get_the_used_step(int step) const;
  33. Vector<JS::Handle<Navigable>> get_all_navigables_whose_current_session_history_entry_will_change_or_reload(int) const;
  34. Vector<int> get_all_used_history_steps() const;
  35. void clear_the_forward_session_history();
  36. void traverse_the_history_by_delta(int delta);
  37. void close_top_level_traversable();
  38. void destroy_top_level_traversable();
  39. void append_session_history_traversal_steps(JS::SafeFunction<void()> steps)
  40. {
  41. m_session_history_traversal_queue.append(move(steps));
  42. }
  43. Page* page() { return m_page; }
  44. Page const* page() const { return m_page; }
  45. private:
  46. TraversableNavigable(Page&);
  47. virtual void visit_edges(Cell::Visitor&) override;
  48. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-current-session-history-step
  49. int m_current_session_history_step { 0 };
  50. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-entries
  51. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> m_session_history_entries;
  52. // FIXME: https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-traversal-queue
  53. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-running-nested-apply-history-step
  54. bool m_running_nested_apply_history_step { false };
  55. // https://html.spec.whatwg.org/multipage/document-sequences.html#system-visibility-state
  56. VisibilityState m_system_visibility_state { VisibilityState::Visible };
  57. SessionHistoryTraversalQueue m_session_history_traversal_queue;
  58. WeakPtr<Page> m_page;
  59. };
  60. void finalize_a_same_document_navigation(JS::NonnullGCPtr<TraversableNavigable> traversable, JS::NonnullGCPtr<Navigable> target_navigable, JS::NonnullGCPtr<SessionHistoryEntry> target_entry, JS::GCPtr<SessionHistoryEntry> entry_to_replace);
  61. }