Преглед изворни кода

Ladybird: Only load a single URL at launch

When we launch Ladybird, we currently:

1. Create a BrowserWindow, whose constructor navigates to the configured
   new tab page URL.
2. Then navigate to either "about:blank" or whatever URL is provided via
   the command line.

This patch removes step 2 and forwards the URL from the command line (if
any) to BrowserWindow. BrowserWindow's constructor then either navigates
to that URL or the new tab page URL.
Timothy Flynn пре 2 година
родитељ
комит
6c7422e8b7
3 измењених фајлова са 13 додато и 10 уклоњено
  1. 7 2
      Ladybird/Qt/BrowserWindow.cpp
  2. 1 1
      Ladybird/Qt/BrowserWindow.h
  3. 5 7
      Ladybird/Qt/main.cpp

+ 7 - 2
Ladybird/Qt/BrowserWindow.cpp

@@ -40,7 +40,7 @@ static QIcon const& app_icon()
     return icon;
 }
 
-BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling, UseLagomNetworking use_lagom_networking)
+BrowserWindow::BrowserWindow(Optional<URL> const& initial_url, Browser::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)
@@ -397,7 +397,12 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive
     m_go_back_action->setEnabled(false);
     m_go_forward_action->setEnabled(false);
 
-    new_tab(s_settings->new_tab_page(), Web::HTML::ActivateTab::Yes);
+    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);
+    } else {
+        new_tab(s_settings->new_tab_page(), Web::HTML::ActivateTab::Yes);
+    }
 
     setCentralWidget(m_tabs_container);
     setContextMenuPolicy(Qt::PreventContextMenu);

+ 1 - 1
Ladybird/Qt/BrowserWindow.h

@@ -28,7 +28,7 @@ class WebContentView;
 class BrowserWindow : public QMainWindow {
     Q_OBJECT
 public:
-    explicit BrowserWindow(Browser::CookieJar&, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling, UseLagomNetworking);
+    explicit BrowserWindow(Optional<URL> const& initial_url, Browser::CookieJar&, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling, UseLagomNetworking);
 
     WebContentView& view() const { return m_current_tab->view(); }
 

+ 5 - 7
Ladybird/Qt/main.cpp

@@ -107,17 +107,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 
     auto cookie_jar = database ? TRY(Browser::CookieJar::create(*database)) : Browser::CookieJar::create();
 
+    Optional<URL> initial_url;
+    if (auto url = TRY(get_formatted_url(raw_url)); url.is_valid())
+        initial_url = move(url);
+
     Ladybird::s_settings = adopt_own_if_nonnull(new Ladybird::Settings());
-    Ladybird::BrowserWindow window(cookie_jar, webdriver_content_ipc_path, enable_callgrind_profiling ? WebView::EnableCallgrindProfiling::Yes : WebView::EnableCallgrindProfiling::No, use_lagom_networking ? Ladybird::UseLagomNetworking::Yes : Ladybird::UseLagomNetworking::No);
+    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);
     window.setWindowTitle("Ladybird");
     window.resize(800, 600);
     window.show();
 
-    if (auto url = TRY(get_formatted_url(raw_url)); url.is_valid()) {
-        window.view().load(url);
-    } else {
-        window.view().load("about:blank"sv);
-    }
-
     return event_loop.exec();
 }