mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibWebView+UI: Migrate some UI process init to LibWebView
No need to do this setup in every UI's main().
This commit is contained in:
parent
6430b215af
commit
39da2d9a2f
Notes:
github-actions[bot]
2025-06-11 11:27:28 +00:00
Author: https://github.com/trflynn89
Commit: 39da2d9a2f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5054
10 changed files with 80 additions and 91 deletions
|
@ -24,6 +24,10 @@
|
|||
#include <LibWebView/Utilities.h>
|
||||
#include <LibWebView/WebContentClient.h>
|
||||
|
||||
#if defined(AK_OS_MACOS)
|
||||
# include <LibWebView/MachPortServer.h>
|
||||
#endif
|
||||
|
||||
namespace WebView {
|
||||
|
||||
Application* Application::s_the = nullptr;
|
||||
|
@ -46,7 +50,7 @@ struct ApplicationSettingsObserver : public SettingsObserver {
|
|||
}
|
||||
};
|
||||
|
||||
Application::Application()
|
||||
Application::Application(Optional<ByteString> ladybird_binary_path)
|
||||
: m_settings(Settings::create({}))
|
||||
{
|
||||
VERIFY(!s_the);
|
||||
|
@ -73,6 +77,8 @@ Application::Application()
|
|||
m_process_manager.on_process_exited = [this](Process&& process) {
|
||||
process_did_exit(move(process));
|
||||
};
|
||||
|
||||
platform_init(move(ladybird_binary_path));
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
|
@ -83,16 +89,30 @@ Application::~Application()
|
|||
s_the = nullptr;
|
||||
}
|
||||
|
||||
void Application::initialize(Main::Arguments const& arguments)
|
||||
ErrorOr<void> Application::initialize(Main::Arguments const& arguments)
|
||||
{
|
||||
TRY(handle_attached_debugger());
|
||||
m_arguments = arguments;
|
||||
|
||||
#ifndef AK_OS_WINDOWS
|
||||
#if !defined(AK_OS_WINDOWS)
|
||||
// Increase the open file limit, as the default limits on Linux cause us to run out of file descriptors with around 15 tabs open.
|
||||
if (auto result = Core::System::set_resource_limits(RLIMIT_NOFILE, 8192); result.is_error())
|
||||
warnln("Unable to increase open file limit: {}", result.error());
|
||||
#endif
|
||||
|
||||
#if defined(AK_OS_MACOS)
|
||||
m_mach_port_server = make<MachPortServer>();
|
||||
set_mach_server_name(m_mach_port_server->server_port_name());
|
||||
|
||||
m_mach_port_server->on_receive_child_mach_port = [this](auto pid, auto port) {
|
||||
set_process_mach_port(pid, move(port));
|
||||
};
|
||||
m_mach_port_server->on_receive_backing_stores = [](MachPortServer::BackingStoresMessage message) {
|
||||
if (auto view = WebContentClient::view_for_pid_and_page_id(message.pid, message.page_id); view.has_value())
|
||||
view->did_allocate_iosurface_backing_stores(message.front_backing_store_id, move(message.front_backing_store_port), message.back_backing_store_id, move(message.back_backing_store_port));
|
||||
};
|
||||
#endif
|
||||
|
||||
Vector<ByteString> raw_urls;
|
||||
Vector<ByteString> certificates;
|
||||
Optional<HeadlessMode> headless_mode;
|
||||
|
@ -256,6 +276,9 @@ void Application::initialize(Main::Arguments const& arguments)
|
|||
create_platform_options(m_browser_options, m_web_content_options);
|
||||
|
||||
m_event_loop = create_platform_event_loop();
|
||||
TRY(launch_services());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<NonnullRefPtr<WebContentClient>> create_web_content_client(Optional<ViewImplementation&> view)
|
||||
|
|
|
@ -50,7 +50,6 @@ public:
|
|||
static ProcessManager& process_manager() { return the().m_process_manager; }
|
||||
|
||||
ErrorOr<NonnullRefPtr<WebContentClient>> launch_web_content_process(ViewImplementation&);
|
||||
ErrorOr<void> launch_services();
|
||||
|
||||
void add_child_process(Process&&);
|
||||
|
||||
|
@ -70,9 +69,9 @@ public:
|
|||
void refresh_tab_list();
|
||||
|
||||
protected:
|
||||
Application();
|
||||
explicit Application(Optional<ByteString> ladybird_binary_path = {});
|
||||
|
||||
void initialize(Main::Arguments const&);
|
||||
ErrorOr<void> initialize(Main::Arguments const&);
|
||||
|
||||
virtual void process_did_exit(Process&&);
|
||||
|
||||
|
@ -85,6 +84,7 @@ protected:
|
|||
Main::Arguments& arguments() { return m_arguments; }
|
||||
|
||||
private:
|
||||
ErrorOr<void> launch_services();
|
||||
void launch_spare_web_content_process();
|
||||
ErrorOr<void> launch_request_server();
|
||||
ErrorOr<void> launch_image_decoder_server();
|
||||
|
@ -145,24 +145,28 @@ private:
|
|||
ProcessManager m_process_manager;
|
||||
bool m_in_shutdown { false };
|
||||
|
||||
#if defined(AK_OS_MACOS)
|
||||
OwnPtr<MachPortServer> m_mach_port_server;
|
||||
#endif
|
||||
|
||||
OwnPtr<DevTools::DevToolsServer> m_devtools;
|
||||
} SWIFT_IMMORTAL_REFERENCE;
|
||||
|
||||
}
|
||||
|
||||
#define WEB_VIEW_APPLICATION(ApplicationType) \
|
||||
public: \
|
||||
template<typename... ApplicationArguments> \
|
||||
static NonnullOwnPtr<ApplicationType> create(Main::Arguments const& arguments, ApplicationArguments&&... application_arguments) \
|
||||
{ \
|
||||
auto app = adopt_own(*new ApplicationType { forward<ApplicationArguments>(application_arguments)... }); \
|
||||
app->initialize(arguments); \
|
||||
return app; \
|
||||
} \
|
||||
\
|
||||
static ApplicationType& the() \
|
||||
{ \
|
||||
return static_cast<ApplicationType&>(WebView::Application::the()); \
|
||||
} \
|
||||
\
|
||||
#define WEB_VIEW_APPLICATION(ApplicationType) \
|
||||
public: \
|
||||
template<typename... ApplicationArguments> \
|
||||
static ErrorOr<NonnullOwnPtr<ApplicationType>> create(Main::Arguments const& arguments, ApplicationArguments&&... application_arguments) \
|
||||
{ \
|
||||
auto app = adopt_own(*new ApplicationType { forward<ApplicationArguments>(application_arguments)... }); \
|
||||
TRY(app->initialize(arguments)); \
|
||||
return app; \
|
||||
} \
|
||||
\
|
||||
static ApplicationType& the() \
|
||||
{ \
|
||||
return static_cast<ApplicationType&>(WebView::Application::the()); \
|
||||
} \
|
||||
\
|
||||
private:
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Platform.h>
|
||||
#include <AK/Traits.h>
|
||||
|
||||
namespace WebView {
|
||||
|
@ -21,6 +22,10 @@ class ViewImplementation;
|
|||
class WebContentClient;
|
||||
class WebUI;
|
||||
|
||||
#if defined(AK_OS_MACOS)
|
||||
class MachPortServer;
|
||||
#endif
|
||||
|
||||
struct Attribute;
|
||||
struct AutocompleteEngine;
|
||||
struct BrowserOptions;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Platform.h>
|
||||
#include <LibCore/Directory.h>
|
||||
#include <LibCore/Environment.h>
|
||||
#include <LibCore/Process.h>
|
||||
#include <LibCore/Resource.h>
|
||||
#include <LibCore/ResourceImplementationFile.h>
|
||||
#include <LibCore/System.h>
|
||||
|
@ -122,4 +123,18 @@ ErrorOr<Vector<ByteString>> get_paths_for_helper_process(StringView process_name
|
|||
return paths;
|
||||
}
|
||||
|
||||
ErrorOr<void> handle_attached_debugger()
|
||||
{
|
||||
#if defined(AK_OS_LINUX)
|
||||
// Let's ignore SIGINT if we're being debugged because GDB incorrectly forwards the signal to us even when it's set
|
||||
// to "nopass". See https://sourceware.org/bugzilla/show_bug.cgi?id=9425 for details.
|
||||
if (TRY(Core::Process::is_being_debugged())) {
|
||||
dbgln("Debugger is attached, ignoring SIGINT");
|
||||
TRY(Core::System::signal(SIGINT, SIG_IGN));
|
||||
}
|
||||
#endif
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,4 +22,6 @@ extern ByteString s_ladybird_resource_root;
|
|||
Optional<ByteString const&> mach_server_name();
|
||||
void set_mach_server_name(ByteString name);
|
||||
|
||||
ErrorOr<void> handle_attached_debugger();
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue