SessionHistoryEntry.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Crypto/Crypto.h>
  7. #include <LibWeb/HTML/BrowsingContext.h>
  8. #include <LibWeb/HTML/DocumentState.h>
  9. #include <LibWeb/HTML/SessionHistoryEntry.h>
  10. namespace Web::HTML {
  11. JS_DEFINE_ALLOCATOR(SessionHistoryEntry);
  12. void SessionHistoryEntry::visit_edges(Cell::Visitor& visitor)
  13. {
  14. Base::visit_edges(visitor);
  15. visitor.visit(m_document_state);
  16. visitor.visit(m_original_source_browsing_context);
  17. }
  18. SessionHistoryEntry::SessionHistoryEntry()
  19. : m_classic_history_api_state(MUST(structured_serialize_for_storage(vm(), JS::js_null())))
  20. , m_navigation_api_state(MUST(structured_serialize_for_storage(vm(), JS::js_undefined())))
  21. , m_navigation_api_key(MUST(Crypto::generate_random_uuid()))
  22. , m_navigation_api_id(MUST(Crypto::generate_random_uuid()))
  23. {
  24. }
  25. JS::NonnullGCPtr<SessionHistoryEntry> SessionHistoryEntry::clone() const
  26. {
  27. JS::NonnullGCPtr<SessionHistoryEntry> entry = *heap().allocate_without_realm<SessionHistoryEntry>();
  28. entry->m_step = m_step;
  29. entry->m_url = m_url;
  30. entry->m_document_state = m_document_state->clone();
  31. entry->m_classic_history_api_state = m_classic_history_api_state;
  32. entry->m_navigation_api_state = m_navigation_api_state;
  33. entry->m_navigation_api_key = m_navigation_api_key;
  34. entry->m_navigation_api_id = m_navigation_api_id;
  35. entry->m_scroll_restoration_mode = m_scroll_restoration_mode;
  36. entry->m_policy_container = m_policy_container;
  37. entry->m_browsing_context_name = m_browsing_context_name;
  38. entry->m_original_source_browsing_context = m_original_source_browsing_context;
  39. return entry;
  40. }
  41. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-document
  42. JS::GCPtr<DOM::Document> SessionHistoryEntry::document() const
  43. {
  44. // To get a session history entry's document, return its document state's document.
  45. if (!m_document_state)
  46. return {};
  47. return m_document_state->document();
  48. }
  49. }