Skip to content

Truly independent web browser

LibWebView+UI/Qt: Move the download presentation into the UI

Andreas Kling2fe77cd6a8c7
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp
index 241249cbe2e..7c9315ca394 100644
--- a/Libraries/LibWebView/Application.cpp
+++ b/Libraries/LibWebView/Application.cpp
@@ -2289,31 +2289,6 @@ void Application::display_error_dialog(StringView error_message) const
warnln("{}", error_message);
}
-static ErrorOr<String> download_path_for_frontend_action(LexicalPath const& path)
-{
- return String::from_utf8(path.string().view());
-}
-
-ErrorOr<String> Application::download_file_path_for_frontend_action(FileDownloader::Download const& download) const
-{
- return download_path_for_frontend_action(download.destination);
-}
-
-ErrorOr<String> Application::download_directory_path_for_frontend_action(FileDownloader::Download const& download) const
-{
- return download_path_for_frontend_action(LexicalPath { download.destination.dirname() });
-}
-
-void Application::open_download(FileDownloader::Download const& download) const
-{
- outln("Open downloaded file: {}", download.destination);
-}
-
-void Application::show_download_in_folder(FileDownloader::Download const& download) const
-{
- outln("Show downloaded file in folder: {}", download.destination);
-}
-
bool Application::supports_clipboard_type(ClipboardType type) const
{
return type == ClipboardType::Text;
diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h
index 1c0f0a21037..560b71a6dab 100644
--- a/Libraries/LibWebView/Application.h
+++ b/Libraries/LibWebView/Application.h
@@ -308,10 +308,6 @@ public:
virtual void display_download_confirmation_dialog(StringView download_name, LexicalPath const& path) const;
virtual void display_error_dialog(StringView error_message) const;
- ErrorOr<String> download_file_path_for_frontend_action(FileDownloader::Download const&) const;
- ErrorOr<String> download_directory_path_for_frontend_action(FileDownloader::Download const&) const;
- virtual void open_download(FileDownloader::Download const&) const;
- virtual void show_download_in_folder(FileDownloader::Download const&) const;
// FIXME: We should implement UI-agnostic platform APIs to interact with the system clipboard.
enum class ClipboardType : u8 {
diff --git a/Libraries/LibWebView/CMakeLists.txt b/Libraries/LibWebView/CMakeLists.txt
index 5e9640bf60e..81ee52fd263 100644
--- a/Libraries/LibWebView/CMakeLists.txt
+++ b/Libraries/LibWebView/CMakeLists.txt
@@ -28,7 +28,6 @@ set(SOURCES
CrashReportReview.cpp
CrashReportStore.cpp
CrashReportSubmission.cpp
- DownloadPresentation.cpp
DownloadSegmentation.cpp
DownloadStore.cpp
ExternalURLHandler.cpp
diff --git a/Services/Hub/Application.cpp b/Services/Hub/Application.cpp
index 06757c1a31e..2f970fdeef4 100644
--- a/Services/Hub/Application.cpp
+++ b/Services/Hub/Application.cpp
@@ -230,28 +230,6 @@ void Application::display_error_dialog(StringView error_message) const
WebView::Application::display_error_dialog(error_message);
}
-void Application::open_download(WebView::FileDownloader::Download const& download) const
-{
- auto path = download_file_path_for_frontend_action(download);
- if (path.is_error()) {
- display_error_dialog("Unable to open downloaded file: path cannot be represented by this frontend"sv);
- return;
- }
- if (auto* ui = ConnectionFromUI::the())
- ui->async_app_open_file(path.release_value());
-}
-
-void Application::show_download_in_folder(WebView::FileDownloader::Download const& download) const
-{
- auto path = download_directory_path_for_frontend_action(download);
- if (path.is_error()) {
- display_error_dialog("Unable to show downloaded file: path cannot be represented by this frontend"sv);
- return;
- }
- if (auto* ui = ConnectionFromUI::the())
- ui->async_app_open_file(path.release_value());
-}
-
void Application::set_clipboard_text(String text, ClipboardType type)
{
if (auto* ui = ConnectionFromUI::the())
diff --git a/Services/Hub/Application.h b/Services/Hub/Application.h
index 90968bf789a..2004bb12084 100644
--- a/Services/Hub/Application.h
+++ b/Services/Hub/Application.h
@@ -88,8 +88,6 @@ private:
virtual NonnullRefPtr<Core::Promise<ByteString>> ask_user_for_download_path(ByteString const& file) const override;
virtual void display_download_confirmation_dialog(StringView download_name, LexicalPath const& path) const override;
virtual void display_error_dialog(StringView error_message) const override;
- virtual void open_download(WebView::FileDownloader::Download const&) const override;
- virtual void show_download_in_folder(WebView::FileDownloader::Download const&) const override;
virtual void set_clipboard_text(String, ClipboardType) override;
virtual void insert_clipboard_item(Web::Clipboard::SystemClipboardItem) override;
virtual void read_clipboard_text(ClipboardType, Function<void(Utf16String)>) const override;
diff --git a/Services/Hub/ConnectionFromUI.cpp b/Services/Hub/ConnectionFromUI.cpp
index 411132962a0..1c9816d93e4 100644
--- a/Services/Hub/ConnectionFromUI.cpp
+++ b/Services/Hub/ConnectionFromUI.cpp
@@ -231,20 +231,6 @@ void ConnectionFromUI::resume_download(u64 id)
Application::the().file_downloader().resume_download(id);
}
-void ConnectionFromUI::open_download(u64 id)
-{
- auto& application = static_cast<WebView::Application&>(Application::the());
- if (auto download = application.file_downloader().download(id); download.has_value())
- application.open_download(*download);
-}
-
-void ConnectionFromUI::show_download_in_folder(u64 id)
-{
- auto& application = static_cast<WebView::Application&>(Application::the());
- if (auto download = application.file_downloader().download(id); download.has_value())
- application.show_download_in_folder(*download);
-}
-
void ConnectionFromUI::prune_inactive_downloads(WebView::IsPrivate is_private)
{
(void)Application::the().file_downloader().prune_inactive_downloads(is_private);
diff --git a/Services/Hub/ConnectionFromUI.h b/Services/Hub/ConnectionFromUI.h
index bf59fe8a53c..bc284a4a8c1 100644
--- a/Services/Hub/ConnectionFromUI.h
+++ b/Services/Hub/ConnectionFromUI.h
@@ -129,8 +129,6 @@ private:
virtual void cancel_download(u64 id) override;
virtual void pause_download(u64 id) override;
virtual void resume_download(u64 id) override;
- virtual void open_download(u64 id) override;
- virtual void show_download_in_folder(u64 id) override;
virtual void prune_inactive_downloads(WebView::IsPrivate is_private) override;
virtual void pause_active_downloads() override;
virtual void cancel_unresumable_downloads() override;
diff --git a/Services/Hub/HubClient.ipc b/Services/Hub/HubClient.ipc
index 878533cccb6..c86bc251ec8 100644
--- a/Services/Hub/HubClient.ipc
+++ b/Services/Hub/HubClient.ipc
@@ -282,7 +282,6 @@ endpoint HubClient
app_open_view_in_new_tab(u64 view_id, Optional<u64> source_view_id, WebView::IsPrivate is_private, Web::HTML::ActivateTab activate_tab) =|
app_display_error_dialog(String message) =|
app_display_download_confirmation_dialog(String download_name, ByteString path) =|
- app_open_file(String path) =|
app_read_clipboard_text(u64 request_id, WebView::Application::ClipboardType type) =|
app_read_clipboard_item(u64 request_id) =|
app_ask_user_for_download_path(u64 request_id, ByteString file) =|
diff --git a/Services/Hub/HubServer.ipc b/Services/Hub/HubServer.ipc
index d5444761cff..eb270e45274 100644
--- a/Services/Hub/HubServer.ipc
+++ b/Services/Hub/HubServer.ipc
@@ -201,8 +201,6 @@ endpoint HubServer
cancel_download(u64 id) =|
pause_download(u64 id) =|
resume_download(u64 id) =|
- open_download(u64 id) =|
- show_download_in_folder(u64 id) =|
prune_inactive_downloads(WebView::IsPrivate is_private) =|
pause_active_downloads() =|
cancel_unresumable_downloads() =|
diff --git a/Tests/LibWebView/TestDownloadSegmentation.cpp b/Tests/LibWebView/TestDownloadSegmentation.cpp
index 902ddcb28cf..a01a84055f9 100644
--- a/Tests/LibWebView/TestDownloadSegmentation.cpp
+++ b/Tests/LibWebView/TestDownloadSegmentation.cpp
@@ -7,8 +7,8 @@
#include <LibHTTP/HeaderList.h>
#include <LibTest/TestCase.h>
#include <LibURL/URL.h>
-#include <LibWebView/DownloadPresentation.h>
#include <LibWebView/DownloadSegmentation.h>
+#include <LibWebView/FileDownloader.h>
static NonnullRefPtr<HTTP::HeaderList> headers(Vector<HTTP::Header> headers)
{
@@ -238,57 +238,3 @@ TEST_CASE(estimated_time_remaining)
download.bytes_per_second = 0;
EXPECT(!download.estimated_time_remaining().has_value());
}
-
-TEST_CASE(time_remaining_text)
-{
- auto text = [](i64 seconds) {
- return WebView::download_time_remaining_text(AK::Duration::from_seconds(seconds));
- };
-
- EXPECT_EQ(text(0), "1 second left"_string);
- EXPECT_EQ(text(45), "45 seconds left"_string);
- EXPECT_EQ(text(59), "59 seconds left"_string);
-
- EXPECT_EQ(text(60), "1 minute left"_string);
- EXPECT_EQ(text(61), "2 minutes left"_string);
- EXPECT_EQ(text(59 * 60), "59 minutes left"_string);
-
- EXPECT_EQ(text(60 * 60), "1 hour left"_string);
- EXPECT_EQ(text(61 * 60), "1 hour 1 minute left"_string);
- EXPECT_EQ(text(90 * 60), "1 hour 30 minutes left"_string);
- EXPECT_EQ(text(7199), "2 hours left"_string);
- EXPECT_EQ(text(25 * 60 * 60), "25 hours left"_string);
-}
-
-TEST_CASE(status_text)
-{
- WebView::FileDownloader::Download download {
- .id = 1,
- .is_private = WebView::IsPrivate::No,
- .url = URL::about_blank(),
- .destination = LexicalPath { "/tmp/file"sv },
- .status = WebView::FileDownloader::DownloadStatus::InProgress,
- .downloaded_size = 12'400'000,
- .total_size = 19'300'000,
- .error = {},
- .can_resume = true,
- .connection_count = 1,
- .bytes_per_second = 862'500,
- .is_waiting_to_retry = false,
- .created_time = {},
- };
- EXPECT_EQ(WebView::download_status_text(download), "12.4 of 19.3 MB · 8 seconds left"_string);
-
- download.total_size = {};
- EXPECT_EQ(WebView::download_status_text(download), "12.4 MB downloaded"_string);
-
- download.status = WebView::FileDownloader::DownloadStatus::Completed;
- download.downloaded_size = 4'200'000;
- EXPECT_EQ(WebView::download_status_text(download), "4.2 MB"_string);
- download.downloaded_size = 512;
- EXPECT_EQ(WebView::download_status_text(download), "512 bytes"_string);
-
- download.status = WebView::FileDownloader::DownloadStatus::Failed;
- download.error = "The connection was interrupted"_string;
- EXPECT_EQ(WebView::download_status_text(download), "Failed · The connection was interrupted"_string);
-}
diff --git a/Tests/UI/Qt/CMakeLists.txt b/Tests/UI/Qt/CMakeLists.txt
index df0556e8484..6428529b417 100644
--- a/Tests/UI/Qt/CMakeLists.txt
+++ b/Tests/UI/Qt/CMakeLists.txt
@@ -29,6 +29,7 @@ ladybird_test("TestFullscreenDebounce.cpp" UI/Qt
set(TEST_SOURCES
TestBackingStoreRelease.cpp
TestChromeIcons.cpp
+ TestDownloadPresentation.cpp
TestHiddenPageSizing.cpp
TestJavaScriptDialog.cpp
TestNativeTextEditingLineEdit.cpp
diff --git a/Tests/UI/Qt/TestDownloadPresentation.cpp b/Tests/UI/Qt/TestDownloadPresentation.cpp
new file mode 100644
index 00000000000..97600103f80
--- /dev/null
+++ b/Tests/UI/Qt/TestDownloadPresentation.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibTest/TestCase.h>
+#include <LibURL/URL.h>
+#include <UI/Qt/DownloadPresentation.h>
+
+TEST_CASE(time_remaining_text)
+{
+ auto text = [](i64 seconds) {
+ return Ladybird::download_time_remaining_text(AK::Duration::from_seconds(seconds));
+ };
+
+ EXPECT_EQ(text(0), "1 second left"_string);
+ EXPECT_EQ(text(45), "45 seconds left"_string);
+ EXPECT_EQ(text(59), "59 seconds left"_string);
+
+ EXPECT_EQ(text(60), "1 minute left"_string);
+ EXPECT_EQ(text(61), "2 minutes left"_string);
+ EXPECT_EQ(text(59 * 60), "59 minutes left"_string);
+
+ EXPECT_EQ(text(60 * 60), "1 hour left"_string);
+ EXPECT_EQ(text(61 * 60), "1 hour 1 minute left"_string);
+ EXPECT_EQ(text(90 * 60), "1 hour 30 minutes left"_string);
+ EXPECT_EQ(text(7199), "2 hours left"_string);
+ EXPECT_EQ(text(25 * 60 * 60), "25 hours left"_string);
+}
+
+TEST_CASE(status_text)
+{
+ WebView::FileDownloader::Download download {
+ .id = 1,
+ .is_private = WebView::IsPrivate::No,
+ .url = URL::about_blank(),
+ .destination = LexicalPath { "/tmp/file"sv },
+ .status = WebView::FileDownloader::DownloadStatus::InProgress,
+ .downloaded_size = 12'400'000,
+ .total_size = 19'300'000,
+ .error = {},
+ .can_resume = true,
+ .connection_count = 1,
+ .bytes_per_second = 862'500,
+ .is_waiting_to_retry = false,
+ .created_time = {},
+ };
+ EXPECT_EQ(Ladybird::download_status_text(download), "12.4 of 19.3 MB · 8 seconds left"_string);
+
+ download.total_size = {};
+ EXPECT_EQ(Ladybird::download_status_text(download), "12.4 MB downloaded"_string);
+
+ download.status = WebView::FileDownloader::DownloadStatus::Completed;
+ download.downloaded_size = 4'200'000;
+ EXPECT_EQ(Ladybird::download_status_text(download), "4.2 MB"_string);
+ download.downloaded_size = 512;
+ EXPECT_EQ(Ladybird::download_status_text(download), "512 bytes"_string);
+
+ download.status = WebView::FileDownloader::DownloadStatus::Failed;
+ download.error = "The connection was interrupted"_string;
+ EXPECT_EQ(Ladybird::download_status_text(download), "Failed · The connection was interrupted"_string);
+}
diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h
index 9fecedadc36..ea55d68d839 100644
--- a/UI/Qt/Application.h
+++ b/UI/Qt/Application.h
@@ -58,6 +58,7 @@ class Application final
friend class ApplicationActions;
friend class Bookmarks;
friend class BookmarksPage;
+ friend class RemoteDownloads;
friend class RemoteView;
friend class HubConnection;
diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txt
index 7b656319d07..9998dcb1182 100644
--- a/UI/Qt/CMakeLists.txt
+++ b/UI/Qt/CMakeLists.txt
@@ -24,6 +24,7 @@ add_library(ladybird_impl STATIC
Bookmarks.cpp
BookmarksBar.cpp
BookmarksPage.cpp
+ DownloadPresentation.cpp
DownloadsPage.cpp
BrowserWindow.cpp
ChromeStyle.cpp
diff --git a/Libraries/LibWebView/DownloadPresentation.cpp b/UI/Qt/DownloadPresentation.cpp
similarity index 89%
rename from Libraries/LibWebView/DownloadPresentation.cpp
rename to UI/Qt/DownloadPresentation.cpp
index 08169b2c18c..81ef5eeb415 100644
--- a/Libraries/LibWebView/DownloadPresentation.cpp
+++ b/UI/Qt/DownloadPresentation.cpp
@@ -8,9 +8,9 @@
#include <AK/StdLibExtras.h>
#include <AK/StringBuilder.h>
#include <AK/StringView.h>
-#include <LibWebView/DownloadPresentation.h>
+#include <UI/Qt/DownloadPresentation.h>
-namespace WebView {
+namespace Ladybird {
static constexpr auto max_visible_downloads_in_popover = 5uz;
@@ -85,9 +85,9 @@ String download_time_remaining_text(AK::Duration time_remaining)
return MUST(String::formatted("{} {} left", download_count_text(hours, "hour"sv, "hours"sv), download_count_text(minutes, "minute"sv, "minutes"sv)));
}
-String download_status_text(FileDownloader::Download const& download)
+String download_status_text(WebView::FileDownloader::Download const& download)
{
- using DownloadStatus = FileDownloader::DownloadStatus;
+ using DownloadStatus = WebView::FileDownloader::DownloadStatus;
// The progress bar beside the status shows how far along a download is, so the status says only how much of
// it has arrived, such as "12.4 of 19.3 MB".
@@ -131,9 +131,9 @@ String download_status_text(FileDownloader::Download const& download)
VERIFY_NOT_REACHED();
}
-Vector<FileDownloader::Download const*> recent_downloads_for_popover(ReadonlySpan<FileDownloader::Download> downloads)
+Vector<WebView::FileDownloader::Download const*> recent_downloads_for_popover(ReadonlySpan<WebView::FileDownloader::Download> downloads)
{
- Vector<FileDownloader::Download const*> visible_downloads;
+ Vector<WebView::FileDownloader::Download const*> visible_downloads;
visible_downloads.ensure_capacity(AK::min(downloads.size(), max_visible_downloads_in_popover));
for (size_t i = downloads.size(); i > 0 && visible_downloads.size() < max_visible_downloads_in_popover; --i)
@@ -142,7 +142,7 @@ Vector<FileDownloader::Download const*> recent_downloads_for_popover(ReadonlySpa
return visible_downloads;
}
-DownloadsButtonState downloads_button_state(ReadonlySpan<FileDownloader::Download> downloads)
+DownloadsButtonState downloads_button_state(ReadonlySpan<WebView::FileDownloader::Download> downloads)
{
DownloadsButtonState state;
state.has_downloads = !downloads.is_empty();
@@ -153,7 +153,7 @@ DownloadsButtonState downloads_button_state(ReadonlySpan<FileDownloader::Downloa
for (auto const& download : downloads) {
switch (download.status) {
- case FileDownloader::DownloadStatus::InProgress:
+ case WebView::FileDownloader::DownloadStatus::InProgress:
++state.active_download_count;
if (download.total_size.has_value() && *download.total_size > 0) {
known_downloaded_size += AK::min(download.downloaded_size, *download.total_size);
@@ -162,15 +162,15 @@ DownloadsButtonState downloads_button_state(ReadonlySpan<FileDownloader::Downloa
++unknown_active_download_count;
}
break;
- case FileDownloader::DownloadStatus::Paused:
+ case WebView::FileDownloader::DownloadStatus::Paused:
++state.paused_download_count;
break;
- case FileDownloader::DownloadStatus::Completed:
+ case WebView::FileDownloader::DownloadStatus::Completed:
++state.completed_download_count;
break;
- case FileDownloader::DownloadStatus::Canceled:
+ case WebView::FileDownloader::DownloadStatus::Canceled:
break;
- case FileDownloader::DownloadStatus::Failed:
+ case WebView::FileDownloader::DownloadStatus::Failed:
++state.failed_download_count;
break;
}
diff --git a/Libraries/LibWebView/DownloadPresentation.h b/UI/Qt/DownloadPresentation.h
similarity index 54%
rename from Libraries/LibWebView/DownloadPresentation.h
rename to UI/Qt/DownloadPresentation.h
index a51f8775094..af29ecbc84f 100644
--- a/Libraries/LibWebView/DownloadPresentation.h
+++ b/UI/Qt/DownloadPresentation.h
@@ -11,12 +11,11 @@
#include <AK/String.h>
#include <AK/Time.h>
#include <AK/Vector.h>
-#include <LibWebView/Export.h>
#include <LibWebView/FileDownloader.h>
-namespace WebView {
+namespace Ladybird {
-struct WEBVIEW_API DownloadsButtonState {
+struct DownloadsButtonState {
bool has_downloads { false };
size_t active_download_count { 0 };
size_t paused_download_count { 0 };
@@ -26,9 +25,9 @@ struct WEBVIEW_API DownloadsButtonState {
String tooltip;
};
-WEBVIEW_API String download_status_text(FileDownloader::Download const&);
-WEBVIEW_API String download_time_remaining_text(AK::Duration time_remaining);
-WEBVIEW_API Vector<FileDownloader::Download const*> recent_downloads_for_popover(ReadonlySpan<FileDownloader::Download>);
-WEBVIEW_API DownloadsButtonState downloads_button_state(ReadonlySpan<FileDownloader::Download>);
+String download_status_text(WebView::FileDownloader::Download const&);
+String download_time_remaining_text(AK::Duration time_remaining);
+Vector<WebView::FileDownloader::Download const*> recent_downloads_for_popover(ReadonlySpan<WebView::FileDownloader::Download>);
+DownloadsButtonState downloads_button_state(ReadonlySpan<WebView::FileDownloader::Download>);
}
diff --git a/UI/Qt/HubConnection.cpp b/UI/Qt/HubConnection.cpp
index dbcce2bf8af..51d87124201 100644
--- a/UI/Qt/HubConnection.cpp
+++ b/UI/Qt/HubConnection.cpp
@@ -320,11 +320,6 @@ void HubConnection::app_display_download_confirmation_dialog(String download_nam
Application::the().display_download_confirmation_dialog(download_name, path);
}
-void HubConnection::app_open_file(String path)
-{
- Application::the().open_file(path);
-}
-
void HubConnection::app_read_clipboard_text(u64 request_id, WebView::Application::ClipboardType type)
{
async_answer_clipboard_text(request_id, Application::the().clipboard_text(type));
diff --git a/UI/Qt/HubConnection.h b/UI/Qt/HubConnection.h
index b8fb97cf663..cf11b26d074 100644
--- a/UI/Qt/HubConnection.h
+++ b/UI/Qt/HubConnection.h
@@ -132,7 +132,6 @@ private:
virtual void app_open_view_in_new_tab(u64 view_id, Optional<u64> source_view_id, WebView::IsPrivate is_private, Web::HTML::ActivateTab activate_tab) override;
virtual void app_display_error_dialog(String message) override;
virtual void app_display_download_confirmation_dialog(String download_name, ByteString path) override;
- virtual void app_open_file(String path) override;
virtual void app_read_clipboard_text(u64 request_id, WebView::Application::ClipboardType type) override;
virtual void app_read_clipboard_item(u64 request_id) override;
virtual void app_ask_user_for_download_path(u64 request_id, ByteString file) override;
diff --git a/UI/Qt/RemoteDownloads.cpp b/UI/Qt/RemoteDownloads.cpp
index 6a2901d6f04..0f08d3114fe 100644
--- a/UI/Qt/RemoteDownloads.cpp
+++ b/UI/Qt/RemoteDownloads.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <UI/Qt/Application.h>
#include <UI/Qt/HubConnection.h>
#include <UI/Qt/RemoteDownloads.h>
@@ -117,14 +118,29 @@ void RemoteDownloads::resume_download(u64 id)
HubConnection::the().async_resume_download(id);
}
+void RemoteDownloads::open_path(ByteString const& path, StringView error_message)
+{
+ if (auto path_string = String::from_byte_string(path); !path_string.is_error())
+ Application::the().open_file(path_string.value());
+ else
+ Application::the().display_error_dialog(error_message);
+}
+
+// NB: The UI opens a download itself, as only it sees the user ask for that. The Hub cannot have the UI open any file.
void RemoteDownloads::open(u64 id)
{
- HubConnection::the().async_open_download(id);
+ auto download = this->download(id);
+ if (!download.has_value() || download->status != WebView::FileDownloader::DownloadStatus::Completed)
+ return;
+ open_path(download->destination.string(), "Unable to open downloaded file: path cannot be represented by this frontend"sv);
}
void RemoteDownloads::show_in_folder(u64 id)
{
- HubConnection::the().async_show_download_in_folder(id);
+ auto download = this->download(id);
+ if (!download.has_value() || download->status != WebView::FileDownloader::DownloadStatus::Completed)
+ return;
+ open_path(download->destination.dirname(), "Unable to show downloaded file: path cannot be represented by this frontend"sv);
}
void RemoteDownloads::prune_inactive_downloads(WebView::IsPrivate is_private)
diff --git a/UI/Qt/RemoteDownloads.h b/UI/Qt/RemoteDownloads.h
index 415ba19427f..010c5191e1d 100644
--- a/UI/Qt/RemoteDownloads.h
+++ b/UI/Qt/RemoteDownloads.h
@@ -45,6 +45,8 @@ public:
private:
friend class RemoteDownloadsObserver;
+ static void open_path(ByteString const& path, StringView error_message);
+
Vector<Download> m_downloads;
HashMap<u64, Vector<WebView::FileDownloader::SegmentProgress>> m_segments;
Vector<RemoteDownloadsObserver&> m_observers;
diff --git a/UI/Qt/WindowToolbar.cpp b/UI/Qt/WindowToolbar.cpp
index 7ead6db6604..ee3fec5735b 100644
--- a/UI/Qt/WindowToolbar.cpp
+++ b/UI/Qt/WindowToolbar.cpp
@@ -11,13 +11,13 @@
#include <AK/kmalloc.h>
#include <LibWebView/Application.h>
#include <LibWebView/CrashReportOutbox.h>
-#include <LibWebView/DownloadPresentation.h>
#include <LibWebView/WebCompatReport.h>
#include <UI/Qt/Application.h>
#include <UI/Qt/ApplicationActions.h>
#include <UI/Qt/BrowserWindow.h>
#include <UI/Qt/ChromeLayout.h>
#include <UI/Qt/ChromeStyle.h>
+#include <UI/Qt/DownloadPresentation.h>
#include <UI/Qt/FeedbackPopover.h>
#include <UI/Qt/Icon.h>
#include <UI/Qt/LadybirdButton.h>
@@ -927,7 +927,7 @@ public:
m_file_name_label->setToolTip(qstring_from_ak_string(download.destination.string()));
m_file_icon->set_extension(qstring_from_ak_string(download.destination.extension()));
- auto status_text = qstring_from_ak_string(WebView::download_status_text(download));
+ auto status_text = qstring_from_ak_string(download_status_text(download));
m_status_label->setText(status_text);
m_status_label->setToolTip(status_text);
auto failed = download.status == WebView::FileDownloader::DownloadStatus::Failed;
@@ -1059,7 +1059,7 @@ public:
bool set_downloads(ReadonlySpan<WebView::FileDownloader::Download> downloads)
{
bool geometry_changed = false;
- auto visible_downloads = WebView::recent_downloads_for_popover(downloads);
+ auto visible_downloads = recent_downloads_for_popover(downloads);
if (!rows_match(visible_downloads)) {
rebuild_rows(visible_downloads);
@@ -1947,7 +1947,7 @@ void WindowToolbar::recreate_icons()
void WindowToolbar::update_downloads_button()
{
auto downloads = RemoteDownloads::the().downloads_of_session(m_is_private);
- auto button_state = WebView::downloads_button_state(downloads);
+ auto button_state = downloads_button_state(downloads);
if (!button_state.has_downloads && m_downloads_popover)
m_downloads_popover->close();
@@ -2041,7 +2041,7 @@ void WindowToolbar::show_feedback_popover()
void WindowToolbar::show_downloads_popover()
{
auto downloads = RemoteDownloads::the().downloads_of_session(m_is_private);
- if (!WebView::downloads_button_state(downloads).has_downloads) {
+ if (!downloads_button_state(downloads).has_downloads) {
m_open_downloads_page_action->trigger();
return;
}