mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +00:00
LibWebView+UI: Move ownership of application services to LibWebView
LibWebView now knows how to launch RequestServer and ImageDecoderServer without help from the UI, so let's move ownership of these services over to LibWebView for de-duplication.
This commit is contained in:
parent
1b38ebcc7f
commit
bb7dff7dfe
Notes:
github-actions[bot]
2024-11-14 10:48:40 +00:00
Author: https://github.com/trflynn89
Commit: bb7dff7dfe
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2327
17 changed files with 99 additions and 188 deletions
|
@ -5,9 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibWebView/HelperProcess.h>
|
||||
#include <LibWebView/URL.h>
|
||||
#include <LibWebView/Utilities.h>
|
||||
#include <UI/Qt/Application.h>
|
||||
#include <UI/Qt/Settings.h>
|
||||
#include <UI/Qt/StringUtils.h>
|
||||
|
@ -54,38 +52,6 @@ bool Application::event(QEvent* event)
|
|||
return QApplication::event(event);
|
||||
}
|
||||
|
||||
static ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_new_image_decoder()
|
||||
{
|
||||
auto paths = TRY(WebView::get_paths_for_helper_process("ImageDecoder"sv));
|
||||
return WebView::launch_image_decoder_process(paths);
|
||||
}
|
||||
|
||||
ErrorOr<void> Application::initialize_image_decoder()
|
||||
{
|
||||
m_image_decoder_client = TRY(launch_new_image_decoder());
|
||||
|
||||
m_image_decoder_client->on_death = [this] {
|
||||
m_image_decoder_client = nullptr;
|
||||
if (auto err = this->initialize_image_decoder(); err.is_error()) {
|
||||
dbgln("Failed to restart image decoder: {}", err.error());
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
auto num_clients = WebView::WebContentClient::client_count();
|
||||
auto new_sockets = m_image_decoder_client->send_sync_but_allow_failure<Messages::ImageDecoderServer::ConnectNewClients>(num_clients);
|
||||
if (!new_sockets || new_sockets->sockets().size() == 0) {
|
||||
dbgln("Failed to connect {} new clients to ImageDecoder", num_clients);
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
WebView::WebContentClient::for_each_client([sockets = new_sockets->take_sockets()](WebView::WebContentClient& client) mutable {
|
||||
client.async_connect_to_image_decoder(sockets.take_last());
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
};
|
||||
return {};
|
||||
}
|
||||
|
||||
void Application::show_task_manager_window()
|
||||
{
|
||||
if (!m_task_manager_window) {
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/HashTable.h>
|
||||
#include <LibImageDecoderClient/Client.h>
|
||||
#include <LibRequests/RequestClient.h>
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWebView/Application.h>
|
||||
#include <UI/Qt/BrowserWindow.h>
|
||||
|
@ -30,10 +27,6 @@ public:
|
|||
virtual bool event(QEvent* event) override;
|
||||
|
||||
Function<void(URL::URL)> on_open_file;
|
||||
RefPtr<Requests::RequestClient> request_server_client;
|
||||
|
||||
NonnullRefPtr<ImageDecoderClient::Client> image_decoder_client() const { return *m_image_decoder_client; }
|
||||
ErrorOr<void> initialize_image_decoder();
|
||||
|
||||
BrowserWindow& new_window(Vector<URL::URL> const& initial_urls, BrowserWindow::IsPopupWindow is_popup_window = BrowserWindow::IsPopupWindow::No, Tab* parent_tab = nullptr, Optional<u64> page_index = {});
|
||||
|
||||
|
@ -50,8 +43,6 @@ private:
|
|||
|
||||
TaskManagerWindow* m_task_manager_window { nullptr };
|
||||
BrowserWindow* m_active_window { nullptr };
|
||||
|
||||
RefPtr<ImageDecoderClient::Client> m_image_decoder_client;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -128,8 +128,7 @@ WebContentView::WebContentView(QWidget* window, RefPtr<WebView::WebContentClient
|
|||
};
|
||||
|
||||
on_request_worker_agent = [&]() {
|
||||
auto& request_server_client = static_cast<Ladybird::Application*>(QApplication::instance())->request_server_client;
|
||||
auto worker_client = MUST(WebView::launch_web_worker_process(MUST(WebView::get_paths_for_helper_process("WebWorker"sv)), *request_server_client));
|
||||
auto worker_client = MUST(WebView::launch_web_worker_process(MUST(WebView::get_paths_for_helper_process("WebWorker"sv))));
|
||||
return worker_client->clone_transport();
|
||||
};
|
||||
|
||||
|
@ -629,13 +628,9 @@ void WebContentView::initialize_client(WebView::ViewImplementation::CreateNewCli
|
|||
if (create_new_client == CreateNewClient::Yes) {
|
||||
m_client_state = {};
|
||||
|
||||
auto& request_server_client = static_cast<Ladybird::Application*>(QApplication::instance())->request_server_client;
|
||||
|
||||
// FIXME: Fail to open the tab, rather than crashing the whole application if this fails
|
||||
auto request_server_socket = WebView::connect_new_request_server_client(*request_server_client).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
auto image_decoder = static_cast<Ladybird::Application*>(QApplication::instance())->image_decoder_client();
|
||||
auto image_decoder_socket = WebView::connect_new_image_decoder_client(*image_decoder).release_value_but_fixme_should_propagate_errors();
|
||||
// FIXME: Fail to open the tab, rather than crashing the whole application if these fail.
|
||||
auto request_server_socket = WebView::connect_new_request_server_client().release_value_but_fixme_should_propagate_errors();
|
||||
auto image_decoder_socket = WebView::connect_new_image_decoder_client().release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
auto candidate_web_content_paths = WebView::get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors();
|
||||
auto new_client = launch_web_content_process(*this, candidate_web_content_paths, AK::move(image_decoder_socket), AK::move(request_server_socket)).release_value_but_fixme_should_propagate_errors();
|
||||
|
|
|
@ -114,12 +114,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
WebView::copy_default_config_files(Ladybird::Settings::the()->directory());
|
||||
|
||||
// FIXME: Create an abstraction to re-spawn the RequestServer and re-hook up its client hooks to each tab on crash
|
||||
auto request_server_paths = TRY(WebView::get_paths_for_helper_process("RequestServer"sv));
|
||||
auto requests_client = TRY(WebView::launch_request_server_process(request_server_paths, WebView::s_ladybird_resource_root));
|
||||
app->request_server_client = move(requests_client);
|
||||
|
||||
TRY(app->initialize_image_decoder());
|
||||
TRY(app->launch_services());
|
||||
|
||||
chrome_process.on_new_window = [&](auto const& urls) {
|
||||
app->new_window(urls);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue