diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 529be4f88e..74e979c350 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -161,11 +161,19 @@ String Document::title() const
void Document::attach_to_frame(Badge, Frame& frame)
{
m_frame = frame.make_weak_ptr();
+ for_each_in_subtree([&](auto& node) {
+ node.document_did_attach_to_frame(frame);
+ return IterationDecision::Continue;
+ });
layout();
}
-void Document::detach_from_frame(Badge, Frame&)
+void Document::detach_from_frame(Badge, Frame& frame)
{
+ for_each_in_subtree([&](auto& node) {
+ node.document_will_detach_from_frame(frame);
+ return IterationDecision::Continue;
+ });
m_layout_root = nullptr;
m_frame = nullptr;
}
diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h
index 771a87f78d..ce1f9e23e0 100644
--- a/Libraries/LibWeb/DOM/Node.h
+++ b/Libraries/LibWeb/DOM/Node.h
@@ -128,6 +128,9 @@ public:
bool is_link() const;
+ virtual void document_did_attach_to_frame(Frame&) {}
+ virtual void document_will_detach_from_frame(Frame&) {}
+
protected:
Node(Document&, NodeType);