From 934cb601c226300eec3287984ae696826e23da8c Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Fri, 16 Dec 2022 23:28:12 +0100 Subject: [PATCH] LibWeb: Implement "destroy the child navigable" on navigable containers Co-authored-by: Andreas Kling --- .../LibWeb/HTML/NavigableContainer.cpp | 35 +++++++++++++++++++ .../LibWeb/HTML/NavigableContainer.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp b/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp index 0248f4404ee..631ac8d6793 100644 --- a/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp +++ b/Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp @@ -10,10 +10,12 @@ #include #include #include +#include #include #include #include #include +#include #include namespace Web::HTML { @@ -235,4 +237,37 @@ void NavigableContainer::navigate_an_iframe_or_frame(JS::NonnullGCPtrnavigate(resource, *source_browsing_context, false, history_handling)); } +// https://html.spec.whatwg.org/multipage/document-sequences.html#destroy-a-child-navigable +void NavigableContainer::destroy_the_child_navigable() +{ + // 1. Let navigable be container's content navigable. + auto navigable = content_navigable(); + + // 2. If navigable is null, then return. + if (!navigable) + return; + + // 3. Set container's content navigable to null. + m_content_navigable = nullptr; + + // 4. Destroy navigable's active document. + navigable->active_document()->destroy(); + + // 5. Let parentDocState be container's node navigable's active session history entry's document state. + auto parent_doc_state = this->navigable()->active_session_history_entry()->document_state; + + // 6. Remove the nested history from parentDocState's nested histories whose id equals navigable's id. + parent_doc_state->nested_histories().remove_all_matching([&](auto& nested_history) { + return navigable->id() == nested_history.id; + }); + + // 7. Let traversable be container's node navigable's traversable navigable. + auto traversable = this->navigable()->traversable_navigable(); + + // FIXME: 8. Append the following session history traversal steps to traversable: + + // 1. Apply pending history changes to traversable. + traversable->apply_pending_history_changes(); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/NavigableContainer.h b/Userland/Libraries/LibWeb/HTML/NavigableContainer.h index d14faf5cbc0..84b0146b118 100644 --- a/Userland/Libraries/LibWeb/HTML/NavigableContainer.h +++ b/Userland/Libraries/LibWeb/HTML/NavigableContainer.h @@ -33,6 +33,8 @@ public: DOM::Document const* get_svg_document() const; + void destroy_the_child_navigable(); + protected: NavigableContainer(DOM::Document&, DOM::QualifiedName);