Truly independent web browser
LibWebView+UI/Qt: Show the full crash report inside its review
Jelle Raaijmakersc483d2b76421
diff --git a/Documentation/CrashReports.md b/Documentation/CrashReports.mdindex 3ef4018ae1b..93f89bdda16 100644--- a/Documentation/CrashReports.md+++ b/Documentation/CrashReports.md@@ -42,8 +42,8 @@ browser UI, so it does not depend on a web content process.The review asks what the user was doing and lets them choose whether to send thereport. Report details lists its main fields, such as the failure, signal,-version and commit, and opens the full report, exactly as it would be attached,-in the system's text viewer. Submissions omit the website URL by default; when+version and commit, and shows the full report, exactly as it would be attached,+in place of the review. Submissions omit the website URL by default; whenthe crashed page had one, the user can explicitly include it and edit it first.Ladybird does not collect contact information. Network errors, timeouts, ratelimits and server errors are retried a few times, honoring the server'sdiff --git a/Libraries/LibWebView/CrashReportReview.cpp b/Libraries/LibWebView/CrashReportReview.cppindex 4465f53bfd6..ed57eb92c9b 100644--- a/Libraries/LibWebView/CrashReportReview.cpp+++ b/Libraries/LibWebView/CrashReportReview.cpp@@ -108,10 +108,10 @@ bool CrashReportReview::has_next_report() constreturn any_of(pending.value(), [&](auto const& name) { return name != m_report_name; });}-ErrorOr<void> CrashReportReview::show_report() const+ErrorOr<ByteString> CrashReportReview::report_text() const{VERIFY(!m_report_name.is_empty());- return m_store.show_report(m_report_name);+ return TRY(m_store.saved_report(m_report_name)).text;}Optional<String> CrashReportReview::validate(StringView description, Optional<StringView> url)diff --git a/Libraries/LibWebView/CrashReportReview.h b/Libraries/LibWebView/CrashReportReview.hindex 451fc09172a..e4ca6163a7f 100644--- a/Libraries/LibWebView/CrashReportReview.h+++ b/Libraries/LibWebView/CrashReportReview.h@@ -32,7 +32,7 @@ public:struct Report {ByteString name;- // The fields that tell crashes apart. The rest is in the report itself, which show_report() opens.+ // The fields that tell crashes apart. The rest is in the report itself, which report_text() reads.Vector<ReportDetail> fields;};@@ -44,8 +44,8 @@ public:ErrorOr<Report> open(Optional<ByteString> const& name = {});bool has_next_report() const;- // Opens the open report's text, exactly as it would be attached, in the system's application for text files.- ErrorOr<void> show_report() const;+ // The open report's text, exactly as it would be attached.+ ErrorOr<ByteString> report_text() const;// A message for the user when these choices cannot be sent.static Optional<String> validate(StringView description, Optional<StringView> url);diff --git a/Libraries/LibWebView/CrashReportStore.cpp b/Libraries/LibWebView/CrashReportStore.cppindex 2be4180e5be..fca3a8af56e 100644--- a/Libraries/LibWebView/CrashReportStore.cpp+++ b/Libraries/LibWebView/CrashReportStore.cpp@@ -457,21 +457,6 @@ ErrorOr<void> CrashReportStore::show_directory() constreturn open_with_system_handler(m_directory);}-ErrorOr<void> CrashReportStore::show_report(ByteString const& name) const-{- if (!is_saved_report_name(name))- return Error::from_string_literal("Invalid crash report name");- auto directory = TRY(open_report_directory(m_directory));- struct stat status {};- if (is_owned_regular_file_at(directory, name, status))- return open_with_system_handler(directory.path().append(name).string());- if (auto seen_directory = TRY(open_seen_directory_if_exists(directory)); seen_directory.has_value()) {- if (is_owned_regular_file_at(*seen_directory, name, status))- return open_with_system_handler(seen_directory->path().append(name).string());- }- return Error::from_string_literal("Crash report no longer exists");-}-#elseErrorOr<CrashReportStore::SavedReport> CrashReportStore::saved_report(ByteString const&) const@@ -502,11 +487,6 @@ ErrorOr<void> CrashReportStore::show_directory() constreturn Error::from_string_literal("Crash reports are not supported on this platform yet");}-ErrorOr<void> CrashReportStore::show_report(ByteString const&) const-{- return Error::from_string_literal("Crash reports are not supported on this platform yet");-}-#endif}diff --git a/Libraries/LibWebView/CrashReportStore.h b/Libraries/LibWebView/CrashReportStore.hindex 3fe942261e6..0ac994e2d85 100644--- a/Libraries/LibWebView/CrashReportStore.h+++ b/Libraries/LibWebView/CrashReportStore.h@@ -51,8 +51,6 @@ public:ErrorOr<void> initialize_browser_crash_handler();ErrorOr<void> show_directory() const;- // Opens the report in the application the system uses for text files.- ErrorOr<void> show_report(ByteString const& name) const;static bool is_saved_report_name(StringView);diff --git a/Tests/UI/Qt/TestCrashReportReviewWidget.cpp b/Tests/UI/Qt/TestCrashReportReviewWidget.cppindex 9e720651fa4..d5be0ce71cb 100644--- a/Tests/UI/Qt/TestCrashReportReviewWidget.cpp+++ b/Tests/UI/Qt/TestCrashReportReviewWidget.cpp@@ -6,6 +6,7 @@#include <AK/LexicalPath.h>#include <AK/ScopeGuard.h>+#include <AK/Vector.h>#include <LibCore/Directory.h>#include <LibCore/File.h>#include <LibCore/StandardPaths.h>@@ -219,6 +220,33 @@ TEST_CASE(sending_shows_its_progress_and_outcome)EXPECT_EQ(message.text(), "Thank you for helping Ladybird.");}+TEST_CASE(the_full_report_is_shown_in_place_of_the_review)+{+ 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 };+ MUST(widget.open_report(name));+ Vector<bool> text_visibility;+ widget.on_report_text_visibility_change = [&](bool visible) { text_visibility.append(visible); };+ widget.show();++ auto& send = child<QPushButton>(widget, "CrashReportSendButton");+ child<QPushButton>(widget, "CrashReportShowReportButton").click();+ EXPECT_EQ(text_visibility, (Vector<bool> { true }));+ auto& text = child<QPlainTextEdit>(widget, "ReportText");+ EXPECT(text.isVisible());+ EXPECT(!send.isVisible());+ EXPECT_EQ(text.toPlainText(), QString::fromUtf8(report_text.characters_without_null_termination(), report_text.length()));++ child<QPushButton>(widget, "ReportTextBackButton").click();+ EXPECT(!text.isVisible());+ EXPECT(send.isVisible());+ EXPECT_EQ(text_visibility, (Vector<bool> { true, false }));+}+TEST_CASE(the_details_toggle_is_written_like_the_text_around_it){cleanup();diff --git a/UI/Qt/CrashReportReviewWidget.cpp b/UI/Qt/CrashReportReviewWidget.cppindex 2816aab7124..435252fef4e 100644--- a/UI/Qt/CrashReportReviewWidget.cpp+++ b/UI/Qt/CrashReportReviewWidget.cpp@@ -80,17 +80,14 @@ CrashReportReviewWidget::CrashReportReviewWidget(QString exit_text, QWidget* parm_fields = create_details_form();details_layout->addLayout(m_fields);details_layout->addSpacing(item_spacing);- auto* show_report_button = new QPushButton(tr("Open full report (.txt)"), m_details);- show_report_button->setAutoDefault(false);- show_report_button->setObjectName("CrashReportShowReportButton");- QObject::connect(show_report_button, &QPushButton::clicked, this, [this] {- if (auto result = m_review.show_report(); result.is_error())- warnln("Could not open the crash report: {}", result.error());- });- details_layout->addWidget(show_report_button, 0, Qt::AlignLeft);+ m_show_report_button = new QPushButton(tr("View full report"), m_details);+ m_show_report_button->setAutoDefault(false);+ m_show_report_button->setObjectName("CrashReportShowReportButton");+ QObject::connect(m_show_report_button, &QPushButton::clicked, this, [this] { show_report_text(); });+ details_layout->addWidget(m_show_report_button, 0, Qt::AlignLeft);auto* details_toggle = create_disclosure(tr("Report details"), m_details, contents);// The toggle comes before what it shows, although it is created after it.- QWidget::setTabOrder(details_toggle, show_report_button);+ QWidget::setTabOrder(details_toggle, m_show_report_button);contents_layout->addWidget(details_toggle);contents_layout->addWidget(m_details);review_layout->addWidget(contents);@@ -158,6 +155,15 @@ CrashReportReviewWidget::CrashReportReviewWidget(QString exit_text, QWidget* parm_status_page->hide();layout->addWidget(m_status_page);+ auto report_text_page = create_report_text_page(this);+ m_report_text_page = report_text_page.page;+ m_report_text = report_text_page.text;+ QObject::connect(report_text_page.back_button, &QPushButton::clicked, this, [this] {+ show_page(*m_review_page);+ m_show_report_button->setFocus(Qt::OtherFocusReason);+ });+ layout->addWidget(m_report_text_page);+QObject::connect(send_button, &QPushButton::clicked, this, [this] { send(); });QObject::connect(decline_button, &QPushButton::clicked, this, [this] {show_declined();@@ -213,7 +219,7 @@ void CrashReportReviewWidget::update_chrome_style()return;m_is_updating_chrome_style = true;- QWidget* fields[] = { m_description_edit, m_website };+ QWidget* fields[] = { m_description_edit, m_website, m_report_text };apply_style(*this, fields);m_is_updating_chrome_style = false;@@ -267,6 +273,24 @@ void CrashReportReviewWidget::show_page(QWidget& page){m_review_page->setVisible(&page == m_review_page);m_status_page->setVisible(&page == m_status_page);+ m_report_text_page->setVisible(&page == m_report_text_page);+ if (on_report_text_visibility_change)+ on_report_text_visibility_change(&page == m_report_text_page);+}++void CrashReportReviewWidget::show_report_text()+{+ auto text = m_review.report_text();+ if (text.is_error()) {+ m_validation->setText(tr("The crash report could not be read."));+ m_validation->show();+ warnln("Could not read the crash report: {}", text.error());+ return;+ }++ m_report_text->setPlainText(qstring_from_ak_string(String::from_utf8_with_replacement_character(text.value().view())));+ show_page(*m_report_text_page);+ m_report_text->setFocus(Qt::OtherFocusReason);}void CrashReportReviewWidget::show_status(QString const& title, QString const& message,diff --git a/UI/Qt/CrashReportReviewWidget.h b/UI/Qt/CrashReportReviewWidget.hindex 8168be4a25c..1440a09f4f0 100644--- a/UI/Qt/CrashReportReviewWidget.h+++ b/UI/Qt/CrashReportReviewWidget.h@@ -47,6 +47,7 @@ public:Function<void()> on_exit;// The user chose to send the report or not, so the screen around the review no longer needs to ask.Function<void()> on_answered;+ Function<void(bool)> on_report_text_visibility_change;protected:virtual bool event(QEvent*) override;@@ -56,6 +57,7 @@ private:void send();void update_chrome_style();void show_page(QWidget&);+ void show_report_text();// Shows the given actions of the status page, with the primary one as the default and focused action.void show_status(QString const& title, QString const& message, Vector<QPushButton*> const& actions = {},QPushButton* primary = nullptr);@@ -68,6 +70,7 @@ private:QWidget* m_review_page { nullptr };QWidget* m_status_page { nullptr };+ QWidget* m_report_text_page { nullptr };QPlainTextEdit* m_description_edit { nullptr };QWidget* m_website_option { nullptr };@@ -75,6 +78,8 @@ private:QLineEdit* m_website { nullptr };QFrame* m_details { nullptr };QFormLayout* m_fields { nullptr };+ QPushButton* m_show_report_button { nullptr };+ QPlainTextEdit* m_report_text { nullptr };QLabel* m_validation { nullptr };QLabel* m_status_title { nullptr };diff --git a/UI/Qt/ReportReview.cpp b/UI/Qt/ReportReview.cppindex 2d77cd1ad77..237755f6c59 100644--- a/UI/Qt/ReportReview.cpp+++ b/UI/Qt/ReportReview.cpp@@ -14,6 +14,7 @@#include <QFormLayout>#include <QFrame>#include <QLabel>+#include <QPlainTextEdit>#include <QPushButton>#include <QScrollArea>#include <QVBoxLayout>@@ -119,6 +120,31 @@ void set_details(QFormLayout& form, ReadonlySpan<WebView::ReportDetail> details,}}+// The full report is read in place of the review that offers to send it, exactly as it would be sent.+ReportTextPage create_report_text_page(QWidget* parent)+{+ auto* page = new QWidget(parent);+ auto* layout = create_group_layout(page);+ layout->addWidget(create_heading(QObject::tr("Full report"), 1, page));++ auto* text = new QPlainTextEdit(page);+ text->setObjectName("ReportText");+ text->setReadOnly(true);+ text->setLineWrapMode(QPlainTextEdit::NoWrap);+ text->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));+ text->setMinimumHeight(text->fontMetrics().lineSpacing() * 24);+ layout->addWidget(text);++ auto* back_button = new QPushButton(QObject::tr("Back"), page);+ back_button->setObjectName("ReportTextBackButton");+ back_button->setAutoDefault(false);+ layout->addSpacing(item_spacing);+ layout->addWidget(back_button, 0, Qt::AlignLeft);++ page->hide();+ return { page, text, back_button };+}+// Only the fields get a stronger placeholder color. The muted lines keep the color the screen around the review uses// for its own.void apply_style(QWidget& review, ReadonlySpan<QWidget*> fields)diff --git a/UI/Qt/ReportReview.h b/UI/Qt/ReportReview.hindex 163399de386..8a626658298 100644--- a/UI/Qt/ReportReview.h+++ b/UI/Qt/ReportReview.h@@ -16,6 +16,7 @@class QFormLayout;class QFrame;class QLabel;+class QPlainTextEdit;class QPushButton;class QVBoxLayout;class QWidget;@@ -38,6 +39,13 @@ QFrame* create_details_panel(QWidget* parent);QFormLayout* create_details_form();void set_details(QFormLayout&, ReadonlySpan<WebView::ReportDetail>, QWidget* parent);+struct ReportTextPage {+ QWidget* page { nullptr };+ QPlainTextEdit* text { nullptr };+ QPushButton* back_button { nullptr };+};+ReportTextPage create_report_text_page(QWidget* parent);+void apply_style(QWidget& review, ReadonlySpan<QWidget*> fields);bool focus_next_control(QWidget& review, bool next);diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cppindex 58f7a2a9d78..44e5bc1470e 100644--- a/UI/Qt/WebContentView.cpp+++ b/UI/Qt/WebContentView.cpp@@ -1271,19 +1271,28 @@ public:column_row->addWidget(m_column, 1);column_row->addStretch();- auto* layout = new QVBoxLayout(m_content);- layout->setContentsMargins(PAGE_OVERLAY_MARGIN, PAGE_OVERLAY_MARGIN, PAGE_OVERLAY_MARGIN, PAGE_OVERLAY_MARGIN);- layout->addStretch();- layout->addLayout(column_row);- layout->addStretch();+ m_layout = new QVBoxLayout(m_content);+ m_layout->setContentsMargins(PAGE_OVERLAY_MARGIN, PAGE_OVERLAY_MARGIN, PAGE_OVERLAY_MARGIN, PAGE_OVERLAY_MARGIN);+ m_layout->addStretch();+ m_layout->addLayout(column_row);+ m_layout->addStretch();}QWidget& content() { return *m_content; }QWidget& column() { return *m_column; }+ // The column takes all of the tab rather than being centered in it, so a review's full report gets as much room as+ // the tab has.+ void set_fills_tab(bool fills_tab)+ {+ m_layout->setStretch(1, fills_tab ? 1 : 0);+ m_column->setMaximumWidth(fills_tab ? QWIDGETSIZE_MAX : PAGE_OVERLAY_MAXIMUM_WIDTH);+ }+private:QWidget* m_content { nullptr };QWidget* m_column { nullptr };+ QVBoxLayout* m_layout { nullptr };};class CrashOverlayUrlLabel final : public QLabel {@@ -1398,6 +1407,7 @@ void WebContentView::set_crash_overlay_visible(bool visible)if (m_crash_report_review) {delete m_crash_report_review;m_crash_report_review = nullptr;+ m_crash_overlay->set_fills_tab(false);}if (m_crash_report_container)m_crash_report_container->hide();@@ -1461,6 +1471,9 @@ void WebContentView::show_crash_report_review(Optional<ByteString> const& hidden}reload();};+ m_crash_report_review->on_report_text_visibility_change = [this](bool visible) {+ m_crash_overlay->set_fills_tab(visible);+ };auto answered_message = is_hidden_crash ? tr("Part of Ladybird stopped unexpectedly.") : crash_screen_message();m_crash_report_review->on_answered = [this, answered_message] {m_crash_overlay_message->setText(answered_message);