LibWebView+UI: Rename ChromeOptions to BrowserOptions

This commit is contained in:
Timothy Flynn 2025-03-15 16:56:52 -04:00 committed by Tim Flynn
commit e00c0c176e
Notes: github-actions[bot] 2025-03-15 23:58:57 +00:00
16 changed files with 42 additions and 42 deletions

View file

@ -149,7 +149,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
if (debug_process_type == ProcessType::WebContent) if (debug_process_type == ProcessType::WebContent)
disable_site_isolation = true; disable_site_isolation = true;
m_chrome_options = { m_browser_options = {
.urls = sanitize_urls(raw_urls, new_tab_page_url), .urls = sanitize_urls(raw_urls, new_tab_page_url),
.raw_urls = move(raw_urls), .raw_urls = move(raw_urls),
.new_tab_page_url = move(new_tab_page_url), .new_tab_page_url = move(new_tab_page_url),
@ -170,7 +170,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
}; };
if (webdriver_content_ipc_path.has_value()) if (webdriver_content_ipc_path.has_value())
m_chrome_options.webdriver_content_ipc_path = *webdriver_content_ipc_path; m_browser_options.webdriver_content_ipc_path = *webdriver_content_ipc_path;
m_web_content_options = { m_web_content_options = {
.command_line = MUST(String::join(' ', arguments.strings)), .command_line = MUST(String::join(' ', arguments.strings)),
@ -188,9 +188,9 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
.paint_viewport_scrollbars = disable_scrollbar_painting ? PaintViewportScrollbars::No : PaintViewportScrollbars::Yes, .paint_viewport_scrollbars = disable_scrollbar_painting ? PaintViewportScrollbars::No : PaintViewportScrollbars::Yes,
}; };
create_platform_options(m_chrome_options, m_web_content_options); create_platform_options(m_browser_options, m_web_content_options);
if (m_chrome_options.disable_sql_database == DisableSQLDatabase::No) { if (m_browser_options.disable_sql_database == DisableSQLDatabase::No) {
m_database = Database::create().release_value_but_fixme_should_propagate_errors(); m_database = Database::create().release_value_but_fixme_should_propagate_errors();
m_cookie_jar = CookieJar::create(*m_database).release_value_but_fixme_should_propagate_errors(); m_cookie_jar = CookieJar::create(*m_database).release_value_but_fixme_should_propagate_errors();
} else { } else {
@ -225,7 +225,7 @@ ErrorOr<NonnullRefPtr<WebContentClient>> Application::launch_web_content_process
void Application::launch_spare_web_content_process() void Application::launch_spare_web_content_process()
{ {
// Disable spare processes when debugging WebContent. Otherwise, it breaks running `gdb attach -p $(pidof WebContent)`. // Disable spare processes when debugging WebContent. Otherwise, it breaks running `gdb attach -p $(pidof WebContent)`.
if (chrome_options().debug_helper_process == ProcessType::WebContent) if (browser_options().debug_helper_process == ProcessType::WebContent)
return; return;
if (m_has_queued_task_to_launch_spare_web_content_process) if (m_has_queued_task_to_launch_spare_web_content_process)
@ -293,7 +293,7 @@ ErrorOr<void> Application::launch_image_decoder_server()
ErrorOr<void> Application::launch_devtools_server() ErrorOr<void> Application::launch_devtools_server()
{ {
VERIFY(!m_devtools); VERIFY(!m_devtools);
m_devtools = TRY(DevTools::DevToolsServer::create(*this, m_chrome_options.devtools_port)); m_devtools = TRY(DevTools::DevToolsServer::create(*this, m_browser_options.devtools_port));
return {}; return {};
} }

View file

@ -35,7 +35,7 @@ public:
static Application& the() { return *s_the; } static Application& the() { return *s_the; }
static ChromeOptions const& chrome_options() { return the().m_chrome_options; } static BrowserOptions const& browser_options() { return the().m_browser_options; }
static WebContentOptions& web_content_options() { return the().m_web_content_options; } static WebContentOptions& web_content_options() { return the().m_web_content_options; }
static Requests::RequestClient& request_server_client() { return *the().m_request_server_client; } static Requests::RequestClient& request_server_client() { return *the().m_request_server_client; }
@ -84,7 +84,7 @@ protected:
virtual void process_did_exit(Process&&); virtual void process_did_exit(Process&&);
virtual void create_platform_arguments(Core::ArgsParser&) { } virtual void create_platform_arguments(Core::ArgsParser&) { }
virtual void create_platform_options(ChromeOptions&, WebContentOptions&) { } virtual void create_platform_options(BrowserOptions&, WebContentOptions&) { }
virtual Optional<ByteString> ask_user_for_download_folder() const { return {}; } virtual Optional<ByteString> ask_user_for_download_folder() const { return {}; }
@ -127,7 +127,7 @@ private:
static Application* s_the; static Application* s_the;
ChromeOptions m_chrome_options; BrowserOptions m_browser_options;
WebContentOptions m_web_content_options; WebContentOptions m_web_content_options;
RefPtr<Requests::RequestClient> m_request_server_client; RefPtr<Requests::RequestClient> m_request_server_client;

View file

@ -118,13 +118,13 @@ void UIProcessConnectionFromClient::die()
void UIProcessConnectionFromClient::create_new_tab(Vector<ByteString> urls) void UIProcessConnectionFromClient::create_new_tab(Vector<ByteString> urls)
{ {
if (on_new_tab) if (on_new_tab)
on_new_tab(sanitize_urls(urls, Application::chrome_options().new_tab_page_url)); on_new_tab(sanitize_urls(urls, Application::browser_options().new_tab_page_url));
} }
void UIProcessConnectionFromClient::create_new_window(Vector<ByteString> urls) void UIProcessConnectionFromClient::create_new_window(Vector<ByteString> urls)
{ {
if (on_new_window) if (on_new_window)
on_new_window(sanitize_urls(urls, Application::chrome_options().new_tab_page_url)); on_new_window(sanitize_urls(urls, Application::browser_options().new_tab_page_url));
} }
} }

View file

@ -19,11 +19,11 @@ static ErrorOr<NonnullRefPtr<ClientType>> launch_server_process(
ClientArguments&&... client_arguments) ClientArguments&&... client_arguments)
{ {
auto process_type = WebView::process_type_from_name(server_name); auto process_type = WebView::process_type_from_name(server_name);
auto const& chrome_options = WebView::Application::chrome_options(); auto const& browser_options = WebView::Application::browser_options();
auto candidate_server_paths = TRY(get_paths_for_helper_process(server_name)); auto candidate_server_paths = TRY(get_paths_for_helper_process(server_name));
if (chrome_options.profile_helper_process == process_type) { if (browser_options.profile_helper_process == process_type) {
arguments.prepend({ arguments.prepend({
"--tool=callgrind"sv, "--tool=callgrind"sv,
"--instr-atstart=no"sv, "--instr-atstart=no"sv,
@ -31,13 +31,13 @@ static ErrorOr<NonnullRefPtr<ClientType>> launch_server_process(
}); });
} }
if (chrome_options.debug_helper_process == process_type) if (browser_options.debug_helper_process == process_type)
arguments.append("--wait-for-debugger"sv); arguments.append("--wait-for-debugger"sv);
for (auto [i, path] : enumerate(candidate_server_paths)) { for (auto [i, path] : enumerate(candidate_server_paths)) {
Core::ProcessSpawnOptions options { .name = server_name, .arguments = arguments }; Core::ProcessSpawnOptions options { .name = server_name, .arguments = arguments };
if (chrome_options.profile_helper_process == process_type) { if (browser_options.profile_helper_process == process_type) {
options.executable = "valgrind"sv; options.executable = "valgrind"sv;
options.search_for_executable_in_path = true; options.search_for_executable_in_path = true;
arguments[2] = path; arguments[2] = path;
@ -60,7 +60,7 @@ static ErrorOr<NonnullRefPtr<ClientType>> launch_server_process(
WebView::Application::the().add_child_process(move(process)); WebView::Application::the().add_child_process(move(process));
if (chrome_options.profile_helper_process == process_type) { if (browser_options.profile_helper_process == process_type) {
dbgln(); dbgln();
dbgln("\033[1;45mLaunched {} process under callgrind!\033[0m", server_name); dbgln("\033[1;45mLaunched {} process under callgrind!\033[0m", server_name);
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"); 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");
@ -187,7 +187,7 @@ ErrorOr<NonnullRefPtr<Requests::RequestClient>> launch_request_server_process()
arguments.append(s_ladybird_resource_root); arguments.append(s_ladybird_resource_root);
} }
for (auto const& certificate : WebView::Application::chrome_options().certificates) for (auto const& certificate : WebView::Application::browser_options().certificates)
arguments.append(ByteString::formatted("--certificate={}", certificate)); arguments.append(ByteString::formatted("--certificate={}", certificate));
if (auto server = mach_server_name(); server.has_value()) { if (auto server = mach_server_name(); server.has_value()) {
@ -196,7 +196,7 @@ ErrorOr<NonnullRefPtr<Requests::RequestClient>> launch_request_server_process()
} }
auto client = TRY(launch_server_process<Requests::RequestClient>("RequestServer"sv, move(arguments))); auto client = TRY(launch_server_process<Requests::RequestClient>("RequestServer"sv, move(arguments)));
WebView::Application::chrome_options().dns_settings.visit( WebView::Application::browser_options().dns_settings.visit(
[](WebView::SystemDNS) {}, [](WebView::SystemDNS) {},
[&](WebView::DNSOverTLS const& dns_over_tls) { [&](WebView::DNSOverTLS const& dns_over_tls) {
dbgln("Setting DNS server to {}:{} with TLS", dns_over_tls.server_address, dns_over_tls.port); dbgln("Setting DNS server to {}:{} with TLS", dns_over_tls.server_address, dns_over_tls.port);

View file

@ -59,7 +59,7 @@ using DNSSettings = Variant<SystemDNS, DNSOverTLS, DNSOverUDP>;
constexpr inline u16 default_devtools_port = 6000; constexpr inline u16 default_devtools_port = 6000;
struct ChromeOptions { struct BrowserOptions {
Vector<URL::URL> urls; Vector<URL::URL> urls;
Vector<ByteString> raw_urls; Vector<ByteString> raw_urls;
URL::URL new_tab_page_url; URL::URL new_tab_page_url;

View file

@ -604,10 +604,10 @@ void ViewImplementation::initialize_client(CreateNewClient create_new_client)
client().async_set_device_pixels_per_css_pixel(m_client_state.page_index, m_device_pixel_ratio); client().async_set_device_pixels_per_css_pixel(m_client_state.page_index, m_device_pixel_ratio);
client().async_set_system_visibility_state(m_client_state.page_index, m_system_visibility_state); client().async_set_system_visibility_state(m_client_state.page_index, m_system_visibility_state);
if (auto webdriver_content_ipc_path = Application::chrome_options().webdriver_content_ipc_path; webdriver_content_ipc_path.has_value()) if (auto webdriver_content_ipc_path = Application::browser_options().webdriver_content_ipc_path; webdriver_content_ipc_path.has_value())
client().async_connect_to_webdriver(m_client_state.page_index, *webdriver_content_ipc_path); client().async_connect_to_webdriver(m_client_state.page_index, *webdriver_content_ipc_path);
if (Application::chrome_options().allow_popups == AllowPopups::Yes) if (Application::browser_options().allow_popups == AllowPopups::Yes)
client().async_debug_request(m_client_state.page_index, "block-pop-ups"sv, "off"sv); client().async_debug_request(m_client_state.page_index, "block-pop-ups"sv, "off"sv);
if (auto const& user_agent_preset = Application::web_content_options().user_agent_preset; user_agent_preset.has_value()) if (auto const& user_agent_preset = Application::web_content_options().user_agent_preset; user_agent_preset.has_value())

View file

@ -286,7 +286,7 @@
self.info_bar = [[InfoBar alloc] init]; self.info_bar = [[InfoBar alloc] init];
} }
auto message = MUST(String::formatted("DevTools is enabled on port {}", WebView::Application::chrome_options().devtools_port)); auto message = MUST(String::formatted("DevTools is enabled on port {}", WebView::Application::browser_options().devtools_port));
[self.info_bar showWithMessage:Ladybird::string_to_ns_string(message) [self.info_bar showWithMessage:Ladybird::string_to_ns_string(message)
dismissButtonTooltip:@"Disable DevTools" dismissButtonTooltip:@"Disable DevTools"
@ -814,7 +814,7 @@
{ {
Tab* tab = nil; Tab* tab = nil;
for (auto const& url : WebView::Application::chrome_options().urls) { for (auto const& url : WebView::Application::browser_options().urls) {
auto activate_tab = tab == nil ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No; auto activate_tab = tab == nil ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No;
auto* controller = [self createNewTab:url auto* controller = [self createNewTab:url

View file

@ -100,8 +100,8 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
m_page_index = 0; m_page_index = 0;
m_settings = { m_settings = {
.scripting_enabled = WebView::Application::chrome_options().disable_scripting == WebView::DisableScripting::Yes ? NO : YES, .scripting_enabled = WebView::Application::browser_options().disable_scripting == WebView::DisableScripting::Yes ? NO : YES,
.block_popups = WebView::Application::chrome_options().allow_popups == WebView::AllowPopups::Yes ? NO : YES, .block_popups = WebView::Application::browser_options().allow_popups == WebView::AllowPopups::Yes ? NO : YES,
.autoplay_enabled = WebView::Application::web_content_options().enable_autoplay == WebView::EnableAutoplay::Yes ? YES : NO, .autoplay_enabled = WebView::Application::web_content_options().enable_autoplay == WebView::EnableAutoplay::Yes ? YES : NO,
}; };
@ -234,7 +234,7 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
self.tab.titlebarAppearsTransparent = NO; self.tab.titlebarAppearsTransparent = NO;
[delegate createNewTab:WebView::Application::chrome_options().new_tab_page_url [delegate createNewTab:WebView::Application::browser_options().new_tab_page_url
fromTab:[self tab] fromTab:[self tab]
activateTab:Web::HTML::ActivateTab::Yes]; activateTab:Web::HTML::ActivateTab::Yes];

View file

@ -58,8 +58,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
WebView::ChromeProcess chrome_process; WebView::ChromeProcess chrome_process;
if (auto const& chrome_options = WebView::Application::chrome_options(); chrome_options.force_new_process == WebView::ForceNewProcess::No) { if (auto const& browser_options = WebView::Application::browser_options(); browser_options.force_new_process == WebView::ForceNewProcess::No) {
auto disposition = TRY(chrome_process.connect(chrome_options.raw_urls, chrome_options.new_window)); auto disposition = TRY(chrome_process.connect(browser_options.raw_urls, browser_options.new_window));
if (disposition == WebView::ChromeProcess::ProcessDisposition::ExitProcess) { if (disposition == WebView::ChromeProcess::ProcessDisposition::ExitProcess) {
outln("Opening in existing process"); outln("Opening in existing process");

View file

@ -64,7 +64,7 @@ void Application::create_platform_arguments(Core::ArgsParser& args_parser)
}); });
} }
void Application::create_platform_options(WebView::ChromeOptions& chrome_options, WebView::WebContentOptions& web_content_options) void Application::create_platform_options(WebView::BrowserOptions& browser_options, WebView::WebContentOptions& web_content_options)
{ {
if (!test_root_path.is_empty()) { if (!test_root_path.is_empty()) {
// --run-tests implies --layout-test-mode. // --run-tests implies --layout-test-mode.
@ -73,7 +73,7 @@ void Application::create_platform_options(WebView::ChromeOptions& chrome_options
if (is_layout_test_mode) { if (is_layout_test_mode) {
// Allow window.open() to succeed for tests. // Allow window.open() to succeed for tests.
chrome_options.allow_popups = WebView::AllowPopups::Yes; browser_options.allow_popups = WebView::AllowPopups::Yes;
// Ensure consistent font rendering between operating systems. // Ensure consistent font rendering between operating systems.
web_content_options.force_fontconfig = WebView::ForceFontconfig::Yes; web_content_options.force_fontconfig = WebView::ForceFontconfig::Yes;

View file

@ -29,7 +29,7 @@ public:
} }
virtual void create_platform_arguments(Core::ArgsParser&) override; virtual void create_platform_arguments(Core::ArgsParser&) override;
virtual void create_platform_options(WebView::ChromeOptions&, WebView::WebContentOptions&) override; virtual void create_platform_options(WebView::BrowserOptions&, WebView::WebContentOptions&) override;
ErrorOr<void> launch_test_fixtures(); ErrorOr<void> launch_test_fixtures();

View file

@ -83,8 +83,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto& view = app->create_web_view(move(theme), window_size); auto& view = app->create_web_view(move(theme), window_size);
VERIFY(!WebView::Application::chrome_options().urls.is_empty()); VERIFY(!WebView::Application::browser_options().urls.is_empty());
auto const& url = WebView::Application::chrome_options().urls.first(); auto const& url = WebView::Application::browser_options().urls.first();
if (!url.is_valid()) { if (!url.is_valid()) {
warnln("Invalid URL: \"{}\"", url); warnln("Invalid URL: \"{}\"", url);
return Error::from_string_literal("Invalid URL"); return Error::from_string_literal("Invalid URL");
@ -99,7 +99,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
} }
RefPtr<Core::Timer> timer; RefPtr<Core::Timer> timer;
if (!WebView::Application::chrome_options().webdriver_content_ipc_path.has_value()) if (!WebView::Application::browser_options().webdriver_content_ipc_path.has_value())
timer = TRY(load_page_for_screenshot_and_exit(Core::EventLoop::current(), view, url, app->screenshot_timeout)); timer = TRY(load_page_for_screenshot_and_exit(Core::EventLoop::current(), view, url, app->screenshot_timeout));
return app->execute(); return app->execute();

View file

@ -21,7 +21,7 @@ Application::Application(Badge<WebView::Application>, Main::Arguments& arguments
{ {
} }
void Application::create_platform_options(WebView::ChromeOptions&, WebView::WebContentOptions& web_content_options) void Application::create_platform_options(WebView::BrowserOptions&, WebView::WebContentOptions& web_content_options)
{ {
web_content_options.config_path = Settings::the()->directory(); web_content_options.config_path = Settings::the()->directory();
} }

View file

@ -37,7 +37,7 @@ public:
void set_active_window(BrowserWindow& w) { m_active_window = &w; } void set_active_window(BrowserWindow& w) { m_active_window = &w; }
private: private:
virtual void create_platform_options(WebView::ChromeOptions&, WebView::WebContentOptions&) override; virtual void create_platform_options(WebView::BrowserOptions&, WebView::WebContentOptions&) override;
virtual Optional<ByteString> ask_user_for_download_folder() const override; virtual Optional<ByteString> ask_user_for_download_folder() const override;

View file

@ -574,7 +574,7 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
m_enable_scripting_action = new QAction("Enable Scripting", this); m_enable_scripting_action = new QAction("Enable Scripting", this);
m_enable_scripting_action->setCheckable(true); m_enable_scripting_action->setCheckable(true);
m_enable_scripting_action->setChecked(WebView::Application::chrome_options().disable_scripting == WebView::DisableScripting::No); m_enable_scripting_action->setChecked(WebView::Application::browser_options().disable_scripting == WebView::DisableScripting::No);
debug_menu->addAction(m_enable_scripting_action); debug_menu->addAction(m_enable_scripting_action);
QObject::connect(m_enable_scripting_action, &QAction::triggered, this, [this] { QObject::connect(m_enable_scripting_action, &QAction::triggered, this, [this] {
bool state = m_enable_scripting_action->isChecked(); bool state = m_enable_scripting_action->isChecked();
@ -596,7 +596,7 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
m_block_pop_ups_action = new QAction("Block Pop-ups", this); m_block_pop_ups_action = new QAction("Block Pop-ups", this);
m_block_pop_ups_action->setCheckable(true); m_block_pop_ups_action->setCheckable(true);
m_block_pop_ups_action->setChecked(WebView::Application::chrome_options().allow_popups == WebView::AllowPopups::No); m_block_pop_ups_action->setChecked(WebView::Application::browser_options().allow_popups == WebView::AllowPopups::No);
debug_menu->addAction(m_block_pop_ups_action); debug_menu->addAction(m_block_pop_ups_action);
QObject::connect(m_block_pop_ups_action, &QAction::triggered, this, [this] { QObject::connect(m_block_pop_ups_action, &QAction::triggered, this, [this] {
bool state = m_block_pop_ups_action->isChecked(); bool state = m_block_pop_ups_action->isChecked();
@ -738,7 +738,7 @@ void BrowserWindow::devtools_enabled()
m_enable_devtools_action->setText("Disable &DevTools"); m_enable_devtools_action->setText("Disable &DevTools");
statusBar()->addPermanentWidget(disable_button); statusBar()->addPermanentWidget(disable_button);
auto message = MUST(String::formatted("DevTools is enabled on port {}", WebView::Application::chrome_options().devtools_port)); auto message = MUST(String::formatted("DevTools is enabled on port {}", WebView::Application::browser_options().devtools_port));
statusBar()->showMessage(qstring_from_ak_string(message)); statusBar()->showMessage(qstring_from_ak_string(message));
} }

View file

@ -84,8 +84,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
WebView::ChromeProcess chrome_process; WebView::ChromeProcess chrome_process;
if (app->chrome_options().force_new_process == WebView::ForceNewProcess::No) { if (app->browser_options().force_new_process == WebView::ForceNewProcess::No) {
auto disposition = TRY(chrome_process.connect(app->chrome_options().raw_urls, app->chrome_options().new_window)); auto disposition = TRY(chrome_process.connect(app->browser_options().raw_urls, app->browser_options().new_window));
if (disposition == WebView::ChromeProcess::ProcessDisposition::ExitProcess) { if (disposition == WebView::ChromeProcess::ProcessDisposition::ExitProcess) {
outln("Opening in existing process"); outln("Opening in existing process");
@ -129,7 +129,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
app->new_window(urls); app->new_window(urls);
}; };
auto& window = app->new_window(app->chrome_options().urls); auto& window = app->new_window(app->browser_options().urls);
window.setWindowTitle("Ladybird"); window.setWindowTitle("Ladybird");
if (Ladybird::Settings::the()->is_maximized()) { if (Ladybird::Settings::the()->is_maximized()) {