mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-14 10:20:36 +00:00
LibWeb+WebContent: Initialise JS console from Document::initialize()
Before this change JS console was initialise from activate_history_entry() which is too late for about:blank documents that are ready to run scripts immediately after creation.
This commit is contained in:
parent
939a8e9393
commit
649f70db65
Notes:
sideshowbarker
2024-07-17 07:08:37 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/649f70db65 Pull-request: https://github.com/SerenityOS/serenity/pull/23931 Issue: https://github.com/SerenityOS/serenity/issues/23892
5 changed files with 14 additions and 9 deletions
|
@ -378,6 +378,8 @@ void Document::initialize(JS::Realm& realm)
|
|||
m_selection = heap().allocate<Selection::Selection>(realm, realm, *this);
|
||||
|
||||
m_list_of_available_images = heap().allocate<HTML::ListOfAvailableImages>(realm);
|
||||
|
||||
page().client().page_did_create_new_document(*this);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/document-lifecycle.html#populate-with-html/head/body
|
||||
|
@ -3408,6 +3410,10 @@ void Document::make_active()
|
|||
// 2. Set document's browsing context's WindowProxy's [[Window]] internal slot value to window.
|
||||
m_browsing_context->window_proxy()->set_window(window);
|
||||
|
||||
if (m_browsing_context->is_top_level()) {
|
||||
page().client().page_did_change_active_document_in_top_level_browsing_context(*this);
|
||||
}
|
||||
|
||||
// 3. Set document's visibility state to document's node navigable's traversable navigable's system visibility state.
|
||||
if (navigable()) {
|
||||
m_visibility_state = navigable()->traversable_navigable()->system_visibility_state();
|
||||
|
|
|
@ -197,10 +197,6 @@ void Navigable::activate_history_entry(JS::GCPtr<SessionHistoryEntry> entry)
|
|||
|
||||
// 5. Make active newDocument.
|
||||
new_document->make_active();
|
||||
|
||||
// Not in the spec:
|
||||
VERIFY(active_browsing_context());
|
||||
active_browsing_context()->page().client().page_did_create_new_document(*new_document);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-document
|
||||
|
|
|
@ -258,6 +258,7 @@ public:
|
|||
virtual Gfx::IntRect page_did_request_fullscreen_window() { return {}; }
|
||||
virtual void page_did_start_loading(URL::URL const&, bool is_redirect) { (void)is_redirect; }
|
||||
virtual void page_did_create_new_document(Web::DOM::Document&) { }
|
||||
virtual void page_did_change_active_document_in_top_level_browsing_context(Web::DOM::Document&) { }
|
||||
virtual void page_did_destroy_document(Web::DOM::Document&) { }
|
||||
virtual void page_did_finish_loading(URL::URL const&) { }
|
||||
virtual void page_did_update_url(URL::URL const&, Web::HTML::HistoryHandlingBehavior) { }
|
||||
|
|
|
@ -355,6 +355,12 @@ void PageClient::page_did_create_new_document(Web::DOM::Document& document)
|
|||
initialize_js_console(document);
|
||||
}
|
||||
|
||||
void PageClient::page_did_change_active_document_in_top_level_browsing_context(Web::DOM::Document& document)
|
||||
{
|
||||
VERIFY(m_console_clients.contains(document));
|
||||
m_top_level_document_console_client = *m_console_clients.get(document).value();
|
||||
}
|
||||
|
||||
void PageClient::page_did_destroy_document(Web::DOM::Document& document)
|
||||
{
|
||||
destroy_js_console(document);
|
||||
|
@ -675,11 +681,6 @@ void PageClient::initialize_js_console(Web::DOM::Document& document)
|
|||
auto console_client = make<WebContentConsoleClient>(console_object->console(), document.realm(), *this);
|
||||
console_object->console().set_client(*console_client);
|
||||
|
||||
VERIFY(document.browsing_context());
|
||||
if (document.browsing_context()->is_top_level()) {
|
||||
m_top_level_document_console_client = console_client->make_weak_ptr();
|
||||
}
|
||||
|
||||
m_console_clients.set(document, move(console_client));
|
||||
}
|
||||
|
||||
|
|
|
@ -117,6 +117,7 @@ private:
|
|||
virtual void page_did_request_media_context_menu(Web::CSSPixelPoint, ByteString const& target, unsigned modifiers, Web::Page::MediaContextMenu) override;
|
||||
virtual void page_did_start_loading(URL::URL const&, bool) override;
|
||||
virtual void page_did_create_new_document(Web::DOM::Document&) override;
|
||||
virtual void page_did_change_active_document_in_top_level_browsing_context(Web::DOM::Document&) override;
|
||||
virtual void page_did_destroy_document(Web::DOM::Document&) override;
|
||||
virtual void page_did_finish_loading(URL::URL const&) override;
|
||||
virtual void page_did_update_url(URL::URL const&, Web::HTML::HistoryHandlingBehavior) override;
|
||||
|
|
Loading…
Reference in a new issue