diff --git a/Ladybird/Qt/BrowserWindow.h b/Ladybird/Qt/BrowserWindow.h index 5e6caee269e..71694f82539 100644 --- a/Ladybird/Qt/BrowserWindow.h +++ b/Ladybird/Qt/BrowserWindow.h @@ -35,6 +35,7 @@ public: WebContentView& view() const { return m_current_tab->view(); } int tab_index(Tab*); + Tab& create_new_tab(Web::HTML::ActivateTab activate_tab); QAction& go_back_action() { @@ -117,7 +118,6 @@ private: virtual void wheelEvent(QWheelEvent*) override; virtual void closeEvent(QCloseEvent*) override; - Tab& create_new_tab(Web::HTML::ActivateTab activate_tab); Tab& create_new_tab(Web::HTML::ActivateTab, Tab& parent, Web::HTML::WebViewHints, Optional page_index); void initialize_tab(Tab*); diff --git a/Ladybird/Qt/main.cpp b/Ladybird/Qt/main.cpp index c49a0d83231..e2d59ddbd89 100644 --- a/Ladybird/Qt/main.cpp +++ b/Ladybird/Qt/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,21 @@ static ErrorOr handle_attached_debugger() return {}; } +static Vector sanitize_urls(Vector const& raw_urls) +{ + Vector sanitized_urls; + for (auto const& raw_url : raw_urls) { + if (auto url = WebView::sanitize_url(raw_url); url.has_value()) + sanitized_urls.append(url.release_value()); + } + + if (sanitized_urls.is_empty()) { + auto new_tab_page = Ladybird::Settings::the()->new_tab_page(); + sanitized_urls.append(ak_string_from_qstring(new_tab_page)); + } + return sanitized_urls; +} + ErrorOr serenity_main(Main::Arguments arguments) { AK::set_rich_debug_enabled(true); @@ -76,7 +92,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"); - Vector raw_urls; + Vector raw_urls; StringView webdriver_content_ipc_path; Vector certificates; bool enable_callgrind_profiling = false; @@ -103,6 +119,17 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_option(expose_internals_object, "Expose internals object", "expose-internals-object"); args_parser.parse(arguments); + WebView::ChromeProcess chrome_process; + auto new_window = false; + if (TRY(chrome_process.connect(raw_urls, new_window)) == WebView::ChromeProcess::ProcessDisposition::ExitProcess) { + outln("Opening in existing process"); + return 0; + } + + chrome_process.on_new_window = [](auto const& urls) { + dbgln("asked to open new window with urls: {}", urls); + }; + WebView::ProcessManager::initialize(); #if defined(AK_OS_MACOS) @@ -124,18 +151,6 @@ ErrorOr serenity_main(Main::Arguments arguments) auto cookie_jar = database ? TRY(WebView::CookieJar::create(*database)) : WebView::CookieJar::create(); - Vector initial_urls; - - for (auto const& raw_url : raw_urls) { - if (auto url = WebView::sanitize_url(raw_url); url.has_value()) - initial_urls.append(url.release_value()); - } - - if (initial_urls.is_empty()) { - auto new_tab_page = Ladybird::Settings::the()->new_tab_page(); - initial_urls.append(ak_string_from_qstring(new_tab_page)); - } - // NOTE: WebWorker *always* needs a request server connection, even if WebContent uses Qt Networking // FIXME: Create an abstraction to re-spawn the RequestServer and re-hook up its client hooks to each tab on crash auto request_server_paths = TRY(get_paths_for_helper_process("RequestServer"sv)); @@ -156,9 +171,19 @@ ErrorOr serenity_main(Main::Arguments arguments) .expose_internals_object = expose_internals_object ? Ladybird::ExposeInternalsObject::Yes : Ladybird::ExposeInternalsObject::No, }; - Ladybird::BrowserWindow window(initial_urls, cookie_jar, web_content_options, webdriver_content_ipc_path); + Ladybird::BrowserWindow window(sanitize_urls(raw_urls), cookie_jar, web_content_options, webdriver_content_ipc_path); window.setWindowTitle("Ladybird"); + chrome_process.on_new_tab = [&](auto const& raw_urls) { + auto urls = sanitize_urls(raw_urls); + for (size_t i = 0; i < urls.size(); ++i) { + window.new_tab_from_url(urls[i], (i == 0) ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No); + } + window.show(); + window.activateWindow(); + window.raise(); + }; + app.on_open_file = [&](auto file_url) { window.view().load(file_url); };