|
@@ -17,6 +17,7 @@
|
|
|
#include <LibCore/System.h>
|
|
|
#include <LibGfx/Font/FontDatabase.h>
|
|
|
#include <LibMain/Main.h>
|
|
|
+#include <LibWebView/ChromeProcess.h>
|
|
|
#include <LibWebView/CookieJar.h>
|
|
|
#include <LibWebView/Database.h>
|
|
|
#include <LibWebView/ProcessManager.h>
|
|
@@ -58,6 +59,21 @@ static ErrorOr<void> handle_attached_debugger()
|
|
|
return {};
|
|
|
}
|
|
|
|
|
|
+static Vector<URL::URL> sanitize_urls(Vector<ByteString> const& raw_urls)
|
|
|
+{
|
|
|
+ Vector<URL::URL> 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<int> serenity_main(Main::Arguments arguments)
|
|
|
{
|
|
|
AK::set_rich_debug_enabled(true);
|
|
@@ -76,7 +92,7 @@ ErrorOr<int> 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<StringView> raw_urls;
|
|
|
+ Vector<ByteString> raw_urls;
|
|
|
StringView webdriver_content_ipc_path;
|
|
|
Vector<ByteString> certificates;
|
|
|
bool enable_callgrind_profiling = false;
|
|
@@ -103,6 +119,17 @@ ErrorOr<int> 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<int> serenity_main(Main::Arguments arguments)
|
|
|
|
|
|
auto cookie_jar = database ? TRY(WebView::CookieJar::create(*database)) : WebView::CookieJar::create();
|
|
|
|
|
|
- Vector<URL::URL> 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<int> 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);
|
|
|
};
|