diff --git a/Ladybird/AppKit/Application/ApplicationDelegate.h b/Ladybird/AppKit/Application/ApplicationDelegate.h index 2012c907ac6..b9fcc48dd6a 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 c604b52cb1d..c509a64fad9 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 845ed3fb045..80566235ceb 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 ebbc052c4ab..c77130b5a64 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 bacc73a5ac4..37983d8b162 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 b450a96388c..666a3070580 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 922ccd183c9..21b51936fb5 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 d3da1bb7735..d22a32cd5f8 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 b1ffa99d412..a8926c60809 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 e10f9ba6933..da0bcdbef1b 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 ac7cbe73347..389644986e9 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 0abac2828c1..4101424d44c 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 e7f959d02a9..5fbd2bd274d 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 1dc89824b5b..6244811915d 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 eab1b73393c..e3ae308d7eb 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 01a778fedde..7d124d03313 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 a72326806ce..1ee9ef3eb15 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 8611e39c635..13e82dee095 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 2e1132b86c9..c39fa1d7500 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 d6f3c41c02d..6a81da2cf48 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 5bdabd99cb8..98a20e490d0 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 b05965cc7a2..140ab9375ab 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()) {