Skip to content

Commit

Permalink
LibWebView+Services+UI: Move process helpers to LibWebView
Browse files Browse the repository at this point in the history
  • Loading branch information
trflynn89 committed Nov 11, 2024
1 parent a14937c commit 0ff91a5
Show file tree
Hide file tree
Showing 29 changed files with 110 additions and 119 deletions.
14 changes: 14 additions & 0 deletions Libraries/LibWebView/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(SOURCES
ChromeProcess.cpp
CookieJar.cpp
Database.cpp
HelperProcess.cpp
InspectorClient.cpp
Plugins/FontPlugin.cpp
Plugins/ImageCodecPlugin.cpp
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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=$<BOOL:${ENABLE_PUBLIC_SUFFIX_DOWNLOAD}>)

if (APPLE)
target_link_libraries(LibWebView PRIVATE LibThreading)
endif()

# Third-party
find_package(SQLite3 REQUIRED)
target_link_libraries(LibWebView PRIVATE SQLite::SQLite3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#include <AK/Enumerate.h>
#include <LibCore/Process.h>
#include <LibWebView/Application.h>
#include <UI/HelperProcess.h>
#include <UI/Utilities.h>
#include <LibWebView/HelperProcess.h>
#include <LibWebView/Utilities.h>

namespace WebView {

template<typename ClientType, typename... ClientArguments>
static ErrorOr<NonnullRefPtr<ClientType>> launch_server_process(
Expand Down Expand Up @@ -191,3 +193,5 @@ ErrorOr<IPC::File> connect_new_image_decoder_client(ImageDecoderClient::Client&

return socket;
}

}
4 changes: 4 additions & 0 deletions UI/HelperProcess.h → Libraries/LibWebView/HelperProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <LibWebView/ViewImplementation.h>
#include <LibWebView/WebContentClient.h>

namespace WebView {

ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
WebView::ViewImplementation& view,
ReadonlySpan<ByteString> candidate_web_content_paths,
Expand All @@ -28,3 +30,5 @@ ErrorOr<NonnullRefPtr<Requests::RequestClient>> launch_request_server_process(Re

ErrorOr<IPC::File> connect_new_request_server_client(Requests::RequestClient&);
ErrorOr<IPC::File> connect_new_image_decoder_client(ImageDecoderClient::Client&);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <AK/Debug.h>
#include <LibCore/Platform/MachMessageTypes.h>
#include <LibCore/Platform/ProcessStatisticsMach.h>
#include <UI/MachPortServer.h>
#include <LibWebView/MachPortServer.h>

namespace Ladybird {
namespace WebView {

MachPortServer::MachPortServer()
: m_thread(Threading::Thread::construct([this]() -> intptr_t { thread_loop(); return 0; }, "MachPortServer"sv))
Expand Down
11 changes: 5 additions & 6 deletions UI/MachPortServer.h → Libraries/LibWebView/MachPortServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@

#pragma once

#include <AK/Atomic.h>
#include <AK/Platform.h>
#include <AK/String.h>
#include <LibCore/MachPort.h>
#include <LibThreading/Thread.h>

#if !defined(AK_OS_MACH)
# error "This file is only for Mach kernel-based OS's"
#endif

#include <AK/Atomic.h>
#include <AK/String.h>
#include <LibCore/MachPort.h>
#include <LibThreading/Thread.h>

namespace Ladybird {
namespace WebView {

class MachPortServer {

Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWebView/Plugins/ImageCodecPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <LibGfx/ImageFormats/ImageDecoder.h>
#include <LibImageDecoderClient/Client.h>
#include <LibWebView/Plugins/ImageCodecPlugin.h>
#include <UI/Utilities.h>
#include <LibWebView/Utilities.h>

namespace WebView {

Expand Down
10 changes: 7 additions & 3 deletions UI/Utilities.cpp → Libraries/LibWebView/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
#include <LibCore/ResourceImplementationFile.h>
#include <LibCore/System.h>
#include <LibFileSystem/FileSystem.h>
#include <UI/Utilities.h>
#include <LibWebView/Utilities.h>

#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;
Expand Down Expand Up @@ -112,3 +114,5 @@ ErrorOr<Vector<ByteString>> get_paths_for_helper_process(StringView process_name
// NOTE: Add platform-specific paths here
return paths;
}

}
4 changes: 4 additions & 0 deletions UI/Utilities.h → Libraries/LibWebView/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <AK/String.h>
#include <AK/Vector.h>

namespace WebView {

void platform_init();
void copy_default_config_files(StringView config_path);
ErrorOr<ByteString> application_directory();
Expand All @@ -20,3 +22,5 @@ ErrorOr<Vector<ByteString>> get_paths_for_helper_process(StringView process_name
extern ByteString s_ladybird_resource_root;
Optional<ByteString const&> mach_server_name();
void set_mach_server_name(ByteString name);

}
1 change: 0 additions & 1 deletion Services/ImageDecoder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion Services/RequestServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions Services/WebContent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions Services/WebContent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <LibWeb/Platform/EventLoopPluginSerenity.h>
#include <LibWebView/Plugins/FontPlugin.h>
#include <LibWebView/Plugins/ImageCodecPlugin.h>
#include <UI/Utilities.h>
#include <LibWebView/Utilities.h>
#include <WebContent/ConnectionFromClient.h>
#include <WebContent/PageClient.h>
#include <WebContent/WebDriverConnection.h>
Expand Down Expand Up @@ -75,7 +75,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
#endif
Core::EventLoop event_loop;

platform_init();
WebView::platform_init();

Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity);

Expand All @@ -92,7 +92,7 @@ ErrorOr<int> 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<ByteString> certificates;
int request_server_socket { -1 };
Expand Down
1 change: 0 additions & 1 deletion Services/WebDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
set(SOURCES
${LADYBIRD_SOURCE_DIR}/UI/Utilities.cpp
Client.cpp
Session.cpp
WebContentConnection.cpp
Expand Down
6 changes: 3 additions & 3 deletions Services/WebDriver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
#include <LibCore/TCPServer.h>
#include <LibMain/Main.h>
#include <LibWeb/WebDriver/Capabilities.h>
#include <UI/Utilities.h>
#include <LibWebView/Utilities.h>
#include <WebDriver/Client.h>

static Vector<ByteString> certificates;

static ErrorOr<pid_t> launch_process(StringView application, ReadonlySpan<ByteString> arguments)
{
auto paths = TRY(get_paths_for_helper_process(application));
auto paths = TRY(WebView::get_paths_for_helper_process(application));

ErrorOr<pid_t> result = -1;
for (auto const& path : paths) {
Expand Down Expand Up @@ -96,7 +96,7 @@ ErrorOr<int> 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);

Expand Down
2 changes: 0 additions & 2 deletions Services/WebWorker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions Services/WebWorker/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/Platform/EventLoopPluginSerenity.h>
#include <LibWeb/WebSockets/WebSocket.h>
#include <LibWebView/HelperProcess.h>
#include <LibWebView/Plugins/FontPlugin.h>
#include <UI/HelperProcess.h>
#include <UI/Utilities.h>
#include <LibWebView/Utilities.h>
#include <WebWorker/ConnectionFromClient.h>

#if defined(HAVE_QT)
Expand Down Expand Up @@ -56,7 +56,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
#endif
Core::EventLoop event_loop;

platform_init();
WebView::platform_init();

Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity);

Expand Down
24 changes: 12 additions & 12 deletions UI/AppKit/Application/Application.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <LibImageDecoderClient/Client.h>
#include <LibRequests/RequestClient.h>
#include <LibWebView/Application.h>
#include <LibWebView/HelperProcess.h>
#include <LibWebView/Utilities.h>
#include <LibWebView/WebContentClient.h>
#include <UI/HelperProcess.h>
#include <UI/Utilities.h>
#include <Utilities/Conversions.h>

#import <Application/Application.h>
Expand Down Expand Up @@ -70,16 +70,16 @@ - (void)setupWebViewApplication:(Main::Arguments&)arguments

- (ErrorOr<void>)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<NonnullRefPtr<ImageDecoderClient::Client>> 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<void>)launchImageDecoder
Expand Down Expand Up @@ -120,19 +120,19 @@ - (void)setupWebViewApplication:(Main::Arguments&)arguments
- (ErrorOr<NonnullRefPtr<WebView::WebContentClient>>)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<IPC::File>)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();
}
Expand Down
2 changes: 0 additions & 2 deletions UI/AppKit/Interface/LadybirdWebViewBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <LibWeb/Crypto/Crypto.h>
#include <LibWebView/Application.h>
#include <LibWebView/UserAgent.h>
#include <UI/HelperProcess.h>
#include <UI/Utilities.h>

#import <Interface/Palette.h>

Expand Down
1 change: 0 additions & 1 deletion UI/AppKit/Interface/Palette.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <LibCore/Resource.h>
#include <LibGfx/Palette.h>
#include <LibGfx/SystemTheme.h>
#include <UI/Utilities.h>

#import <Cocoa/Cocoa.h>
#import <Interface/Palette.h>
Expand Down
1 change: 0 additions & 1 deletion UI/AppKit/Interface/Tab.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <LibGfx/ShareableBitmap.h>
#include <LibURL/URL.h>
#include <LibWebView/ViewImplementation.h>
#include <UI/Utilities.h>

#import <Application/ApplicationDelegate.h>
#import <Interface/Inspector.h>
Expand Down
Loading

0 comments on commit 0ff91a5

Please sign in to comment.