Skip to content

Truly independent web browser

UI/Qt: Show no browsing history on about:history in a private window

Andreas Klinge0461f7f47eb
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index c14cd709732..c175e99a7d1 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -1058,8 +1058,8 @@ void Application::create_platform_actions()
};
m_web_ui_pages = make<WebUIPages>();
m_bookmarks = make<Bookmarks>(*m_bookmark_store);
- m_web_ui_pages->register_page("history"_string, "History"_string, [](u64 web_ui_id, WebView::IsPrivate) -> NonnullOwnPtr<WebUIPage> {
- return make<HistoryPage>(web_ui_id);
+ m_web_ui_pages->register_page("history"_string, "History"_string, [](u64 web_ui_id, WebView::IsPrivate is_private) -> NonnullOwnPtr<WebUIPage> {
+ return make<HistoryPage>(web_ui_id, is_private);
});
m_web_ui_pages->register_page("downloads"_string, "Downloads"_string, [](u64 web_ui_id, WebView::IsPrivate is_private) -> NonnullOwnPtr<WebUIPage> {
return make<DownloadsPage>(web_ui_id, is_private);
diff --git a/UI/Qt/HistoryPage.cpp b/UI/Qt/HistoryPage.cpp
index b0ce8f80ecb..73ce5b02402 100644
--- a/UI/Qt/HistoryPage.cpp
+++ b/UI/Qt/HistoryPage.cpp
@@ -52,8 +52,9 @@ static JsonObject serialize_history_entry(WebView::HistoryEntry const& entry)
return serialized;
}
-HistoryPage::HistoryPage(u64 web_ui_id)
+HistoryPage::HistoryPage(u64 web_ui_id, WebView::IsPrivate is_private)
: WebUIPage(web_ui_id)
+ , m_is_private(is_private)
{
}
@@ -84,7 +85,10 @@ void HistoryPage::load_history_entries(JsonValue const& data)
else
limit = DEFAULT_HISTORY_PAGE_SIZE;
- auto entries = Application::history_store().list_entries(query, offset, *limit + 1);
+ // NB: A private window keeps no history, so its page shows none of the normal windows' history.
+ Vector<WebView::HistoryEntry> entries;
+ if (m_is_private == WebView::IsPrivate::No)
+ entries = Application::history_store().list_entries(query, offset, *limit + 1);
auto has_more = entries.size() > *limit;
if (has_more)
entries.resize(*limit);
@@ -106,7 +110,7 @@ void HistoryPage::load_history_entries(JsonValue const& data)
void HistoryPage::remove_history_entry(JsonValue const& data)
{
- if (!data.is_object())
+ if (m_is_private == WebView::IsPrivate::Yes || !data.is_object())
return;
auto url = data.as_object().get_string("url"sv);
@@ -124,7 +128,7 @@ void HistoryPage::remove_history_entry(JsonValue const& data)
void HistoryPage::forget_history_site(JsonValue const& data)
{
- if (!data.is_object())
+ if (m_is_private == WebView::IsPrivate::Yes || !data.is_object())
return;
auto url = data.as_object().get_string("url"sv);
diff --git a/UI/Qt/HistoryPage.h b/UI/Qt/HistoryPage.h
index ce278554d30..decdf07751e 100644
--- a/UI/Qt/HistoryPage.h
+++ b/UI/Qt/HistoryPage.h
@@ -12,7 +12,7 @@ namespace Ladybird {
class HistoryPage final : public WebUIPage {
public:
- explicit HistoryPage(u64 web_ui_id);
+ HistoryPage(u64 web_ui_id, WebView::IsPrivate);
virtual void received_message(String const& name, JsonValue const& data) override;
@@ -20,6 +20,8 @@ private:
void load_history_entries(JsonValue const&);
void remove_history_entry(JsonValue const&);
void forget_history_site(JsonValue const&);
+
+ WebView::IsPrivate m_is_private { WebView::IsPrivate::No };
};
}