Skip to content

Truly independent web browser

LibWebView+Hub+UI/Qt: Show in the task manager which tabs can unload

Andreas Kling7d7cf6098412
diff --git a/Libraries/LibWebView/DiscardBlockers.h b/Libraries/LibWebView/DiscardBlockers.h
new file mode 100644
index 00000000000..3ff2cd8da82
--- /dev/null
+++ b/Libraries/LibWebView/DiscardBlockers.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/EnumBits.h>
+#include <AK/Types.h>
+
+namespace WebView {
+
+// What keeps a tab from being discarded, which lets it stay loaded while the user doesn't see it.
+enum class DiscardBlockers : u32 {
+ None = 0,
+ NotATab = 1 << 0,
+ NotRestorable = 1 << 16,
+ Visible = 1 << 1,
+ Pinned = 1 << 2,
+ CurrentTabOfWindow = 1 << 3,
+ Loading = 1 << 4,
+ Crashed = 1 << 5,
+ PlayingAudio = 1 << 6,
+ RecentlyPlayedAudio = 1 << 7,
+ CapturingAudio = 1 << 8,
+ UsingLocation = 1 << 9,
+ OwnsAView = 1 << 10,
+ DevToolsConnected = 1 << 11,
+ AsksBeforeUnloading = 1 << 12,
+ // Only a tab hidden for long is kept for these, as they're work the tab does for the user in the background.
+ ChangedTitleOrFaviconWhileHidden = 1 << 13,
+ MayShowNotifications = 1 << 14,
+};
+
+AK_ENUM_BITWISE_OPERATORS(DiscardBlockers);
+
+}
diff --git a/Libraries/LibWebView/ProcessSnapshot.cpp b/Libraries/LibWebView/ProcessSnapshot.cpp
index 1bdec62fb49..6aafd001e24 100644
--- a/Libraries/LibWebView/ProcessSnapshot.cpp
+++ b/Libraries/LibWebView/ProcessSnapshot.cpp
@@ -27,6 +27,7 @@ Vector<ProcessSnapshot> process_snapshots(ProcessManager& manager)
HashMap<u64, ProcessPage> process_pages;
HashMap<u64, Vector<ProcessTabSnapshot>> process_tabs;
HashMap<u64, Vector<ProcessFrameSnapshot>> process_frames;
+ auto now = MonotonicTime::now();
// NB: The Application is only asked once there is a view, so that a ProcessManager without one can be described.
bool did_look_up_active_view = false;
Optional<ViewImplementation&> active_view;
@@ -52,14 +53,26 @@ Vector<ProcessSnapshot> process_snapshots(ProcessManager& manager)
};
auto top_level_child_id = view.page().client().child_id();
add_page(top_level_child_id, view.url(), ProcessPageKind::TopLevel);
- process_tabs.ensure(top_level_child_id).append(ProcessTabSnapshot {
+ ProcessTabSnapshot tab {
.title = view.title(),
.page = {
.view_id = view.view_id(),
.url = view.url(),
.kind = ProcessPageKind::TopLevel,
},
- });
+ .discard_blockers_under_memory_pressure = view.discard_blockers(ViewImplementation::DiscardReason::MemoryPressure, now),
+ .discard_blockers_after_inactivity = {},
+ .seconds_until_discarded_after_inactivity = {},
+ };
+ if (auto minutes = Application::settings().tab_settings().discard_hidden_tabs_after_minutes; minutes != 0) {
+ auto blockers = view.discard_blockers(ViewImplementation::DiscardReason::Inactivity, now);
+ tab.discard_blockers_after_inactivity = blockers;
+ if (blockers == DiscardBlockers::None && view.hidden_since().has_value()) {
+ auto remaining = AK::Duration::from_seconds(static_cast<i64>(minutes) * 60) - (now - *view.hidden_since());
+ tab.seconds_until_discarded_after_inactivity = max<i64>(0, remaining.to_seconds());
+ }
+ }
+ process_tabs.ensure(top_level_child_id).append(move(tab));
view.traversable().for_each_in_subtree([&](auto const& navigable) {
if (navigable.has_remote_host() && navigable.replicated_state().has_value()) {
auto child_id = navigable.remote_host().client().child_id();
diff --git a/Libraries/LibWebView/ProcessSnapshot.h b/Libraries/LibWebView/ProcessSnapshot.h
index c2446b76138..631c19170bd 100644
--- a/Libraries/LibWebView/ProcessSnapshot.h
+++ b/Libraries/LibWebView/ProcessSnapshot.h
@@ -13,6 +13,7 @@
#include <AK/Vector.h>
#include <LibURL/URL.h>
#include <LibWebView/BrowsingSession.h>
+#include <LibWebView/DiscardBlockers.h>
#include <LibWebView/Export.h>
#include <LibWebView/Forward.h>
#include <LibWebView/ProcessType.h>
@@ -35,6 +36,12 @@ struct ProcessPageSnapshot {
struct ProcessTabSnapshot {
Utf16String title;
ProcessPageSnapshot page;
+ // What keeps the tab loaded when the system is about to run out of memory, and once it was hidden for as long as
+ // the user's settings allow, if they allow it.
+ DiscardBlockers discard_blockers_under_memory_pressure { DiscardBlockers::None };
+ Optional<DiscardBlockers> discard_blockers_after_inactivity;
+ // How long until the tab is discarded for being hidden, if nothing keeps it.
+ Optional<i64> seconds_until_discarded_after_inactivity;
};
// A frame whose document a WebContent process hosts for a tab another process displays.
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 995a71d6fa0..dff1f4ef54c 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -93,9 +93,27 @@ Optional<ViewImplementation&> ViewImplementation::tab_view()
return find_view_by_id(*m_owner_view_id);
}
+void ViewImplementation::set_owner_view(ViewImplementation& owner_view)
+{
+ VERIFY(!m_owner_view_id.has_value());
+ m_owner_view_id = owner_view.view_id();
+ ++owner_view.m_owned_view_count;
+ m_counts_as_owned_view = true;
+}
+
+void ViewImplementation::stop_counting_as_owned_view()
+{
+ if (!exchange(m_counts_as_owned_view, false))
+ return;
+ if (auto owner = find_view_by_id(*m_owner_view_id); owner.has_value())
+ --owner->m_owned_view_count;
+}
+
void ViewImplementation::did_leave_owners_tab(Badge<PictureInPictureWindow>)
{
m_owner_document = nullptr;
+ // NB: A window that left its owner's tab is hidden until its page closes, so the user doesn't see it anymore.
+ stop_counting_as_owned_view();
// Whether a process may capture audio depends on the tabs its pages are part of.
traversable().for_each_hosting_page([](WebContentPage& page) {
@@ -129,6 +147,7 @@ ViewImplementation::ViewImplementation(IsPrivate is_private)
ViewImplementation::~ViewImplementation()
{
+ stop_counting_as_owned_view();
Application::the().media_session_coordinator().remove_view(view_id());
// The frontend may be torn down already, so clearing the ongoing navigation must not report a URL change to it, nor
// cancelling the view's location requests or closing the view's page (which revokes its audio playback and capture)
@@ -622,60 +641,74 @@ static constexpr auto time_silent_before_discarding = AK::Duration::from_seconds
bool ViewImplementation::may_be_discarded(DiscardReason reason, AK::Duration minimum_time_hidden, MonotonicTime now) const
{
- if (!supports_discarding() || m_discard_requested || !m_top_level_traversable)
- return false;
- if (traversable().system_visibility_state() != Web::HTML::VisibilityState::Hidden || !m_hidden_since.has_value() || now - *m_hidden_since < minimum_time_hidden)
+ if (m_discard_requested || !m_hidden_since.has_value() || now - *m_hidden_since < minimum_time_hidden)
return false;
+ return discard_blockers(reason, now) == DiscardBlockers::None;
+}
+
+DiscardBlockers ViewImplementation::discard_blockers(DiscardReason reason, MonotonicTime now) const
+{
+ if (!supports_discarding() || !m_top_level_traversable)
+ return DiscardBlockers::NotATab;
+
+ auto blockers = DiscardBlockers::None;
+ // NB: The UI brings a discarded tab back from the session history it keeps for the tab, which it only keeps for the
+ // tabs that report it.
+ if (!m_reports_session_history)
+ blockers |= DiscardBlockers::NotRestorable;
+ if (traversable().system_visibility_state() != Web::HTML::VisibilityState::Hidden)
+ blockers |= DiscardBlockers::Visible;
// The user keeps a pinned tab at hand, and sees a window's current tab whenever they look at the window.
- if (m_pinned || m_current_tab_of_window)
- return false;
+ if (m_pinned)
+ blockers |= DiscardBlockers::Pinned;
+ if (m_current_tab_of_window)
+ blockers |= DiscardBlockers::CurrentTabOfWindow;
// NB: A tab that hasn't loaded yet has nothing to restore, and a crashed tab shows the user what happened to it.
- if (is_loading() || m_crash_state.has_value())
- return false;
+ if (is_loading())
+ blockers |= DiscardBlockers::Loading;
+ if (m_crash_state.has_value())
+ blockers |= DiscardBlockers::Crashed;
// A tab that the user hears, or that listens or follows them, would stop doing it.
- if (is_playing_audio() || is_capturing_audio() || m_tab_indicators.is_active(TabIndicator::UsingLocation))
- return false;
- if (m_stopped_playing_audio_time.has_value() && now - *m_stopped_playing_audio_time < time_silent_before_discarding)
- return false;
+ if (is_playing_audio())
+ blockers |= DiscardBlockers::PlayingAudio;
+ else if (m_stopped_playing_audio_time.has_value() && now - *m_stopped_playing_audio_time < time_silent_before_discarding)
+ blockers |= DiscardBlockers::RecentlyPlayedAudio;
+ if (is_capturing_audio())
+ blockers |= DiscardBlockers::CapturingAudio;
+ if (m_tab_indicators.is_active(TabIndicator::UsingLocation))
+ blockers |= DiscardBlockers::UsingLocation;
// A view that this one owns, such as a Picture-in-Picture window, shows the user what the tab does.
- auto owns_a_view = false;
- for_each_view([&](ViewImplementation& view) {
- if (view.owner_view_id() != m_view_id)
- return IterationDecision::Continue;
- owns_a_view = true;
- return IterationDecision::Break;
- });
- if (owns_a_view || m_devtools_connected)
- return false;
+ if (m_owned_view_count > 0)
+ blockers |= DiscardBlockers::OwnsAView;
+ if (m_devtools_connected)
+ blockers |= DiscardBlockers::DevToolsConnected;
// NB: A page asks to be checked before it's unloaded when it holds something the user would lose, such as what they
// typed into a form.
if (needs_beforeunload_check())
- return false;
+ blockers |= DiscardBlockers::AsksBeforeUnloading;
if (reason == DiscardReason::Inactivity) {
// A tab that changes what it shows in the tab strip, such as the count of unread messages in its title, does
// work for the user in the background. So does one that may show them notifications.
if (m_changed_title_or_favicon_while_hidden)
- return false;
+ blockers |= DiscardBlockers::ChangedTitleOrFaviconWhileHidden;
if (auto origin = permission_origin(); !origin.is_opaque()) {
if (session().permission_manager->effective_state(Web::Permissions::PermissionName::Notifications, origin) == Web::Permissions::EffectiveState::Granted)
- return false;
+ blockers |= DiscardBlockers::MayShowNotifications;
} else {
// NB: A file: page's grant goes away with the page, so it would not even come back with the tab.
- auto may_show_notifications = false;
traversable().for_each_hosting_page([&](WebContentPage& page) {
- may_show_notifications |= page.hosts_a_local_file_document_that_may_use(Web::Permissions::PermissionName::Notifications);
+ if (page.hosts_a_local_file_document_that_may_use(Web::Permissions::PermissionName::Notifications))
+ blockers |= DiscardBlockers::MayShowNotifications;
});
- if (may_show_notifications)
- return false;
}
}
- return true;
+ return blockers;
}
// The user should find the tab as they left it, so the processes hosting it first save where the user was in each of
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index bf3fd049796..c78df378fa0 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -73,6 +73,7 @@
#include <LibWebView/CanonicalTraversable.h>
#include <LibWebView/ContentBlocking.h>
#include <LibWebView/ContextMenuRequest.h>
+#include <LibWebView/DiscardBlockers.h>
#include <LibWebView/ExternalURLHandler.h>
#include <LibWebView/Forward.h>
#include <LibWebView/HistoryVisitTransition.h>
@@ -239,6 +240,7 @@ public:
Inactivity,
};
bool may_be_discarded(DiscardReason, AK::Duration minimum_time_hidden, MonotonicTime now) const;
+ DiscardBlockers discard_blockers(DiscardReason, MonotonicTime now) const;
// Whether discarding the view would let a process exit, which is how its memory comes back.
bool discarding_ends_a_process() const;
void set_pinned(bool pinned);
@@ -833,7 +835,7 @@ protected:
explicit ViewImplementation(IsPrivate = IsPrivate::No);
- void set_owner_view(ViewImplementation const& owner_view) { m_owner_view_id = owner_view.view_id(); }
+ void set_owner_view(ViewImplementation& owner_view);
void did_update_url();
void settle_permission_prompt(PermissionPromptRequest const&, Web::Permissions::PromptOutcome);
@@ -844,6 +846,7 @@ protected:
void set_favicon(Optional<Gfx::Bitmap const&>);
void did_change_title_or_favicon();
void finish_discard_request();
+ void stop_counting_as_owned_view();
void start_being_hidden();
Optional<URL::URL const&> browser_ui_load_url() const;
void update_displayed_url();
@@ -1292,6 +1295,9 @@ protected:
// is required to be globally unique for Firefox DevTools.
u64 m_view_id { 0 };
Optional<u64> m_owner_view_id;
+ // NB: Counted so that whether this view owns another is known without looking at every view.
+ size_t m_owned_view_count { 0 };
+ bool m_counts_as_owned_view { false };
WeakPtr<CanonicalDocument const> m_owner_document;
HashMap<u64, NavigationListener> m_navigation_listeners;
diff --git a/Services/Hub/HubServer.ipc b/Services/Hub/HubServer.ipc
index 1896df5c97e..fb6ff76c43e 100644
--- a/Services/Hub/HubServer.ipc
+++ b/Services/Hub/HubServer.ipc
@@ -82,6 +82,9 @@ struct WebView::ProcessPageSnapshot {
struct WebView::ProcessTabSnapshot {
Utf16String title;
WebView::ProcessPageSnapshot page;
+ WebView::DiscardBlockers discard_blockers_under_memory_pressure;
+ Optional<WebView::DiscardBlockers> discard_blockers_after_inactivity;
+ Optional<i64> seconds_until_discarded_after_inactivity;
}
[ExistingCpp]
diff --git a/Tests/UI/Qt/TestProcessManagerWindow.cpp b/Tests/UI/Qt/TestProcessManagerWindow.cpp
index e56a7059117..305a341aa1a 100644
--- a/Tests/UI/Qt/TestProcessManagerWindow.cpp
+++ b/Tests/UI/Qt/TestProcessManagerWindow.cpp
@@ -61,9 +61,9 @@ TEST_CASE(palette_changes_do_not_reenter_style_updates)
auto* processes = window.findChild<QTreeWidget*>();
EXPECT(processes);
- EXPECT_EQ(processes->columnCount(), 4);
+ EXPECT_EQ(processes->columnCount(), 5);
EXPECT(processes->headerItem()->textAlignment(0) & Qt::AlignLeft);
- for (int column = 1; column < 4; ++column)
+ for (int column = 1; column < 5; ++column)
EXPECT(processes->headerItem()->textAlignment(column) & Qt::AlignRight);
}
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp
index ba0aecfd50c..b939d1e6493 100644
--- a/UI/Qt/BrowserWindow.cpp
+++ b/UI/Qt/BrowserWindow.cpp
@@ -1205,10 +1205,10 @@ bool BrowserWindow::close_tab(int index, SessionStore::KeepForReopening keep_for
// Closing the tab's view closes its pages, and so lets the processes that hosted them exit if they host nothing else.
void BrowserWindow::discard_tab(Tab& tab)
{
- // NB: The Hub decides which tabs to discard. The user may have selected or pinned the tab while the request
- // was on its way, which the Hub learns of soon after, and a tab that a session can't restore can't be
- // discarded. A tab that reviews a report would lose the report, which only its page holds, and one with an
- // unfinished edit of its address would lose the edit.
+ // NB: The Hub decides which tabs to discard. The user may have selected or pinned the tab while the request was on
+ // its way, or its window may have stopped keeping its history, which the Hub learns of soon after. A tab that
+ // reviews a report would lose the report, which only its page holds, and one with an unfinished edit of its
+ // address would lose the edit.
auto index = tab_index(&tab);
if (index < 0 || &tab == m_current_tab || tab.is_pinned() || tab.is_in_report_review() || tab.location_edit_with_parked_editing())
return;
diff --git a/UI/Qt/ProcessManagerWindow.cpp b/UI/Qt/ProcessManagerWindow.cpp
index 3d8802aed89..5dcdb7ebe5a 100644
--- a/UI/Qt/ProcessManagerWindow.cpp
+++ b/UI/Qt/ProcessManagerWindow.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/Array.h>
#include <AK/HashMap.h>
#include <AK/QuickSort.h>
#include <AK/kmalloc.h>
@@ -73,6 +74,7 @@ enum Column {
CPU,
Memory,
PID,
+ CanUnload,
};
enum class RowKind {
@@ -279,6 +281,104 @@ public:
}
};
+static QString duration_text(i64 seconds)
+{
+ if (seconds < 60)
+ return QObject::tr("less than a minute");
+ auto minutes = seconds / 60;
+ if (minutes < 60)
+ return QObject::tr("%1 min").arg(minutes);
+ return QObject::tr("%1 h %2 min").arg(minutes / 60).arg(minutes % 60);
+}
+
+struct CanUnloadState {
+ bool can_unload { false };
+ QString explanation;
+};
+
+// Whether a tab can be unloaded to save memory, and when it will be, or what keeps it loaded.
+static CanUnloadState can_unload_state(WebView::ProcessTabSnapshot const& tab)
+{
+ using WebView::DiscardBlockers;
+ auto blockers = tab.discard_blockers_after_inactivity.value_or(tab.discard_blockers_under_memory_pressure);
+
+ if (blockers == DiscardBlockers::None) {
+ if (!tab.discard_blockers_after_inactivity.has_value())
+ return { true, QObject::tr("Only when the system is about to run out of memory") };
+ if (tab.seconds_until_discarded_after_inactivity.has_value())
+ return { true, QObject::tr("Unloads in %1 if it stays hidden").arg(duration_text(*tab.seconds_until_discarded_after_inactivity)) };
+ return { true, {} };
+ }
+
+ struct Description {
+ DiscardBlockers blocker;
+ char const* text;
+ };
+ static constexpr Array descriptions {
+ Description { DiscardBlockers::NotATab, QT_TRANSLATE_NOOP("QObject", "It isn't a tab") },
+ Description { DiscardBlockers::NotRestorable, QT_TRANSLATE_NOOP("QObject", "Its window doesn't keep its history") },
+ Description { DiscardBlockers::Visible, QT_TRANSLATE_NOOP("QObject", "It's visible") },
+ Description { DiscardBlockers::Pinned, QT_TRANSLATE_NOOP("QObject", "It's pinned") },
+ Description { DiscardBlockers::CurrentTabOfWindow, QT_TRANSLATE_NOOP("QObject", "It's the current tab of its window") },
+ Description { DiscardBlockers::Loading, QT_TRANSLATE_NOOP("QObject", "It's loading") },
+ Description { DiscardBlockers::Crashed, QT_TRANSLATE_NOOP("QObject", "It crashed") },
+ Description { DiscardBlockers::PlayingAudio, QT_TRANSLATE_NOOP("QObject", "It's playing sound") },
+ Description { DiscardBlockers::RecentlyPlayedAudio, QT_TRANSLATE_NOOP("QObject", "It played sound in the last minute") },
+ Description { DiscardBlockers::CapturingAudio, QT_TRANSLATE_NOOP("QObject", "It's using the microphone") },
+ Description { DiscardBlockers::UsingLocation, QT_TRANSLATE_NOOP("QObject", "It's using your location") },
+ Description { DiscardBlockers::OwnsAView, QT_TRANSLATE_NOOP("QObject", "It has a Picture-in-Picture window") },
+ Description { DiscardBlockers::DevToolsConnected, QT_TRANSLATE_NOOP("QObject", "DevTools are open for it") },
+ Description { DiscardBlockers::AsksBeforeUnloading, QT_TRANSLATE_NOOP("QObject", "The page asks to be checked before it's unloaded") },
+ Description { DiscardBlockers::ChangedTitleOrFaviconWhileHidden, QT_TRANSLATE_NOOP("QObject", "It changed its title or icon while hidden") },
+ Description { DiscardBlockers::MayShowNotifications, QT_TRANSLATE_NOOP("QObject", "The site may show notifications") },
+ };
+ QStringList lines { QObject::tr("Stays loaded:") };
+ for (auto const& description : descriptions) {
+ if (has_flag(blockers, description.blocker))
+ lines.append(QStringLiteral("• ") + QObject::tr(description.text));
+ }
+ // NB: A tab that only inactivity keeps loaded can still be unloaded, as one is when the timer is off.
+ auto can_unload_under_memory_pressure = tab.discard_blockers_after_inactivity.has_value() && tab.discard_blockers_under_memory_pressure == DiscardBlockers::None;
+ if (can_unload_under_memory_pressure)
+ lines.append(QObject::tr("It can still be unloaded when the system is about to run out of memory."));
+ return { can_unload_under_memory_pressure, lines.join('\n') };
+}
+
+// A row for several tabs, such as a site's, says whether all, some, or none of them can be unloaded, and why for each.
+static void set_can_unload(QTreeWidgetItem& item, Vector<WebView::ProcessTabSnapshot const*> const& tabs)
+{
+ if (tabs.is_empty())
+ return;
+
+ size_t unloadable_count = 0;
+ QStringList explanations;
+ for (auto const* tab : tabs) {
+ auto state = can_unload_state(*tab);
+ if (state.can_unload)
+ ++unloadable_count;
+ if (tabs.size() == 1) {
+ explanations.append(state.explanation);
+ continue;
+ }
+ auto title = tab->title.is_empty() ? QObject::tr("Untitled") : qstring_from_utf16_string(tab->title);
+ explanations.append(state.explanation.isEmpty() ? title : title + QStringLiteral("\n") + state.explanation);
+ }
+
+ // NB: Rows sort by how much of them can be unloaded, after the rows of processes that show no tab.
+ item.setTextAlignment(CanUnload, Qt::AlignRight | Qt::AlignVCenter);
+ if (unloadable_count == tabs.size()) {
+ item.setText(CanUnload, QObject::tr("Yes"));
+ item.setData(CanUnload, Qt::UserRole, 3);
+ } else if (unloadable_count == 0) {
+ item.setText(CanUnload, QObject::tr("No"));
+ item.setData(CanUnload, Qt::UserRole, 1);
+ } else {
+ item.setText(CanUnload, QObject::tr("Some"));
+ item.setData(CanUnload, Qt::UserRole, 2);
+ }
+ item.setToolTip(CanUnload, explanations.join(QStringLiteral("\n\n")));
+}
+
// A frame's URL without what follows its path, which on the frames this names most often is a long tracking query.
static QString frame_name(URL::URL const& url)
{
@@ -406,7 +506,7 @@ ProcessManagerWindow::ProcessManagerWindow(Source source)
process_tree->on_context_menu = [this](auto const& position) { show_context_menu(position); };
m_processes = process_tree;
m_processes->setHeader(new ProcessHeader(m_processes));
- m_processes->setHeaderLabels({ tr("Name"), tr("CPU"), tr("Memory"), tr("PID") });
+ m_processes->setHeaderLabels({ tr("Name"), tr("CPU"), tr("Memory"), tr("PID"), tr("Can unload") });
m_processes->headerItem()->setTextAlignment(Name, Qt::AlignLeft | Qt::AlignVCenter);
m_processes->setIconSize(QSize(16, 16));
m_processes->setAccessibleName(tr("Processes"));
@@ -423,7 +523,7 @@ ProcessManagerWindow::ProcessManagerWindow(Source source)
m_processes->header()->setFixedHeight(30);
m_processes->header()->setStretchLastSection(false);
m_processes->header()->setSectionResizeMode(Name, QHeaderView::Stretch);
- for (auto column : { CPU, Memory, PID }) {
+ for (auto column : { CPU, Memory, PID, CanUnload }) {
m_processes->header()->setSectionResizeMode(column, QHeaderView::Interactive);
m_processes->setColumnWidth(column, column == Memory ? 122 : 102);
m_processes->headerItem()->setTextAlignment(column, Qt::AlignRight | Qt::AlignVCenter);
@@ -781,6 +881,7 @@ void ProcessManagerWindow::refresh()
item->setData(PID, Qt::UserRole, static_cast<qlonglong>(process.pid));
item->setData(PID, ChildIDRole, static_cast<qulonglong>(process.child_id));
set_numbers(*item, process.cpu_percent, process.memory_usage_bytes);
+ Vector<WebView::ProcessTabSnapshot const*> process_tabs;
for (auto const& tab : process.tabs) {
auto title = tab.title.is_empty() ? tr("Untitled") : qstring_from_utf16_string(tab.title);
auto* tab_item = new QTreeWidgetItem(item, { title });
@@ -788,7 +889,10 @@ void ProcessManagerWindow::refresh()
tab_item->setFlags(Qt::ItemIsEnabled);
tab_item->setToolTip(Name, title);
tab_item->setIcon(Name, favicon_for(tab.page));
+ set_can_unload(*tab_item, { &tab });
+ process_tabs.append(&tab);
}
+ set_can_unload(*item, process_tabs);
size_t sandboxed_frame_count = 0;
for (auto const& frame : process.frames) {
auto* frame_item = new QTreeWidgetItem(item, { frame_name(frame.url) });
@@ -878,6 +982,12 @@ void ProcessManagerWindow::refresh()
note.append(site.frame_count == 1 ? tr("1 embedded frame") : tr("%1 embedded frames").arg(site.frame_count));
item->setData(Name, NoteRole, note.join(QStringLiteral(" · ")));
set_numbers(*item, site.cpu, site.memory);
+ Vector<WebView::ProcessTabSnapshot const*> site_tabs;
+ for (auto const* process : site.processes) {
+ for (auto const& tab : process->tabs)
+ site_tabs.append(&tab);
+ }
+ set_can_unload(*item, site_tabs);
site_items.append(item);
Vector<QTreeWidgetItem*> process_items;