mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWebView: Create a spare WebContent process
Since cross-site navigation is a pretty frequent task, creating a spare process is commonplace in other browsers to reduce the overhead of directing the target site to a new process. We store this process on the WebView application. If it is unavailable, we queue a task to create it later.
This commit is contained in:
parent
5810c8073e
commit
aca4385daf
Notes:
github-actions[bot]
2025-03-11 11:11:42 +00:00
Author: https://github.com/trflynn89
Commit: aca4385daf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3882
Reviewed-by: https://github.com/gmta ✅
8 changed files with 98 additions and 9 deletions
|
@ -191,6 +191,52 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
|
|||
}
|
||||
}
|
||||
|
||||
static ErrorOr<NonnullRefPtr<WebContentClient>> create_web_content_client(Optional<ViewImplementation&> view)
|
||||
{
|
||||
auto request_server_socket = TRY(connect_new_request_server_client());
|
||||
auto image_decoder_socket = TRY(connect_new_image_decoder_client());
|
||||
|
||||
if (view.has_value())
|
||||
return WebView::launch_web_content_process(*view, move(image_decoder_socket), move(request_server_socket));
|
||||
return WebView::launch_spare_web_content_process(move(image_decoder_socket), move(request_server_socket));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<WebContentClient>> Application::launch_web_content_process(ViewImplementation& view)
|
||||
{
|
||||
if (m_spare_web_content_process) {
|
||||
auto web_content_client = m_spare_web_content_process.release_nonnull();
|
||||
launch_spare_web_content_process();
|
||||
|
||||
web_content_client->assign_view({}, view);
|
||||
return web_content_client;
|
||||
}
|
||||
|
||||
launch_spare_web_content_process();
|
||||
return create_web_content_client(view);
|
||||
}
|
||||
|
||||
void Application::launch_spare_web_content_process()
|
||||
{
|
||||
if (m_has_queued_task_to_launch_spare_web_content_process)
|
||||
return;
|
||||
m_has_queued_task_to_launch_spare_web_content_process = true;
|
||||
|
||||
Core::deferred_invoke([this]() {
|
||||
m_has_queued_task_to_launch_spare_web_content_process = false;
|
||||
|
||||
auto web_content_client = create_web_content_client({});
|
||||
if (web_content_client.is_error()) {
|
||||
dbgln("Unable to create spare web content client: {}", web_content_client.error());
|
||||
return;
|
||||
}
|
||||
|
||||
m_spare_web_content_process = web_content_client.release_value();
|
||||
|
||||
if (auto process = find_process(m_spare_web_content_process->pid()); process.has_value())
|
||||
process->set_title("(spare)"_string);
|
||||
});
|
||||
}
|
||||
|
||||
ErrorOr<void> Application::launch_services()
|
||||
{
|
||||
TRY(launch_request_server());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue