mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
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:
parent
f07ac8f20a
commit
33500bb6db
Notes:
sideshowbarker
2024-07-17 22:09:47 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/33500bb6db
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue