From 0ff91a5273348dc822a134b3c171bcdaa17456e2 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 10 Nov 2024 10:26:07 -0500 Subject: [PATCH] LibWebView+Services+UI: Move process helpers to LibWebView --- Libraries/LibWebView/CMakeLists.txt | 14 +++++++++ .../LibWebView}/HelperProcess.cpp | 8 +++-- {UI => Libraries/LibWebView}/HelperProcess.h | 4 +++ .../LibWebView}/MachPortServer.cpp | 4 +-- {UI => Libraries/LibWebView}/MachPortServer.h | 11 ++++--- .../LibWebView/Plugins/ImageCodecPlugin.cpp | 2 +- {UI => Libraries/LibWebView}/Utilities.cpp | 10 +++++-- {UI => Libraries/LibWebView}/Utilities.h | 4 +++ Services/ImageDecoder/CMakeLists.txt | 1 - Services/RequestServer/CMakeLists.txt | 1 - Services/WebContent/CMakeLists.txt | 2 -- Services/WebContent/main.cpp | 6 ++-- Services/WebDriver/CMakeLists.txt | 1 - Services/WebDriver/main.cpp | 6 ++-- Services/WebWorker/CMakeLists.txt | 2 -- Services/WebWorker/main.cpp | 6 ++-- UI/AppKit/Application/Application.mm | 24 +++++++-------- UI/AppKit/Interface/LadybirdWebViewBridge.cpp | 2 -- UI/AppKit/Interface/Palette.mm | 1 - UI/AppKit/Interface/Tab.mm | 1 - UI/AppKit/main.mm | 13 ++++---- UI/CMakeLists.txt | 30 +------------------ UI/Headless/Application.cpp | 14 ++++----- UI/Headless/HeadlessWebView.cpp | 16 +++++----- UI/Headless/main.cpp | 4 +-- UI/Qt/Application.cpp | 8 ++--- UI/Qt/BrowserWindow.cpp | 1 - UI/Qt/WebContentView.cpp | 12 ++++---- UI/Qt/main.cpp | 21 ++++++------- 29 files changed, 110 insertions(+), 119 deletions(-) rename {UI => Libraries/LibWebView}/HelperProcess.cpp (98%) rename {UI => Libraries/LibWebView}/HelperProcess.h (98%) rename {UI => Libraries/LibWebView}/MachPortServer.cpp (98%) rename {UI => Libraries/LibWebView}/MachPortServer.h (98%) rename {UI => Libraries/LibWebView}/Utilities.cpp (95%) rename {UI => Libraries/LibWebView}/Utilities.h (96%) diff --git a/Libraries/LibWebView/CMakeLists.txt b/Libraries/LibWebView/CMakeLists.txt index 657424e4dc9..88df9a4efc5 100644 --- a/Libraries/LibWebView/CMakeLists.txt +++ b/Libraries/LibWebView/CMakeLists.txt @@ -7,6 +7,7 @@ set(SOURCES ChromeProcess.cpp CookieJar.cpp Database.cpp + HelperProcess.cpp InspectorClient.cpp Plugins/FontPlugin.cpp Plugins/ImageCodecPlugin.cpp @@ -17,11 +18,16 @@ set(SOURCES SourceHighlighter.cpp URL.cpp UserAgent.cpp + Utilities.cpp ViewImplementation.cpp WebContentClient.cpp ${PUBLIC_SUFFIX_SOURCES} ) +if (APPLE) + list(APPEND SOURCES MachPortServer.cpp) +endif() + if (ENABLE_QT) list(APPEND SOURCES EventLoop/EventLoopImplementationQt.cpp @@ -49,6 +55,10 @@ embed_as_string( compile_ipc(UIProcessServer.ipc UIProcessServerEndpoint.h) compile_ipc(UIProcessClient.ipc UIProcessClientEndpoint.h) +if (NOT APPLE AND NOT CMAKE_INSTALL_LIBEXECDIR STREQUAL "libexec") + set_source_files_properties(Utilities.cpp PROPERTIES COMPILE_DEFINITIONS LADYBIRD_LIBEXECDIR="${CMAKE_INSTALL_LIBEXECDIR}") +endif() + set(GENERATED_SOURCES ${GENERATED_SOURCES} ../../Services/RequestServer/RequestClientEndpoint.h @@ -66,6 +76,10 @@ serenity_lib(LibWebView webview) target_link_libraries(LibWebView PRIVATE LibCore LibFileSystem LibGfx LibImageDecoderClient LibIPC LibRequests LibJS LibWeb LibUnicode LibURL LibSyntax) target_compile_definitions(LibWebView PRIVATE ENABLE_PUBLIC_SUFFIX=$) +if (APPLE) + target_link_libraries(LibWebView PRIVATE LibThreading) +endif() + # Third-party find_package(SQLite3 REQUIRED) target_link_libraries(LibWebView PRIVATE SQLite::SQLite3) diff --git a/UI/HelperProcess.cpp b/Libraries/LibWebView/HelperProcess.cpp similarity index 98% rename from UI/HelperProcess.cpp rename to Libraries/LibWebView/HelperProcess.cpp index 493784243a4..9b5955fefc2 100644 --- a/UI/HelperProcess.cpp +++ b/Libraries/LibWebView/HelperProcess.cpp @@ -7,8 +7,10 @@ #include #include #include -#include -#include +#include +#include + +namespace WebView { template static ErrorOr> launch_server_process( @@ -191,3 +193,5 @@ ErrorOr connect_new_image_decoder_client(ImageDecoderClient::Client& return socket; } + +} diff --git a/UI/HelperProcess.h b/Libraries/LibWebView/HelperProcess.h similarity index 98% rename from UI/HelperProcess.h rename to Libraries/LibWebView/HelperProcess.h index 16a59f2dd5e..a46c6a6e8cd 100644 --- a/UI/HelperProcess.h +++ b/Libraries/LibWebView/HelperProcess.h @@ -16,6 +16,8 @@ #include #include +namespace WebView { + ErrorOr> launch_web_content_process( WebView::ViewImplementation& view, ReadonlySpan candidate_web_content_paths, @@ -28,3 +30,5 @@ ErrorOr> launch_request_server_process(Re ErrorOr connect_new_request_server_client(Requests::RequestClient&); ErrorOr connect_new_image_decoder_client(ImageDecoderClient::Client&); + +} diff --git a/UI/MachPortServer.cpp b/Libraries/LibWebView/MachPortServer.cpp similarity index 98% rename from UI/MachPortServer.cpp rename to Libraries/LibWebView/MachPortServer.cpp index 6a7a8491792..69a5fef09b5 100644 --- a/UI/MachPortServer.cpp +++ b/Libraries/LibWebView/MachPortServer.cpp @@ -7,9 +7,9 @@ #include #include #include -#include +#include -namespace Ladybird { +namespace WebView { MachPortServer::MachPortServer() : m_thread(Threading::Thread::construct([this]() -> intptr_t { thread_loop(); return 0; }, "MachPortServer"sv)) diff --git a/UI/MachPortServer.h b/Libraries/LibWebView/MachPortServer.h similarity index 98% rename from UI/MachPortServer.h rename to Libraries/LibWebView/MachPortServer.h index a3eb048e22d..7fdf4f673fe 100644 --- a/UI/MachPortServer.h +++ b/Libraries/LibWebView/MachPortServer.h @@ -6,18 +6,17 @@ #pragma once +#include #include +#include +#include +#include #if !defined(AK_OS_MACH) # error "This file is only for Mach kernel-based OS's" #endif -#include -#include -#include -#include - -namespace Ladybird { +namespace WebView { class MachPortServer { diff --git a/Libraries/LibWebView/Plugins/ImageCodecPlugin.cpp b/Libraries/LibWebView/Plugins/ImageCodecPlugin.cpp index d49c6e0c3be..90f79b962af 100644 --- a/Libraries/LibWebView/Plugins/ImageCodecPlugin.cpp +++ b/Libraries/LibWebView/Plugins/ImageCodecPlugin.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace WebView { diff --git a/UI/Utilities.cpp b/Libraries/LibWebView/Utilities.cpp similarity index 95% rename from UI/Utilities.cpp rename to Libraries/LibWebView/Utilities.cpp index a41f60e0145..9f5350cd25d 100644 --- a/UI/Utilities.cpp +++ b/Libraries/LibWebView/Utilities.cpp @@ -13,16 +13,18 @@ #include #include #include -#include +#include #define TOKENCAT(x, y) x##y #define STRINGIFY(x) TOKENCAT(x, sv) +namespace WebView { + // This is expected to be set from the build scripts, if a packager desires #if defined(LADYBIRD_LIBEXECDIR) -constexpr auto libexec_path = STRINGIFY(LADYBIRD_LIBEXECDIR); +static constexpr auto libexec_path = STRINGIFY(LADYBIRD_LIBEXECDIR); #else -constexpr auto libexec_path = "libexec"sv; +static constexpr auto libexec_path = "libexec"sv; #endif ByteString s_ladybird_resource_root; @@ -112,3 +114,5 @@ ErrorOr> get_paths_for_helper_process(StringView process_name // NOTE: Add platform-specific paths here return paths; } + +} diff --git a/UI/Utilities.h b/Libraries/LibWebView/Utilities.h similarity index 96% rename from UI/Utilities.h rename to Libraries/LibWebView/Utilities.h index 2f12e61fc11..7d002a857b9 100644 --- a/UI/Utilities.h +++ b/Libraries/LibWebView/Utilities.h @@ -12,6 +12,8 @@ #include #include +namespace WebView { + void platform_init(); void copy_default_config_files(StringView config_path); ErrorOr application_directory(); @@ -20,3 +22,5 @@ ErrorOr> get_paths_for_helper_process(StringView process_name extern ByteString s_ladybird_resource_root; Optional mach_server_name(); void set_mach_server_name(ByteString name); + +} diff --git a/Services/ImageDecoder/CMakeLists.txt b/Services/ImageDecoder/CMakeLists.txt index b315b30ac1b..e4ea770236b 100644 --- a/Services/ImageDecoder/CMakeLists.txt +++ b/Services/ImageDecoder/CMakeLists.txt @@ -10,7 +10,6 @@ if (ANDROID) add_library(imagedecoderservice SHARED ${LADYBIRD_SOURCE_DIR}/UI/Android/src/main/cpp/ImageDecoderService.cpp ${LADYBIRD_SOURCE_DIR}/UI/Android/src/main/cpp/LadybirdServiceBaseJNI.cpp - ${LADYBIRD_SOURCE_DIR}/UI/Utilities.cpp ${SOURCES} ) else() diff --git a/Services/RequestServer/CMakeLists.txt b/Services/RequestServer/CMakeLists.txt index d3ff5dedf53..4016ebe5463 100644 --- a/Services/RequestServer/CMakeLists.txt +++ b/Services/RequestServer/CMakeLists.txt @@ -10,7 +10,6 @@ if (ANDROID) add_library(requestserverservice SHARED ${LADYBIRD_SOURCE_DIR}/UI/Android/src/main/cpp/RequestServerService.cpp ${LADYBIRD_SOURCE_DIR}/UI/Android/src/main/cpp/LadybirdServiceBaseJNI.cpp - ${LADYBIRD_SOURCE_DIR}/UI/Utilities.cpp ${SOURCES} ) else() diff --git a/Services/WebContent/CMakeLists.txt b/Services/WebContent/CMakeLists.txt index c8fc5995950..8e65fccddc1 100644 --- a/Services/WebContent/CMakeLists.txt +++ b/Services/WebContent/CMakeLists.txt @@ -1,8 +1,6 @@ include(pulseaudio) set(SOURCES - ${LADYBIRD_SOURCE_DIR}/UI/HelperProcess.cpp - ${LADYBIRD_SOURCE_DIR}/UI/Utilities.cpp ConnectionFromClient.cpp ConsoleGlobalEnvironmentExtensions.cpp BackingStoreManager.cpp diff --git a/Services/WebContent/main.cpp b/Services/WebContent/main.cpp index fa8f8fd5dc5..457724af6c6 100644 --- a/Services/WebContent/main.cpp +++ b/Services/WebContent/main.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -75,7 +75,7 @@ ErrorOr serenity_main(Main::Arguments arguments) #endif Core::EventLoop event_loop; - platform_init(); + WebView::platform_init(); Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity); @@ -92,7 +92,7 @@ ErrorOr serenity_main(Main::Arguments arguments) StringView command_line {}; StringView executable_path {}; - auto config_path = ByteString::formatted("{}/ladybird/default-config", s_ladybird_resource_root); + auto config_path = ByteString::formatted("{}/ladybird/default-config", WebView::s_ladybird_resource_root); StringView mach_server_name {}; Vector certificates; int request_server_socket { -1 }; diff --git a/Services/WebDriver/CMakeLists.txt b/Services/WebDriver/CMakeLists.txt index 698730776e7..c95830db79c 100644 --- a/Services/WebDriver/CMakeLists.txt +++ b/Services/WebDriver/CMakeLists.txt @@ -1,5 +1,4 @@ set(SOURCES - ${LADYBIRD_SOURCE_DIR}/UI/Utilities.cpp Client.cpp Session.cpp WebContentConnection.cpp diff --git a/Services/WebDriver/main.cpp b/Services/WebDriver/main.cpp index e2a028bc8ab..088311c54d4 100644 --- a/Services/WebDriver/main.cpp +++ b/Services/WebDriver/main.cpp @@ -14,14 +14,14 @@ #include #include #include -#include +#include #include static Vector certificates; static ErrorOr launch_process(StringView application, ReadonlySpan arguments) { - auto paths = TRY(get_paths_for_helper_process(application)); + auto paths = TRY(WebView::get_paths_for_helper_process(application)); ErrorOr result = -1; for (auto const& path : paths) { @@ -96,7 +96,7 @@ ErrorOr serenity_main(Main::Arguments arguments) return 1; } - platform_init(); + WebView::platform_init(); Web::WebDriver::set_default_interface_mode(headless ? Web::WebDriver::InterfaceMode::Headless : Web::WebDriver::InterfaceMode::Graphical); diff --git a/Services/WebWorker/CMakeLists.txt b/Services/WebWorker/CMakeLists.txt index 26623d714f0..7aab10451c0 100644 --- a/Services/WebWorker/CMakeLists.txt +++ b/Services/WebWorker/CMakeLists.txt @@ -1,6 +1,4 @@ set(WEBWORKER_SOURCES - ${LADYBIRD_SOURCE_DIR}/UI/HelperProcess.cpp - ${LADYBIRD_SOURCE_DIR}/UI/Utilities.cpp ConnectionFromClient.cpp DedicatedWorkerHost.cpp PageHost.cpp diff --git a/Services/WebWorker/main.cpp b/Services/WebWorker/main.cpp index ac710af7f3b..f579f65b2aa 100644 --- a/Services/WebWorker/main.cpp +++ b/Services/WebWorker/main.cpp @@ -19,9 +19,9 @@ #include #include #include +#include #include -#include -#include +#include #include #if defined(HAVE_QT) @@ -56,7 +56,7 @@ ErrorOr serenity_main(Main::Arguments arguments) #endif Core::EventLoop event_loop; - platform_init(); + WebView::platform_init(); Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity); diff --git a/UI/AppKit/Application/Application.mm b/UI/AppKit/Application/Application.mm index 109d748dfa7..240ebaf8eb7 100644 --- a/UI/AppKit/Application/Application.mm +++ b/UI/AppKit/Application/Application.mm @@ -10,9 +10,9 @@ #include #include #include +#include +#include #include -#include -#include #include #import @@ -70,16 +70,16 @@ ApplicationBridge::ApplicationBridge(Badge, Main::Argument - (ErrorOr)launchRequestServer { - auto request_server_paths = TRY(get_paths_for_helper_process("RequestServer"sv)); - m_request_server_client = TRY(launch_request_server_process(request_server_paths, s_ladybird_resource_root)); + auto request_server_paths = TRY(WebView::get_paths_for_helper_process("RequestServer"sv)); + m_request_server_client = TRY(WebView::launch_request_server_process(request_server_paths, WebView::s_ladybird_resource_root)); return {}; } static ErrorOr> launch_new_image_decoder() { - auto image_decoder_paths = TRY(get_paths_for_helper_process("ImageDecoder"sv)); - return launch_image_decoder_process(image_decoder_paths); + auto image_decoder_paths = TRY(WebView::get_paths_for_helper_process("ImageDecoder"sv)); + return WebView::launch_image_decoder_process(image_decoder_paths); } - (ErrorOr)launchImageDecoder @@ -120,19 +120,19 @@ static ErrorOr> launch_new_image_decod - (ErrorOr>)launchWebContent:(Ladybird::WebViewBridge&)web_view_bridge { // FIXME: Fail to open the tab, rather than crashing the whole application if this fails - auto request_server_socket = TRY(connect_new_request_server_client(*m_request_server_client)); - auto image_decoder_socket = TRY(connect_new_image_decoder_client(*m_image_decoder_client)); + auto request_server_socket = TRY(WebView::connect_new_request_server_client(*m_request_server_client)); + auto image_decoder_socket = TRY(WebView::connect_new_image_decoder_client(*m_image_decoder_client)); - auto web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv)); - auto web_content = TRY(launch_web_content_process(web_view_bridge, web_content_paths, move(image_decoder_socket), move(request_server_socket))); + auto web_content_paths = TRY(WebView::get_paths_for_helper_process("WebContent"sv)); + auto web_content = TRY(WebView::launch_web_content_process(web_view_bridge, web_content_paths, move(image_decoder_socket), move(request_server_socket))); return web_content; } - (ErrorOr)launchWebWorker { - auto web_worker_paths = TRY(get_paths_for_helper_process("WebWorker"sv)); - auto worker_client = TRY(launch_web_worker_process(web_worker_paths, *m_request_server_client)); + auto web_worker_paths = TRY(WebView::get_paths_for_helper_process("WebWorker"sv)); + auto worker_client = TRY(WebView::launch_web_worker_process(web_worker_paths, *m_request_server_client)); return worker_client->clone_transport(); } diff --git a/UI/AppKit/Interface/LadybirdWebViewBridge.cpp b/UI/AppKit/Interface/LadybirdWebViewBridge.cpp index 9a786c72ff7..846daae443c 100644 --- a/UI/AppKit/Interface/LadybirdWebViewBridge.cpp +++ b/UI/AppKit/Interface/LadybirdWebViewBridge.cpp @@ -11,8 +11,6 @@ #include #include #include -#include -#include #import diff --git a/UI/AppKit/Interface/Palette.mm b/UI/AppKit/Interface/Palette.mm index ac516feaded..e13c3dd1056 100644 --- a/UI/AppKit/Interface/Palette.mm +++ b/UI/AppKit/Interface/Palette.mm @@ -8,7 +8,6 @@ #include #include #include -#include #import #import diff --git a/UI/AppKit/Interface/Tab.mm b/UI/AppKit/Interface/Tab.mm index bb3b4d163b6..da3ba1f5146 100644 --- a/UI/AppKit/Interface/Tab.mm +++ b/UI/AppKit/Interface/Tab.mm @@ -11,7 +11,6 @@ #include #include #include -#include #import #import diff --git a/UI/AppKit/main.mm b/UI/AppKit/main.mm index 43767071d87..6b53938a492 100644 --- a/UI/AppKit/main.mm +++ b/UI/AppKit/main.mm @@ -10,12 +10,12 @@ #include #include #include +#include #include +#include #include #include #include -#include -#include #import #import @@ -51,7 +51,7 @@ ErrorOr serenity_main(Main::Arguments arguments) Core::EventLoopManager::install(*new WebView::EventLoopManagerMacOS); [application setupWebViewApplication:arguments newTabPageURL:Browser::default_new_tab_url]; - platform_init(); + WebView::platform_init(); WebView::ChromeProcess chrome_process; @@ -72,12 +72,13 @@ ErrorOr serenity_main(Main::Arguments arguments) open_urls_from_client(raw_urls, WebView::NewWindow::Yes); }; - auto mach_port_server = make(); - set_mach_server_name(mach_port_server->server_port_name()); + auto mach_port_server = make(); + WebView::set_mach_server_name(mach_port_server->server_port_name()); + mach_port_server->on_receive_child_mach_port = [&](auto pid, auto port) { WebView::Application::the().set_process_mach_port(pid, move(port)); }; - mach_port_server->on_receive_backing_stores = [](Ladybird::MachPortServer::BackingStoresMessage message) { + mach_port_server->on_receive_backing_stores = [](WebView::MachPortServer::BackingStoresMessage message) { if (auto view = WebView::WebContentClient::view_for_pid_and_page_id(message.pid, message.page_id); view.has_value()) view->did_allocate_iosurface_backing_stores(message.front_backing_store_id, move(message.front_backing_store_port), message.back_backing_store_id, move(message.back_backing_store_port)); }; diff --git a/UI/CMakeLists.txt b/UI/CMakeLists.txt index d6d5073797e..97d2121139b 100644 --- a/UI/CMakeLists.txt +++ b/UI/CMakeLists.txt @@ -1,14 +1,5 @@ include(cmake/ResourceFiles.cmake) -set(LADYBIRD_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/HelperProcess.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Utilities.cpp -) -set(LADYBIRD_HEADERS - HelperProcess.h - Utilities.h -) - function(create_ladybird_bundle target_name) set_target_properties(${target_name} PROPERTIES OUTPUT_NAME "Ladybird" @@ -64,26 +55,13 @@ elseif(ANDROID) add_subdirectory(Android) else() # TODO: Check for other GUI frameworks here when we move them in-tree - # For now, we can export a static library of common files for chromes to link to - add_library(ladybird STATIC ${LADYBIRD_SOURCES}) + return() endif() if (NOT TARGET ladybird) message(FATAL_ERROR "UI Framework selection must declare a ladybird target") endif() -if (APPLE) - target_sources(ladybird PRIVATE MachPortServer.cpp) - target_link_libraries(ladybird PRIVATE LibThreading) -endif() - -if (ENABLE_INSTALL_HEADERS) - target_sources(ladybird PUBLIC FILE_SET ladybird TYPE HEADERS - BASE_DIRS ${LADYBIRD_SOURCE_DIR} - FILES ${LADYBIRD_HEADERS} - ) -endif() - if (TARGET ladybird_impl) set(LADYBIRD_TARGET ladybird_impl PUBLIC) else() @@ -104,12 +82,6 @@ function(set_helper_process_properties) set_target_properties(${targets} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "$") else() set_target_properties(${targets} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${IN_BUILD_PREFIX}${CMAKE_INSTALL_LIBEXECDIR}") - - if (NOT CMAKE_INSTALL_LIBEXECDIR STREQUAL "libexec") - set_source_files_properties(Utilities.cpp PROPERTIES COMPILE_DEFINITIONS LADYBIRD_LIBEXECDIR="${CMAKE_INSTALL_LIBEXECDIR}") - set_source_files_properties(Utilities.cpp TARGET_DIRECTORY ladybird PROPERTIES COMPILE_DEFINITIONS LADYBIRD_LIBEXECDIR="${CMAKE_INSTALL_LIBEXECDIR}") - set_source_files_properties(Utilities.cpp TARGET_DIRECTORY ${targets} PROPERTIES COMPILE_DEFINITIONS LADYBIRD_LIBEXECDIR="${CMAKE_INSTALL_LIBEXECDIR}") - endif() endif() endfunction() diff --git a/UI/Headless/Application.cpp b/UI/Headless/Application.cpp index 55803eccada..b45f2196607 100644 --- a/UI/Headless/Application.cpp +++ b/UI/Headless/Application.cpp @@ -7,16 +7,16 @@ #include #include #include +#include +#include #include #include #include -#include -#include namespace Ladybird { Application::Application(Badge, Main::Arguments&) - : resources_folder(s_ladybird_resource_root) + : resources_folder(WebView::s_ladybird_resource_root) , test_concurrency(Core::System::hardware_concurrency()) , python_executable_path("python3") @@ -73,11 +73,11 @@ void Application::create_platform_options(WebView::ChromeOptions& chrome_options ErrorOr Application::launch_services() { - auto request_server_paths = TRY(get_paths_for_helper_process("RequestServer"sv)); - m_request_client = TRY(launch_request_server_process(request_server_paths, resources_folder)); + auto request_server_paths = TRY(WebView::get_paths_for_helper_process("RequestServer"sv)); + m_request_client = TRY(WebView::launch_request_server_process(request_server_paths, resources_folder)); - auto image_decoder_paths = TRY(get_paths_for_helper_process("ImageDecoder"sv)); - m_image_decoder_client = TRY(launch_image_decoder_process(image_decoder_paths)); + auto image_decoder_paths = TRY(WebView::get_paths_for_helper_process("ImageDecoder"sv)); + m_image_decoder_client = TRY(WebView::launch_image_decoder_process(image_decoder_paths)); return {}; } diff --git a/UI/Headless/HeadlessWebView.cpp b/UI/Headless/HeadlessWebView.cpp index 72a5ef9a0f8..c4996de5efb 100644 --- a/UI/Headless/HeadlessWebView.cpp +++ b/UI/Headless/HeadlessWebView.cpp @@ -7,10 +7,10 @@ #include #include #include +#include +#include #include #include -#include -#include namespace Ladybird { @@ -32,8 +32,8 @@ HeadlessWebView::HeadlessWebView(Core::AnonymousBuffer theme, Gfx::IntSize viewp }; on_request_worker_agent = []() { - auto web_worker_paths = MUST(get_paths_for_helper_process("WebWorker"sv)); - auto worker_client = MUST(launch_web_worker_process(web_worker_paths, Application::request_client())); + auto web_worker_paths = MUST(WebView::get_paths_for_helper_process("WebWorker"sv)); + auto worker_client = MUST(WebView::launch_web_worker_process(web_worker_paths, Application::request_client())); return worker_client->clone_transport(); }; @@ -143,11 +143,11 @@ NonnullOwnPtr HeadlessWebView::create_child(HeadlessWebView con void HeadlessWebView::initialize_client(CreateNewClient create_new_client) { if (create_new_client == CreateNewClient::Yes) { - auto request_server_socket = connect_new_request_server_client(Application::request_client()).release_value_but_fixme_should_propagate_errors(); - auto image_decoder_socket = connect_new_image_decoder_client(Application::image_decoder_client()).release_value_but_fixme_should_propagate_errors(); + auto request_server_socket = WebView::connect_new_request_server_client(Application::request_client()).release_value_but_fixme_should_propagate_errors(); + auto image_decoder_socket = WebView::connect_new_image_decoder_client(Application::image_decoder_client()).release_value_but_fixme_should_propagate_errors(); - auto web_content_paths = get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors(); - m_client_state.client = launch_web_content_process(*this, web_content_paths, move(image_decoder_socket), move(request_server_socket)).release_value_but_fixme_should_propagate_errors(); + auto web_content_paths = WebView::get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors(); + m_client_state.client = WebView::launch_web_content_process(*this, web_content_paths, move(image_decoder_socket), move(request_server_socket)).release_value_but_fixme_should_propagate_errors(); } else { m_client_state.client->register_view(m_client_state.page_index, *this); } diff --git a/UI/Headless/main.cpp b/UI/Headless/main.cpp index 823bad74ca6..5ee648c2ab1 100644 --- a/UI/Headless/main.cpp +++ b/UI/Headless/main.cpp @@ -21,10 +21,10 @@ #include #include #include +#include #include #include #include -#include static ErrorOr> load_page_for_screenshot_and_exit(Core::EventLoop& event_loop, Ladybird::HeadlessWebView& view, URL::URL const& url, int screenshot_timeout) { @@ -61,7 +61,7 @@ static ErrorOr> load_page_for_screenshot_and_exit(Cor ErrorOr serenity_main(Main::Arguments arguments) { - platform_init(); + WebView::platform_init(); auto app = Ladybird::Application::create(arguments, "about:newtab"sv); TRY(app->launch_services()); diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp index 2e9fcf48924..9ffa71e9870 100644 --- a/UI/Qt/Application.cpp +++ b/UI/Qt/Application.cpp @@ -5,13 +5,13 @@ */ #include +#include #include -#include +#include #include #include #include #include -#include #include #include @@ -56,8 +56,8 @@ bool Application::event(QEvent* event) static ErrorOr> launch_new_image_decoder() { - auto paths = TRY(get_paths_for_helper_process("ImageDecoder"sv)); - return launch_image_decoder_process(paths); + auto paths = TRY(WebView::get_paths_for_helper_process("ImageDecoder"sv)); + return WebView::launch_image_decoder_process(paths); } ErrorOr Application::initialize_image_decoder() diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp index 0d1d3d7a25d..5518d8221be 100644 --- a/UI/Qt/BrowserWindow.cpp +++ b/UI/Qt/BrowserWindow.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cpp index 47a77e38a5b..20b733a3d3c 100644 --- a/UI/Qt/WebContentView.cpp +++ b/UI/Qt/WebContentView.cpp @@ -24,12 +24,12 @@ #include #include #include +#include +#include #include -#include #include #include #include -#include #include #include @@ -129,7 +129,7 @@ WebContentView::WebContentView(QWidget* window, RefPtr(QApplication::instance())->request_server_client; - auto worker_client = MUST(launch_web_worker_process(MUST(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)), *request_server_client)); return worker_client->clone_transport(); }; @@ -632,12 +632,12 @@ void WebContentView::initialize_client(WebView::ViewImplementation::CreateNewCli auto& request_server_client = static_cast(QApplication::instance())->request_server_client; // FIXME: Fail to open the tab, rather than crashing the whole application if this fails - auto request_server_socket = connect_new_request_server_client(*request_server_client).release_value_but_fixme_should_propagate_errors(); + 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(QApplication::instance())->image_decoder_client(); - auto image_decoder_socket = connect_new_image_decoder_client(*image_decoder).release_value_but_fixme_should_propagate_errors(); + auto image_decoder_socket = WebView::connect_new_image_decoder_client(*image_decoder).release_value_but_fixme_should_propagate_errors(); - auto candidate_web_content_paths = get_paths_for_helper_process("WebContent"sv).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(); m_client_state.client = new_client; diff --git a/UI/Qt/main.cpp b/UI/Qt/main.cpp index f9204f7d6b8..738c80db90a 100644 --- a/UI/Qt/main.cpp +++ b/UI/Qt/main.cpp @@ -13,17 +13,17 @@ #include #include #include +#include #include #include -#include +#include #include #include #include #include -#include #if defined(AK_OS_MACOS) -# include +# include #endif namespace Ladybird { @@ -71,7 +71,7 @@ ErrorOr serenity_main(Main::Arguments arguments) static_cast(Core::EventLoop::current().impl()).set_main_loop(); TRY(handle_attached_debugger()); - platform_init(); + WebView::platform_init(); WebView::ChromeProcess chrome_process; @@ -100,22 +100,23 @@ ErrorOr serenity_main(Main::Arguments arguments) }; #if defined(AK_OS_MACOS) - auto mach_port_server = make(); - set_mach_server_name(mach_port_server->server_port_name()); + auto mach_port_server = make(); + WebView::set_mach_server_name(mach_port_server->server_port_name()); + mach_port_server->on_receive_child_mach_port = [&app](auto pid, auto port) { app->set_process_mach_port(pid, move(port)); }; - mach_port_server->on_receive_backing_stores = [](Ladybird::MachPortServer::BackingStoresMessage message) { + mach_port_server->on_receive_backing_stores = [](WebView::MachPortServer::BackingStoresMessage message) { if (auto view = WebView::WebContentClient::view_for_pid_and_page_id(message.pid, message.page_id); view.has_value()) view->did_allocate_iosurface_backing_stores(message.front_backing_store_id, move(message.front_backing_store_port), message.back_backing_store_id, move(message.back_backing_store_port)); }; #endif - copy_default_config_files(Ladybird::Settings::the()->directory()); + 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(get_paths_for_helper_process("RequestServer"sv)); - auto requests_client = TRY(launch_request_server_process(request_server_paths, s_ladybird_resource_root)); + 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());