Преглед на файлове

LibWeb: Implement most of "destroy a top-level traversable"

Co-authored-by: Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
Andreas Kling преди 2 години
родител
ревизия
40e7f64433
променени са 2 файла, в които са добавени 29 реда и са изтрити 0 реда
  1. 27 0
      Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp
  2. 2 0
      Userland/Libraries/LibWeb/HTML/TraversableNavigable.h

+ 27 - 0
Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp

@@ -508,4 +508,31 @@ void TraversableNavigable::apply_pending_history_changes()
     apply_the_history_step(target_step);
 }
 
+// https://html.spec.whatwg.org/multipage/document-sequences.html#destroy-a-top-level-traversable
+void TraversableNavigable::destroy_top_level_traversable()
+{
+    VERIFY(is_top_level_traversable());
+
+    // 1. Let browsingContext be traversable's active browsing context.
+    auto browsing_context = active_browsing_context();
+
+    // 2. For each historyEntry in traversable's session history entries:
+    for (auto& history_entry : m_session_history_entries) {
+        // 1. Let document be historyEntry's document.
+        auto document = history_entry->document_state->document();
+
+        // 2. If document is not null, then destroy document.
+        if (document)
+            document->destroy();
+    }
+
+    // 3. Remove browsingContext.
+    browsing_context->remove();
+
+    // FIXME: 4. Remove traversable from the user interface (e.g., close or hide its tab in a tabbed browser).
+
+    // 5. Remove traversable from the user agent's top-level traversable set.
+    user_agent_top_level_traversable_set().remove(this);
+}
+
 }

+ 2 - 0
Userland/Libraries/LibWeb/HTML/TraversableNavigable.h

@@ -45,6 +45,8 @@ public:
     void clear_the_forward_session_history();
     void traverse_the_history_by_delta(int delta);
 
+    void destroy_top_level_traversable();
+
 private:
     TraversableNavigable();