SessionHistoryEntry.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-document
  26. JS::GCPtr<DOM::Document> SessionHistoryEntry::document() const
  27. {
  28. // To get a session history entry's document, return its document state's document.
  29. if (!m_document_state)
  30. return {};
  31. return m_document_state->document();
  32. }
  33. }