Truly independent web browser
UI/Qt: Draw the sandbox-off bar as a general notification bar
Luke Wilde5f7399152f1a
diff --git a/Documentation/UI/QuietDesign.md b/Documentation/UI/QuietDesign.mdindex 2f04a5f9378..0483379366a 100644--- a/Documentation/UI/QuietDesign.md+++ b/Documentation/UI/QuietDesign.md@@ -590,18 +590,25 @@ settings.- Sent or deleted rows disappear. An empty list says "No crash reports waiting".- A "Crash report settings" link at the bottom goes to Settings → Feedback.-### Sandbox off+### Notification bars-When Ladybird runs with `--disable-sandbox`, every window shows a bar directly below the-toolbar (or at the top of the page area in the sidebar layouts):+Every window shows its notification bars directly below the toolbar (or at the top of the+page area in the sidebar layouts), one below the other in a fixed order:- 32 px plus a `divider` line below, in the `toolbar` color, so it reads as part of thechrome, not as a page banner. The page starts below it.-- The `warning` icon (16 px) and one sentence in `text`: "The sandbox is off. Websites are- less isolated from your computer."-- No close button, no action button, no amber fill. It can't be dismissed, because the state- can't be changed from inside the browser, and it should be in every screenshot that ends- up in a bug report.+- The `warning` icon (16 px) and one sentence in `text`, cut short with an ellipsis when the+ window is too narrow for it. Then any text buttons, and a close button if the bar can be+ closed. No amber fill.++### Sandbox off++When Ladybird runs with `--disable-sandbox`, every window shows a notification bar: "The+sandbox is off. Websites are less isolated from your computer."++- No close button and no action button. It can't be dismissed, because the state can't be+ changed from inside the browser, and it should be in every screenshot that ends up in a+ bug report.- Bug reports and crash reports include "sandbox: off" in their prefilled details.- Nothing else changes: no badge on the Ladybird button, no tint, nothing in the addressfield (which describes the site, not the browser).diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txtindex c7bed45c468..aca157eee8c 100644--- a/UI/Qt/CMakeLists.txt+++ b/UI/Qt/CMakeLists.txt@@ -47,6 +47,7 @@ add_library(ladybird_impl STATICMenu.cppNativeTextEditingLineEdit.cppNativeWindowContainer.cpp+ NotificationBar.cppPageCard.cppPerformanceMonitorWidget.cppPermissionPromptPopover.cpp@@ -57,7 +58,6 @@ add_library(ladybird_impl STATICRemoteDownloads.cppRemoteView.cppReportReview.cpp- SandboxOffBar.cppScreenshotSelectionOverlay.cppScreenshotViewer.cppSessionHistorySnapshotStorage.cppdiff --git a/UI/Qt/ChromeStyle.cpp b/UI/Qt/ChromeStyle.cppindex 9562fb5b5bd..29072dd46a8 100644--- a/UI/Qt/ChromeStyle.cpp+++ b/UI/Qt/ChromeStyle.cpp@@ -1075,6 +1075,41 @@ QWidget#LadybirdDevToolsBanner QPushButton:pressed {{background, border, control_border, hover, pressed, text);}+QString notification_bar_style_sheet(QPalette const& palette)+{+ auto const& chrome = Theme::chrome(palette);++ return qformatted(R"(+QWidget#LadybirdNotificationBar QLabel {{+ color: {0};+}}++QWidget#LadybirdNotificationBar QPushButton {{+ color: {0};+ background: transparent;+ border: 0;+ border-radius: 5px;+ padding: 4px 6px;+ font-weight: 500;+}}++QWidget#LadybirdNotificationBar QPushButton:hover {{+ text-decoration: underline;+}}++QWidget#LadybirdNotificationBar QToolButton {{+ background: transparent;+ border: 0;+ border-radius: 6px;+}}++QWidget#LadybirdNotificationBar QToolButton:hover {{+ background: {1};+}}+)",+ style_sheet_color(chrome.text), style_sheet_color(chrome.hover));+}+QString tab_widget_style_sheet(QPalette const& palette){auto dark = is_dark(palette);diff --git a/UI/Qt/ChromeStyle.h b/UI/Qt/ChromeStyle.hindex 7a7ae92694f..fdc96872800 100644--- a/UI/Qt/ChromeStyle.h+++ b/UI/Qt/ChromeStyle.h@@ -104,6 +104,7 @@ QString bookmark_dialog_style_sheet(QPalette const&);QString report_review_style_sheet(QPalette const&);QColor report_review_placeholder_text(QPalette const&);QString devtools_banner_style_sheet(QPalette const&);+QString notification_bar_style_sheet(QPalette const&);QString tab_widget_style_sheet(QPalette const&);QString autocomplete_popup_style_sheet(QPalette const&);QString downloads_popover_style_sheet(QPalette const&);diff --git a/UI/Qt/NotificationBar.cpp b/UI/Qt/NotificationBar.cppnew file mode 100644index 00000000000..2c7d99c4348--- /dev/null+++ b/UI/Qt/NotificationBar.cpp@@ -0,0 +1,103 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <UI/Qt/ChromeStyle.h>+#include <UI/Qt/ElidedLabel.h>+#include <UI/Qt/Icon.h>+#include <UI/Qt/NotificationBar.h>+#include <UI/Qt/Theme.h>++#include <QEvent>+#include <QHBoxLayout>+#include <QPainter>+#include <QPushButton>+#include <QToolButton>++namespace Ladybird {++static constexpr int BAR_HEIGHT = 32;+static constexpr int DIVIDER_HEIGHT = 1;+static constexpr int ICON_SIZE = 16;+static constexpr int CLOSE_ICON_SIZE = 12;+static constexpr int CLOSE_BUTTON_SIZE = 24;+static constexpr int HORIZONTAL_INSET = 12;+static constexpr int ICON_TEXT_SPACING = 8;++NotificationBar::NotificationBar(QWidget& parent, QString const& message, Vector<Button> buttons, Function<void()> on_close)+ : QWidget(&parent)+{+ setObjectName("LadybirdNotificationBar");+ setAttribute(Qt::WA_OpaquePaintEvent);+ setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);+ setFixedHeight(BAR_HEIGHT + DIVIDER_HEIGHT);+ setAccessibleName(message);++ auto* layout = new QHBoxLayout(this);+ auto end_inset = HORIZONTAL_INSET;+ // NB: The close icon ends at the inset, like the warning icon starts at it.+ if (on_close)+ end_inset -= (CLOSE_BUTTON_SIZE - CLOSE_ICON_SIZE) / 2;+ layout->setContentsMargins(HORIZONTAL_INSET, 0, end_inset, DIVIDER_HEIGHT);+ layout->setSpacing(ICON_TEXT_SPACING);++ m_icon_area = new QWidget(this);+ m_icon_area->setFixedSize(ICON_SIZE, ICON_SIZE);+ layout->addWidget(m_icon_area);++ layout->addWidget(new ElidedLabel(message, Qt::ElideRight, this), 1);++ for (auto& button : buttons) {+ auto* push_button = new QPushButton(button.label, this);+ push_button->setCursor(Qt::PointingHandCursor);+ QObject::connect(push_button, &QPushButton::clicked, this, [on_click = AK::move(button.on_click)] {+ on_click();+ });+ layout->addWidget(push_button);+ }++ if (on_close) {+ m_close_button = new QToolButton(this);+ m_close_button->setAutoRaise(true);+ m_close_button->setFixedSize(CLOSE_BUTTON_SIZE, CLOSE_BUTTON_SIZE);+ m_close_button->setIconSize({ CLOSE_ICON_SIZE, CLOSE_ICON_SIZE });+ m_close_button->setToolTip("Dismiss");+ m_close_button->setAccessibleName("Dismiss");+ QObject::connect(m_close_button, &QToolButton::clicked, this, [on_close = AK::move(on_close)] {+ on_close();+ });+ layout->addWidget(m_close_button);+ }++ update_chrome_style();+}++bool NotificationBar::event(QEvent* event)+{+ if (event->type() == QEvent::PaletteChange)+ update_chrome_style();+ return QWidget::event(event);+}++void NotificationBar::update_chrome_style()+{+ // NB: Setting a style sheet changes the palette, so it is only set when it changed, or it would set itself forever.+ if (auto style_sheet = ChromeStyle::notification_bar_style_sheet(Theme::chrome_palette(*this)); styleSheet() != style_sheet)+ setStyleSheet(style_sheet);+ if (m_close_button)+ m_close_button->setIcon(create_chrome_icon(ChromeIcon::Close, Theme::chrome(*this).icon));+}++void NotificationBar::paintEvent(QPaintEvent*)+{+ auto const& chrome = Theme::chrome(*this);++ QPainter painter(this);+ painter.fillRect(QRect { 0, 0, width(), BAR_HEIGHT }, chrome.toolbar);+ painter.fillRect(QRect { 0, BAR_HEIGHT, width(), DIVIDER_HEIGHT }, chrome.divider);+ create_chrome_icon(ChromeIcon::Warning, chrome.warning).paint(&painter, m_icon_area->geometry());+}++}diff --git a/UI/Qt/NotificationBar.h b/UI/Qt/NotificationBar.hnew file mode 100644index 00000000000..1f1efe3e889--- /dev/null+++ b/UI/Qt/NotificationBar.h@@ -0,0 +1,43 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/Function.h>+#include <AK/Vector.h>+#include <AK/kmalloc.h>++#include <QString>+#include <QWidget>++class QToolButton;++namespace Ladybird {++// A warning in a bar above the pages of a window.+class NotificationBar final : public QWidget {+public:+ AK_ALLOC_WITH_KMALLOC;++ struct Button {+ QString label;+ Function<void()> on_click;+ };++ // The bar has a close button if `on_close` is set.+ NotificationBar(QWidget& parent, QString const& message, Vector<Button>, Function<void()> on_close);++private:+ virtual bool event(QEvent*) override;+ virtual void paintEvent(QPaintEvent*) override;++ void update_chrome_style();++ QWidget* m_icon_area { nullptr };+ QToolButton* m_close_button { nullptr };+};++}diff --git a/UI/Qt/SandboxOffBar.cpp b/UI/Qt/SandboxOffBar.cppdeleted file mode 100644index 704ff270c81..00000000000--- a/UI/Qt/SandboxOffBar.cpp+++ /dev/null@@ -1,74 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <UI/Qt/Icon.h>-#include <UI/Qt/SandboxOffBar.h>-#include <UI/Qt/Theme.h>--#include <QEvent>-#include <QPainter>--namespace Ladybird {--static constexpr int BAR_HEIGHT = 32;-static constexpr int DIVIDER_HEIGHT = 1;-static constexpr int ICON_SIZE = 16;-static constexpr int HORIZONTAL_INSET = 12;-static constexpr int ICON_TEXT_SPACING = 8;--static constexpr auto MESSAGE = "The sandbox is off. Websites are less isolated from your computer.";--SandboxOffBar::SandboxOffBar(QWidget* parent)- : QWidget(parent)-{- setObjectName("LadybirdSandboxOffBar");- setAttribute(Qt::WA_OpaquePaintEvent);- setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);- setFixedHeight(BAR_HEIGHT + DIVIDER_HEIGHT);- setAccessibleName(MESSAGE);-}--bool SandboxOffBar::event(QEvent* event)-{- switch (event->type()) {- case QEvent::PaletteChange:- case QEvent::FontChange:- case QEvent::LayoutDirectionChange:- update();- break;- default:- break;- }- return QWidget::event(event);-}--void SandboxOffBar::paintEvent(QPaintEvent*)-{- auto const& chrome = Theme::chrome(*this);-- QPainter painter(this);- painter.fillRect(QRect { 0, 0, width(), BAR_HEIGHT }, chrome.toolbar);- painter.fillRect(QRect { 0, BAR_HEIGHT, width(), DIVIDER_HEIGHT }, chrome.divider);-- QRect content_rect { HORIZONTAL_INSET, 0, width() - 2 * HORIZONTAL_INSET, BAR_HEIGHT };- QRect icon_rect { 0, (BAR_HEIGHT - ICON_SIZE) / 2, ICON_SIZE, ICON_SIZE };- QRect text_rect { 0, 0, content_rect.width() - ICON_SIZE - ICON_TEXT_SPACING, BAR_HEIGHT };- if (layoutDirection() == Qt::RightToLeft) {- icon_rect.moveRight(content_rect.right());- text_rect.moveRight(icon_rect.left() - ICON_TEXT_SPACING - 1);- } else {- icon_rect.moveLeft(content_rect.left());- text_rect.moveLeft(icon_rect.right() + 1 + ICON_TEXT_SPACING);- }-- create_chrome_icon(ChromeIcon::Warning, chrome.warning).paint(&painter, icon_rect);-- painter.setPen(chrome.text);- auto text = fontMetrics().elidedText(MESSAGE, Qt::ElideRight, text_rect.width());- painter.drawText(text_rect, Qt::AlignVCenter | Qt::AlignLeading, text);-}--}diff --git a/UI/Qt/SandboxOffBar.h b/UI/Qt/SandboxOffBar.hdeleted file mode 100644index 756fe053ffe..00000000000--- a/UI/Qt/SandboxOffBar.h+++ /dev/null@@ -1,30 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/kmalloc.h>--#include <QWidget>--namespace Ladybird {--// The bar every window shows below its toolbar while the browser runs without the sandbox. It can't be dismissed, as-// nothing in the browser can turn the sandbox back on.-class SandboxOffBar final : public QWidget {- Q_OBJECT--public:- AK_ALLOC_WITH_KMALLOC;-- explicit SandboxOffBar(QWidget* parent = nullptr);--private:- virtual bool event(QEvent*) override;- virtual void paintEvent(QPaintEvent*) override;-};--}diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cppindex a6877c8281a..3e3fd31b491 100644--- a/UI/Qt/TabBar.cpp+++ b/UI/Qt/TabBar.cpp@@ -31,7 +31,6 @@#include <UI/Qt/Menu.h>#include <UI/Qt/Motion.h>#include <UI/Qt/Popover.h>-#include <UI/Qt/SandboxOffBar.h>#include <UI/Qt/StringUtils.h>#include <UI/Qt/SystemAppearance.h>#include <UI/Qt/TabBar.h>@@ -3104,8 +3103,13 @@ TabWidget::TabWidget(WebView::IsPrivate is_private, QWidget* parent)m_page_column_layout->setContentsMargins(0, 0, 0, 0);m_bookmarks_bar = new BookmarksBarContainer(*m_toolbar, *m_stacked_widget, m_page_column);m_bookmarks_bar->bar().installEventFilter(this);+ m_notification_bar_column = new QWidget(m_page_column);+ m_notification_bar_column->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);+ m_notification_bar_column_layout = new QVBoxLayout(m_notification_bar_column);+ m_notification_bar_column_layout->setSpacing(0);+ m_notification_bar_column_layout->setContentsMargins(0, 0, 0, 0);if (Application::browser_options().disable_sandbox == WebView::DisableSandbox::Yes)- m_sandbox_off_bar = new SandboxOffBar(m_page_column);+ show_notification_bar(NotificationBarSlot::SandboxOff, "The sandbox is off. Websites are less isolated from your computer.");m_ladybird_button = new LadybirdButton(is_private, this);@@ -3488,8 +3492,7 @@ void TabWidget::set_tab_bar_visible(bool visible)if (!m_tab_bar_visible)set_vertical_tabs_hover_expanded(false);- if (m_sandbox_off_bar)- m_sandbox_off_bar->setVisible(m_tab_bar_visible);+ m_notification_bar_column->setVisible(m_tab_bar_visible);update_tab_chrome_visibility();update_tab_layout();@@ -3498,6 +3501,34 @@ void TabWidget::set_tab_bar_visible(bool visible)place_toolbar_sidebar_buttons();}+// The notification bars stack in the order of their slots.+void TabWidget::show_notification_bar(NotificationBarSlot slot, QString const& message, Vector<NotificationBar::Button> buttons, Function<void()> on_close)+{+ hide_notification_bar(slot);++ int index = 0;+ for (size_t i = 0; i < to_underlying(slot); ++i) {+ if (m_notification_bars[i])+ ++index;+ }++ auto* bar = new NotificationBar(*m_notification_bar_column, message, AK::move(buttons), AK::move(on_close));+ m_notification_bar_column_layout->insertWidget(index, bar);+ m_notification_bars[to_underlying(slot)] = bar;+}++void TabWidget::hide_notification_bar(NotificationBarSlot slot)+{+ auto*& bar = m_notification_bars[to_underlying(slot)];+ if (!bar)+ return;++ m_notification_bar_column_layout->removeWidget(bar);+ bar->hide();+ bar->deleteLater();+ bar = nullptr;+}+void TabWidget::set_window_controls_visible(bool visible){auto changed = m_window_controls_visible != visible;@@ -4965,12 +4996,11 @@ void TabWidget::rebuild_page_column()add_page_to_page_column();}-// The bar that says the sandbox is off, if it is, and then the bookmarks bar head the page, unless the bookmarks bar-// only shows over the page while the pointer is near the toolbar. The tab performance monitor's row ends the column.+// The notification bars and then the bookmarks bar head the page, unless the bookmarks bar only shows over the page+// while the pointer is near the toolbar. The tab performance monitor's row ends the column.void TabWidget::add_page_to_page_column(){- if (m_sandbox_off_bar)- m_page_column_layout->addWidget(m_sandbox_off_bar);+ m_page_column_layout->addWidget(m_notification_bar_column);if (!m_bookmarks_bar->shows_over_page())m_page_column_layout->addWidget(m_bookmarks_bar);m_page_column_layout->addWidget(m_stacked_widget, 1);diff --git a/UI/Qt/TabBar.h b/UI/Qt/TabBar.hindex 89937fc6463..efd58a407b8 100644--- a/UI/Qt/TabBar.h+++ b/UI/Qt/TabBar.h@@ -8,6 +8,7 @@#pragma once+#include <AK/Array.h>#include <AK/HashMap.h>#include <AK/HashTable.h>#include <AK/Optional.h>@@ -17,6 +18,7 @@#include <LibWebView/BrowsingSession.h>#include <LibWebView/Settings.h>#include <UI/Qt/BookmarksBar.h>+#include <UI/Qt/NotificationBar.h>#include <UI/Qt/PlainText.h>#include <UI/Qt/Tab.h>#include <UI/Qt/WindowToolbar.h>@@ -56,7 +58,6 @@ namespace Ladybird {class AllTabsPopover;class ChromeHeaderButton;class LadybirdButton;-class SandboxOffBar;class TabMicrophoneIndicator;class TabWidget;@@ -332,6 +333,13 @@ public:void set_tab_icon(int index, QIcon const& icon);void set_tab_bar_visible(bool visible);++ enum class NotificationBarSlot : u8 {+ SandboxOff,+ };+ void show_notification_bar(NotificationBarSlot, QString const& message, Vector<NotificationBar::Button> = {}, Function<void()> on_close = {});+ void hide_notification_bar(NotificationBarSlot);+void set_new_tab_action(QAction* action);void set_window_controls_visible(bool);void window_control_buttons_changed();@@ -458,7 +466,9 @@ private:WindowControlsReveal* m_window_controls_reveal { nullptr };WindowToolbar* m_toolbar { nullptr };BookmarksBarContainer* m_bookmarks_bar { nullptr };- SandboxOffBar* m_sandbox_off_bar { nullptr };+ QWidget* m_notification_bar_column { nullptr };+ QBoxLayout* m_notification_bar_column_layout { nullptr };+ Array<NotificationBar*, 1> m_notification_bars {};QWidget* m_page_column { nullptr };QWidget* m_toolbar_placeholder { nullptr };bool m_toolbar_follows_page_column { false };