From a9f8d4eadaf792eb6907a6ce7302acfe623635f6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 14 Mar 2023 17:12:09 +0300 Subject: [PATCH] LibWeb+LibWebView+WebContent+Ladybird: Add IPC call that opens new tab --- Ladybird/WebContentView.cpp | 5 +++++ Ladybird/WebContentView.h | 1 + Userland/Libraries/LibWeb/Page/Page.h | 1 + Userland/Libraries/LibWebView/OutOfProcessWebView.cpp | 8 ++++++++ Userland/Libraries/LibWebView/OutOfProcessWebView.h | 2 ++ Userland/Libraries/LibWebView/ViewImplementation.h | 1 + Userland/Libraries/LibWebView/WebContentClient.cpp | 5 +++++ Userland/Libraries/LibWebView/WebContentClient.h | 1 + Userland/Services/WebContent/PageHost.cpp | 5 +++++ Userland/Services/WebContent/PageHost.h | 1 + Userland/Services/WebContent/WebContentClient.ipc | 1 + Userland/Utilities/headless-browser.cpp | 1 + 12 files changed, 32 insertions(+) diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 6281e2b6d7..278ab0ff3d 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -975,6 +975,11 @@ void WebContentView::notify_server_did_close_browsing_context(Badge) +{ + return {}; +} + void WebContentView::notify_server_did_update_cookie(Badge, Web::Cookie::Cookie const& cookie) { if (on_update_cookie) diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h index 23a402de6b..4728e603d5 100644 --- a/Ladybird/WebContentView.h +++ b/Ladybird/WebContentView.h @@ -145,6 +145,7 @@ public: virtual DeprecatedString notify_server_did_request_cookie(Badge, const AK::URL& url, Web::Cookie::Source source) override; virtual void notify_server_did_set_cookie(Badge, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) override; virtual void notify_server_did_update_cookie(Badge, Web::Cookie::Cookie const& cookie) override; + virtual String notify_request_open_new_tab(Badge) override; virtual void notify_server_did_close_browsing_context(Badge) override; virtual void notify_server_did_update_resource_count(i32 count_waiting) override; virtual void notify_server_did_request_restore_window() override; diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index 199bac0a8e..05c15a18b4 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -201,6 +201,7 @@ public: virtual void page_did_set_cookie(const AK::URL&, Cookie::ParsedCookie const&, Cookie::Source) { } virtual void page_did_update_cookie(Web::Cookie::Cookie) { } virtual void page_did_update_resource_count(i32) { } + virtual String page_did_request_new_tab() { return {}; } virtual void page_did_close_browsing_context(HTML::BrowsingContext const&) { } virtual void request_file(FileRequest) = 0; diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index 1c6070825f..e230d6b632 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -59,6 +59,14 @@ void OutOfProcessWebView::handle_web_content_process_crash() load_html(builder.to_deprecated_string(), m_url); } +String OutOfProcessWebView::notify_request_open_new_tab(Badge) +{ + if (on_new_tab) + return on_new_tab(); + + return {}; +} + void OutOfProcessWebView::create_client() { m_client_state = {}; diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index 0a2eef0efc..f1465e9ecc 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -57,6 +57,7 @@ public: // In practice, this means that OOPWV may render scaled stale versions of the content while resizing. void set_content_scales_to_viewport(bool); + Function on_new_tab; Function on_close; Function on_context_menu_request; Function on_link_click; @@ -161,6 +162,7 @@ private: virtual DeprecatedString notify_server_did_request_cookie(Badge, const AK::URL& url, Web::Cookie::Source source) override; virtual void notify_server_did_set_cookie(Badge, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) override; virtual void notify_server_did_update_cookie(Badge, Web::Cookie::Cookie const& cookie) override; + virtual String notify_request_open_new_tab(Badge) override; virtual void notify_server_did_close_browsing_context(Badge) override; virtual void notify_server_did_update_resource_count(i32 count_waiting) override; virtual void notify_server_did_request_restore_window() override; diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 958932d52d..4bde4ed607 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -98,6 +98,7 @@ public: virtual DeprecatedString notify_server_did_request_cookie(Badge, const AK::URL& url, Web::Cookie::Source source) = 0; virtual void notify_server_did_set_cookie(Badge, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) = 0; virtual void notify_server_did_update_cookie(Badge, Web::Cookie::Cookie const& cookie) = 0; + virtual String notify_request_open_new_tab(Badge) = 0; virtual void notify_server_did_close_browsing_context(Badge) = 0; virtual void notify_server_did_update_resource_count(i32 count_waiting) = 0; virtual void notify_server_did_request_restore_window() = 0; diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp index 117bb9d420..25301251d2 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -240,6 +240,11 @@ void WebContentClient::did_update_cookie(Web::Cookie::Cookie const& cookie) m_view.notify_server_did_update_cookie({}, cookie); } +Messages::WebContentClient::DidRequestNewTabResponse WebContentClient::did_request_new_tab() +{ + return m_view.notify_request_open_new_tab({}); +} + void WebContentClient::did_close_browsing_context() { m_view.notify_server_did_close_browsing_context({}); diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index 17fcc86130..5cfdcefc19 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -79,6 +79,7 @@ private: virtual Messages::WebContentClient::DidRequestFullscreenWindowResponse did_request_fullscreen_window() override; virtual void did_request_file(DeprecatedString const& path, i32) override; virtual void did_finish_handling_input_event(bool event_was_accepted) override; + virtual Messages::WebContentClient::DidRequestNewTabResponse did_request_new_tab() override; ViewImplementation& m_view; }; diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp index 582d731735..069124ffdd 100644 --- a/Userland/Services/WebContent/PageHost.cpp +++ b/Userland/Services/WebContent/PageHost.cpp @@ -377,6 +377,11 @@ void PageHost::page_did_update_resource_count(i32 count_waiting) m_client.async_did_update_resource_count(count_waiting); } +String PageHost::page_did_request_new_tab() +{ + return m_client.did_request_new_tab(); +} + void PageHost::page_did_close_browsing_context(Web::HTML::BrowsingContext const&) { m_client.async_did_close_browsing_context(); diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h index fafbb8f676..447774796f 100644 --- a/Userland/Services/WebContent/PageHost.h +++ b/Userland/Services/WebContent/PageHost.h @@ -98,6 +98,7 @@ private: virtual void page_did_set_cookie(const URL&, Web::Cookie::ParsedCookie const&, Web::Cookie::Source) override; virtual void page_did_update_cookie(Web::Cookie::Cookie) override; virtual void page_did_update_resource_count(i32) override; + virtual String page_did_request_new_tab() override; virtual void page_did_close_browsing_context(Web::HTML::BrowsingContext const&) override; virtual void request_file(Web::FileRequest) override; diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index 2f6423b343..cc7c201291 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -55,6 +55,7 @@ endpoint WebContentClient did_request_fullscreen_window() => (Gfx::IntRect window_rect) did_request_file(DeprecatedString path, i32 request_id) =| did_finish_handling_input_event(bool event_was_accepted) =| + did_request_new_tab() => (String handle) did_output_js_console_message(i32 message_index) =| did_get_js_console_messages(i32 start_index, Vector message_types, Vector messages) =| diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 5ce84c9c39..6cbe8fee1e 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -132,6 +132,7 @@ private: DeprecatedString notify_server_did_request_cookie(Badge, const URL&, Web::Cookie::Source) override { return {}; } void notify_server_did_set_cookie(Badge, const URL&, Web::Cookie::ParsedCookie const&, Web::Cookie::Source) override { } void notify_server_did_update_cookie(Badge, Web::Cookie::Cookie const&) override { } + String notify_request_open_new_tab(Badge) override { return {}; } void notify_server_did_close_browsing_context(Badge) override { } void notify_server_did_update_resource_count(i32) override { } void notify_server_did_request_restore_window() override { }