Skip to content

Truly independent web browser

LibWebView+UI/Qt: List the frames of a process in the Task Manager

Andreas Kling6875816afd39
diff --git a/Libraries/LibWebView/ProcessSnapshot.cpp b/Libraries/LibWebView/ProcessSnapshot.cpp
index 54a6d6f6ba8..525e1ba4300 100644
--- a/Libraries/LibWebView/ProcessSnapshot.cpp
+++ b/Libraries/LibWebView/ProcessSnapshot.cpp
@@ -5,7 +5,9 @@
*/
#include <AK/HashMap.h>
+#include <LibWebCommon/HTML/SandboxingFlagSet.h>
#include <LibWebView/Application.h>
+#include <LibWebView/CanonicalDocument.h>
#include <LibWebView/CanonicalTraversable.h>
#include <LibWebView/FaviconStore.h>
#include <LibWebView/ProcessManager.h>
@@ -25,7 +27,7 @@ Vector<ProcessSnapshot> process_snapshots(ProcessManager& manager)
};
HashMap<u64, ProcessPage> process_pages;
HashMap<u64, Vector<ProcessTabSnapshot>> process_tabs;
- HashMap<u64, size_t> process_frame_counts;
+ HashMap<u64, Vector<ProcessFrameSnapshot>> process_frames;
// 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;
@@ -64,8 +66,12 @@ Vector<ProcessSnapshot> process_snapshots(ProcessManager& manager)
if (navigable.has_remote_host() && navigable.replicated_state().has_value()) {
auto child_id = navigable.remote_host().client().child_id();
add_page(child_id, navigable.replicated_state()->active_document_url, ProcessPageKind::Frame);
- if (child_id != top_level_child_id)
- ++process_frame_counts.ensure(child_id);
+ if (child_id != top_level_child_id) {
+ process_frames.ensure(child_id).append({
+ .url = navigable.replicated_state()->active_document_url,
+ .is_sandboxed = has_flag(navigable.active_document().active_sandboxing_flag_set(), Web::HTML::SandboxingFlagSet::SandboxedOrigin),
+ });
+ }
}
return IterationDecision::Continue;
});
@@ -86,7 +92,7 @@ Vector<ProcessSnapshot> process_snapshots(ProcessManager& manager)
.memory_usage_bytes = statistics.memory_usage_bytes,
.page = {},
.tabs = process_tabs.get(process.child_id()).value_or({}),
- .frame_count = process_frame_counts.get(process.child_id()).value_or(0),
+ .frames = process_frames.get(process.child_id()).value_or({}),
};
if (auto page = process_pages.get(process.child_id()); page.has_value()) {
snapshot.site_url = page->url;
diff --git a/Libraries/LibWebView/ProcessSnapshot.h b/Libraries/LibWebView/ProcessSnapshot.h
index ec26bbd7b39..a2349459db5 100644
--- a/Libraries/LibWebView/ProcessSnapshot.h
+++ b/Libraries/LibWebView/ProcessSnapshot.h
@@ -37,6 +37,12 @@ struct ProcessTabSnapshot {
ProcessPageSnapshot page;
};
+// A frame whose document a WebContent process hosts for a tab another process displays.
+struct ProcessFrameSnapshot {
+ URL::URL url;
+ bool is_sandboxed { false };
+};
+
struct ProcessSnapshot {
u64 child_id { 0 };
pid_t pid { 0 };
@@ -47,9 +53,9 @@ struct ProcessSnapshot {
float cpu_percent { 0 };
u64 memory_usage_bytes { 0 };
Optional<ProcessPageSnapshot> page;
- // The tabs whose pages the process hosts, and how many frames of other tabs' pages it hosts.
+ // The tabs whose pages the process hosts, and the frames of other tabs' pages it hosts.
Vector<ProcessTabSnapshot> tabs;
- size_t frame_count { 0 };
+ Vector<ProcessFrameSnapshot> frames;
};
// Updates the process statistics, and describes every process with the page that best represents it.
diff --git a/UI/Qt/ProcessManagerWindow.cpp b/UI/Qt/ProcessManagerWindow.cpp
index 2ee229fca4e..604430fcc88 100644
--- a/UI/Qt/ProcessManagerWindow.cpp
+++ b/UI/Qt/ProcessManagerWindow.cpp
@@ -78,6 +78,7 @@ enum class RowKind {
Site,
Group,
Tab,
+ Frame,
};
// Process rows are identified by the process's child ID, which, unlike its PID, never comes to name another process.
@@ -276,6 +277,16 @@ public:
}
};
+// 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)
+{
+ if (url.host().has_value())
+ return qstring_from_ak_string(ByteString::formatted("{}{}", url.host()->serialize(), url.serialize_path()));
+ if (url.scheme() == "data"sv)
+ return QStringLiteral("data:");
+ return qstring_from_ak_string(url.serialize_for_display());
+}
+
// What a row is sorted by in a column.
QVariant sort_key(QTreeWidgetItem const* item, int column)
{
@@ -677,7 +688,7 @@ void ProcessManagerWindow::refresh()
}
site->processes.append(&process);
site->tab_count += process.tabs.size();
- site->frame_count += process.frame_count;
+ site->frame_count += process.frames.size();
if (process.page.has_value() && (!site->page || (process.page->kind == WebView::ProcessPageKind::TopLevel && site->page->kind != WebView::ProcessPageKind::TopLevel)))
site->page = &*process.page;
site->cpu += process.cpu_percent;
@@ -752,6 +763,27 @@ void ProcessManagerWindow::refresh()
tab_item->setToolTip(Name, title);
tab_item->setIcon(Name, favicon_for(tab.page));
}
+ size_t sandboxed_frame_count = 0;
+ for (auto const& frame : process.frames) {
+ auto* frame_item = new QTreeWidgetItem(item, { frame_name(frame.url) });
+ frame_item->setData(Name, KindRole, static_cast<int>(RowKind::Frame));
+ frame_item->setFlags(Qt::ItemIsEnabled);
+ frame_item->setToolTip(Name, qstring_from_ak_string(frame.url.serialize_for_display()));
+ if (frame.is_sandboxed) {
+ frame_item->setData(Name, NoteRole, tr("Sandboxed"));
+ ++sandboxed_frame_count;
+ }
+ }
+ if (auto frame_count = process.frames.size(); frame_count > 0) {
+ if (sandboxed_frame_count == frame_count)
+ item->setData(Name, NoteRole, frame_count == 1 ? tr("1 sandboxed frame") : tr("%1 sandboxed frames").arg(frame_count));
+ else if (sandboxed_frame_count > 0)
+ item->setData(Name, NoteRole, tr("%1 frames, %2 sandboxed").arg(frame_count).arg(sandboxed_frame_count));
+ else
+ item->setData(Name, NoteRole, frame_count == 1 ? tr("1 frame") : tr("%1 frames").arg(frame_count));
+ if (sandboxed_frame_count > 0)
+ item->setToolTip(Name, tr("Sandboxed frames run apart from the other documents of their site."));
+ }
return item;
};