Bläddra i källkod

LibWeb: Implement "destroy the child navigable" on navigable containers

Co-authored-by: Andreas Kling <kling@serenityos.org>
Aliaksandr Kalenik 2 år sedan
förälder
incheckning
934cb601c2

+ 35 - 0
Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp

@@ -10,10 +10,12 @@
 #include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
 #include <LibWeb/HTML/BrowsingContext.h>
 #include <LibWeb/HTML/BrowsingContextGroup.h>
+#include <LibWeb/HTML/DocumentState.h>
 #include <LibWeb/HTML/HTMLIFrameElement.h>
 #include <LibWeb/HTML/NavigableContainer.h>
 #include <LibWeb/HTML/NavigationParams.h>
 #include <LibWeb/HTML/Origin.h>
+#include <LibWeb/HTML/TraversableNavigable.h>
 #include <LibWeb/Page/Page.h>
 
 namespace Web::HTML {
@@ -235,4 +237,37 @@ void NavigableContainer::navigate_an_iframe_or_frame(JS::NonnullGCPtr<Fetch::Inf
     MUST(m_nested_browsing_context->navigate(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();
+}
+
 }

+ 2 - 0
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);