diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index 112c91fdad..6b6a7d4f08 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -333,7 +333,7 @@ void BrowserWindow::debug_request(DeprecatedString const& request, DeprecatedStr m_current_tab->debug_request(request, argument); } -void BrowserWindow::new_tab(QString const& url, Activate activate) +Tab& BrowserWindow::new_tab(QString const& url, Activate activate) { auto tab = make(this, m_webdriver_content_ipc_path); auto tab_ptr = tab.ptr(); @@ -358,6 +358,11 @@ void BrowserWindow::new_tab(QString const& url, Activate activate) new_tab(urls[i].toString(), Activate::No); }); + tab_ptr->view().on_new_tab = [this]() { + auto& tab = new_tab("about:blank", Activate::Yes); + return tab.view().handle(); + }; + tab_ptr->view().on_get_all_cookies = [this](auto const& url) { return m_cookie_jar.get_all_cookies(url); }; @@ -386,6 +391,8 @@ void BrowserWindow::new_tab(QString const& url, Activate activate) // We make it HistoryNavigation so that the initial page doesn't get added to the history. tab_ptr->navigate(url, Tab::LoadType::HistoryNavigation); } + + return *tab_ptr; } void BrowserWindow::close_tab(int index) diff --git a/Ladybird/BrowserWindow.h b/Ladybird/BrowserWindow.h index 29e85aad44..dc8f9b80fb 100644 --- a/Ladybird/BrowserWindow.h +++ b/Ladybird/BrowserWindow.h @@ -39,7 +39,7 @@ public: public slots: void tab_title_changed(int index, QString const&); void tab_favicon_changed(int index, QIcon icon); - void new_tab(QString const&, Activate); + Tab& new_tab(QString const&, Activate); void close_tab(int index); void close_current_tab(); void open_next_tab(); diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 278ab0ff3d..7214476531 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -977,6 +977,9 @@ void WebContentView::notify_server_did_close_browsing_context(Badge) { + if (on_new_tab) + return on_new_tab(); + return {}; } diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h index 4728e603d5..421db81a70 100644 --- a/Ladybird/WebContentView.h +++ b/Ladybird/WebContentView.h @@ -49,6 +49,7 @@ public: explicit WebContentView(StringView webdriver_content_ipc_path); virtual ~WebContentView() override; + Function on_new_tab; Function on_close; Function on_context_menu_request; Function on_link_click;