mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 00:29:15 +00:00
Ladybird: Use MachPortServer to get WebContent Mach ports on macOS
This commit is contained in:
parent
8c5e64e686
commit
3b5ac433ef
Notes:
sideshowbarker
2024-07-18 03:20:18 +09:00
Author: https://github.com/ADKaster
Commit: 3b5ac433ef
Pull-request: https://github.com/SerenityOS/serenity/pull/23841
Reviewed-by: https://github.com/bugaevc
Reviewed-by: https://github.com/nico ✅
Reviewed-by: https://github.com/trflynn89 ✅
7 changed files with 58 additions and 4 deletions
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <BrowserSettings/Defaults.h>
|
#include <BrowserSettings/Defaults.h>
|
||||||
|
#include <Ladybird/MachPortServer.h>
|
||||||
#include <Ladybird/Types.h>
|
#include <Ladybird/Types.h>
|
||||||
#include <Ladybird/Utilities.h>
|
#include <Ladybird/Utilities.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
|
@ -56,6 +57,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
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.parse(arguments);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
|
WebView::ProcessManager::initialize();
|
||||||
|
|
||||||
|
auto mach_port_server = make<Ladybird::MachPortServer>();
|
||||||
|
set_mach_server_name(mach_port_server->server_port_name());
|
||||||
|
mach_port_server->on_receive_child_mach_port = [](auto pid, auto port) {
|
||||||
|
WebView::ProcessManager::the().add_process(pid, move(port));
|
||||||
|
};
|
||||||
|
|
||||||
auto sql_server_paths = TRY(get_paths_for_helper_process("SQLServer"sv));
|
auto sql_server_paths = TRY(get_paths_for_helper_process("SQLServer"sv));
|
||||||
auto database = TRY(WebView::Database::create(move(sql_server_paths)));
|
auto database = TRY(WebView::Database::create(move(sql_server_paths)));
|
||||||
auto cookie_jar = TRY(WebView::CookieJar::create(*database));
|
auto cookie_jar = TRY(WebView::CookieJar::create(*database));
|
||||||
|
@ -82,8 +91,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
.wait_for_debugger = debug_web_content ? Ladybird::WaitForDebugger::Yes : Ladybird::WaitForDebugger::No,
|
.wait_for_debugger = debug_web_content ? Ladybird::WaitForDebugger::Yes : Ladybird::WaitForDebugger::No,
|
||||||
};
|
};
|
||||||
|
|
||||||
WebView::ProcessManager::initialize();
|
|
||||||
|
|
||||||
auto* delegate = [[ApplicationDelegate alloc] init:move(initial_urls)
|
auto* delegate = [[ApplicationDelegate alloc] init:move(initial_urls)
|
||||||
newTabPageURL:move(new_tab_page_url)
|
newTabPageURL:move(new_tab_page_url)
|
||||||
withCookieJar:move(cookie_jar)
|
withCookieJar:move(cookie_jar)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "HelperProcess.h"
|
#include "HelperProcess.h"
|
||||||
|
#include "Utilities.h"
|
||||||
#include <LibCore/Environment.h>
|
#include <LibCore/Environment.h>
|
||||||
#include <LibWebView/ProcessManager.h>
|
#include <LibWebView/ProcessManager.h>
|
||||||
|
|
||||||
|
@ -64,6 +65,10 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
|
||||||
arguments.append("--use-gpu-painting"sv);
|
arguments.append("--use-gpu-painting"sv);
|
||||||
if (web_content_options.wait_for_debugger == Ladybird::WaitForDebugger::Yes)
|
if (web_content_options.wait_for_debugger == Ladybird::WaitForDebugger::Yes)
|
||||||
arguments.append("--wait-for-debugger"sv);
|
arguments.append("--wait-for-debugger"sv);
|
||||||
|
if (auto server = mach_server_name(); server.has_value()) {
|
||||||
|
arguments.append("--mach-server-name"sv);
|
||||||
|
arguments.append(server.value());
|
||||||
|
}
|
||||||
Vector<ByteString> certificate_args;
|
Vector<ByteString> certificate_args;
|
||||||
for (auto const& certificate : web_content_options.certificates) {
|
for (auto const& certificate : web_content_options.certificates) {
|
||||||
certificate_args.append(ByteString::formatted("--certificate={}", certificate));
|
certificate_args.append(ByteString::formatted("--certificate={}", certificate));
|
||||||
|
|
|
@ -23,6 +23,10 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFileOpenEvent>
|
#include <QFileOpenEvent>
|
||||||
|
|
||||||
|
#if defined(AK_OS_MACOS)
|
||||||
|
# include <Ladybird/MachPortServer.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Ladybird {
|
namespace Ladybird {
|
||||||
|
|
||||||
bool is_using_dark_system_theme(QWidget& widget)
|
bool is_using_dark_system_theme(QWidget& widget)
|
||||||
|
@ -125,6 +129,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
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.parse(arguments);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
|
WebView::ProcessManager::initialize();
|
||||||
|
|
||||||
|
#if defined(AK_OS_MACOS)
|
||||||
|
auto mach_port_server = make<Ladybird::MachPortServer>();
|
||||||
|
set_mach_server_name(mach_port_server->server_port_name());
|
||||||
|
mach_port_server->on_receive_child_mach_port = [](auto pid, auto port) {
|
||||||
|
WebView::ProcessManager::the().add_process(pid, move(port));
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
RefPtr<WebView::Database> database;
|
RefPtr<WebView::Database> database;
|
||||||
|
|
||||||
if (!disable_sql_database) {
|
if (!disable_sql_database) {
|
||||||
|
@ -158,8 +172,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
.wait_for_debugger = debug_web_content ? Ladybird::WaitForDebugger::Yes : Ladybird::WaitForDebugger::No,
|
.wait_for_debugger = debug_web_content ? Ladybird::WaitForDebugger::Yes : Ladybird::WaitForDebugger::No,
|
||||||
};
|
};
|
||||||
|
|
||||||
WebView::ProcessManager::initialize();
|
|
||||||
|
|
||||||
Ladybird::BrowserWindow window(initial_urls, cookie_jar, web_content_options, webdriver_content_ipc_path);
|
Ladybird::BrowserWindow window(initial_urls, cookie_jar, web_content_options, webdriver_content_ipc_path);
|
||||||
window.setWindowTitle("Ladybird");
|
window.setWindowTitle("Ladybird");
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,16 @@ constexpr auto libexec_path = "libexec"sv;
|
||||||
|
|
||||||
ByteString s_serenity_resource_root;
|
ByteString s_serenity_resource_root;
|
||||||
|
|
||||||
|
Optional<ByteString> s_mach_server_name;
|
||||||
|
Optional<ByteString> mach_server_name()
|
||||||
|
{
|
||||||
|
return s_mach_server_name;
|
||||||
|
}
|
||||||
|
void set_mach_server_name(ByteString name)
|
||||||
|
{
|
||||||
|
s_mach_server_name = move(name);
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<ByteString> application_directory()
|
ErrorOr<ByteString> application_directory()
|
||||||
{
|
{
|
||||||
auto current_executable_path = TRY(Core::System::current_executable_path());
|
auto current_executable_path = TRY(Core::System::current_executable_path());
|
||||||
|
|
|
@ -17,3 +17,5 @@ ErrorOr<ByteString> application_directory();
|
||||||
ErrorOr<Vector<ByteString>> get_paths_for_helper_process(StringView process_name);
|
ErrorOr<Vector<ByteString>> get_paths_for_helper_process(StringView process_name);
|
||||||
|
|
||||||
extern ByteString s_serenity_resource_root;
|
extern ByteString s_serenity_resource_root;
|
||||||
|
Optional<ByteString> mach_server_name();
|
||||||
|
void set_mach_server_name(ByteString name);
|
||||||
|
|
|
@ -45,6 +45,10 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(AK_OS_MACOS)
|
||||||
|
# include <LibWebView/Platform/ProcessStatisticsMach.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static ErrorOr<void> load_content_filters();
|
static ErrorOr<void> load_content_filters();
|
||||||
static ErrorOr<void> load_autoplay_allowlist();
|
static ErrorOr<void> load_autoplay_allowlist();
|
||||||
static ErrorOr<void> initialize_lagom_networking(Vector<ByteString> const& certificates);
|
static ErrorOr<void> initialize_lagom_networking(Vector<ByteString> const& certificates);
|
||||||
|
@ -78,6 +82,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
StringView command_line {};
|
StringView command_line {};
|
||||||
StringView executable_path {};
|
StringView executable_path {};
|
||||||
|
StringView mach_server_name {};
|
||||||
Vector<ByteString> certificates;
|
Vector<ByteString> certificates;
|
||||||
int webcontent_fd_passing_socket { -1 };
|
int webcontent_fd_passing_socket { -1 };
|
||||||
bool is_layout_test_mode = false;
|
bool is_layout_test_mode = false;
|
||||||
|
@ -94,6 +99,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
args_parser.add_option(use_lagom_networking, "Enable Lagom servers for networking", "use-lagom-networking", 0);
|
args_parser.add_option(use_lagom_networking, "Enable Lagom servers for networking", "use-lagom-networking", 0);
|
||||||
args_parser.add_option(use_gpu_painting, "Enable GPU painting", "use-gpu-painting", 0);
|
args_parser.add_option(use_gpu_painting, "Enable GPU painting", "use-gpu-painting", 0);
|
||||||
args_parser.add_option(wait_for_debugger, "Wait for debugger", "wait-for-debugger", 0);
|
args_parser.add_option(wait_for_debugger, "Wait for debugger", "wait-for-debugger", 0);
|
||||||
|
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);
|
||||||
|
|
||||||
|
@ -107,6 +113,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
WebContent::PageClient::set_use_gpu_painter();
|
WebContent::PageClient::set_use_gpu_painter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(AK_OS_MACOS)
|
||||||
|
if (!mach_server_name.is_empty()) {
|
||||||
|
WebView::register_with_mach_server(mach_server_name);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_QT)
|
#if defined(HAVE_QT)
|
||||||
if (!use_lagom_networking)
|
if (!use_lagom_networking)
|
||||||
Web::ResourceLoader::initialize(Ladybird::RequestManagerQt::create());
|
Web::ResourceLoader::initialize(Ladybird::RequestManagerQt::create());
|
||||||
|
|
|
@ -80,6 +80,12 @@ void ProcessManager::initialize()
|
||||||
MUST(Core::System::sigaction(SIGCHLD, &action, nullptr));
|
MUST(Core::System::sigaction(SIGCHLD, &action, nullptr));
|
||||||
|
|
||||||
the().add_process(WebView::ProcessType::Chrome, getpid());
|
the().add_process(WebView::ProcessType::Chrome, getpid());
|
||||||
|
#ifdef AK_OS_MACH
|
||||||
|
auto self_send_port = mach_task_self();
|
||||||
|
auto res = mach_port_mod_refs(mach_task_self(), self_send_port, MACH_PORT_RIGHT_SEND, +1);
|
||||||
|
VERIFY(res == KERN_SUCCESS);
|
||||||
|
the().add_process(getpid(), Core::MachPort::adopt_right(self_send_port, Core::MachPort::PortRight::Send));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessManager::add_process(ProcessType type, pid_t pid)
|
void ProcessManager::add_process(ProcessType type, pid_t pid)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue