From 07e9a8f79bc8abbad87a931d54ef880bcdfbd8e1 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 1 Dec 2023 12:18:40 -0500 Subject: [PATCH] Ladybird+LibWebView: Move options used to launch WebContent to a struct It is currently a bit messy to pass these options along from main() to where WebContent is actually launched. If a new flag were to be added, there are a couple dozen files that need to be updated to pass that flag along. With this change, the flag can just be added to the struct, set in main(), and handled in launch_web_content_process(). --- .../AppKit/Application/ApplicationDelegate.h | 3 +++ .../AppKit/Application/ApplicationDelegate.mm | 9 +++++++ Ladybird/AppKit/UI/LadybirdWebView.mm | 2 +- Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp | 13 +++++----- Ladybird/AppKit/UI/LadybirdWebViewBridge.h | 9 ++++--- Ladybird/AppKit/main.mm | 6 +++++ Ladybird/HelperProcess.cpp | 18 +++++++------- Ladybird/HelperProcess.h | 8 +++---- Ladybird/Qt/BrowserWindow.cpp | 8 +++---- Ladybird/Qt/BrowserWindow.h | 8 +++---- Ladybird/Qt/ConsoleWidget.cpp | 2 +- Ladybird/Qt/InspectorWidget.cpp | 2 +- Ladybird/Qt/Tab.cpp | 4 ++-- Ladybird/Qt/Tab.h | 3 ++- Ladybird/Qt/WebContentView.cpp | 11 ++++----- Ladybird/Qt/WebContentView.h | 7 +++--- Ladybird/Qt/main.cpp | 8 ++++++- Ladybird/Types.h | 24 ++++++++++++++++++- .../LibWebView/OutOfProcessWebView.cpp | 2 +- .../LibWebView/OutOfProcessWebView.h | 2 +- .../Libraries/LibWebView/ViewImplementation.h | 18 +------------- Userland/Utilities/headless-browser.cpp | 11 +++++---- 22 files changed, 104 insertions(+), 74 deletions(-) diff --git a/Ladybird/AppKit/Application/ApplicationDelegate.h b/Ladybird/AppKit/Application/ApplicationDelegate.h index 2012c907ac..b9fcc48dd6 100644 --- a/Ladybird/AppKit/Application/ApplicationDelegate.h +++ b/Ladybird/AppKit/Application/ApplicationDelegate.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ - (nullable instancetype)init:(Vector)initial_urls newTabPageURL:(URL)new_tab_page_url withCookieJar:(WebView::CookieJar)cookie_jar + webContentOptions:(Ladybird::WebContentOptions const&)web_content_options webdriverContentIPCPath:(StringView)webdriver_content_ipc_path; - (nonnull TabController*)createNewTab:(Optional const&)url @@ -38,6 +40,7 @@ - (void)removeTab:(nonnull TabController*)controller; - (WebView::CookieJar&)cookieJar; +- (Ladybird::WebContentOptions const&)webContentOptions; - (Optional const&)webdriverContentIPCPath; - (Web::CSS::PreferredColorScheme)preferredColorScheme; - (WebView::SearchEngine const&)searchEngine; diff --git a/Ladybird/AppKit/Application/ApplicationDelegate.mm b/Ladybird/AppKit/Application/ApplicationDelegate.mm index c604b52cb1..c509a64fad 100644 --- a/Ladybird/AppKit/Application/ApplicationDelegate.mm +++ b/Ladybird/AppKit/Application/ApplicationDelegate.mm @@ -25,6 +25,7 @@ // This will always be populated, but we cannot have a non-default constructible instance variable. Optional m_cookie_jar; + Ladybird::WebContentOptions m_web_content_options; Optional m_webdriver_content_ipc_path; Web::CSS::PreferredColorScheme m_preferred_color_scheme; @@ -52,6 +53,7 @@ - (instancetype)init:(Vector)initial_urls newTabPageURL:(URL)new_tab_page_url withCookieJar:(WebView::CookieJar)cookie_jar + webContentOptions:(Ladybird::WebContentOptions const&)web_content_options webdriverContentIPCPath:(StringView)webdriver_content_ipc_path { if (self = [super init]) { @@ -75,6 +77,8 @@ m_cookie_jar = move(cookie_jar); + m_web_content_options = web_content_options; + if (!webdriver_content_ipc_path.is_empty()) { m_webdriver_content_ipc_path = webdriver_content_ipc_path; } @@ -122,6 +126,11 @@ return *m_cookie_jar; } +- (Ladybird::WebContentOptions const&)webContentOptions +{ + return m_web_content_options; +} + - (Optional const&)webdriverContentIPCPath { return m_webdriver_content_ipc_path; diff --git a/Ladybird/AppKit/UI/LadybirdWebView.mm b/Ladybird/AppKit/UI/LadybirdWebView.mm index 845ed3fb04..80566235ce 100644 --- a/Ladybird/AppKit/UI/LadybirdWebView.mm +++ b/Ladybird/AppKit/UI/LadybirdWebView.mm @@ -93,7 +93,7 @@ struct HideCursor { // This returns device pixel ratio of the screen the window is opened in auto device_pixel_ratio = [[NSScreen mainScreen] backingScaleFactor]; - m_web_view_bridge = MUST(Ladybird::WebViewBridge::create(move(screen_rects), device_pixel_ratio, [delegate webdriverContentIPCPath], [delegate preferredColorScheme])); + m_web_view_bridge = MUST(Ladybird::WebViewBridge::create(move(screen_rects), device_pixel_ratio, [delegate webContentOptions], [delegate webdriverContentIPCPath], [delegate preferredColorScheme])); [self setWebViewCallbacks]; auto* area = [[NSTrackingArea alloc] initWithRect:[self bounds] diff --git a/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp b/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp index ebbc052c4a..c77130b5a6 100644 --- a/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp +++ b/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp @@ -23,19 +23,20 @@ static T scale_for_device(T size, float device_pixel_ratio) return size.template to_type().scaled(device_pixel_ratio).template to_type(); } -ErrorOr> WebViewBridge::create(Vector screen_rects, float device_pixel_ratio, Optional webdriver_content_ipc_path, Web::CSS::PreferredColorScheme preferred_color_scheme) +ErrorOr> WebViewBridge::create(Vector screen_rects, float device_pixel_ratio, WebContentOptions const& web_content_options, Optional webdriver_content_ipc_path, Web::CSS::PreferredColorScheme preferred_color_scheme) { - return adopt_nonnull_own_or_enomem(new (nothrow) WebViewBridge(move(screen_rects), device_pixel_ratio, move(webdriver_content_ipc_path), preferred_color_scheme)); + return adopt_nonnull_own_or_enomem(new (nothrow) WebViewBridge(move(screen_rects), device_pixel_ratio, web_content_options, move(webdriver_content_ipc_path), preferred_color_scheme)); } -WebViewBridge::WebViewBridge(Vector screen_rects, float device_pixel_ratio, Optional webdriver_content_ipc_path, Web::CSS::PreferredColorScheme preferred_color_scheme) +WebViewBridge::WebViewBridge(Vector screen_rects, float device_pixel_ratio, WebContentOptions const& web_content_options, Optional webdriver_content_ipc_path, Web::CSS::PreferredColorScheme preferred_color_scheme) : m_screen_rects(move(screen_rects)) + , m_web_content_options(web_content_options) , m_webdriver_content_ipc_path(move(webdriver_content_ipc_path)) , m_preferred_color_scheme(preferred_color_scheme) { m_device_pixel_ratio = device_pixel_ratio; - create_client(WebView::EnableCallgrindProfiling::No); + create_client(); on_scroll_by_delta = [this](auto x_delta, auto y_delta) { auto position = m_viewport_rect.location(); @@ -184,12 +185,12 @@ Gfx::IntPoint WebViewBridge::to_widget_position(Gfx::IntPoint content_position) return scale_for_device(content_position, inverse_device_pixel_ratio()); } -void WebViewBridge::create_client(WebView::EnableCallgrindProfiling enable_callgrind_profiling) +void WebViewBridge::create_client() { m_client_state = {}; auto candidate_web_content_paths = MUST(get_paths_for_helper_process("WebContent"sv)); - auto new_client = MUST(launch_web_content_process(*this, candidate_web_content_paths, enable_callgrind_profiling, WebView::IsLayoutTestMode::No, Ladybird::UseLagomNetworking::Yes, WebView::EnableGPUPainting::No)); + auto new_client = MUST(launch_web_content_process(*this, candidate_web_content_paths, m_web_content_options)); m_client_state.client = new_client; m_client_state.client->on_web_content_process_crash = [this] { diff --git a/Ladybird/AppKit/UI/LadybirdWebViewBridge.h b/Ladybird/AppKit/UI/LadybirdWebViewBridge.h index bacc73a5ac..37983d8b16 100644 --- a/Ladybird/AppKit/UI/LadybirdWebViewBridge.h +++ b/Ladybird/AppKit/UI/LadybirdWebViewBridge.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include @@ -22,7 +23,7 @@ namespace Ladybird { class WebViewBridge final : public WebView::ViewImplementation { public: - static ErrorOr> create(Vector screen_rects, float device_pixel_ratio, Optional webdriver_content_ipc_path, Web::CSS::PreferredColorScheme); + static ErrorOr> create(Vector screen_rects, float device_pixel_ratio, WebContentOptions const&, Optional webdriver_content_ipc_path, Web::CSS::PreferredColorScheme); virtual ~WebViewBridge() override; float device_pixel_ratio() const { return m_device_pixel_ratio; } @@ -59,19 +60,21 @@ public: Function on_scroll; private: - WebViewBridge(Vector screen_rects, float device_pixel_ratio, Optional webdriver_content_ipc_path, Web::CSS::PreferredColorScheme); + WebViewBridge(Vector screen_rects, float device_pixel_ratio, WebContentOptions const&, Optional webdriver_content_ipc_path, Web::CSS::PreferredColorScheme); virtual void update_zoom() override; virtual Gfx::IntRect viewport_rect() const override; virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override; virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override; - virtual void create_client(WebView::EnableCallgrindProfiling) override; + virtual void create_client() override; Vector m_screen_rects; Gfx::IntRect m_viewport_rect; + WebContentOptions m_web_content_options; Optional m_webdriver_content_ipc_path; + Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto }; }; diff --git a/Ladybird/AppKit/main.mm b/Ladybird/AppKit/main.mm index b450a96388..666a307058 100644 --- a/Ladybird/AppKit/main.mm +++ b/Ladybird/AppKit/main.mm @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -61,9 +62,14 @@ ErrorOr serenity_main(Main::Arguments arguments) if (initial_urls.is_empty()) initial_urls.append(new_tab_page_url); + Ladybird::WebContentOptions web_content_options { + .use_lagom_networking = Ladybird::UseLagomNetworking::Yes, + }; + auto* delegate = [[ApplicationDelegate alloc] init:move(initial_urls) newTabPageURL:move(new_tab_page_url) withCookieJar:move(cookie_jar) + webContentOptions:web_content_options webdriverContentIPCPath:webdriver_content_ipc_path]; [NSApp setDelegate:delegate]; diff --git a/Ladybird/HelperProcess.cpp b/Ladybird/HelperProcess.cpp index 922ccd183c..21b51936fb 100644 --- a/Ladybird/HelperProcess.cpp +++ b/Ladybird/HelperProcess.cpp @@ -6,12 +6,10 @@ #include "HelperProcess.h" -ErrorOr> launch_web_content_process(WebView::ViewImplementation& view, +ErrorOr> launch_web_content_process( + WebView::ViewImplementation& view, ReadonlySpan candidate_web_content_paths, - WebView::EnableCallgrindProfiling enable_callgrind_profiling, - WebView::IsLayoutTestMode is_layout_test_mode, - Ladybird::UseLagomNetworking use_lagom_networking, - WebView::EnableGPUPainting enable_gpu_painting) + Ladybird::WebContentOptions const& web_content_options) { int socket_fds[2] {}; TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds)); @@ -49,13 +47,13 @@ ErrorOr> launch_web_content_process(Web "--webcontent-fd-passing-socket"sv, webcontent_fd_passing_socket_string }; - if (enable_callgrind_profiling == WebView::EnableCallgrindProfiling::No) + if (web_content_options.enable_callgrind_profiling == Ladybird::EnableCallgrindProfiling::No) arguments.remove(0, callgrind_prefix_length); - if (is_layout_test_mode == WebView::IsLayoutTestMode::Yes) + if (web_content_options.is_layout_test_mode == Ladybird::IsLayoutTestMode::Yes) arguments.append("--layout-test-mode"sv); - if (use_lagom_networking == Ladybird::UseLagomNetworking::Yes) + if (web_content_options.use_lagom_networking == Ladybird::UseLagomNetworking::Yes) arguments.append("--use-lagom-networking"sv); - if (enable_gpu_painting == WebView::EnableGPUPainting::Yes) + if (web_content_options.enable_gpu_painting == Ladybird::EnableGPUPainting::Yes) arguments.append("--use-gpu-painting"sv); result = Core::System::exec(arguments[0], arguments.span(), Core::System::SearchInPath::Yes); @@ -77,7 +75,7 @@ ErrorOr> launch_web_content_process(Web auto new_client = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) WebView::WebContentClient(move(socket), view))); new_client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(ui_fd_passing_fd))); - if (enable_callgrind_profiling == WebView::EnableCallgrindProfiling::Yes) { + if (web_content_options.enable_callgrind_profiling == Ladybird::EnableCallgrindProfiling::Yes) { dbgln(); dbgln("\033[1;45mLaunched WebContent process under callgrind!\033[0m"); dbgln("\033[100mRun `\033[4mcallgrind_control -i on\033[24m` to start instrumentation and `\033[4mcallgrind_control -i off\033[24m` stop it again.\033[0m"); diff --git a/Ladybird/HelperProcess.h b/Ladybird/HelperProcess.h index d3da1bb773..d22a32cd5f 100644 --- a/Ladybird/HelperProcess.h +++ b/Ladybird/HelperProcess.h @@ -16,12 +16,10 @@ #include #include -ErrorOr> launch_web_content_process(WebView::ViewImplementation& view, +ErrorOr> launch_web_content_process( + WebView::ViewImplementation& view, ReadonlySpan candidate_web_content_paths, - WebView::EnableCallgrindProfiling, - WebView::IsLayoutTestMode, - Ladybird::UseLagomNetworking, - WebView::EnableGPUPainting); + Ladybird::WebContentOptions const&); ErrorOr> launch_image_decoder_process(ReadonlySpan candidate_image_decoder_paths); ErrorOr> launch_request_server_process(ReadonlySpan candidate_request_server_paths, StringView serenity_resource_root); diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index b1ffa99d41..a8926c6080 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -42,12 +42,10 @@ static QIcon const& app_icon() return icon; } -BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::CookieJar& cookie_jar, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling, UseLagomNetworking use_lagom_networking, WebView::EnableGPUPainting use_gpu_painting) +BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path) : m_cookie_jar(cookie_jar) + , m_web_content_options(web_content_options) , m_webdriver_content_ipc_path(webdriver_content_ipc_path) - , m_enable_callgrind_profiling(enable_callgrind_profiling) - , m_use_lagom_networking(use_lagom_networking) - , m_use_gpu_painting(use_gpu_painting) { setWindowIcon(app_icon()); m_tabs_container = new QTabWidget(this); @@ -464,7 +462,7 @@ Tab& BrowserWindow::new_tab(StringView html, Web::HTML::ActivateTab activate_tab Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab) { - auto tab = make(this, m_webdriver_content_ipc_path, m_enable_callgrind_profiling, m_use_lagom_networking, m_use_gpu_painting); + auto tab = make(this, m_web_content_options, m_webdriver_content_ipc_path); auto tab_ptr = tab.ptr(); m_tabs.append(std::move(tab)); diff --git a/Ladybird/Qt/BrowserWindow.h b/Ladybird/Qt/BrowserWindow.h index e10f9ba693..da0bcdbef1 100644 --- a/Ladybird/Qt/BrowserWindow.h +++ b/Ladybird/Qt/BrowserWindow.h @@ -8,6 +8,7 @@ #pragma once #include "Tab.h" +#include #include #include #include @@ -24,8 +25,9 @@ class WebContentView; class BrowserWindow : public QMainWindow { Q_OBJECT + public: - explicit BrowserWindow(Vector const& initial_urls, WebView::CookieJar&, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling, UseLagomNetworking, WebView::EnableGPUPainting); + BrowserWindow(Vector const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path); WebContentView& view() const { return m_current_tab->view(); } @@ -118,10 +120,8 @@ private: WebView::CookieJar& m_cookie_jar; + WebContentOptions m_web_content_options; StringView m_webdriver_content_ipc_path; - WebView::EnableCallgrindProfiling m_enable_callgrind_profiling; - UseLagomNetworking m_use_lagom_networking; - WebView::EnableGPUPainting m_use_gpu_painting; }; } diff --git a/Ladybird/Qt/ConsoleWidget.cpp b/Ladybird/Qt/ConsoleWidget.cpp index ac7cbe7334..389644986e 100644 --- a/Ladybird/Qt/ConsoleWidget.cpp +++ b/Ladybird/Qt/ConsoleWidget.cpp @@ -25,7 +25,7 @@ ConsoleWidget::ConsoleWidget(WebContentView& content_view) { setLayout(new QVBoxLayout); - m_output_view = new WebContentView({}, WebView::EnableCallgrindProfiling::No, UseLagomNetworking::No, WebView::EnableGPUPainting::No); + m_output_view = new WebContentView({}, {}); if (is_using_dark_system_theme(*this)) m_output_view->update_palette(WebContentView::PaletteMode::Dark); diff --git a/Ladybird/Qt/InspectorWidget.cpp b/Ladybird/Qt/InspectorWidget.cpp index 0abac2828c..4101424d44 100644 --- a/Ladybird/Qt/InspectorWidget.cpp +++ b/Ladybird/Qt/InspectorWidget.cpp @@ -15,7 +15,7 @@ extern bool is_using_dark_system_theme(QWidget&); InspectorWidget::InspectorWidget(WebContentView& content_view) { - m_inspector_view = make(StringView {}, WebView::EnableCallgrindProfiling::No, UseLagomNetworking::No, WebView::EnableGPUPainting::No); + m_inspector_view = make(WebContentOptions {}, StringView {}); if (is_using_dark_system_theme(*this)) m_inspector_view->update_palette(WebContentView::PaletteMode::Dark); diff --git a/Ladybird/Qt/Tab.cpp b/Ladybird/Qt/Tab.cpp index e7f959d02a..5fbd2bd274 100644 --- a/Ladybird/Qt/Tab.cpp +++ b/Ladybird/Qt/Tab.cpp @@ -52,7 +52,7 @@ static QIcon create_tvg_icon_with_theme_colors(QString name, QPalette const& pal return QIcon(icon_engine); } -Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling, UseLagomNetworking use_lagom_networking, WebView::EnableGPUPainting enable_gpu_painting) +Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path) : QWidget(window) , m_window(window) { @@ -60,7 +60,7 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView:: m_layout->setSpacing(0); m_layout->setContentsMargins(0, 0, 0, 0); - m_view = new WebContentView(webdriver_content_ipc_path, enable_callgrind_profiling, use_lagom_networking, enable_gpu_painting); + m_view = new WebContentView(web_content_options, webdriver_content_ipc_path); m_toolbar = new QToolBar(this); m_location_edit = new LocationEdit(this); diff --git a/Ladybird/Qt/Tab.h b/Ladybird/Qt/Tab.h index 1dc89824b5..6244811915 100644 --- a/Ladybird/Qt/Tab.h +++ b/Ladybird/Qt/Tab.h @@ -27,8 +27,9 @@ class InspectorWidget; class Tab final : public QWidget { Q_OBJECT + public: - Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling, UseLagomNetworking, WebView::EnableGPUPainting); + Tab(BrowserWindow* window, WebContentOptions const&, StringView webdriver_content_ipc_path); virtual ~Tab() override; WebContentView& view() { return *m_view; } diff --git a/Ladybird/Qt/WebContentView.cpp b/Ladybird/Qt/WebContentView.cpp index eab1b73393..e3ae308d7e 100644 --- a/Ladybird/Qt/WebContentView.cpp +++ b/Ladybird/Qt/WebContentView.cpp @@ -53,9 +53,8 @@ namespace Ladybird { bool is_using_dark_system_theme(QWidget&); -WebContentView::WebContentView(StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling, UseLagomNetworking use_lagom_networking, WebView::EnableGPUPainting enable_gpu_painting) - : m_use_lagom_networking(use_lagom_networking) - , m_use_gpu_painting(enable_gpu_painting) +WebContentView::WebContentView(WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path) + : m_web_content_options(web_content_options) , m_webdriver_content_ipc_path(webdriver_content_ipc_path) { setMouseTracking(true); @@ -76,7 +75,7 @@ WebContentView::WebContentView(StringView webdriver_content_ipc_path, WebView::E update_viewport_rect(); }); - create_client(enable_callgrind_profiling); + create_client(); on_did_layout = [this](auto content_size) { verticalScrollBar()->setMinimum(0); @@ -600,12 +599,12 @@ void WebContentView::update_palette(PaletteMode mode) client().async_update_system_theme(make_system_theme_from_qt_palette(*this, mode)); } -void WebContentView::create_client(WebView::EnableCallgrindProfiling enable_callgrind_profiling) +void WebContentView::create_client() { m_client_state = {}; auto candidate_web_content_paths = get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors(); - auto new_client = launch_web_content_process(*this, candidate_web_content_paths, enable_callgrind_profiling, WebView::IsLayoutTestMode::No, m_use_lagom_networking, m_use_gpu_painting).release_value_but_fixme_should_propagate_errors(); + auto new_client = launch_web_content_process(*this, candidate_web_content_paths, m_web_content_options).release_value_but_fixme_should_propagate_errors(); m_client_state.client = new_client; m_client_state.client->on_web_content_process_crash = [this] { diff --git a/Ladybird/Qt/WebContentView.h b/Ladybird/Qt/WebContentView.h index 01a778fedd..7d124d0331 100644 --- a/Ladybird/Qt/WebContentView.h +++ b/Ladybird/Qt/WebContentView.h @@ -42,7 +42,7 @@ class WebContentView final , public WebView::ViewImplementation { Q_OBJECT public: - explicit WebContentView(StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling, UseLagomNetworking, WebView::EnableGPUPainting); + WebContentView(WebContentOptions const&, StringView webdriver_content_ipc_path); virtual ~WebContentView() override; Function on_tab_open_request; @@ -81,7 +81,7 @@ signals: private: // ^WebView::ViewImplementation - virtual void create_client(WebView::EnableCallgrindProfiling = WebView::EnableCallgrindProfiling::No) override; + virtual void create_client() override; virtual void update_zoom() override; virtual Gfx::IntRect viewport_rect() const override; virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override; @@ -92,11 +92,10 @@ private: qreal m_inverse_pixel_scaling_ratio { 1.0 }; bool m_should_show_line_box_borders { false }; - UseLagomNetworking m_use_lagom_networking {}; - WebView::EnableGPUPainting m_use_gpu_painting {}; Gfx::IntRect m_viewport_rect; + WebContentOptions m_web_content_options; StringView m_webdriver_content_ipc_path; }; diff --git a/Ladybird/Qt/main.cpp b/Ladybird/Qt/main.cpp index a72326806c..1ee9ef3eb1 100644 --- a/Ladybird/Qt/main.cpp +++ b/Ladybird/Qt/main.cpp @@ -140,7 +140,13 @@ ErrorOr serenity_main(Main::Arguments arguments) initial_urls.append(MUST(ak_string_from_qstring(new_tab_page))); } - Ladybird::BrowserWindow window(initial_urls, cookie_jar, webdriver_content_ipc_path, enable_callgrind_profiling ? WebView::EnableCallgrindProfiling::Yes : WebView::EnableCallgrindProfiling::No, use_lagom_networking ? Ladybird::UseLagomNetworking::Yes : Ladybird::UseLagomNetworking::No, use_gpu_painting ? WebView::EnableGPUPainting::Yes : WebView::EnableGPUPainting::No); + Ladybird::WebContentOptions web_content_options { + .enable_callgrind_profiling = enable_callgrind_profiling ? Ladybird::EnableCallgrindProfiling::Yes : Ladybird::EnableCallgrindProfiling::No, + .enable_gpu_painting = use_gpu_painting ? Ladybird::EnableGPUPainting::Yes : Ladybird::EnableGPUPainting::No, + .use_lagom_networking = use_lagom_networking ? Ladybird::UseLagomNetworking::Yes : Ladybird::UseLagomNetworking::No, + }; + + Ladybird::BrowserWindow window(initial_urls, cookie_jar, web_content_options, webdriver_content_ipc_path); window.setWindowTitle("Ladybird"); app.on_open_file = [&](auto file_url) { diff --git a/Ladybird/Types.h b/Ladybird/Types.h index 8611e39c63..13e82dee09 100644 --- a/Ladybird/Types.h +++ b/Ladybird/Types.h @@ -8,9 +8,31 @@ namespace Ladybird { -enum UseLagomNetworking { +enum class EnableCallgrindProfiling { No, Yes }; +enum class EnableGPUPainting { + No, + Yes +}; + +enum class IsLayoutTestMode { + No, + Yes +}; + +enum class UseLagomNetworking { + No, + Yes +}; + +struct WebContentOptions { + EnableCallgrindProfiling enable_callgrind_profiling { EnableCallgrindProfiling::No }; + EnableGPUPainting enable_gpu_painting { EnableGPUPainting::No }; + IsLayoutTestMode is_layout_test_mode { IsLayoutTestMode::No }; + UseLagomNetworking use_lagom_networking { UseLagomNetworking::No }; +}; + } diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index 2e1132b86c..c39fa1d750 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -79,7 +79,7 @@ OutOfProcessWebView::OutOfProcessWebView() OutOfProcessWebView::~OutOfProcessWebView() = default; -void OutOfProcessWebView::create_client(EnableCallgrindProfiling) +void OutOfProcessWebView::create_client() { m_client_state = {}; diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index d6f3c41c02..6a81da2cf4 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -78,7 +78,7 @@ private: virtual void did_scroll() override; // ^WebView::ViewImplementation - virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) override; + virtual void create_client() override; virtual void update_zoom() override; virtual Gfx::IntRect viewport_rect() const override; diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 5bdabd99cb..98a20e490d 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -19,22 +19,6 @@ namespace WebView { -// Note: This only exists inside Serenity to avoid #ifdefs in all implementors of ViewImplementation. -enum class EnableCallgrindProfiling { - No, - Yes -}; - -enum class EnableGPUPainting { - No, - Yes -}; - -enum class IsLayoutTestMode { - No, - Yes -}; - class ViewImplementation { public: virtual ~ViewImplementation() { } @@ -190,7 +174,7 @@ protected: void request_repaint(); void handle_resize(); - virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) { } + virtual void create_client() { } void handle_web_content_process_crash(); diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index b05965cc7a..140ab9375a 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -54,7 +55,7 @@ constexpr int DEFAULT_TIMEOUT_MS = 30000; // 30sec class HeadlessWebContentView final : public WebView::ViewImplementation { public: - static ErrorOr> create(Core::AnonymousBuffer theme, Gfx::IntSize const& window_size, StringView web_driver_ipc_path, WebView::IsLayoutTestMode is_layout_test_mode = WebView::IsLayoutTestMode::No) + static ErrorOr> create(Core::AnonymousBuffer theme, Gfx::IntSize const& window_size, StringView web_driver_ipc_path, Ladybird::IsLayoutTestMode is_layout_test_mode = Ladybird::IsLayoutTestMode::No) { auto view = TRY(adopt_nonnull_own_or_enomem(new (nothrow) HeadlessWebContentView)); @@ -62,8 +63,10 @@ public: view->m_client_state.client = TRY(WebView::WebContentClient::try_create(*view)); (void)is_layout_test_mode; #else + Ladybird::WebContentOptions web_content_options { .is_layout_test_mode = is_layout_test_mode }; + auto candidate_web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv)); - view->m_client_state.client = TRY(launch_web_content_process(*view, candidate_web_content_paths, WebView::EnableCallgrindProfiling::No, is_layout_test_mode, Ladybird::UseLagomNetworking::No, WebView::EnableGPUPainting::No)); + view->m_client_state.client = TRY(launch_web_content_process(*view, candidate_web_content_paths, web_content_options)); #endif view->client().async_update_system_theme(move(theme)); @@ -108,7 +111,7 @@ private: HeadlessWebContentView() = default; void update_zoom() override { } - void create_client(WebView::EnableCallgrindProfiling) override { } + void create_client() override { } virtual Gfx::IntRect viewport_rect() const override { return m_viewport_rect; } virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override { return widget_position; } @@ -451,7 +454,7 @@ ErrorOr serenity_main(Main::Arguments arguments) is_layout_test_mode = true; } - auto view = TRY(HeadlessWebContentView::create(move(theme), window_size, web_driver_ipc_path, is_layout_test_mode ? WebView::IsLayoutTestMode::Yes : WebView::IsLayoutTestMode::No)); + auto view = TRY(HeadlessWebContentView::create(move(theme), window_size, web_driver_ipc_path, is_layout_test_mode ? Ladybird::IsLayoutTestMode::Yes : Ladybird::IsLayoutTestMode::No)); RefPtr timer; if (!test_root_path.is_empty()) {