From 7bf842a974da8630cc47ae07bdf5ae78038220dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Harald=20J=C3=B8rgensen?= <58829763+adamjoer@users.noreply.github.com> Date: Mon, 11 Sep 2023 15:31:23 +0200 Subject: [PATCH] Ladybird: Allow opening multiple URLs at once from the command line Each URL is opened in a separate tab on startup, and the active tab is the first URL supplied. --- Ladybird/Qt/BrowserWindow.cpp | 12 ++++++++---- Ladybird/Qt/BrowserWindow.h | 2 +- Ladybird/Qt/main.cpp | 15 +++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index bca7d0d817..33bccd8173 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -39,7 +39,7 @@ static QIcon const& app_icon() return icon; } -BrowserWindow::BrowserWindow(Optional const& initial_url, WebView::CookieJar& cookie_jar, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling, UseLagomNetworking use_lagom_networking) +BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::CookieJar& cookie_jar, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling, UseLagomNetworking use_lagom_networking) : m_cookie_jar(cookie_jar) , m_webdriver_content_ipc_path(webdriver_content_ipc_path) , m_enable_callgrind_profiling(enable_callgrind_profiling) @@ -403,9 +403,13 @@ BrowserWindow::BrowserWindow(Optional const& initial_url, WebView::CookieJa m_go_forward_action->setEnabled(false); m_reload_action->setEnabled(false); - if (initial_url.has_value()) { - auto initial_url_string = qstring_from_ak_deprecated_string(initial_url->serialize()); - new_tab(initial_url_string, Web::HTML::ActivateTab::Yes); + if (!initial_urls.is_empty()) { + bool is_first_tab = true; + for (auto const& url : initial_urls) { + auto initial_url_string = qstring_from_ak_deprecated_string(url.serialize()); + new_tab(initial_url_string, is_first_tab ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No); + is_first_tab = false; + } } else { new_tab(Settings::the()->new_tab_page(), Web::HTML::ActivateTab::Yes); } diff --git a/Ladybird/Qt/BrowserWindow.h b/Ladybird/Qt/BrowserWindow.h index 33eca72ca5..cd344425aa 100644 --- a/Ladybird/Qt/BrowserWindow.h +++ b/Ladybird/Qt/BrowserWindow.h @@ -25,7 +25,7 @@ class WebContentView; class BrowserWindow : public QMainWindow { Q_OBJECT public: - explicit BrowserWindow(Optional const& initial_url, WebView::CookieJar&, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling, UseLagomNetworking); + explicit BrowserWindow(Vector const& initial_urls, WebView::CookieJar&, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling, UseLagomNetworking); WebContentView& view() const { return m_current_tab->view(); } diff --git a/Ladybird/Qt/main.cpp b/Ladybird/Qt/main.cpp index 7ba7246021..726764434a 100644 --- a/Ladybird/Qt/main.cpp +++ b/Ladybird/Qt/main.cpp @@ -70,7 +70,7 @@ ErrorOr serenity_main(Main::Arguments arguments) Gfx::FontDatabase::set_default_font_query("Katica 10 400 0"); Gfx::FontDatabase::set_fixed_width_font_query("Csilla 10 400 0"); - StringView raw_url; + Vector raw_urls; StringView webdriver_content_ipc_path; bool enable_callgrind_profiling = false; bool enable_sql_database = false; @@ -78,7 +78,7 @@ ErrorOr serenity_main(Main::Arguments arguments) Core::ArgsParser args_parser; args_parser.set_general_help("The Ladybird web browser :^)"); - args_parser.add_positional_argument(raw_url, "URL to open", "url", Core::ArgsParser::Required::No); + args_parser.add_positional_argument(raw_urls, "URLs to open", "url", Core::ArgsParser::Required::No); args_parser.add_option(webdriver_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path", Core::ArgsParser::OptionHideMode::CommandLineAndMarkdown); args_parser.add_option(enable_callgrind_profiling, "Enable Callgrind profiling", "enable-callgrind-profiling", 'P'); args_parser.add_option(enable_sql_database, "Enable SQL database", "enable-sql-database", 0); @@ -103,11 +103,14 @@ ErrorOr serenity_main(Main::Arguments arguments) auto cookie_jar = database ? TRY(WebView::CookieJar::create(*database)) : WebView::CookieJar::create(); - Optional initial_url; - if (auto url = TRY(get_formatted_url(raw_url)); url.is_valid()) - initial_url = move(url); + Vector initial_urls; - Ladybird::BrowserWindow window(initial_url, cookie_jar, webdriver_content_ipc_path, enable_callgrind_profiling ? WebView::EnableCallgrindProfiling::Yes : WebView::EnableCallgrindProfiling::No, use_lagom_networking ? Ladybird::UseLagomNetworking::Yes : Ladybird::UseLagomNetworking::No); + for (auto const& raw_url : raw_urls) { + if (auto url = TRY(get_formatted_url(raw_url)); url.is_valid()) + initial_urls.append(move(url)); + } + + 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); window.setWindowTitle("Ladybird"); if (Ladybird::Settings::the()->is_maximized()) {