mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibCore/Process: Make all spawn overloads return ErrorOr<Process>
This commit is contained in:
@@ -19,8 +19,8 @@
|
||||
namespace WebDriver {
|
||||
|
||||
struct LaunchBrowserCallbacks {
|
||||
Function<ErrorOr<pid_t>(ByteString const&)> launch_browser;
|
||||
Function<ErrorOr<pid_t>(ByteString const&)> launch_headless_browser;
|
||||
Function<ErrorOr<Core::Process>(ByteString const&)> launch_browser;
|
||||
Function<ErrorOr<Core::Process>(ByteString const&)> launch_headless_browser;
|
||||
};
|
||||
|
||||
class Client final : public Web::WebDriver::Client {
|
||||
|
||||
@@ -43,10 +43,9 @@ Session::~Session()
|
||||
// from active sessions
|
||||
|
||||
// 3. Perform any implementation-specific cleanup steps.
|
||||
if (m_browser_pid.has_value()) {
|
||||
MUST(Core::System::kill(*m_browser_pid, SIGTERM));
|
||||
m_browser_pid = {};
|
||||
}
|
||||
if (m_browser_process.has_value())
|
||||
MUST(Core::System::kill(m_browser_process->pid(), SIGTERM));
|
||||
|
||||
if (m_web_content_socket_path.has_value()) {
|
||||
MUST(Core::System::unlink(*m_web_content_socket_path));
|
||||
m_web_content_socket_path = {};
|
||||
@@ -172,9 +171,9 @@ ErrorOr<void> Session::start(LaunchBrowserCallbacks const& callbacks)
|
||||
m_web_content_server = TRY(create_server(promise));
|
||||
|
||||
if (m_options.headless)
|
||||
m_browser_pid = TRY(callbacks.launch_headless_browser(*m_web_content_socket_path));
|
||||
m_browser_process = TRY(callbacks.launch_headless_browser(*m_web_content_socket_path));
|
||||
else
|
||||
m_browser_pid = TRY(callbacks.launch_browser(*m_web_content_socket_path));
|
||||
m_browser_process = TRY(callbacks.launch_browser(*m_web_content_socket_path));
|
||||
|
||||
// FIXME: Allow this to be more asynchronous. For now, this at least allows us to propagate
|
||||
// errors received while accepting the Browser and WebContent sockets.
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <AK/ScopeGuard.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/Process.h>
|
||||
#include <LibCore/Promise.h>
|
||||
#include <LibWeb/WebDriver/Capabilities.h>
|
||||
#include <LibWeb/WebDriver/Error.h>
|
||||
@@ -95,7 +96,7 @@ private:
|
||||
String m_current_window_handle;
|
||||
|
||||
Optional<ByteString> m_web_content_socket_path;
|
||||
Optional<pid_t> m_browser_pid;
|
||||
Optional<Core::Process> m_browser_process;
|
||||
|
||||
RefPtr<Core::LocalServer> m_web_content_server;
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
static Vector<ByteString> certificates;
|
||||
|
||||
static ErrorOr<pid_t> launch_process(StringView application, ReadonlySpan<ByteString> arguments)
|
||||
static ErrorOr<Core::Process> launch_process(StringView application, ReadonlySpan<ByteString> arguments)
|
||||
{
|
||||
auto paths = TRY(WebView::get_paths_for_helper_process(application));
|
||||
|
||||
ErrorOr<pid_t> result = -1;
|
||||
ErrorOr<Core::Process> result = Error::from_string_literal("All paths failed to launch");
|
||||
for (auto const& path : paths) {
|
||||
auto path_view = path.view();
|
||||
result = Core::Process::spawn(path_view, arguments, {}, Core::Process::KeepAsChild::Yes);
|
||||
@@ -56,13 +56,13 @@ static Vector<ByteString> create_arguments(ByteString const& socket_path, bool f
|
||||
return arguments;
|
||||
}
|
||||
|
||||
static ErrorOr<pid_t> launch_browser(ByteString const& socket_path, bool force_cpu_painting)
|
||||
static ErrorOr<Core::Process> launch_browser(ByteString const& socket_path, bool force_cpu_painting)
|
||||
{
|
||||
auto arguments = create_arguments(socket_path, force_cpu_painting);
|
||||
return launch_process("Ladybird"sv, arguments.span());
|
||||
}
|
||||
|
||||
static ErrorOr<pid_t> launch_headless_browser(ByteString const& socket_path, bool force_cpu_painting)
|
||||
static ErrorOr<Core::Process> launch_headless_browser(ByteString const& socket_path, bool force_cpu_painting)
|
||||
{
|
||||
auto arguments = create_arguments(socket_path, force_cpu_painting);
|
||||
return launch_process("headless-browser"sv, arguments.span());
|
||||
|
||||
Reference in New Issue
Block a user