Преглед изворни кода

LibWeb: Tear down old layout tree when new document becomes active

When a new document becomes the active document of a browsing context,
we now notify the old document, allowing it to tear down its layout
tree. In the future, there might be more cleanups we'd like to do here.
Andreas Kling пре 2 година
родитељ
комит
dbee75af19

+ 5 - 0
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -2256,4 +2256,9 @@ void Document::unload(bool recursive_flag, Optional<DocumentUnloadTimingInfo> un
     m_unload_counter -= 1;
     m_unload_counter -= 1;
 }
 }
 
 
+void Document::did_stop_being_active_document_in_browsing_context(Badge<HTML::BrowsingContext>)
+{
+    tear_down_layout_tree();
+}
+
 }
 }

+ 2 - 0
Userland/Libraries/LibWeb/DOM/Document.h

@@ -440,6 +440,8 @@ public:
     DocumentUnloadTimingInfo const& previous_document_unload_timing() const { return m_previous_document_unload_timing; }
     DocumentUnloadTimingInfo const& previous_document_unload_timing() const { return m_previous_document_unload_timing; }
     void set_previous_document_unload_timing(DocumentUnloadTimingInfo const& previous_document_unload_timing) { m_previous_document_unload_timing = previous_document_unload_timing; }
     void set_previous_document_unload_timing(DocumentUnloadTimingInfo const& previous_document_unload_timing) { m_previous_document_unload_timing = previous_document_unload_timing; }
 
 
+    void did_stop_being_active_document_in_browsing_context(Badge<HTML::BrowsingContext>);
+
 protected:
 protected:
     virtual void visit_edges(Cell::Visitor&) override;
     virtual void visit_edges(Cell::Visitor&) override;
 
 

+ 5 - 0
Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp

@@ -295,6 +295,8 @@ bool BrowsingContext::is_focused_context() const
 // https://html.spec.whatwg.org/multipage/browsers.html#set-the-active-document
 // https://html.spec.whatwg.org/multipage/browsers.html#set-the-active-document
 void BrowsingContext::set_active_document(JS::NonnullGCPtr<DOM::Document> document)
 void BrowsingContext::set_active_document(JS::NonnullGCPtr<DOM::Document> document)
 {
 {
+    auto previously_active_document = active_document();
+
     // 1. Let window be document's relevant global object.
     // 1. Let window be document's relevant global object.
     auto& window = verify_cast<HTML::Window>(relevant_global_object(document));
     auto& window = verify_cast<HTML::Window>(relevant_global_object(document));
 
 
@@ -315,6 +317,9 @@ void BrowsingContext::set_active_document(JS::NonnullGCPtr<DOM::Document> docume
 
 
     if (m_page && is_top_level())
     if (m_page && is_top_level())
         m_page->client().page_did_change_title(document->title());
         m_page->client().page_did_change_title(document->title());
+
+    if (previously_active_document && previously_active_document != document.ptr())
+        previously_active_document->did_stop_being_active_document_in_browsing_context({});
 }
 }
 
 
 void BrowsingContext::set_viewport_rect(Gfx::IntRect const& rect)
 void BrowsingContext::set_viewport_rect(Gfx::IntRect const& rect)