Truly independent web browser
Hub+UI/Qt: Let the UI do what takes its windows and the desktop
Andreas Kling8897497ce298
diff --git a/Services/Hub/Application.cpp b/Services/Hub/Application.cppindex ef17058a919..0f91433e56f 100644--- a/Services/Hub/Application.cpp+++ b/Services/Hub/Application.cpp@@ -7,6 +7,7 @@#include <Hub/ActionMirror.h>#include <Hub/Application.h>#include <Hub/ConnectionFromUI.h>+#include <Hub/Proxies.h>#include <LibCore/EventLoop.h>#include <LibWebView/WebContentPage.h>@@ -260,10 +261,8 @@ NonnullOwnPtr<WebView::MicrophoneAuthorizer> Application::create_microphone_authNonnullOwnPtr<WebView::NotificationBackend> Application::create_notification_backend(){- if (m_host) {- if (auto backend = m_host->create_notification_backend())- return backend.release_nonnull();- }+ if (ConnectionFromUI::the())+ return make<NotificationBackendInUI>();return WebView::Application::create_notification_backend();}@@ -428,22 +427,6 @@ Optional<String> Application::system_font_family() constreturn WebView::Application::system_font_family();}-void Application::focus_page_from_notification(WebView::WebContentPage& page)-{- if (m_host)- m_host->focus_page_from_notification(page);- else- WebView::Application::focus_page_from_notification(page);-}--void Application::open_url_in_new_tab_from_notification(URL::URL const& url, Web::PageId originating_page, WebView::CanonicalTraversable* canonical_traversable, WebView::IsPrivate is_private)-{- if (m_host)- m_host->open_url_in_new_tab_from_notification(url, originating_page, canonical_traversable, is_private);- else- WebView::Application::open_url_in_new_tab_from_notification(url, originating_page, canonical_traversable, is_private);-}-bool Application::supports_picture_in_picture() const{if (m_host)@@ -453,23 +436,74 @@ bool Application::supports_picture_in_picture() constOwnPtr<WebView::PictureInPictureWindow> Application::create_picture_in_picture_window(WebView::WebContentPage& requesting_page, WebView::CanonicalTraversable& traversable, Gfx::IntSize video_size){- if (!m_host)+ if (!ConnectionFromUI::the())return WebView::Application::create_picture_in_picture_window(requesting_page, traversable, video_size);auto& owner_view = static_cast<View&>(requesting_page.view());auto initial_state = owner_view.initial_state_for_related_view();initial_state.owner_view_id = owner_view.view_id();initial_state.is_tab = false;+ auto screen_size = owner_view.screen_size();auto& view = create_view(move(initial_state), traversable);- return m_host->create_picture_in_picture_window(owner_view, view.view_id(), video_size);+ return make<PictureInPictureWindowInUI>(view, owner_view.view_id(), video_size, WebView::PictureInPictureWindow::initial_size(video_size, screen_size));+}++void Application::focus_page_from_notification(WebView::WebContentPage& page)+{+ if (auto* ui = ConnectionFromUI::the())+ ui->async_app_focus_view_from_notification(page.view().view_id());+}++void Application::open_url_in_new_tab_from_notification(URL::URL const& url, Web::PageId, WebView::CanonicalTraversable* canonical_traversable, WebView::IsPrivate is_private)+{+ Optional<u64> view_id;+ if (canonical_traversable) {+ if (auto view = canonical_traversable->view(); view.has_value())+ view_id = view->view_id();+ }+ if (auto* ui = ConnectionFromUI::the())+ ui->async_app_open_url_in_new_tab_from_notification(url, view_id, is_private);}void Application::resolve_external_url_handler(URL::URL const& url, WebView::ExternalURLHandlerCallback callback) const{- if (m_host)- m_host->resolve_external_url_handler(url, move(callback));- else+ auto* ui = ConnectionFromUI::the();+ if (!ui) {WebView::Application::resolve_external_url_handler(url, move(callback));+ return;+ }+ auto request_id = m_next_ui_request_id++;+ m_pending_external_url_handlers.set(request_id, move(callback));+ ui->async_external_url_resolve_handler(request_id, url);+}++void Application::did_resolve_external_url_handler(u64 request_id, Optional<u64> handler_id, String application_name, bool is_ladybird)+{+ auto callback = m_pending_external_url_handlers.take(request_id);+ if (!callback.has_value())+ return;+ if (handler_id.has_value())+ (*callback)(adopt_ref(*new ExternalURLHandlerInUI(*handler_id, move(application_name), is_ladybird)));+ else+ (*callback)(nullptr);+}++void Application::launch_external_url(u64 handler_id, URL::URL const& url, Function<void(bool)> callback) const+{+ auto* ui = ConnectionFromUI::the();+ if (!ui) {+ callback(false);+ return;+ }+ auto request_id = m_next_ui_request_id++;+ m_pending_external_url_launches.set(request_id, move(callback));+ ui->async_external_url_launch(handler_id, request_id, url);+}++void Application::did_launch_external_url(u64 request_id, bool launched)+{+ if (auto callback = m_pending_external_url_launches.take(request_id); callback.has_value())+ (*callback)(launched);}bool Application::supports_clipboard_type(WebView::Application::ClipboardType type) constdiff --git a/Services/Hub/Application.h b/Services/Hub/Application.hindex f28f52f23ea..9f41652218a 100644--- a/Services/Hub/Application.h+++ b/Services/Hub/Application.h@@ -26,17 +26,12 @@ public:// The platform's own, if it has one.virtual OwnPtr<WebView::MicrophoneAuthorizer> create_microphone_authorizer() = 0;- virtual OwnPtr<WebView::NotificationBackend> create_notification_backend() = 0;virtual void create_platform_actions() = 0;virtual Optional<String> ui_font_family() const = 0;virtual Web::CSS::PreferredColorScheme interface_color_scheme() const = 0;virtual Optional<String> system_font_family() const = 0;- virtual void focus_page_from_notification(WebView::WebContentPage& page) = 0;- virtual void open_url_in_new_tab_from_notification(URL::URL const& url, Web::PageId originating_page, WebView::CanonicalTraversable* canonical_traversable, WebView::IsPrivate is_private) = 0;virtual bool supports_picture_in_picture() const = 0;- virtual OwnPtr<WebView::PictureInPictureWindow> create_picture_in_picture_window(WebView::ViewImplementation& owner_view, u64 view_id, Gfx::IntSize video_size) = 0;- virtual void resolve_external_url_handler(URL::URL const& url, WebView::ExternalURLHandlerCallback callback) const = 0;virtual bool supports_clipboard_type(WebView::Application::ClipboardType type) const = 0;virtual bool supports_system_menu_bar() const = 0;virtual bool supports_vertical_tabs() const = 0;@@ -64,6 +59,9 @@ public:void destroy_all_views() { m_views.clear(); }void set_active_view(Optional<u64> view_id);+ void did_resolve_external_url_handler(u64 request_id, Optional<u64> handler_id, String application_name, bool is_ladybird);+ void launch_external_url(u64 handler_id, URL::URL const&, Function<void(bool)>) const;+ void did_launch_external_url(u64 request_id, bool launched);void did_read_bookmarks_for_all_tabs(u64 request_id, Vector<WebView::BookmarkItem::Bookmark>);void did_get_bookmark_dialog_result(u64 request_id, Optional<Hub::BookmarkDialogResult>);void set_bookmark_context_menu_item(Optional<String> item_id, Optional<String> target_folder_id, Optional<String> parent_folder_id);@@ -143,6 +141,8 @@ private:mutable HashMap<u64, NonnullRefPtr<Core::Promise<ByteString>>> m_pending_download_paths;mutable HashMap<u64, Function<void(Vector<WebView::BookmarkItem::Bookmark>)>> m_pending_bookmarks_for_all_tabs;mutable HashMap<u64, NonnullRefPtr<BookmarkPromise>> m_pending_bookmark_dialogs;+ mutable HashMap<u64, WebView::ExternalURLHandlerCallback> m_pending_external_url_handlers;+ mutable HashMap<u64, Function<void(bool)>> m_pending_external_url_launches;mutable u64 m_next_ui_request_id { 1 };NonnullRefPtr<BookmarkPromise> display_bookmark_dialog(BookmarkDialogKind, Optional<String> item_id, Optional<String> default_title, Optional<String> folder_id) const;diff --git a/Services/Hub/CMakeLists.txt b/Services/Hub/CMakeLists.txtindex ccd1330aafa..7f38989a8e2 100644--- a/Services/Hub/CMakeLists.txt+++ b/Services/Hub/CMakeLists.txt@@ -6,6 +6,7 @@ set(SOURCESActionMirror.cppApplication.cppConnectionFromUI.cpp+ Proxies.cppView.cpp)diff --git a/Services/Hub/ConnectionFromUI.cpp b/Services/Hub/ConnectionFromUI.cppindex 8e5504d45c8..693219e270a 100644--- a/Services/Hub/ConnectionFromUI.cpp+++ b/Services/Hub/ConnectionFromUI.cpp@@ -7,6 +7,7 @@#include <Hub/ActionMirror.h>#include <Hub/Application.h>#include <Hub/ConnectionFromUI.h>+#include <Hub/Proxies.h>namespace Hub {@@ -280,6 +281,52 @@ void ConnectionFromUI::omnibox_record_engagement(u64 client_id, WebView::Omniboxautocomplete->record_engagement(move(engagement));}+void ConnectionFromUI::pip_did_resize(u64 view_id, Gfx::IntSize size)+{+ if (auto* window = PictureInPictureWindowInUI::find(view_id))+ window->did_resize(size);+}++void ConnectionFromUI::pip_did_close(u64 view_id, bool video_keeps_playing)+{+ if (auto* window = PictureInPictureWindowInUI::find(view_id))+ window->did_close(video_keeps_playing);+}++void ConnectionFromUI::notification_shown(u64 id)+{+ if (auto* backend = NotificationBackendInUI::the(); backend && backend->on_shown)+ backend->on_shown(id);+}++void ConnectionFromUI::notification_failed(u64 id)+{+ if (auto* backend = NotificationBackendInUI::the(); backend && backend->on_failed)+ backend->on_failed(id);+}++void ConnectionFromUI::notification_clicked(u64 id)+{+ if (auto* backend = NotificationBackendInUI::the(); backend && backend->on_clicked)+ backend->on_clicked(id);+}++void ConnectionFromUI::notification_closed(u64 id, bool by_user)+{+ if (auto* backend = NotificationBackendInUI::the(); backend && backend->on_closed)+ backend->on_closed(id, by_user ? WebView::NotificationBackend::ByUser::Yes : WebView::NotificationBackend::ByUser::No);+}++void ConnectionFromUI::external_url_handler_resolved(u64 request_id, Optional<u64> handler_id, String application_name, bool is_ladybird)+{+ Application::the().did_resolve_external_url_handler(request_id, handler_id, move(application_name), is_ladybird);+}++void ConnectionFromUI::external_url_launched(u64 request_id, bool launched)+{+ Application::the().did_launch_external_url(request_id, launched);+}+void ConnectionFromUI::update_settings(ByteString settings_json){auto settings = JsonValue::from_string(settings_json);diff --git a/Services/Hub/ConnectionFromUI.h b/Services/Hub/ConnectionFromUI.hindex bbee37d622a..b5e57a09f92 100644--- a/Services/Hub/ConnectionFromUI.h+++ b/Services/Hub/ConnectionFromUI.h@@ -47,6 +47,14 @@ private:virtual void download_removed(u64 id, WebView::IsPrivate) override;// ^HubServerEndpoint+ virtual void pip_did_resize(u64 view_id, Gfx::IntSize size) override;+ virtual void pip_did_close(u64 view_id, bool video_keeps_playing) override;+ virtual void notification_shown(u64 id) override;+ virtual void notification_failed(u64 id) override;+ virtual void notification_clicked(u64 id) override;+ virtual void notification_closed(u64 id, bool by_user) override;+ virtual void external_url_handler_resolved(u64 request_id, Optional<u64> handler_id, String application_name, bool is_ladybird) override;+ virtual void external_url_launched(u64 request_id, bool launched) override;virtual void omnibox_open(u64 client_id, WebView::IsPrivate is_private) override;virtual void omnibox_close(u64 client_id) override;virtual void omnibox_query(u64 client_id, u64 query_id, String query, u64 max_suggestions) override;diff --git a/Services/Hub/HubClient.ipc b/Services/Hub/HubClient.ipcindex 7eb35fb9c55..acfffd35059 100644--- a/Services/Hub/HubClient.ipc+++ b/Services/Hub/HubClient.ipc@@ -7,6 +7,7 @@#include <LibGfx/SharedImage.h>#include <LibGfx/Size.h>#include <LibURL/Origin.h>+#include <LibWebCommon/NotificationsAPI/NotificationData.h>#include <LibURL/URL.h>#include <LibWebCommon/WebView/DictionaryLookup.h>#include <LibWebCommon/HTML/FileFilter.h>@@ -239,6 +240,17 @@ struct Hub::ViewState {// What the Hub tells the UI.endpoint HubClient{+ pip_open(u64 view_id, u64 owner_view_id, Gfx::IntSize video_size) =|+ pip_hide(u64 view_id) =|+ pip_set_video_size(u64 view_id, Gfx::IntSize video_size) =|+ pip_close(u64 view_id) =|+ notification_show(u64 id, u64 page_id, Optional<u64> replaces, Web::NotificationsAPI::NotificationData data, String attribution, Optional<Gfx::ShareableBitmap> icon) =|+ notification_close(u64 id) =|+ app_focus_view_from_notification(u64 view_id) =|+ app_open_url_in_new_tab_from_notification(URL::URL url, Optional<u64> view_id, WebView::IsPrivate is_private) =|+ external_url_resolve_handler(u64 request_id, URL::URL url) =|+ external_url_launch(u64 handler_id, u64 request_id, URL::URL url) =|+ external_url_release_handler(u64 handler_id) =|omnibox_suggestions(u64 client_id, u64 query_id, Vector<WebView::AutocompleteSuggestion> suggestions) =|bookmarks_changed(ByteString bookmarks_json) =|app_read_bookmarks_for_all_tabs(u64 request_id) =|diff --git a/Services/Hub/HubServer.ipc b/Services/Hub/HubServer.ipcindex 1d2d2c77497..ace9417a742 100644--- a/Services/Hub/HubServer.ipc+++ b/Services/Hub/HubServer.ipc@@ -31,6 +31,14 @@ struct WebView::OmniboxEngagement {// What the UI asks of the Hub.endpoint HubServer{+ pip_did_resize(u64 view_id, Gfx::IntSize size) =|+ pip_did_close(u64 view_id, bool video_keeps_playing) =|+ notification_shown(u64 id) =|+ notification_failed(u64 id) =|+ notification_clicked(u64 id) =|+ notification_closed(u64 id, bool by_user) =|+ external_url_handler_resolved(u64 request_id, Optional<u64> handler_id, String application_name, bool is_ladybird) =|+ external_url_launched(u64 request_id, bool launched) =|omnibox_open(u64 client_id, WebView::IsPrivate is_private) =|omnibox_close(u64 client_id) =|omnibox_query(u64 client_id, u64 query_id, String query, u64 max_suggestions) =|diff --git a/Services/Hub/Proxies.cpp b/Services/Hub/Proxies.cppnew file mode 100644index 00000000000..6ec0e7a715d--- /dev/null+++ b/Services/Hub/Proxies.cpp@@ -0,0 +1,113 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <AK/HashMap.h>+#include <Hub/Application.h>+#include <Hub/ConnectionFromUI.h>+#include <Hub/Proxies.h>++namespace Hub {++static HashMap<u64, PictureInPictureWindowInUI*> s_picture_in_picture_windows;++PictureInPictureWindowInUI::PictureInPictureWindowInUI(View& view, u64 owner_view_id, Gfx::IntSize video_size, Gfx::IntSize initial_size)+ : m_view(view)+ , m_view_id(view.view_id())+ , m_size(initial_size)+{+ s_picture_in_picture_windows.set(m_view_id, this);+ report_page_close_of(view);+ if (auto* ui = ConnectionFromUI::the())+ ui->async_pip_open(m_view_id, owner_view_id, video_size);+}++PictureInPictureWindowInUI::~PictureInPictureWindowInUI()+{+ s_picture_in_picture_windows.remove(m_view_id);+ if (auto* ui = ConnectionFromUI::the())+ ui->async_pip_close(m_view_id);+}++PictureInPictureWindowInUI* PictureInPictureWindowInUI::find(u64 view_id)+{+ return s_picture_in_picture_windows.get(view_id).value_or(nullptr);+}++void PictureInPictureWindowInUI::did_resize(Gfx::IntSize size)+{+ m_size = size;+ if (on_resize)+ on_resize(size);+}++void PictureInPictureWindowInUI::did_close(bool video_keeps_playing)+{+ if (on_close)+ on_close(video_keeps_playing ? VideoKeepsPlaying::Yes : VideoKeepsPlaying::No);+}++void PictureInPictureWindowInUI::hide()+{+ if (auto* ui = ConnectionFromUI::the())+ ui->async_pip_hide(m_view_id);+}++void PictureInPictureWindowInUI::set_video_size(Gfx::IntSize video_size)+{+ if (auto* ui = ConnectionFromUI::the())+ ui->async_pip_set_video_size(m_view_id, video_size);+}++static NotificationBackendInUI* s_notification_backend;++NotificationBackendInUI::NotificationBackendInUI()+{+ s_notification_backend = this;+}++NotificationBackendInUI::~NotificationBackendInUI()+{+ s_notification_backend = nullptr;+}++NotificationBackendInUI* NotificationBackendInUI::the()+{+ return s_notification_backend;+}++void NotificationBackendInUI::show(WebView::PlatformNotification const& notification)+{+ Optional<Gfx::ShareableBitmap> icon;+ if (notification.icon)+ icon = notification.icon->to_shareable_bitmap();+ if (auto* ui = ConnectionFromUI::the())+ ui->async_notification_show(notification.id, notification.page_id.value(), notification.replaces, notification.data, notification.attribution, move(icon));+}++void NotificationBackendInUI::close(u64 id)+{+ if (auto* ui = ConnectionFromUI::the())+ ui->async_notification_close(id);+}++ExternalURLHandlerInUI::ExternalURLHandlerInUI(u64 handler_id, String application_name, bool is_ladybird)+ : ExternalURLHandler(move(application_name), is_ladybird)+ , m_handler_id(handler_id)+{+}++ExternalURLHandlerInUI::~ExternalURLHandlerInUI()+{+ if (auto* ui = ConnectionFromUI::the())+ ui->async_external_url_release_handler(m_handler_id);+}++void ExternalURLHandlerInUI::launch(URL::URL const& url, LaunchCallback callback) const+{+ Application::the().launch_external_url(m_handler_id, url, move(callback));+}++}diff --git a/Services/Hub/Proxies.h b/Services/Hub/Proxies.hnew file mode 100644index 00000000000..aa84249496a--- /dev/null+++ b/Services/Hub/Proxies.h@@ -0,0 +1,62 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <Hub/View.h>+#include <LibWebView/ExternalURLHandler.h>+#include <LibWebView/NotificationBackend.h>+#include <LibWebView/PictureInPictureWindow.h>++namespace Hub {++// These stand in for what only the UI can do, as it has the windows and the desktop.++class PictureInPictureWindowInUI final : public WebView::PictureInPictureWindow {+public:+ PictureInPictureWindowInUI(View&, u64 owner_view_id, Gfx::IntSize video_size, Gfx::IntSize initial_size);+ virtual ~PictureInPictureWindowInUI() override;++ static PictureInPictureWindowInUI* find(u64 view_id);++ void did_resize(Gfx::IntSize);+ void did_close(bool video_keeps_playing);++private:+ virtual Gfx::IntSize size() const override { return m_size; }+ virtual String handle() const override { return m_view.handle(); }+ virtual void hide() override;+ virtual void set_video_size(Gfx::IntSize) override;++ View& m_view;+ u64 m_view_id { 0 };+ Gfx::IntSize m_size;+};++class NotificationBackendInUI final : public WebView::NotificationBackend {+public:+ NotificationBackendInUI();+ virtual ~NotificationBackendInUI() override;++ static NotificationBackendInUI* the();++private:+ virtual void show(WebView::PlatformNotification const&) override;+ virtual void close(u64 id) override;+};++class ExternalURLHandlerInUI final : public WebView::ExternalURLHandler {+public:+ ExternalURLHandlerInUI(u64 handler_id, String application_name, bool is_ladybird);+ virtual ~ExternalURLHandlerInUI() override;++ virtual void launch(URL::URL const&, LaunchCallback) const override;++private:+ u64 m_handler_id { 0 };+};++}diff --git a/Services/Hub/View.cpp b/Services/Hub/View.cppindex 4b9e1c0eb42..0ed36b3b53f 100644--- a/Services/Hub/View.cpp+++ b/Services/Hub/View.cpp@@ -118,6 +118,13 @@ View::InitialState View::initial_state_for_related_view() const};}+Gfx::IntSize View::screen_size() const+{+ if (!m_screen_rects.has_value() || m_screen_rects->main_screen_index >= m_screen_rects->available_rects.size())+ return m_viewport_size.to_type<int>();+ return m_screen_rects->available_rects[m_screen_rects->main_screen_index].size().to_type<int>();+}+void View::set_viewport(Web::DevicePixelSize size, double device_pixel_ratio){m_viewport_size = size;diff --git a/Services/Hub/View.h b/Services/Hub/View.hindex c1695529614..02e55271c34 100644--- a/Services/Hub/View.h+++ b/Services/Hub/View.h@@ -42,6 +42,8 @@ public:void did_get_answer(u64 answer_id, bool answer);void did_get_permission_answer(u64 answer_id, Web::Permissions::PromptOutcome);+ Gfx::IntSize screen_size() const;+void set_viewport(Web::DevicePixelSize, double device_pixel_ratio);void set_system_theme(Core::AnonymousBuffer);void set_screen_rects(ScreenRects);diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cppindex 64c21be6dd0..71e385e3a9f 100644--- a/UI/Qt/Application.cpp+++ b/UI/Qt/Application.cpp@@ -19,6 +19,7 @@# include <LibWebView/NotificationBackendFreedesktop.h>#endif#include <Hub/ActionMirror.h>+#include <LibWebView/NoOpNotificationBackend.h>#include <LibWebView/SessionStore.h>#include <LibWebView/URL.h>#include <LibWebView/Utilities.h>@@ -659,7 +660,7 @@ Application::~Application()delete window.data();// A Picture-in-Picture window is a widget too, so it must also go before the QApplication does.- WebView::PictureInPictureManager::the().destroy_all_windows();+ m_picture_in_picture_windows.clear();}void Application::show_process_manager()@@ -1380,9 +1381,47 @@ bool Application::confirm_stop_active_downloads(QWidget* parent)return true;}-OwnPtr<WebView::PictureInPictureWindow> Application::create_picture_in_picture_window(WebView::ViewImplementation& owner_view, u64 view_id, Gfx::IntSize video_size)+void Application::open_picture_in_picture_window(u64 view_id, u64 owner_view_id, Gfx::IntSize video_size){- return Ladybird::create_picture_in_picture_window(owner_view, view_id, video_size);+ auto* owner_view = RemoteView::find(owner_view_id);+ if (!owner_view) {+ // NB: The owner went away before this arrived. The Hub must still hear that the window closed, or it would keep+ // the window and its view.+ if (auto* hub = HubConnection::the_if_connected())+ hub->async_pip_did_close(view_id, false);+ return;+ }+ auto window = Ladybird::create_picture_in_picture_window(*owner_view, view_id, video_size);+ window->on_resize = [view_id](Gfx::IntSize size) {+ if (auto* hub = HubConnection::the_if_connected())+ hub->async_pip_did_resize(view_id, size);+ };+ window->on_close = [view_id](auto video_keeps_playing) {+ if (auto* hub = HubConnection::the_if_connected())+ hub->async_pip_did_close(view_id, video_keeps_playing == WebView::PictureInPictureWindow::VideoKeepsPlaying::Yes);+ };+ m_picture_in_picture_windows.set(view_id, move(window));+}++void Application::hide_picture_in_picture_window(u64 view_id)+{+ if (auto* window = m_picture_in_picture_windows.get(view_id).value_or(nullptr))+ window->hide();+}++void Application::set_picture_in_picture_video_size(u64 view_id, Gfx::IntSize video_size)+{+ if (auto* window = m_picture_in_picture_windows.get(view_id).value_or(nullptr))+ window->set_video_size(video_size);+}++void Application::close_picture_in_picture_window(u64 view_id)+{+ // NB: A window holds the view, which lets the Hub's view go as it goes. With no window, nothing here ever held it.+ if (m_picture_in_picture_windows.remove(view_id))+ return;+ if (auto* hub = HubConnection::the_if_connected())+ hub->async_destroy_view(view_id);}// The window that shows this view in one of its tabs, if any.@@ -1406,21 +1445,25 @@ OwnPtr<WebView::NotificationBackend> Application::create_notification_backend()#endif}-void Application::focus_page_from_notification(WebView::WebContentPage& page)+void Application::focus_view_from_notification(u64 view_id){- auto* window = window_for_view(page.view());+ auto* view = RemoteView::find(view_id);+ if (!view)+ return;+ auto& hub_view = view->hub_view();+ auto* window = window_for_view(hub_view);if (!window)return;- window->activate_tab(window->tab_index(window->tab_for_view(page.view())));+ window->activate_tab(window->tab_index(window->tab_for_view(hub_view)));window->bring_to_front();}-void Application::open_url_in_new_tab_from_notification(URL::URL const& url, Web::PageId, WebView::CanonicalTraversable* traversable, WebView::IsPrivate is_private)+void Application::open_url_in_new_tab_from_notification(URL::URL const& url, Optional<u64> view_id, WebView::IsPrivate is_private){BrowserWindow* window = nullptr;- if (traversable) {- if (auto view = traversable->view(); view.has_value())- window = window_for_view(*view);+ if (view_id.has_value()) {+ if (auto* view = RemoteView::find(*view_id))+ window = window_for_view(view->hub_view());}// The site opens in the notification's own session: a private window's notification never lands in a normal// window, nor a normal one in a private window.@@ -1888,6 +1931,69 @@ NonnullRefPtr<Application::BookmarkPromise> Application::display_edit_bookmark_freturn display_add_or_edit_bookmark_folder_dialog(active_tab(), BookmarkDialog::Type::EditFolder, current_folder.folder().title, parent_folder_id, current_folder.id);}+WebView::NotificationBackend& Application::notification_backend()+{+ if (m_notification_backend)+ return *m_notification_backend;++ m_notification_backend = create_notification_backend();+ if (!m_notification_backend)+ m_notification_backend = make<WebView::NoOpNotificationBackend>();+ m_notification_backend->on_shown = [](u64 id) {+ if (auto* hub = HubConnection::the_if_connected())+ hub->async_notification_shown(id);+ };+ m_notification_backend->on_failed = [](u64 id) {+ if (auto* hub = HubConnection::the_if_connected())+ hub->async_notification_failed(id);+ };+ m_notification_backend->on_clicked = [](u64 id) {+ if (auto* hub = HubConnection::the_if_connected())+ hub->async_notification_clicked(id);+ };+ m_notification_backend->on_closed = [](u64 id, WebView::NotificationBackend::ByUser by_user) {+ if (auto* hub = HubConnection::the_if_connected())+ hub->async_notification_closed(id, by_user == WebView::NotificationBackend::ByUser::Yes);+ };+ return *m_notification_backend;+}++void Application::resolve_external_url_handler_for_hub(u64 request_id, URL::URL const& url)+{+ resolve_external_url_handler(url, [this, request_id](RefPtr<WebView::ExternalURLHandler> handler) {+ auto* hub = HubConnection::the_if_connected();+ if (!hub)+ return;+ if (!handler) {+ hub->async_external_url_handler_resolved(request_id, Optional<u64> {}, String {}, false);+ return;+ }+ auto handler_id = m_next_external_url_handler_id++;+ auto application_name = handler->application_name();+ auto is_ladybird = handler->is_ladybird();+ m_external_url_handlers.set(handler_id, handler.release_nonnull());+ hub->async_external_url_handler_resolved(request_id, handler_id, move(application_name), is_ladybird);+ });+}++void Application::launch_external_url(u64 handler_id, u64 request_id, URL::URL const& url)+{+ auto handler = m_external_url_handlers.get(handler_id);+ if (!handler.has_value()) {+ HubConnection::the().async_external_url_launched(request_id, false);+ return;+ }+ (*handler)->launch(url, [request_id](bool launched) {+ if (auto* hub = HubConnection::the_if_connected())+ hub->async_external_url_launched(request_id, launched);+ });+}++void Application::release_external_url_handler(u64 handler_id)+{+ m_external_url_handlers.remove(handler_id);+}+void Application::report_active_view() const{auto* hub = HubConnection::the_if_connected();diff --git a/UI/Qt/Application.h b/UI/Qt/Application.hindex fb76e814c8b..fc943ea3c50 100644--- a/UI/Qt/Application.h+++ b/UI/Qt/Application.h@@ -165,12 +165,16 @@ private:void show_bookmark_popover();virtual Optional<String> system_font_family() const override;- virtual OwnPtr<WebView::NotificationBackend> create_notification_backend() override;- virtual void focus_page_from_notification(WebView::WebContentPage&) override;- virtual void open_url_in_new_tab_from_notification(URL::URL const&, Web::PageId originating_page, WebView::CanonicalTraversable*, WebView::IsPrivate) override;+ OwnPtr<WebView::NotificationBackend> create_notification_backend();+ WebView::NotificationBackend& notification_backend();+ void focus_view_from_notification(u64 view_id);+ void open_url_in_new_tab_from_notification(URL::URL const&, Optional<u64> view_id, WebView::IsPrivate);virtual bool supports_picture_in_picture() const override { return true; }- virtual OwnPtr<WebView::PictureInPictureWindow> create_picture_in_picture_window(WebView::ViewImplementation& owner_view, u64 view_id, Gfx::IntSize video_size) override;+ void open_picture_in_picture_window(u64 view_id, u64 owner_view_id, Gfx::IntSize video_size);+ void hide_picture_in_picture_window(u64 view_id);+ void set_picture_in_picture_video_size(u64 view_id, Gfx::IntSize);+ void close_picture_in_picture_window(u64 view_id);Vector<WebView::BookmarkItem::Bookmark> bookmarks_for_all_tabs_in_current_window() const;Tab* activate_tab_with_url(URL::URL const&, URL::ExcludeFragment) const;@@ -183,7 +187,10 @@ private:void open_navigation_in_new_tab(Web::HTML::PreparedNavigationDescriptor, Web::HTML::ActivateTab) const;void open_navigation_in_new_window(Web::HTML::PreparedNavigationDescriptor, WebView::IsPrivate);- virtual void resolve_external_url_handler(URL::URL const&, WebView::ExternalURLHandlerCallback) const override;+ void resolve_external_url_handler(URL::URL const&, WebView::ExternalURLHandlerCallback) const;+ void resolve_external_url_handler_for_hub(u64 request_id, URL::URL const&);+ void launch_external_url(u64 handler_id, u64 request_id, URL::URL const&);+ void release_external_url_handler(u64 handler_id);void ask_user_for_download_path(u64 request_id, ByteString const& file) const;void display_download_confirmation_dialog(StringView download_name, ByteString const& path) const;@@ -239,6 +246,10 @@ private:RefPtr<Hub::ConnectionFromUI> m_connection_from_ui;RefPtr<HubConnection> m_hub_connection;OwnPtr<QApplication> m_application;+ HashMap<u64, NonnullOwnPtr<WebView::PictureInPictureWindow>> m_picture_in_picture_windows;+ OwnPtr<WebView::NotificationBackend> m_notification_backend;+ HashMap<u64, NonnullRefPtr<WebView::ExternalURLHandler>> m_external_url_handlers;+ u64 m_next_external_url_handler_id { 1 };BrowserWindow* m_active_window { nullptr };OwnPtr<ProcessManagerWindow> m_process_manager_window;diff --git a/UI/Qt/HubConnection.cpp b/UI/Qt/HubConnection.cppindex a582788bd6d..9f916cb9944 100644--- a/UI/Qt/HubConnection.cpp+++ b/UI/Qt/HubConnection.cpp@@ -382,6 +382,71 @@ void HubConnection::omnibox_suggestions(u64 client_id, u64 query_id, Vector<WebVprovider->on_suggestions(query_id, move(suggestions));}+void HubConnection::pip_open(u64 view_id, u64 owner_view_id, Gfx::IntSize video_size)+{+ Application::the().open_picture_in_picture_window(view_id, owner_view_id, video_size);+}++void HubConnection::pip_hide(u64 view_id)+{+ Application::the().hide_picture_in_picture_window(view_id);+}++void HubConnection::pip_set_video_size(u64 view_id, Gfx::IntSize video_size)+{+ Application::the().set_picture_in_picture_video_size(view_id, video_size);+}++void HubConnection::pip_close(u64 view_id)+{+ Application::the().close_picture_in_picture_window(view_id);+}++void HubConnection::notification_show(u64 id, u64 page_id, Optional<u64> replaces, Web::NotificationsAPI::NotificationData data, String attribution, Optional<Gfx::ShareableBitmap> icon)+{+ RefPtr<Gfx::Bitmap const> icon_bitmap;+ if (icon.has_value() && icon->is_valid())+ icon_bitmap = icon->bitmap();+ Application::the().notification_backend().show({+ .id = id,+ .page_id = Web::PageId { page_id },+ .replaces = replaces,+ .data = move(data),+ .attribution = move(attribution),+ .icon = move(icon_bitmap),+ });+}++void HubConnection::notification_close(u64 id)+{+ Application::the().notification_backend().close(id);+}++void HubConnection::app_focus_view_from_notification(u64 view_id)+{+ Application::the().focus_view_from_notification(view_id);+}++void HubConnection::app_open_url_in_new_tab_from_notification(URL::URL url, Optional<u64> view_id, WebView::IsPrivate is_private)+{+ Application::the().open_url_in_new_tab_from_notification(url, view_id, is_private);+}++void HubConnection::external_url_resolve_handler(u64 request_id, URL::URL url)+{+ Application::the().resolve_external_url_handler_for_hub(request_id, url);+}++void HubConnection::external_url_launch(u64 handler_id, u64 request_id, URL::URL url)+{+ Application::the().launch_external_url(handler_id, request_id, url);+}++void HubConnection::external_url_release_handler(u64 handler_id)+{+ Application::the().release_external_url_handler(handler_id);+}+void HubConnection::settings_changed(ByteString settings_json){auto settings = JsonValue::from_string(settings_json);diff --git a/UI/Qt/HubConnection.h b/UI/Qt/HubConnection.hindex f4755fb05d6..aa4d10f2857 100644--- a/UI/Qt/HubConnection.h+++ b/UI/Qt/HubConnection.h@@ -29,6 +29,17 @@ private:virtual void die() override;// ^HubClientEndpoint+ virtual void pip_open(u64 view_id, u64 owner_view_id, Gfx::IntSize video_size) override;+ virtual void pip_hide(u64 view_id) override;+ virtual void pip_set_video_size(u64 view_id, Gfx::IntSize video_size) override;+ virtual void pip_close(u64 view_id) override;+ virtual void notification_show(u64 id, u64 page_id, Optional<u64> replaces, Web::NotificationsAPI::NotificationData data, String attribution, Optional<Gfx::ShareableBitmap> icon) override;+ virtual void notification_close(u64 id) override;+ virtual void app_focus_view_from_notification(u64 view_id) override;+ virtual void app_open_url_in_new_tab_from_notification(URL::URL url, Optional<u64> view_id, WebView::IsPrivate is_private) override;+ virtual void external_url_resolve_handler(u64 request_id, URL::URL url) override;+ virtual void external_url_launch(u64 handler_id, u64 request_id, URL::URL url) override;+ virtual void external_url_release_handler(u64 handler_id) override;virtual void omnibox_suggestions(u64 client_id, u64 query_id, Vector<WebView::AutocompleteSuggestion> suggestions) override;virtual void bookmarks_changed(ByteString bookmarks_json) override;virtual void app_read_bookmarks_for_all_tabs(u64 request_id) override;diff --git a/UI/Qt/PictureInPictureWindow.cpp b/UI/Qt/PictureInPictureWindow.cppindex 35e3f740aa3..516beadd87a 100644--- a/UI/Qt/PictureInPictureWindow.cpp+++ b/UI/Qt/PictureInPictureWindow.cpp@@ -56,11 +56,11 @@ class PictureInPictureWindow finalpublic:AK_ALLOC_WITH_KMALLOC;- PictureInPictureWindow(WebView::ViewImplementation const& owner_view, u64 view_id, Gfx::IntSize video_size)+ PictureInPictureWindow(RemoteView const& owner_view, u64 view_id, Gfx::IntSize video_size): QWidget(nullptr, window_flags()){// The window's native window and view are created for the screen of the browser window it is opened from.- auto* screen = static_cast<WebContentView&>(RemoteView::of(owner_view)).screen();+ auto* screen = static_cast<WebContentView const&>(owner_view).screen();setScreen(screen);setAttribute(Qt::WA_ShowWithoutActivating);@@ -92,7 +92,6 @@ public:m_screen_observer->on_display_metadata_change = [this] {m_view->set_display_metadata(m_screen_observer->display_id(), m_screen_observer->refresh_rate());};- report_page_close_of(m_view->hub_view());m_view->installEventFilter(this);// The window's controls, and its page's, show on hover, which works while Ladybird is in the background too.m_view->set_follows_mouse_while_inactive(true);@@ -232,8 +231,8 @@ private:// minimized, to play the video there.void go_back_to_tab(u64 owner_view_id){- if (auto owner = WebView::ViewImplementation::find_view_by_id(owner_view_id); owner.has_value()) {- auto* browser_window = static_cast<WebContentView&>(RemoteView::of(*owner)).window();+ if (auto* owner = RemoteView::find(owner_view_id)) {+ auto* browser_window = static_cast<WebContentView&>(*owner).window();browser_window->setWindowState(browser_window->windowState() & ~Qt::WindowMinimized);browser_window->raise();browser_window->activateWindow();@@ -356,7 +355,7 @@ private:Optional<Press> m_press;};-NonnullOwnPtr<WebView::PictureInPictureWindow> create_picture_in_picture_window(WebView::ViewImplementation const& owner_view, u64 view_id, Gfx::IntSize video_size)+NonnullOwnPtr<WebView::PictureInPictureWindow> create_picture_in_picture_window(RemoteView const& owner_view, u64 view_id, Gfx::IntSize video_size){return make<PictureInPictureWindow>(owner_view, view_id, video_size);}diff --git a/UI/Qt/PictureInPictureWindow.h b/UI/Qt/PictureInPictureWindow.hindex f256df8f8f0..79355a86768 100644--- a/UI/Qt/PictureInPictureWindow.h+++ b/UI/Qt/PictureInPictureWindow.h@@ -12,6 +12,8 @@namespace Ladybird {-NonnullOwnPtr<WebView::PictureInPictureWindow> create_picture_in_picture_window(WebView::ViewImplementation const& owner_view, u64 view_id, Gfx::IntSize video_size);+class RemoteView;++NonnullOwnPtr<WebView::PictureInPictureWindow> create_picture_in_picture_window(RemoteView const& owner_view, u64 view_id, Gfx::IntSize video_size);}