mirror of
https://github.com/RGBCube/serenity
synced 2025-09-13 07:17:34 +00:00
Ladybird+Userland: Use ByteString for candidate server paths
We've adopted a stance that paths should be ByteStrings rather than UTF-8 strings, so apply that to the Ladybird helpers.
This commit is contained in:
parent
1e0dd9aa8c
commit
0a55749a39
10 changed files with 30 additions and 31 deletions
|
@ -8,7 +8,7 @@
|
|||
|
||||
ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
|
||||
WebView::ViewImplementation& view,
|
||||
ReadonlySpan<String> candidate_web_content_paths,
|
||||
ReadonlySpan<ByteString> candidate_web_content_paths,
|
||||
Ladybird::WebContentOptions const& web_content_options)
|
||||
{
|
||||
int socket_fds[2] {};
|
||||
|
@ -43,7 +43,7 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
|
|||
"valgrind"sv,
|
||||
"--tool=callgrind"sv,
|
||||
"--instr-atstart=no"sv,
|
||||
path.bytes_as_string_view(),
|
||||
path.view(),
|
||||
"--command-line"sv,
|
||||
web_content_options.command_line,
|
||||
"--executable-path"sv,
|
||||
|
@ -97,7 +97,7 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
|
|||
}
|
||||
|
||||
template<typename Client>
|
||||
ErrorOr<NonnullRefPtr<Client>> launch_generic_server_process(ReadonlySpan<String> candidate_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates, StringView server_name)
|
||||
ErrorOr<NonnullRefPtr<Client>> launch_generic_server_process(ReadonlySpan<ByteString> candidate_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates, StringView server_name)
|
||||
{
|
||||
int socket_fds[2] {};
|
||||
TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds));
|
||||
|
@ -127,7 +127,7 @@ ErrorOr<NonnullRefPtr<Client>> launch_generic_server_process(ReadonlySpan<String
|
|||
continue;
|
||||
|
||||
auto arguments = Vector<StringView, 5> {
|
||||
path.bytes_as_string_view(),
|
||||
path.view(),
|
||||
"--fd-passing-socket"sv,
|
||||
fd_passing_socket_string,
|
||||
};
|
||||
|
@ -163,22 +163,22 @@ ErrorOr<NonnullRefPtr<Client>> launch_generic_server_process(ReadonlySpan<String
|
|||
return new_client;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_image_decoder_process(ReadonlySpan<String> candidate_image_decoder_paths)
|
||||
ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_image_decoder_process(ReadonlySpan<ByteString> candidate_image_decoder_paths)
|
||||
{
|
||||
return launch_generic_server_process<ImageDecoderClient::Client>(candidate_image_decoder_paths, ""sv, {}, "ImageDecoder"sv);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<String> candidate_web_worker_paths, Vector<ByteString> const& certificates)
|
||||
ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<ByteString> candidate_web_worker_paths, Vector<ByteString> const& certificates)
|
||||
{
|
||||
return launch_generic_server_process<Web::HTML::WebWorkerClient>(candidate_web_worker_paths, ""sv, certificates, "WebWorker"sv);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Protocol::RequestClient>> launch_request_server_process(ReadonlySpan<String> candidate_request_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates)
|
||||
ErrorOr<NonnullRefPtr<Protocol::RequestClient>> launch_request_server_process(ReadonlySpan<ByteString> candidate_request_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates)
|
||||
{
|
||||
return launch_generic_server_process<Protocol::RequestClient>(candidate_request_server_paths, serenity_resource_root, certificates, "RequestServer"sv);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Protocol::WebSocketClient>> launch_web_socket_process(ReadonlySpan<String> candidate_web_socket_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates)
|
||||
ErrorOr<NonnullRefPtr<Protocol::WebSocketClient>> launch_web_socket_process(ReadonlySpan<ByteString> candidate_web_socket_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates)
|
||||
{
|
||||
return launch_generic_server_process<Protocol::WebSocketClient>(candidate_web_socket_paths, serenity_resource_root, certificates, "WebSocket"sv);
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
|
||||
ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
|
||||
WebView::ViewImplementation& view,
|
||||
ReadonlySpan<String> candidate_web_content_paths,
|
||||
ReadonlySpan<ByteString> candidate_web_content_paths,
|
||||
Ladybird::WebContentOptions const&);
|
||||
|
||||
ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_image_decoder_process(ReadonlySpan<String> candidate_image_decoder_paths);
|
||||
ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<String> candidate_web_worker_paths, Vector<ByteString> const& certificates);
|
||||
ErrorOr<NonnullRefPtr<Protocol::RequestClient>> launch_request_server_process(ReadonlySpan<String> candidate_request_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates);
|
||||
ErrorOr<NonnullRefPtr<Protocol::WebSocketClient>> launch_web_socket_process(ReadonlySpan<String> candidate_web_socket_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates);
|
||||
ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_image_decoder_process(ReadonlySpan<ByteString> candidate_image_decoder_paths);
|
||||
ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<ByteString> candidate_web_worker_paths, Vector<ByteString> const& certificates);
|
||||
ErrorOr<NonnullRefPtr<Protocol::RequestClient>> launch_request_server_process(ReadonlySpan<ByteString> candidate_request_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates);
|
||||
ErrorOr<NonnullRefPtr<Protocol::WebSocketClient>> launch_web_socket_process(ReadonlySpan<ByteString> candidate_web_socket_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates);
|
||||
|
|
|
@ -14,11 +14,10 @@
|
|||
|
||||
ByteString s_serenity_resource_root;
|
||||
|
||||
ErrorOr<String> application_directory()
|
||||
ErrorOr<ByteString> application_directory()
|
||||
{
|
||||
auto current_executable_path = TRY(Core::System::current_executable_path());
|
||||
auto dirname = LexicalPath::dirname(current_executable_path);
|
||||
return String::from_byte_string(dirname);
|
||||
return LexicalPath::dirname(current_executable_path);
|
||||
}
|
||||
|
||||
void platform_init()
|
||||
|
@ -33,7 +32,7 @@ void platform_init()
|
|||
auto home_lagom = ByteString::formatted("{}/.lagom", home);
|
||||
if (FileSystem::is_directory(home_lagom))
|
||||
return home_lagom;
|
||||
auto app_dir = application_directory().release_value_but_fixme_should_propagate_errors().to_byte_string();
|
||||
auto app_dir = MUST(application_directory());
|
||||
#ifdef AK_OS_MACOS
|
||||
return LexicalPath(app_dir).parent().append("Resources"sv).string();
|
||||
#else
|
||||
|
@ -44,13 +43,13 @@ void platform_init()
|
|||
Core::ResourceImplementation::install(make<Core::ResourceImplementationFile>(MUST(String::formatted("{}/res", s_serenity_resource_root))));
|
||||
}
|
||||
|
||||
ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name)
|
||||
ErrorOr<Vector<ByteString>> get_paths_for_helper_process(StringView process_name)
|
||||
{
|
||||
auto application_path = TRY(application_directory());
|
||||
Vector<String> paths;
|
||||
Vector<ByteString> paths;
|
||||
|
||||
TRY(paths.try_append(TRY(String::formatted("{}/{}", application_path, process_name))));
|
||||
TRY(paths.try_append(TRY(String::formatted("./{}", process_name))));
|
||||
TRY(paths.try_append(ByteString::formatted("{}/{}", application_path, process_name)));
|
||||
TRY(paths.try_append(ByteString::formatted("./{}", process_name)));
|
||||
// NOTE: Add platform-specific paths here
|
||||
return paths;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <AK/Vector.h>
|
||||
|
||||
void platform_init();
|
||||
ErrorOr<String> application_directory();
|
||||
ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name);
|
||||
ErrorOr<ByteString> application_directory();
|
||||
ErrorOr<Vector<ByteString>> get_paths_for_helper_process(StringView process_name);
|
||||
|
||||
extern ByteString s_serenity_resource_root;
|
||||
|
|
|
@ -24,7 +24,7 @@ static ErrorOr<pid_t> launch_process(StringView application, ReadonlySpan<char c
|
|||
|
||||
ErrorOr<pid_t> result = -1;
|
||||
for (auto const& path : paths) {
|
||||
auto path_view = path.bytes_as_string_view();
|
||||
auto path_view = path.view();
|
||||
result = Core::Process::spawn(path_view, arguments, {}, Core::Process::KeepAsChild::Yes);
|
||||
if (!result.is_error())
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue