1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:37:34 +00:00

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().
This commit is contained in:
Timothy Flynn 2023-12-01 12:18:40 -05:00 committed by Tim Flynn
parent 8504d8f588
commit 07e9a8f79b
22 changed files with 104 additions and 74 deletions

View file

@ -10,6 +10,7 @@
#include <AK/StringView.h>
#include <AK/URL.h>
#include <AK/Vector.h>
#include <Ladybird/Types.h>
#include <LibWeb/CSS/PreferredColorScheme.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWebView/CookieJar.h>
@ -24,6 +25,7 @@
- (nullable instancetype)init:(Vector<URL>)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<URL> const&)url
@ -38,6 +40,7 @@
- (void)removeTab:(nonnull TabController*)controller;
- (WebView::CookieJar&)cookieJar;
- (Ladybird::WebContentOptions const&)webContentOptions;
- (Optional<StringView> const&)webdriverContentIPCPath;
- (Web::CSS::PreferredColorScheme)preferredColorScheme;
- (WebView::SearchEngine const&)searchEngine;

View file

@ -25,6 +25,7 @@
// This will always be populated, but we cannot have a non-default constructible instance variable.
Optional<WebView::CookieJar> m_cookie_jar;
Ladybird::WebContentOptions m_web_content_options;
Optional<StringView> m_webdriver_content_ipc_path;
Web::CSS::PreferredColorScheme m_preferred_color_scheme;
@ -52,6 +53,7 @@
- (instancetype)init:(Vector<URL>)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<StringView> const&)webdriverContentIPCPath
{
return m_webdriver_content_ipc_path;

View file

@ -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]

View file

@ -23,19 +23,20 @@ static T scale_for_device(T size, float device_pixel_ratio)
return size.template to_type<float>().scaled(device_pixel_ratio).template to_type<int>();
}
ErrorOr<NonnullOwnPtr<WebViewBridge>> WebViewBridge::create(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme preferred_color_scheme)
ErrorOr<NonnullOwnPtr<WebViewBridge>> WebViewBridge::create(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, WebContentOptions const& web_content_options, Optional<StringView> 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<Gfx::IntRect> screen_rects, float device_pixel_ratio, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme preferred_color_scheme)
WebViewBridge::WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, WebContentOptions const& web_content_options, Optional<StringView> 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] {

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/Vector.h>
#include <Ladybird/Types.h>
#include <LibGfx/Point.h>
#include <LibGfx/Rect.h>
#include <LibGfx/Size.h>
@ -22,7 +23,7 @@ namespace Ladybird {
class WebViewBridge final : public WebView::ViewImplementation {
public:
static ErrorOr<NonnullOwnPtr<WebViewBridge>> create(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme);
static ErrorOr<NonnullOwnPtr<WebViewBridge>> create(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, WebContentOptions const&, Optional<StringView> 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<void(Gfx::IntPoint)> on_scroll;
private:
WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme);
WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, WebContentOptions const&, Optional<StringView> 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<Gfx::IntRect> m_screen_rects;
Gfx::IntRect m_viewport_rect;
WebContentOptions m_web_content_options;
Optional<StringView> m_webdriver_content_ipc_path;
Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto };
};

View file

@ -5,6 +5,7 @@
*/
#include <BrowserSettings/Defaults.h>
#include <Ladybird/Types.h>
#include <Ladybird/Utilities.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
@ -61,9 +62,14 @@ ErrorOr<int> 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];