1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:37:34 +00:00

LibWeb: Make BrowsingContext GC-allocated

(And BrowsingContextGroup had to come along for the ride as well.)
This solves a number of nasty reference cycles between browsing
contexts, history items, and their documents.
This commit is contained in:
Andreas Kling 2022-10-17 11:06:50 +02:00
parent 2898701459
commit 83c5ff57d8
15 changed files with 225 additions and 44 deletions

View file

@ -13,7 +13,7 @@ namespace Web {
Page::Page(PageClient& client)
: m_client(client)
{
m_top_level_browsing_context = HTML::BrowsingContext::create_a_new_top_level_browsing_context(*this);
m_top_level_browsing_context = JS::make_handle(*HTML::BrowsingContext::create_a_new_top_level_browsing_context(*this));
}
Page::~Page() = default;
@ -95,4 +95,14 @@ bool Page::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point)
return focused_context().event_handler().handle_keyup(key, modifiers, code_point);
}
HTML::BrowsingContext& Page::top_level_browsing_context()
{
return *m_top_level_browsing_context;
}
HTML::BrowsingContext const& Page::top_level_browsing_context() const
{
return *m_top_level_browsing_context;
}
}

View file

@ -17,6 +17,7 @@
#include <LibGfx/Forward.h>
#include <LibGfx/Palette.h>
#include <LibGfx/StandardCursor.h>
#include <LibJS/Heap/Handle.h>
#include <LibWeb/CSS/PreferredColorScheme.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Loader/FileRequest.h>
@ -36,8 +37,8 @@ public:
PageClient& client() { return m_client; }
PageClient const& client() const { return m_client; }
HTML::BrowsingContext& top_level_browsing_context() { return *m_top_level_browsing_context; }
HTML::BrowsingContext const& top_level_browsing_context() const { return *m_top_level_browsing_context; }
HTML::BrowsingContext& top_level_browsing_context();
HTML::BrowsingContext const& top_level_browsing_context() const;
HTML::BrowsingContext& focused_context();
HTML::BrowsingContext const& focused_context() const { return const_cast<Page*>(this)->focused_context(); }
@ -74,7 +75,7 @@ public:
private:
PageClient& m_client;
RefPtr<HTML::BrowsingContext> m_top_level_browsing_context;
JS::Handle<HTML::BrowsingContext> m_top_level_browsing_context;
WeakPtr<HTML::BrowsingContext> m_focused_context;
// FIXME: Enable this by default once CORS preflight checks are supported.