瀏覽代碼

Ladybird: Implement `notify_request_open_new_tab`

Aliaksandr Kalenik 2 年之前
父節點
當前提交
640864b32e
共有 4 個文件被更改,包括 13 次插入2 次删除
  1. 8 1
      Ladybird/BrowserWindow.cpp
  2. 1 1
      Ladybird/BrowserWindow.h
  3. 3 0
      Ladybird/WebContentView.cpp
  4. 1 0
      Ladybird/WebContentView.h

+ 8 - 1
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<Tab>(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)

+ 1 - 1
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();

+ 3 - 0
Ladybird/WebContentView.cpp

@@ -977,6 +977,9 @@ void WebContentView::notify_server_did_close_browsing_context(Badge<WebContentCl
 
 String WebContentView::notify_request_open_new_tab(Badge<WebContentClient>)
 {
+    if (on_new_tab)
+        return on_new_tab();
+
     return {};
 }
 

+ 1 - 0
Ladybird/WebContentView.h

@@ -49,6 +49,7 @@ public:
     explicit WebContentView(StringView webdriver_content_ipc_path);
     virtual ~WebContentView() override;
 
+    Function<String()> on_new_tab;
     Function<void()> on_close;
     Function<void(Gfx::IntPoint screen_position)> on_context_menu_request;
     Function<void(const AK::URL&, DeprecatedString const& target, unsigned modifiers)> on_link_click;