LibWeb: Protect against null deref during Web::Page initialization

BrowsingContext::set_active_document() may end up asking for the Page's
top level browsing context before Page has one. Do a workaround for now
where we have an API to ask if it's initialized.

Long-term we should find a cleaner solution.
This commit is contained in:
Andreas Kling 2023-05-27 18:37:02 +02:00
parent f07ac8f20a
commit 33500bb6db
Notes: sideshowbarker 2024-07-17 22:09:47 +09:00
3 changed files with 9 additions and 1 deletions

View File

@ -532,7 +532,7 @@ void BrowsingContext::set_active_document(JS::NonnullGCPtr<DOM::Document> docume
// AD-HOC:
document->set_browsing_context(this);
if (m_page && this == &m_page->top_level_browsing_context())
if (m_page && m_page->top_level_browsing_context_is_initialized() && this == &m_page->top_level_browsing_context())
m_page->client().page_did_change_title(document->title());
if (previously_active_document && previously_active_document != document.ptr())

View File

@ -158,6 +158,11 @@ bool Page::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point)
return focused_context().event_handler().handle_keyup(key, modifiers, code_point);
}
bool Page::top_level_browsing_context_is_initialized() const
{
return m_top_level_browsing_context;
}
HTML::BrowsingContext& Page::top_level_browsing_context()
{
return *m_top_level_browsing_context;

View File

@ -44,6 +44,9 @@ public:
PageClient& client() { return m_client; }
PageClient const& client() const { return m_client; }
// FIXME: This is a hack.
bool top_level_browsing_context_is_initialized() const;
HTML::BrowsingContext& top_level_browsing_context();
HTML::BrowsingContext const& top_level_browsing_context() const;