Truly independent web browser
LibWebView+UI/Qt: Keep unanswered tab crash reports in about:crashes
Andreas Klingee428e065f3e
diff --git a/Base/res/ladybird/about-pages/crashes.html b/Base/res/ladybird/about-pages/crashes.htmlindex f734eeea2da..e46753e7084 100644--- a/Base/res/ladybird/about-pages/crashes.html+++ b/Base/res/ladybird/about-pages/crashes.html@@ -219,6 +219,39 @@box-shadow: inset 0 0 0 2px var(--link);}+ .report-websites {+ display: flex;+ flex-direction: column;+ gap: 6px;++ color: var(--body);+ font-size: 12px;+ }++ .report-website-list {+ display: flex;+ flex-direction: column;+ gap: 6px;+ max-height: 96px;+ overflow: auto;+ }++ .report-website {+ display: flex;+ align-items: flex-start;+ gap: 8px;+ }++ .report-website input {+ margin: 0;+ }++ .report-website-address {+ min-width: 0;+ color: var(--muted);+ overflow-wrap: anywhere;+ }+.report-footer {display: flex;align-items: center;@@ -299,6 +332,10 @@What were you doing? (optional)<textarea maxlength="4096"></textarea></label>+ <div class="report-websites hidden">+ <span class="report-websites-title">Include website addresses</span>+ <div class="report-website-list"></div>+ </div><p class="report-text-note hidden"></p><pre class="report-text hidden"></pre><div class="report-footer">@@ -364,9 +401,59 @@return `${group.names.length} times · last ${when.charAt(0).toLowerCase()}${when.slice(1)}`;}+ function tickedWebsites(card) {+ const ticked = card.querySelectorAll(".report-website input:checked");+ return new Set([...ticked].map(input => input.value));+ }++ function createWebsite(website, isOnlyWebsite) {+ const label = document.createElement("label");+ label.className = "report-website";++ const input = document.createElement("input");+ input.type = "checkbox";+ input.value = website;+ label.append(input);++ if (isOnlyWebsite) label.append("Include website address");++ const address = document.createElement("span");+ address.className = "report-website-address";+ address.textContent = website;+ label.append(address);+ return label;+ }++ // Every website that would be sent is listed with its own box, so nothing leaves that the user did not tick.+ function updateWebsites(card, group) {+ const list = card.querySelector(".report-website-list");+ const key = JSON.stringify(group.websites);+ if (list.dataset.websites !== key) {+ const ticked = tickedWebsites(card);+ list.dataset.websites = key;+ list.replaceChildren(+ ...group.websites.map(website => createWebsite(website, group.websites.length === 1))+ );+ list.querySelectorAll("input").forEach(input => {+ input.checked = ticked.has(input.value);+ });+ }++ list.querySelectorAll("input").forEach(input => {+ input.disabled = group.isSending;+ });+ card.querySelector(".report-websites").classList.toggle("hidden", group.websites.length === 0);+ card.querySelector(".report-websites-title").classList.toggle("hidden", group.websites.length < 2);+ }+function reportsToSend(group, card) {const description = card.querySelector("textarea").value;- return group.names.map(name => ({ name, description }));+ const ticked = tickedWebsites(card);+ return group.names.map((name, index) => ({+ name,+ description,+ includeWebsite: ticked.has(group.websiteOfEachReport[index]),+ }));}function createCard(id) {@@ -422,6 +509,8 @@});card.querySelector("textarea").disabled = group.isSending;+ updateWebsites(card, group);+const expanded =card.classList.contains("expanded") || (groups.length === 1 && !collapsedByUser.has(group.id));card.classList.toggle("expanded", expanded);diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cppindex 953e94cc6d9..dbdd663aeab 100644--- a/Libraries/LibWebView/Application.cpp+++ b/Libraries/LibWebView/Application.cpp@@ -2346,7 +2346,6 @@ void Application::process_did_exit(Process&& process, Optional<int>)dbgln_if(WEBVIEW_PROCESS_DEBUG, "Process {} died, type: {}", process.pid(), process_name_from_type(process.type()));auto const& report_name = process.saved_crash_report_name();- auto crash_is_shown_in_tab = false;switch (process.type()) {case ProcessType::Compositor:@@ -2381,10 +2380,8 @@ void Application::process_did_exit(Process&& process, Optional<int>)case ProcessType::WebContent:if (auto client = process.client<WebContentClient>()) {client->did_lose_process();- if (!report_name.is_empty()) {+ if (!report_name.is_empty())client->did_save_crash_report(report_name);- crash_is_shown_in_tab = client->has_crashed_views();- }m_web_content_clients.remove(client.release_nonnull());}break;@@ -2399,14 +2396,8 @@ void Application::process_did_exit(Process&& process, Optional<int>)if (report_name.is_empty())return;- // The tab's crash screen already asks about this report. Every other crash is hidden from the user, so its report- // waits to be reviewed.- if (!crash_is_shown_in_tab) {- CrashReportOutbox::the().reports_changed();- } else if (!browser_options().headless_mode.has_value()) {- if (auto result = CrashReportStore::the().mark_seen(report_name); result.is_error())- warnln("Could not mark crash report as seen: {}", result.error());- }+ // A report waits until it is answered, on a tab's crash screen or in the list of reports.+ CrashReportOutbox::the().reports_changed();}static bool download_path_is_available(LexicalPath const& path)@@ -2606,6 +2597,9 @@ NonnullRefPtr<Core::Promise<Empty>> Application::clear_browsing_data(ClearBrowsiif (auto result = private_session->session_store->remove_entries_accessed_since(options.since); result.is_error())dbgln("Unable to remove closed private session entries: {}", result.error());}+ if (auto result = CrashReportStore::the().remove_websites_saved_since(options.since); result.is_error())+ dbgln("Unable to remove the websites of crash reports: {}", result.error());+ CrashReportOutbox::the().reports_changed();did_change_history = true;}diff --git a/Libraries/LibWebView/CrashReportOutbox.cpp b/Libraries/LibWebView/CrashReportOutbox.cppindex 900b862126b..06d8dd5a970 100644--- a/Libraries/LibWebView/CrashReportOutbox.cpp+++ b/Libraries/LibWebView/CrashReportOutbox.cpp@@ -60,6 +60,26 @@ void CrashReportOutbox::send(Vector<Report> reports)reports_changed();}+Optional<String> CrashReportOutbox::send_from_review(CrashReportReview& review, String const& description, Optional<String> const& url)+{+ auto name = review.report_name();+ if (is_sending(name))+ return "This report is already being sent."_string;++ if (auto reason = review.send(description, url); reason.has_value())+ return reason;++ if (auto* submission = review.submission()) {+ submission->on_finished = [this, name] {+ m_submissions_from_reviews.remove(name);+ reports_changed();+ };+ m_submissions_from_reviews.set(name, *submission);+ }+ reports_changed();+ return {};+}+void CrashReportOutbox::send_next(){while (!m_report_being_sent.has_value() && !m_queue.is_empty()) {@@ -67,14 +87,14 @@ void CrashReportOutbox::send_next()m_report_being_sent = report.name;m_report_being_sent_was_retried = false;- if (auto opened = m_review.open(report.name, CrashReportReview::MarkAsSeen::No); opened.is_error()) {+ if (auto opened = m_review.open(report.name); opened.is_error()) {warnln("Could not open crash report {}: {}", report.name, opened.error());report_failed();continue;}if (report.earlier_attempt.has_value())m_review.set_prepared_submission(report.earlier_attempt.release_value());- if (auto reason = m_review.send(report.description, {}); reason.has_value()) {+ if (auto reason = m_review.send(report.description, report.url); reason.has_value()) {warnln("Could not send crash report {}: {}", report.name, *reason);report_failed();}@@ -104,6 +124,9 @@ void CrashReportOutbox::discard_all()m_could_not_send.clear();m_review.cancel_sending();m_report_being_sent.clear();+ auto submissions_from_reviews = move(m_submissions_from_reviews);+ for (auto& submission : submissions_from_reviews)+ submission.value->cancel();if (auto result = m_store.remove_all_reports(); result.is_error())warnln("Could not delete crash reports: {}", result.error());reports_changed();@@ -112,6 +135,7 @@ void CrashReportOutbox::discard_all()bool CrashReportOutbox::is_sending(ByteString const& name) const{return m_report_being_sent == name+ || m_submissions_from_reviews.contains(name)|| any_of(m_queue, [&](auto const& report) { return report.name == name; });}diff --git a/Libraries/LibWebView/CrashReportOutbox.h b/Libraries/LibWebView/CrashReportOutbox.hindex e4a9566beec..7a8407263df 100644--- a/Libraries/LibWebView/CrashReportOutbox.h+++ b/Libraries/LibWebView/CrashReportOutbox.h@@ -25,6 +25,7 @@ public:struct Report {ByteString name;String description;+ Optional<String> url {};Optional<CrashReportReview::PreparedSubmission> earlier_attempt {};};@@ -34,6 +35,11 @@ public:void send(Vector<Report>);+ // Sends the report a review has open, for a review that shows the sending itself. Returns why nothing was sent, or+ // nothing when the report is on its way. Only one place at a time can send a report, and it counts as being sent+ // here for as long as it is on its way, whatever becomes of the review.+ Optional<String> send_from_review(CrashReportReview&, String const& description, Optional<String> const& url);+// A report on its way is no longer the user's to delete.void remove(ReadonlySpan<ByteString> names);@@ -59,6 +65,7 @@ private:CrashReportReview m_review;Vector<Report> m_queue;Optional<ByteString> m_report_being_sent;+ HashMap<ByteString, NonnullRefPtr<CrashReportSubmission>> m_submissions_from_reviews;HashMap<ByteString, Optional<CrashReportReview::PreparedSubmission>> m_could_not_send;bool m_report_being_sent_was_retried { false };Vector<CrashReportOutboxObserver&> m_observers;diff --git a/Libraries/LibWebView/CrashReportReview.cpp b/Libraries/LibWebView/CrashReportReview.cppindex 4a9a3d403a3..cb35ede0a94 100644--- a/Libraries/LibWebView/CrashReportReview.cpp+++ b/Libraries/LibWebView/CrashReportReview.cpp@@ -7,6 +7,7 @@#include <AK/Hex.h>#include <AK/WeakPtr.h>#include <LibCrypto/Hash/SHA2.h>+#include <LibURL/URL.h>#include <LibWebView/CrashReportDiagnostics.h>#include <LibWebView/CrashReportReview.h>@@ -29,7 +30,7 @@ CrashReportReview::CrashReportReview(CrashReportStore& store)CrashReportReview::~CrashReportReview() = default;-ErrorOr<CrashReportReview::Report> CrashReportReview::open(ByteString const& report_name, MarkAsSeen mark_as_seen)+ErrorOr<CrashReportReview::Report> CrashReportReview::open(ByteString const& report_name){VERIFY(!m_submission);@@ -41,12 +42,6 @@ ErrorOr<CrashReportReview::Report> CrashReportReview::open(ByteString const& repauto saved_report = TRY(m_store.saved_report(report_name));- // Without this, a report closed rather than answered would come back on every launch.- if (mark_as_seen == MarkAsSeen::Yes) {- if (auto result = m_store.mark_seen(report_name); result.is_error())- warnln("Could not mark crash report as seen: {}", result.error());- }-m_report_name = report_name;m_text_digest = sha256_hex(saved_report.text.bytes());@@ -98,6 +93,20 @@ ErrorOr<ByteString> CrashReportReview::report_text() constreturn TRY(m_store.saved_report(m_report_name)).text;}+Optional<String> CrashReportReview::website_from_url(URL::URL const& url)+{+ if (url.scheme() != "http"sv && url.scheme() != "https"sv)+ return {};++ auto website = url;+ website.set_username(""sv);+ website.set_password(""sv);+ auto serialized_website = website.serialize(URL::ExcludeFragment::Yes);+ if (serialized_website.bytes().size() > maximum_url_bytes)+ return {};+ return serialized_website;+}+Optional<String> CrashReportReview::validate(StringView description, Optional<StringView> url){if (description.length() > maximum_description_bytes)@@ -178,6 +187,13 @@ void CrashReportReview::set_prepared_submission(PreparedSubmission submission){m_prepared_manifest = move(submission.manifest);m_prepared_description = move(submission.description);+ m_prepared_url = move(submission.url);+}++ErrorOr<void> CrashReportReview::decline()+{+ VERIFY(!m_report_name.is_empty());+ return m_store.mark_seen(m_report_name);}// The report stays on the device, and sending it again sends the same submission, which the server recognizes if thediff --git a/Libraries/LibWebView/CrashReportReview.h b/Libraries/LibWebView/CrashReportReview.hindex 07e90cf8d87..6b56de5fe50 100644--- a/Libraries/LibWebView/CrashReportReview.h+++ b/Libraries/LibWebView/CrashReportReview.h@@ -14,6 +14,7 @@#include <AK/String.h>#include <AK/Vector.h>#include <AK/Weakable.h>+#include <LibURL/Forward.h>#include <LibWebView/CrashReportStore.h>#include <LibWebView/CrashReportSubmission.h>#include <LibWebView/Forward.h>@@ -34,6 +35,7 @@ public:struct PreparedSubmission {ByteString manifest;String description;+ Optional<String> url;};struct Report {@@ -45,28 +47,29 @@ public:explicit CrashReportReview(CrashReportStore& = CrashReportStore::the());~CrashReportReview();- enum class MarkAsSeen : u8 {- No,- Yes,- };+ // Opens the named report, which goes on waiting until it is sent or declined.+ ErrorOr<Report> open(ByteString const& name);- // Opens the named report. Being shown as the user's one prompt for a report makes- // it count as seen from then on, so declining it needs no further step. A report that goes on waiting whatever- // comes of this review is opened without that.- ErrorOr<Report> open(ByteString const& name, MarkAsSeen = MarkAsSeen::Yes);+ // The user's answer that this report is not to be sent, after which it no longer waits.+ ErrorOr<void> decline();// The open report's text, exactly as it would be attached.ErrorOr<ByteString> report_text() const;+ // What a report may say about the page that crashed: an http or https URL without its credentials and fragment.+ static Optional<String> website_from_url(URL::URL const&);+// A message for the user when these choices cannot be sent.static Optional<String> validate(StringView description, Optional<StringView> url);// Returns why nothing was sent, or nothing when the report is on its way. A report on its way keeps being sent if// the review is destroyed, which then only stops hearing about it.Optional<String> send(String const& description, Optional<String> const& url);- PreparedSubmission prepared_submission() const { return { m_prepared_manifest, m_prepared_description }; }+ PreparedSubmission prepared_submission() const { return { m_prepared_manifest, m_prepared_description, m_prepared_url }; }void set_prepared_submission(PreparedSubmission);bool is_sending() const { return m_submission; }+ CrashReportSubmission* submission() { return m_submission; }+ ByteString const& report_name() const { return m_report_name; }void cancel_sending();Function<void(ReportSubmission::Stage)> on_progress;diff --git a/Libraries/LibWebView/CrashReportStore.cpp b/Libraries/LibWebView/CrashReportStore.cppindex a4e6efe2e68..92ea2475a95 100644--- a/Libraries/LibWebView/CrashReportStore.cpp+++ b/Libraries/LibWebView/CrashReportStore.cpp@@ -42,7 +42,7 @@ ByteString CrashReportStore::default_directory()return LexicalPath::join(Core::StandardPaths::user_data_directory(), "Ladybird"sv, "CrashReports"sv).string();}-// The browser's own store lives under the user data directory.+// The browser's own store. It moves into the profile once the profile is known.CrashReportStore& CrashReportStore::the(){static NeverDestroyed<CrashReportStore> store { default_directory() };@@ -209,6 +209,18 @@ static ErrorOr<void> move_report(Core::Directory const& from, Core::Directory coreturn Error::from_string_literal("Crash report no longer exists");}+static constexpr auto website_suffix = ".website"sv;++static ByteString website_file_name(StringView report_name)+{+ return ByteString::formatted("{}{}", report_name, website_suffix);+}++static void remove_website(Core::Directory const& directory, StringView report_name)+{+ (void)unlinkat(directory.fd(), website_file_name(report_name).characters(), 0);+}+static void move_all_reports(Core::Directory const& from, Core::Directory const& to){Core::DirIterator iterator(from.path().string(), Core::DirIterator::SkipDots);@@ -316,7 +328,23 @@ static void remove_reports_older_than(Core::Directory const& directory, Optionalstruct stat status {};if (!is_owned_regular_file_at(directory, name, status))continue;- if (!earliest_time.has_value() || UnixDateTime::from_unix_timespec(modified_time(status)) < *earliest_time)+ if (!earliest_time.has_value() || UnixDateTime::from_unix_timespec(modified_time(status)) < *earliest_time) {+ (void)unlinkat(directory.fd(), name.characters(), 0);+ remove_website(directory, name);+ }+ }+}++// A website goes after its report, so stopping between the two can leave it behind without one.+static void remove_orphaned_websites(Core::Directory const& directory)+{+ Core::DirIterator iterator(directory.path().string(), Core::DirIterator::SkipDots);+ while (iterator.has_next()) {+ auto name = iterator.next_path();+ if (!name.ends_with(website_suffix))+ continue;+ struct stat status {};+ if (!is_owned_regular_file_at(directory, name.substring(0, name.length() - website_suffix.length()), status))(void)unlinkat(directory.fd(), name.characters(), 0);}}@@ -326,17 +354,12 @@ ErrorOr<void> CrashReportStore::remove_expired_reports(UnixDateTime now) constauto directory = TRY(open_report_directory(m_directory));auto earliest_time = now - maximum_unsent_report_age;remove_reports_older_than(directory, earliest_time);+ remove_orphaned_websites(directory);if (auto seen_directory = TRY(open_seen_directory_if_exists(directory)); seen_directory.has_value())remove_reports_older_than(*seen_directory, earliest_time);return {};}-bool CrashReportStore::has_pending_reports(UnixDateTime now) const-{- auto names = pending_report_names(now);- return !names.is_error() && !names.value().is_empty();-}-ErrorOr<void> CrashReportStore::mark_seen(ByteString const& name) const{if (!is_saved_report_name(name))@@ -344,10 +367,34 @@ ErrorOr<void> CrashReportStore::mark_seen(ByteString const& name) constauto directory = TRY(open_report_directory(m_directory));auto seen_directory = TRY(open_seen_directory(directory));TRY(move_report(directory, seen_directory, name));+ remove_website(directory, name);apply_retention(seen_directory, name);return {};}+ErrorOr<void> CrashReportStore::save_website(ByteString const& name, StringView website) const+{+ if (!is_saved_report_name(name))+ return Error::from_string_literal("Invalid crash report name");+ auto directory = TRY(open_report_directory(m_directory));+ auto file = TRY(directory.open(website_file_name(name), Core::File::OpenMode::Write | Core::File::OpenMode::Truncate | Core::File::OpenMode::NoFollow, 0600));+ TRY(file->write_until_depleted(website.bytes()));+ return {};+}++Optional<String> CrashReportStore::website(ByteString const& name) const+{+ if (!is_saved_report_name(name))+ return {};+ auto directory = open_report_directory(m_directory);+ if (directory.is_error())+ return {};+ auto contents = read_owned_file(directory.value(), website_file_name(name));+ if (contents.is_error() || contents.value().is_empty())+ return {};+ return String::from_utf8_with_replacement_character(contents.value().view());+}+ErrorOr<void> CrashReportStore::adopt_reports_from(ByteString const& directory) const{if (directory == m_directory || !FileSystem::exists(directory))@@ -363,10 +410,28 @@ ErrorOr<void> CrashReportStore::adopt_reports_from(ByteString const& directory)return {};}+ErrorOr<void> CrashReportStore::remove_websites_saved_since(UnixDateTime since) const+{+ auto directory = TRY(open_report_directory(m_directory));+ Core::DirIterator iterator(directory.path().string(), Core::DirIterator::SkipDots);+ while (iterator.has_next()) {+ auto name = iterator.next_path();+ if (!name.ends_with(website_suffix))+ continue;+ struct stat status {};+ if (!is_owned_regular_file_at(directory, name, status))+ continue;+ if (UnixDateTime::from_unix_timespec(modified_time(status)) >= since)+ (void)unlinkat(directory.fd(), name.characters(), 0);+ }+ return {};+}+ErrorOr<void> CrashReportStore::remove_all_reports() const{auto directory = TRY(open_report_directory(m_directory));remove_reports_older_than(directory, {});+ remove_orphaned_websites(directory);if (auto seen_directory = TRY(open_seen_directory_if_exists(directory)); seen_directory.has_value())remove_reports_older_than(*seen_directory, {});return {};@@ -390,6 +455,7 @@ ErrorOr<void> CrashReportStore::remove_report(ByteString const& name) constauto directory = TRY(open_report_directory(m_directory));TRY(remove_from(directory));+ remove_website(directory, name);if (auto seen_directory = TRY(open_seen_directory_if_exists(directory)); seen_directory.has_value())TRY(remove_from(*seen_directory));return {};@@ -545,11 +611,13 @@ ErrorOr<CrashReportStore::SavedReport> CrashReportStore::saved_report(ByteString}ErrorOr<Vector<ByteString>> CrashReportStore::pending_report_names(UnixDateTime) const { return Vector<ByteString> {}; }-bool CrashReportStore::has_pending_reports(UnixDateTime) const { return false; }ErrorOr<void> CrashReportStore::mark_seen(ByteString const&) const { return {}; }ErrorOr<void> CrashReportStore::remove_report(ByteString const&) const { return {}; }ErrorOr<void> CrashReportStore::remove_all_reports() const { return {}; }ErrorOr<void> CrashReportStore::adopt_reports_from(ByteString const&) const { return {}; }+ErrorOr<void> CrashReportStore::save_website(ByteString const&, StringView) const { return {}; }+Optional<String> CrashReportStore::website(ByteString const&) const { return {}; }+ErrorOr<void> CrashReportStore::remove_websites_saved_since(UnixDateTime) const { return {}; }ErrorOr<ByteString> CrashReportStore::store_report(ProcessType, StringView, UnixDateTime) const{diff --git a/Libraries/LibWebView/CrashReportStore.h b/Libraries/LibWebView/CrashReportStore.hindex 75d85f8791d..ca99c882715 100644--- a/Libraries/LibWebView/CrashReportStore.h+++ b/Libraries/LibWebView/CrashReportStore.h@@ -8,6 +8,8 @@#include <AK/ByteString.h>#include <AK/Error.h>+#include <AK/Optional.h>+#include <AK/String.h>#include <AK/Time.h>#include <AK/Vector.h>#include <LibWebView/Forward.h>@@ -38,10 +40,15 @@ public:ErrorOr<SavedReport> saved_report(ByteString const& name) const;+ // The website a waiting report's crash happened on. It sits next to the report rather than in it, so that it stays+ // on this computer unless the user chooses to include it.+ ErrorOr<void> save_website(ByteString const& name, StringView website) const;+ Optional<String> website(ByteString const& name) const;+ ErrorOr<void> remove_websites_saved_since(UnixDateTime) const;+// The reports waiting to be reviewed, newest first. A report of a crash from before the hard cutoff date// (October 2, 2026 20:00 UTC) or more than 30 days before `now` is never pending.ErrorOr<Vector<ByteString>> pending_report_names(UnixDateTime now = UnixDateTime::now()) const;- bool has_pending_reports(UnixDateTime now = UnixDateTime::now()) const;// Seen reports move into a subdirectory, where the newest of them are kept for reference and never offered again.ErrorOr<void> mark_seen(ByteString const& name) const;diff --git a/Libraries/LibWebView/ReportSubmission.cpp b/Libraries/LibWebView/ReportSubmission.cppindex 7d713ef8cb1..7fedc56c430 100644--- a/Libraries/LibWebView/ReportSubmission.cpp+++ b/Libraries/LibWebView/ReportSubmission.cpp@@ -229,6 +229,8 @@ void ReportSubmission::cancel()if (auto request = move(m_request))request->stop();m_self_while_in_flight = nullptr;++ did_finish();}void ReportSubmission::begin_attempt()@@ -258,6 +260,7 @@ void ReportSubmission::fail_preparation(String reason)m_self_while_in_flight = nullptr;if (on_failed)on_failed(Failure::Preparation, move(reason));+ did_finish();}void ReportSubmission::request_challenge()@@ -442,6 +445,15 @@ void ReportSubmission::finish()m_self_while_in_flight = nullptr;if (on_sent)on_sent();+ did_finish();+}++void ReportSubmission::did_finish()+{+ auto finished = move(on_finished);+ on_finished = nullptr;+ if (finished)+ finished();}void ReportSubmission::fail(String reason, ShouldRetry should_retry, Optional<int> retry_after_ms)@@ -458,6 +470,7 @@ void ReportSubmission::fail(String reason, ShouldRetry should_retry, Optional<inm_self_while_in_flight = nullptr;if (on_failed)on_failed(Failure::Sending, move(reason));+ did_finish();return;}diff --git a/Libraries/LibWebView/ReportSubmission.h b/Libraries/LibWebView/ReportSubmission.hindex bbee323c8ac..eb03e46a6d0 100644--- a/Libraries/LibWebView/ReportSubmission.h+++ b/Libraries/LibWebView/ReportSubmission.h@@ -88,6 +88,9 @@ public:Function<void()> on_sent;Function<void(Failure, String reason)> on_failed;+ // However it ended, even if it was canceled, and even if nothing is left of whoever started it.+ Function<void()> on_finished;+protected:ReportSubmission();@@ -95,6 +98,8 @@ protected:virtual void did_send() { }private:+ void did_finish();+struct ProofOfWork {ByteString token;u64 nonce { 0 };diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex b9cd40233dc..0dd3e38b831 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -31,6 +31,7 @@#include <LibWebView/Application.h>#include <LibWebView/BookmarkStore.h>#include <LibWebView/CanonicalSessionHistoryEntry.h>+#include <LibWebView/CrashReportOutbox.h>#include <LibWebView/CrashReportReview.h>#include <LibWebView/ErrorHTML.h>#include <LibWebView/FaviconStore.h>@@ -4385,6 +4386,14 @@ void ViewImplementation::did_save_crash_report(ByteString report_name)if (!m_crash_state.has_value())return;m_crash_state->report_name = move(report_name);++ // It stays on this computer unless the user chooses to include it, and a private window leaves no trace of it.+ if (auto website = crash_report_website(); website.has_value() && is_private() == IsPrivate::No) {+ if (auto result = CrashReportStore::the().save_website(m_crash_state->report_name, *website); result.is_error())+ warnln("Could not save the website of a crash report: {}", result.error());+ CrashReportOutbox::the().reports_changed();+ }+if (on_crash_report_saved)on_crash_report_saved();}@@ -4406,13 +4415,7 @@ Optional<String> ViewImplementation::crash_report_website() const{if (!m_crash_state.has_value())return {};- auto const& failed_url = m_crash_state->failed_url;- if (failed_url.scheme() != "http"sv && failed_url.scheme() != "https"sv)- return {};- auto serialized_url = failed_url.serialize();- if (serialized_url.bytes().size() > CrashReportReview::maximum_url_bytes)- return {};- return serialized_url;+ return CrashReportReview::website_from_url(m_crash_state->failed_url);}String ViewImplementation::force_dark_host() constdiff --git a/Libraries/LibWebView/WebContentClient.h b/Libraries/LibWebView/WebContentClient.hindex 2b8d1afaf5a..a4d0f1e7006 100644--- a/Libraries/LibWebView/WebContentClient.h+++ b/Libraries/LibWebView/WebContentClient.h@@ -158,8 +158,6 @@ public:void did_lose_process();void did_save_crash_report(ByteString const& report_name);- // Whether a tab was told this process was lost, and so shows its crash.- bool has_crashed_views() const { return !m_crashed_view_ids.is_empty(); }ErrorOr<void> reconnect_to_compositor_process(Badge<Application>);ErrorOr<void> recreate_compositor_contexts(Badge<Application>);// The user let the page at the URL capture audio. The process's AudioServer hears of the permission before thisdiff --git a/Libraries/LibWebView/WebUI/CrashReportsUI.cpp b/Libraries/LibWebView/WebUI/CrashReportsUI.cppindex 93c3b4ecf14..3dbae4b7138 100644--- a/Libraries/LibWebView/WebUI/CrashReportsUI.cpp+++ b/Libraries/LibWebView/WebUI/CrashReportsUI.cpp@@ -9,6 +9,7 @@#include <AK/JsonArray.h>#include <AK/JsonObject.h>#include <LibCrypto/Hash/SHA2.h>+#include <LibURL/Parser.h>#include <LibWebView/CrashReportDiagnostics.h>#include <LibWebView/CrashReportStore.h>#include <LibWebView/WebUI/CrashReportsUI.h>@@ -38,6 +39,14 @@ static StringView plain_process_name(StringView process)return "Ladybird"sv;}+static Optional<String> website_host(String const& website)+{+ auto url = URL::Parser::basic_parse(website);+ if (!url.has_value() || !url->host().has_value())+ return {};+ return MUST(String::from_utf8(url->serialized_host()));+}+void CrashReportsUI::register_interfaces(){register_interface("loadReports"sv, [this](auto const&) {@@ -64,9 +73,12 @@ void CrashReportsUI::load_reports(){struct Group {ByteString id;- StringView process;+ String process;Optional<UnixDateTime> last_crashed_at;Vector<ByteString> names;+ Vector<String> websites;+ Vector<Optional<String>> website_of_each_report;+ Vector<String> hosts;};auto& store = CrashReportStore::the();@@ -83,7 +95,7 @@ void CrashReportsUI::load_reports()HashMap<ByteString, size_t> group_indices;for (auto const& name : names) {ByteString signature { "Unreadable"sv };- StringView process = "Unreadable report"sv;+ String process = "Unreadable report"_string;Optional<UnixDateTime> crashed_at;// A report that cannot be read still counts as waiting, so it gets a row of its own to delete it from.@@ -92,7 +104,7 @@ void CrashReportsUI::load_reports()} else {auto diagnostics = CrashReportDiagnostics::parse(report.value().text);signature = diagnostics.signature();- process = plain_process_name(diagnostics.header("Process"sv));+ process = MUST(String::from_utf8(plain_process_name(diagnostics.header("Process"sv))));crashed_at = diagnostics.crashed_at;}@@ -102,10 +114,23 @@ void CrashReportsUI::load_reports().process = process,.last_crashed_at = crashed_at,.names = {},+ .websites = {},+ .website_of_each_report = {},+ .hosts = {},});return groups.size() - 1;});- groups[index].names.append(name);+ auto& group = groups[index];+ group.names.append(name);++ auto website = store.website(name);+ group.website_of_each_report.append(website);+ if (website.has_value()) {+ if (auto host = website_host(*website); host.has_value() && !group.hosts.contains_slow(*host))+ group.hosts.append(host.release_value());+ if (!group.websites.contains_slow(*website))+ group.websites.append(website.release_value());+ }}JsonArray serialized_groups;@@ -122,10 +147,28 @@ void CrashReportsUI::load_reports()JsonObject serialized_group;serialized_group.set("id"sv, String::from_utf8_with_replacement_character(group.id));- serialized_group.set("process"sv, group.process);+ // A row only names a site when that is the whole truth about the websites it would send.+ if (group.hosts.size() == 1)+ serialized_group.set("process"sv, MUST(String::formatted("{} on {}", group.process, group.hosts.first())));+ else if (group.hosts.size() > 1)+ serialized_group.set("process"sv, MUST(String::formatted("{} on {} websites", group.process, group.hosts.size())));+ else+ serialized_group.set("process"sv, group.process);if (group.last_crashed_at.has_value())serialized_group.set("lastCrashedAt"sv, group.last_crashed_at->milliseconds_since_epoch());serialized_group.set("names"sv, move(serialized_names));++ JsonArray serialized_websites;+ for (auto const& website : group.websites)+ serialized_websites.must_append(website);+ serialized_group.set("websites"sv, move(serialized_websites));++ // In the order of the names, so that the page can tell which reports a ticked website belongs to.+ JsonArray serialized_website_of_each_report;+ for (auto const& website : group.website_of_each_report)+ serialized_website_of_each_report.must_append(website.has_value() ? JsonValue { *website } : JsonValue {});+ serialized_group.set("websiteOfEachReport"sv, move(serialized_website_of_each_report));+serialized_group.set("isSending"sv, is_sending);serialized_group.set("couldNotSend"sv, could_not_send);serialized_groups.must_append(move(serialized_group));@@ -145,8 +188,15 @@ void CrashReportsUI::send_reports(JsonValue const& data)return;auto name = value.as_object().get_string("name"sv);auto description = value.as_object().get_string("description"sv);- if (name.has_value())- reports.append({ name->to_byte_string(), description.has_value() ? *description : String {} });+ if (!name.has_value())+ return;++ // The website only ever leaves this computer because the user ticked its box for this report.+ auto report_name = name->to_byte_string();+ Optional<String> url;+ if (value.as_object().get_bool("includeWebsite"sv).value_or(false))+ url = CrashReportStore::the().website(report_name);+ reports.append({ move(report_name), description.has_value() ? *description : String {}, move(url) });});CrashReportOutbox::the().send(move(reports));diff --git a/Tests/LibWebView/TestCrashReportReview.cpp b/Tests/LibWebView/TestCrashReportReview.cppindex e5011648cb6..27d7d920268 100644--- a/Tests/LibWebView/TestCrashReportReview.cpp+++ b/Tests/LibWebView/TestCrashReportReview.cpp@@ -10,10 +10,13 @@#include <LibCore/Directory.h>#include <LibCore/File.h>#include <LibCore/StandardPaths.h>+#include <LibCore/System.h>#include <LibFileSystem/FileSystem.h>#include <LibTest/TestCase.h>+#include <LibURL/Parser.h>#include <LibWebView/CrashReportReview.h>#include <stdlib.h>+#include <sys/time.h>#include <time.h>#include <unistd.h>@@ -145,7 +148,7 @@ TEST_CASE(a_report_that_does_not_say_when_it_crashed_has_no_crash_date)EXPECT(field.label != "Crash date"sv);}-TEST_CASE(a_report_opened_without_marking_it_seen_stays_pending)+TEST_CASE(a_report_waits_until_it_is_declined){cleanup();ScopeGuard guard = cleanup;@@ -154,10 +157,73 @@ TEST_CASE(a_report_opened_without_marking_it_seen_stays_pending)WebView::CrashReportStore store { test_directory() };CrashReportReview review { store };- EXPECT_EQ(MUST(review.open(name, CrashReportReview::MarkAsSeen::No)).name, name);+ EXPECT_EQ(MUST(review.open(name)).name, name);+ EXPECT(is_pending(name));++ MUST(review.decline());+ EXPECT(!is_pending(name));+}++TEST_CASE(a_website_stays_out_of_the_report_and_goes_with_it)+{+ cleanup();+ ScopeGuard guard = cleanup;++ auto name = write_report("2026-10-01T12-00-00Z"sv);+ WebView::CrashReportStore store { test_directory() };+ MUST(store.save_website(name, "https://example.com/page"sv));+ EXPECT_EQ(store.website(name), "https://example.com/page"_string);+ EXPECT(!MUST(store.saved_report(name)).text.contains("example.com"sv));++ auto website_path = LexicalPath::join(test_directory(), ByteString::formatted("{}.website", name)).string();+ EXPECT_EQ(static_cast<u32>(MUST(Core::System::stat(website_path)).st_mode & 0777), 0600u);++ MUST(store.mark_seen(name));+ EXPECT(!store.website(name).has_value());+}++TEST_CASE(clearing_history_removes_websites_but_keeps_reports)+{+ cleanup();+ ScopeGuard guard = cleanup;++ auto name = write_report("2026-10-01T12-00-00Z"sv);+ WebView::CrashReportStore store { test_directory() };+ MUST(store.save_website(name, "https://example.com/page"sv));++ MUST(store.remove_websites_saved_since(UnixDateTime::now() + AK::Duration::from_seconds(3600)));+ EXPECT(store.website(name).has_value());++ // A website saved at the very moment history is cleared from goes too.+ auto website_path = LexicalPath::join(test_directory(), ByteString::formatted("{}.website", name)).string();+ time_t saved_at = 1'790'000'000;+ timeval times[2] { { saved_at, 0 }, { saved_at, 0 } };+ VERIFY(utimes(website_path.characters(), times) == 0);++ MUST(store.remove_websites_saved_since(UnixDateTime::from_seconds_since_epoch(saved_at + 1)));+ EXPECT(store.website(name).has_value());++ MUST(store.remove_websites_saved_since(UnixDateTime::from_seconds_since_epoch(saved_at)));+ EXPECT(!store.website(name).has_value());EXPECT(is_pending(name));}+TEST_CASE(a_website_keeps_its_query_but_not_its_credentials_or_fragment)+{+ auto website = [](StringView url) {+ return CrashReportReview::website_from_url(URL::Parser::basic_parse(url).release_value());+ };++ EXPECT_EQ(website("https://user:[email protected]/page?id=1#private"sv), "https://example.com/page?id=1"_string);+ EXPECT(!website("file:///etc/passwd"sv).has_value());+ EXPECT(!website("about:blank"sv).has_value());++ auto prefix = "https://example.com/"sv;+ auto longest_url = ByteString::formatted("{}{}", prefix, ByteString::repeated('a', CrashReportReview::maximum_url_bytes - prefix.length()));+ EXPECT(website(longest_url).has_value());+ EXPECT(!website(ByteString::formatted("{}a", longest_url)).has_value());+}+TEST_CASE(a_report_can_be_reopened_by_name_once_seen){cleanup();@@ -217,10 +283,7 @@ TEST_CASE(a_report_changed_after_it_was_reviewed_is_not_sent)CrashReportReview review { store };MUST(review.open(name));- auto seen_directory = LexicalPath::join(test_directory(), "Seen"sv).string();- auto directory = MUST(Core::Directory::create(seen_directory, Core::Directory::CreateDirectories::No));- auto file = MUST(directory.open(name, Core::File::OpenMode::Write | Core::File::OpenMode::Truncate));- MUST(file->write_until_depleted("Ladybird crash report, format 1\nProcess: Browser\n"sv.bytes()));+ write_named_report(name, "Ladybird crash report, format 1\nProcess: Browser\n"sv);Optional<ReportSubmission::Failure> failure;String reason;diff --git a/Tests/LibWebView/TestCrashReportStore.cpp b/Tests/LibWebView/TestCrashReportStore.cppindex 1e8aca4d22a..5d2c1471e5e 100644--- a/Tests/LibWebView/TestCrashReportStore.cpp+++ b/Tests/LibWebView/TestCrashReportStore.cpp@@ -102,6 +102,22 @@ TEST_CASE(a_name_cannot_reach_outside_the_store)EXPECT(!WebView::CrashReportStore::is_saved_report_name("2026-03-04T05-06-07Z-WebContent-abc.12.txt"sv));}+TEST_CASE(a_website_left_without_its_report_is_removed)+{+ cleanup();+ ScopeGuard guard = cleanup;++ auto store = test_store();+ auto name = report_name("2026-10-05T12-00-00Z"sv);+ write_file(name, "A report\n"sv);+ write_file(ByteString::formatted("{}.website", name), "https://example.com/"sv);+ write_file(ByteString::formatted("{}.website", report_name("2026-10-05T12-00-01Z"sv)), "https://example.org/"sv);++ MUST(store.remove_expired_reports(now));+ EXPECT(store.website(name).has_value());+ EXPECT_EQ(directory_entries().size(), 2u);+}+TEST_CASE(pending_reports_are_listed_newest_first){cleanup();@@ -140,10 +156,10 @@ TEST_CASE(a_seen_report_is_no_longer_pending)write_file(name, "A report\n"sv);auto store = test_store();- EXPECT(store.has_pending_reports(now));+ EXPECT(!MUST(store.pending_report_names(now)).is_empty());MUST(store.mark_seen(name));MUST(store.mark_seen(name));- EXPECT(!store.has_pending_reports(now));+ EXPECT(MUST(store.pending_report_names(now)).is_empty());EXPECT(directory_entries().is_empty());EXPECT_EQ(directory_entries("Seen"sv), Vector<ByteString> { name });@@ -151,7 +167,7 @@ TEST_CASE(a_seen_report_is_no_longer_pending)EXPECT_EQ(MUST(store.saved_report(name)).text, "A report\n"sv);write_file(report_name("2026-03-05T05-06-07Z"sv), "Another report\n"sv);- EXPECT(store.has_pending_reports(now));+ EXPECT(!MUST(store.pending_report_names(now)).is_empty());}TEST_CASE(a_report_from_before_the_hard_cutoff_date_is_not_pending)@@ -186,11 +202,11 @@ TEST_CASE(a_report_older_than_30_days_is_not_pending)auto in_30_days = UnixDateTime::from_unix_time_parts(2026, 11, 4, 12, 0, 0, 0);EXPECT_EQ(MUST(store.pending_report_names(in_30_days)), Vector<ByteString> { fresh });- EXPECT(store.has_pending_reports(in_30_days));+ EXPECT(!MUST(store.pending_report_names(in_30_days)).is_empty());auto later = in_30_days + AK::Duration::from_seconds(1);EXPECT(MUST(store.pending_report_names(later)).is_empty());- EXPECT(!store.has_pending_reports(later));+ EXPECT(MUST(store.pending_report_names(later)).is_empty());}TEST_CASE(unsent_reports_are_deleted_after_30_days)diff --git a/Tests/LibWebView/TestCrashReportSubmission.cpp b/Tests/LibWebView/TestCrashReportSubmission.cppindex 6be3043e153..1c8cafced02 100644--- a/Tests/LibWebView/TestCrashReportSubmission.cpp+++ b/Tests/LibWebView/TestCrashReportSubmission.cpp@@ -16,6 +16,7 @@#include <LibCore/File.h>#include <LibFileSystem/FileSystem.h>#include <LibTest/TestCase.h>+#include <LibWebView/CrashReportOutbox.h>#include <LibWebView/CrashReportReview.h>using namespace ReportServerTest;@@ -142,7 +143,7 @@ TEST_CASE(crash_report_submission)// Once the server has a report, the local copy has done its job.VERIFY(!FileSystem::exists(LexicalPath::join(reports_directory, "Seen"sv, name).string()));- VERIFY(!store.has_pending_reports());+ VERIFY(MUST(store.pending_report_names()).is_empty());// A request the server rejects would be rejected again, so it ends the submission until the user tries again.server.requests.clear();@@ -210,5 +211,35 @@ TEST_CASE(crash_report_submission)VERIFY(server.requests.size() == 2);VERIFY(server.requests[1].path == "/api/v1/reports"sv);+ // Only one place sends a report at a time, and a report sent from a review counts as on its way until it has gone,+ // even when the review goes first.+ WebView::CrashReportOutbox outbox { store };+ name = write_report(reports_directory, "2026-10-01T15-00-00Z-WebContent-abc123.txt"sv);+ {+ WebView::CrashReportReview first_review { store };+ WebView::CrashReportReview second_review { store };+ MUST(first_review.open(name));+ MUST(second_review.open(name));+ server.respond_with(challenge("fifth"sv));+ server.respond_with({ 200, R"({"receipt":"receipt-4"})", {} });+ VERIFY(!outbox.send_from_review(first_review, ""_string, {}).has_value());+ VERIFY(outbox.is_sending(name));+ VERIFY(outbox.send_from_review(second_review, ""_string, {}).has_value());+ }+ Core::EventLoop::current().spin_until([&] { return !outbox.is_sending(name); });+ VERIFY(MUST(store.pending_report_names()).is_empty());++ // Choosing to keep nothing stops what a review has started.+ name = write_report(reports_directory, "2026-10-01T16-00-00Z-WebContent-abc123.txt"sv);+ {+ WebView::CrashReportReview review_to_stop { store };+ MUST(review_to_stop.open(name));+ VERIFY(!outbox.send_from_review(review_to_stop, ""_string, {}).has_value());+ VERIFY(outbox.is_sending(name));+ outbox.discard_all();+ VERIFY(!outbox.is_sending(name));+ }+ VERIFY(MUST(store.pending_report_names()).is_empty());+outln("PASS: Crash reports reach the report server in the format it expects");}diff --git a/Tests/UI/Qt/TestCrashReportReviewWidget.cpp b/Tests/UI/Qt/TestCrashReportReviewWidget.cppindex f233da9ee65..5a17287c63a 100644--- a/Tests/UI/Qt/TestCrashReportReviewWidget.cpp+++ b/Tests/UI/Qt/TestCrashReportReviewWidget.cpp@@ -359,3 +359,24 @@ TEST_CASE(answering_the_report_is_announced_once_the_choice_is_made)child<QPushButton>(widget, "CrashReportDeclineButton").click();EXPECT_EQ(answers, 1);}++TEST_CASE(a_report_that_cannot_be_declined_stays_unanswered)+{+ cleanup();+ ScopeGuard guard = cleanup;++ auto name = write_report("2026-10-01T12-00-00Z"sv);+ WebView::CrashReportStore store { test_directory() };+ CrashReportReviewWidget widget { QStringLiteral("Reload page"), nullptr, store };+ auto answers = 0;+ widget.on_answered = [&] { ++answers; };+ MUST(widget.open_report(name));+ widget.show();++ // The list of crash reports can answer a report while its review is open.+ MUST(store.remove_report(name));+ child<QPushButton>(widget, "CrashReportDeclineButton").click();+ EXPECT_EQ(answers, 0);+ EXPECT(child<QLabel>(widget, "CrashReportValidation").isVisible());+ EXPECT(child<QPushButton>(widget, "CrashReportSendButton").isVisible());+}diff --git a/UI/Qt/CrashReportReviewWidget.cpp b/UI/Qt/CrashReportReviewWidget.cppindex c4e8132630e..7455a11eea9 100644--- a/UI/Qt/CrashReportReviewWidget.cpp+++ b/UI/Qt/CrashReportReviewWidget.cpp@@ -4,6 +4,7 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <LibWebView/CrashReportOutbox.h>#include <UI/Qt/CrashReportReviewWidget.h>#include <UI/Qt/ReportReview.h>#include <UI/Qt/StringUtils.h>@@ -165,11 +166,21 @@ CrashReportReviewWidget::CrashReportReviewWidget(QString exit_text, QWidget* parlayout->addWidget(m_report_text_page);QObject::connect(send_button, &QPushButton::clicked, this, [this] { send(); });- QObject::connect(decline_button, &QPushButton::clicked, this, [this] { show_declined(); });- QObject::connect(m_retry_button, &QPushButton::clicked, this, [this] {- show_progress(WebView::ReportSubmission::Stage::Preparing);- VERIFY(!m_review.send(m_description, m_url).has_value());+ QObject::connect(decline_button, &QPushButton::clicked, this, [this] {+ if (WebView::CrashReportOutbox::the().is_sending(m_review.report_name())) {+ show_already_sending();+ return;+ }+ if (auto result = m_review.decline(); result.is_error()) {+ warnln("Could not mark crash report as seen: {}", result.error());+ m_validation->setText(tr("This report could not be declined. It may already have been sent or deleted."));+ m_validation->show();+ return;+ }+ WebView::CrashReportOutbox::the().reports_changed();+ show_declined();});+ QObject::connect(m_retry_button, &QPushButton::clicked, this, [this] { start_sending(); });QObject::connect(m_cancel_button, &QPushButton::clicked, this, [this] {m_review.cancel_sending();show_page(*m_review_page);@@ -257,8 +268,21 @@ void CrashReportReviewWidget::send()}m_validation->hide();+ start_sending();+}++void CrashReportReviewWidget::start_sending()+{show_progress(WebView::ReportSubmission::Stage::Preparing);- VERIFY(!m_review.send(m_description, m_url).has_value());+ if (WebView::CrashReportOutbox::the().send_from_review(m_review, m_description, m_url).has_value())+ show_already_sending();+}++// The list of crash reports took this report on first, so there is nothing left to answer here.+void CrashReportReviewWidget::show_already_sending()+{+ m_progress->hide();+ show_outcome(tr("Report already on its way"), tr("This report is being sent from the list of crash reports."));}void CrashReportReviewWidget::show_page(QWidget& page)diff --git a/UI/Qt/CrashReportReviewWidget.h b/UI/Qt/CrashReportReviewWidget.hindex 85fd8d2d522..9db647e3d9e 100644--- a/UI/Qt/CrashReportReviewWidget.h+++ b/UI/Qt/CrashReportReviewWidget.h@@ -55,6 +55,8 @@ protected:private:void send();+ void start_sending();+ void show_already_sending();void update_chrome_style();void show_page(QWidget&);void show_report_text();