Truly independent web browser
LibWebView+UI/Qt: End Picture-in-Picture windows with the application
Andreas Kling73c155e40de9
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cppindex af57c79d42e..24d0188be37 100644--- a/Libraries/LibWebView/Application.cpp+++ b/Libraries/LibWebView/Application.cpp@@ -64,6 +64,7 @@#include <LibWebView/NoOpMicrophoneAuthorizer.h>#include <LibWebView/NoOpNotificationBackend.h>#include <LibWebView/PermissionManager.h>+#include <LibWebView/PictureInPictureManager.h>#include <LibWebView/PictureInPictureWindow.h>#include <LibWebView/ProcessType.h>#include <LibWebView/RequestServerManager.h>@@ -282,6 +283,8 @@ Application::~Application()m_spare_web_content_process = nullptr;+ PictureInPictureManager::the().destroy_all_windows();+// Connection die() handlers use the process manager, so destroy the processes while it is still reachable.if (m_process_manager)m_process_manager->remove_all_processes();diff --git a/Libraries/LibWebView/PictureInPictureManager.cpp b/Libraries/LibWebView/PictureInPictureManager.cppindex a87f0102a8b..0674f0509f9 100644--- a/Libraries/LibWebView/PictureInPictureManager.cpp+++ b/Libraries/LibWebView/PictureInPictureManager.cpp@@ -146,15 +146,25 @@ void PictureInPictureManager::window_did_close(PictureInPictureWindow& window, Pvoid PictureInPictureManager::window_page_did_close(PictureInPictureWindow& window){- OwnPtr<PictureInPictureWindow> closed_window;if (auto index = index_of(window); index.has_value()) {- closed_window = m_windows.take(*index).window;+ m_closed_windows.append(m_windows.take(*index).window);} else if (auto index = m_retired_windows.find_first_index_if([&](auto const& retired_window) { return retired_window.ptr() == &window; }); index.has_value()) {- closed_window = m_retired_windows.take(*index);+ m_closed_windows.append(m_retired_windows.take(*index));}- // The window's page closes from within a callback of its view, so the window is destroyed once that returns.- Core::deferred_invoke([closed_window = move(closed_window)] { });+ // The window's page closes from within a callback of its view, so the window is destroyed once that returns. The+ // event loop may never get to this, so the window stays here for destroy_all_windows() to find.+ Core::deferred_invoke([this] {+ auto closed_windows = exchange(m_closed_windows, {});+ });+}++void PictureInPictureManager::destroy_all_windows()+{+ // Destroying a window's view closes its page, which comes back here, so the windows leave their lists first.+ auto windows = exchange(m_windows, {});+ auto retired_windows = exchange(m_retired_windows, {});+ auto closed_windows = exchange(m_closed_windows, {});}}diff --git a/Libraries/LibWebView/PictureInPictureManager.h b/Libraries/LibWebView/PictureInPictureManager.hindex 9c5a543f016..7a727abe2a0 100644--- a/Libraries/LibWebView/PictureInPictureManager.h+++ b/Libraries/LibWebView/PictureInPictureManager.h@@ -36,6 +36,9 @@ public:void close_window_and_its_page(WebContentPage&);void video_size_did_change(WebContentPage&, Gfx::IntSize);+ // Windows need the application to be destroyed, and this manager outlives it, so the application ends them first.+ void destroy_all_windows();+bool document_has_open_window(CanonicalNavigable const&) const;void active_documents_did_change();@@ -57,6 +60,7 @@ private:Vector<Window> m_windows;Vector<NonnullOwnPtr<PictureInPictureWindow>> m_retired_windows;+ Vector<NonnullOwnPtr<PictureInPictureWindow>> m_closed_windows;};}diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cppindex 42e37a7268a..2f281dae34c 100644--- a/UI/Qt/Application.cpp+++ b/UI/Qt/Application.cpp@@ -11,6 +11,7 @@#include <LibWebView/MicrophoneAuthorizer.h>#include <LibWebView/NotificationBackend.h>#include <LibWebView/PageTranslation.h>+#include <LibWebView/PictureInPictureManager.h>#if defined(AK_OS_MACOS)# include <LibWebView/MicrophoneAuthorizerMacOS.h># include <LibWebView/NotificationBackendMacOS.h>@@ -593,6 +594,9 @@ Application::~Application()}for (auto& window : windows)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();}void Application::show_process_manager()