TraversableNavigable.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. JS_DECLARE_ALLOCATOR(TraversableNavigable);
  16. public:
  17. static WebIDL::ExceptionOr<JS::NonnullGCPtr<TraversableNavigable>> create_a_new_top_level_traversable(JS::NonnullGCPtr<Page>, JS::GCPtr<BrowsingContext> opener, String target_name);
  18. static WebIDL::ExceptionOr<JS::NonnullGCPtr<TraversableNavigable>> create_a_fresh_top_level_traversable(JS::NonnullGCPtr<Page>, AK::URL const& initial_navigation_url, Variant<Empty, String, POSTResource> = Empty {});
  19. virtual ~TraversableNavigable() override;
  20. virtual bool is_top_level_traversable() const override;
  21. int current_session_history_step() const { return m_current_session_history_step; }
  22. Vector<JS::NonnullGCPtr<SessionHistoryEntry>>& session_history_entries() { return m_session_history_entries; }
  23. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> const& session_history_entries() const { return m_session_history_entries; }
  24. bool running_nested_apply_history_step() const { return m_running_nested_apply_history_step; }
  25. VisibilityState system_visibility_state() const { return m_system_visibility_state; }
  26. void set_system_visibility_state(VisibilityState);
  27. struct HistoryObjectLengthAndIndex {
  28. u64 script_history_length;
  29. u64 script_history_index;
  30. };
  31. HistoryObjectLengthAndIndex get_the_history_object_length_and_index(int) const;
  32. void apply_the_reload_history_step();
  33. void apply_the_push_or_replace_history_step(int step);
  34. void update_for_navigable_creation_or_destruction();
  35. int get_the_used_step(int step) const;
  36. Vector<JS::Handle<Navigable>> get_all_navigables_whose_current_session_history_entry_will_change_or_reload(int) const;
  37. Vector<int> get_all_used_history_steps() const;
  38. void clear_the_forward_session_history();
  39. void traverse_the_history_by_delta(int delta);
  40. void close_top_level_traversable();
  41. void destroy_top_level_traversable();
  42. void append_session_history_traversal_steps(JS::SafeFunction<void()> steps)
  43. {
  44. m_session_history_traversal_queue.append(move(steps));
  45. }
  46. void process_session_history_traversal_queue()
  47. {
  48. m_session_history_traversal_queue.process();
  49. }
  50. Page& page() { return m_page; }
  51. Page const& page() const { return m_page; }
  52. private:
  53. TraversableNavigable(JS::NonnullGCPtr<Page>);
  54. virtual void visit_edges(Cell::Visitor&) override;
  55. void apply_the_history_step(int step, Optional<SourceSnapshotParams> = {});
  56. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> get_session_history_entries_for_the_navigation_api(JS::NonnullGCPtr<Navigable>, int);
  57. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-current-session-history-step
  58. int m_current_session_history_step { 0 };
  59. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-entries
  60. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> m_session_history_entries;
  61. // FIXME: https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-traversal-queue
  62. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-running-nested-apply-history-step
  63. bool m_running_nested_apply_history_step { false };
  64. // https://html.spec.whatwg.org/multipage/document-sequences.html#system-visibility-state
  65. VisibilityState m_system_visibility_state { VisibilityState::Visible };
  66. SessionHistoryTraversalQueue m_session_history_traversal_queue;
  67. JS::NonnullGCPtr<Page> m_page;
  68. };
  69. struct BrowsingContextAndDocument {
  70. JS::NonnullGCPtr<HTML::BrowsingContext> browsing_context;
  71. JS::NonnullGCPtr<DOM::Document> document;
  72. };
  73. WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_top_level_browsing_context_and_document(JS::NonnullGCPtr<Page> page);
  74. 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);
  75. }