Ladybird: Register RequestServer with the chrome's mach server on macOS

This ensures we register RequestServer with the appropriate mach server
name.
This commit is contained in:
Timothy Flynn 2024-04-22 12:57:38 -04:00 committed by Andrew Kaster
parent b83babdf8b
commit d2bd692bbe
Notes: sideshowbarker 2024-07-17 09:48:50 +09:00
2 changed files with 17 additions and 0 deletions

View file

@ -176,12 +176,18 @@ ErrorOr<NonnullRefPtr<Protocol::RequestClient>> launch_request_server_process(Re
arguments.append("--serenity-resource-root"sv); arguments.append("--serenity-resource-root"sv);
arguments.append(serenity_resource_root); arguments.append(serenity_resource_root);
} }
Vector<ByteString> certificate_args; Vector<ByteString> certificate_args;
for (auto const& certificate : certificates) { for (auto const& certificate : certificates) {
certificate_args.append(ByteString::formatted("--certificate={}", certificate)); certificate_args.append(ByteString::formatted("--certificate={}", certificate));
arguments.append(certificate_args.last().view()); arguments.append(certificate_args.last().view());
} }
if (auto server = mach_server_name(); server.has_value()) {
arguments.append("--mach-server-name"sv);
arguments.append(server.value());
}
return launch_generic_server_process<Protocol::RequestClient>(candidate_request_server_paths, "RequestServer"sv, move(arguments)); return launch_generic_server_process<Protocol::RequestClient>(candidate_request_server_paths, "RequestServer"sv, move(arguments));
} }

View file

@ -20,6 +20,10 @@
#include <RequestServer/HttpProtocol.h> #include <RequestServer/HttpProtocol.h>
#include <RequestServer/HttpsProtocol.h> #include <RequestServer/HttpsProtocol.h>
#if defined(AK_OS_MACOS)
# include <LibCore/Platform/ProcessStatisticsMach.h>
#endif
ErrorOr<ByteString> find_certificates(StringView serenity_resource_root) ErrorOr<ByteString> find_certificates(StringView serenity_resource_root)
{ {
auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root); auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root);
@ -34,10 +38,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
StringView serenity_resource_root; StringView serenity_resource_root;
Vector<ByteString> certificates; Vector<ByteString> certificates;
StringView mach_server_name;
Core::ArgsParser args_parser; Core::ArgsParser args_parser;
args_parser.add_option(certificates, "Path to a certificate file", "certificate", 'C', "certificate"); args_parser.add_option(certificates, "Path to a certificate file", "certificate", 'C', "certificate");
args_parser.add_option(serenity_resource_root, "Absolute path to directory for serenity resources", "serenity-resource-root", 'r', "serenity-resource-root"); args_parser.add_option(serenity_resource_root, "Absolute path to directory for serenity resources", "serenity-resource-root", 'r', "serenity-resource-root");
args_parser.add_option(mach_server_name, "Mach server name", "mach-server-name", 0, "mach_server_name");
args_parser.parse(arguments); args_parser.parse(arguments);
// Ensure the certificates are read out here. // Ensure the certificates are read out here.
@ -48,6 +54,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Core::EventLoop event_loop; Core::EventLoop event_loop;
#if defined(AK_OS_MACOS)
if (!mach_server_name.is_empty())
Core::Platform::register_with_mach_server(mach_server_name);
#endif
RequestServer::GeminiProtocol::install(); RequestServer::GeminiProtocol::install();
RequestServer::HttpProtocol::install(); RequestServer::HttpProtocol::install();
RequestServer::HttpsProtocol::install(); RequestServer::HttpsProtocol::install();