Skip to content

Truly independent web browser

UI/Qt: Add per-site content blocking controls to the toolbar

Timothy Flynn48b1e790397e
diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txt
index d60b36ef0bb..224648aaa29 100644
--- a/UI/Qt/CMakeLists.txt
+++ b/UI/Qt/CMakeLists.txt
@@ -28,6 +28,8 @@ target_sources(ladybird PRIVATE
BookmarksBar.cpp
BrowserWindow.cpp
ChromeStyle.cpp
+ ContentBlockingButton.cpp
+ ContentBlockingPopover.cpp
CrashReportNotifier.cpp
CrashReportReviewWidget.cpp
DevToolsBanner.cpp
diff --git a/UI/Qt/ChromeStyle.cpp b/UI/Qt/ChromeStyle.cpp
index 3f013242ec7..f72789a7196 100644
--- a/UI/Qt/ChromeStyle.cpp
+++ b/UI/Qt/ChromeStyle.cpp
@@ -1423,6 +1423,51 @@ QPushButton#LadybirdMessagePopoverAcceptButton:pressed {{
text, surface, border, muted_text, control_border, hover_surface, pressed_surface, accent_color, accent_hover, accent_pressed);
}
+QString content_blocking_popover_style_sheet(QPalette const& palette)
+{
+ auto text = style_sheet_color(chrome_text(palette));
+ auto surface = style_sheet_color(chrome_surface(palette));
+ auto border = style_sheet_color(chrome_border(palette));
+ auto muted_text = style_sheet_color(chrome_muted_text(palette));
+ auto recessed_surface = style_sheet_color(chrome_surface_recessed(palette));
+ auto footer_surface = style_sheet_color(chrome_background(palette));
+
+ return qformatted(R"(
+QFrame#LadybirdContentBlockingPopover {{
+ color: {0};
+ background: {1};
+ border: 1px solid {2};
+ border-radius: 8px;
+}}
+
+QFrame#LadybirdContentBlockingPopover QLabel,
+QFrame#LadybirdContentBlockingPopover QCheckBox {{
+ color: {0};
+}}
+
+QLabel#LadybirdContentBlockingSite,
+QLabel#LadybirdContentBlockingCount {{
+ font-weight: 600;
+}}
+
+QLabel#LadybirdContentBlockingCount {{
+ background: {4};
+ border-radius: 12px;
+ padding: 12px 16px;
+}}
+
+QFrame#LadybirdContentBlockingPopover QLabel#LadybirdContentBlockingNote {{
+ color: {3};
+ background: {5};
+ border-top: 1px solid {2};
+ border-bottom-left-radius: 7px;
+ border-bottom-right-radius: 7px;
+ padding: 12px 16px;
+}}
+)",
+ text, surface, border, muted_text, recessed_surface, footer_surface);
+}
+
static void paint_circular_control_frame(QPainter& painter, QRect const& rect, qreal device_pixel_ratio, QColor const& background, QColor const& border)
{
auto frame_rect = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5);
diff --git a/UI/Qt/ChromeStyle.h b/UI/Qt/ChromeStyle.h
index c5bb5916b3b..64a87966422 100644
--- a/UI/Qt/ChromeStyle.h
+++ b/UI/Qt/ChromeStyle.h
@@ -50,6 +50,7 @@ QString tab_widget_style_sheet(QPalette const&);
QString autocomplete_popup_style_sheet(QPalette const&);
QString downloads_popover_style_sheet(QPalette const&);
QString message_popover_style_sheet(QPalette const&);
+QString content_blocking_popover_style_sheet(QPalette const&);
enum class CircularControlFrameStyle {
InteractionOnly,
diff --git a/UI/Qt/ContentBlockingButton.cpp b/UI/Qt/ContentBlockingButton.cpp
new file mode 100644
index 00000000000..64ca47b368a
--- /dev/null
+++ b/UI/Qt/ContentBlockingButton.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <UI/Qt/ChromeStyle.h>
+#include <UI/Qt/ContentBlockingButton.h>
+#include <UI/Qt/StringUtils.h>
+
+#include <QPainter>
+#include <QStyleOptionToolButton>
+#include <QStylePainter>
+
+namespace Ladybird {
+
+ContentBlockingButton::ContentBlockingButton(QWidget* parent)
+ : QToolButton(parent)
+{
+ setObjectName("ContentBlockingButton");
+ setAccessibleName("Ad blocking");
+ setAutoRaise(true);
+ setFixedSize(sizeHint());
+ setFocusPolicy(Qt::StrongFocus);
+}
+
+void ContentBlockingButton::set_snapshot(WebView::ContentBlockingSnapshot const& snapshot)
+{
+ m_snapshot = snapshot;
+ setEnabled(snapshot.state != WebView::ContentBlockingState::Unavailable);
+ update();
+}
+
+QString ContentBlockingButton::badge_text() const
+{
+ if (!m_snapshot.enabled() || m_snapshot.blocked_request_count == 0)
+ return {};
+ return m_snapshot.blocked_request_count > 99 ? "99+" : qformatted("{}", m_snapshot.blocked_request_count);
+}
+
+void ContentBlockingButton::paintEvent(QPaintEvent*)
+{
+ QStyleOptionToolButton option;
+ initStyleOption(&option);
+ option.icon = {};
+
+ QStylePainter painter(this);
+ ChromeStyle::paint_circular_control_frame(painter, *this);
+ painter.drawComplexControl(QStyle::CC_ToolButton, option);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.save();
+
+ if (!m_snapshot.enabled())
+ painter.setOpacity(0.45);
+
+ auto logo_rect = QRect((width() - 20) / 2, (height() - 20) / 2, 20, 20);
+ m_logo.paint(&painter, logo_rect);
+ painter.restore();
+
+ auto badge = badge_text();
+ if (badge.isEmpty())
+ return;
+
+ auto badge_font = font();
+ badge_font.setPointSizeF(7.5);
+ badge_font.setBold(true);
+
+ painter.setFont(badge_font);
+
+ auto badge_width = painter.fontMetrics().horizontalAdvance(badge) + 6;
+ auto badge_height = painter.fontMetrics().height() + 2;
+ auto badge_rect = QRect(width() - badge_width - 1, 1, badge_width, badge_height);
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(QColor(88, 117, 153));
+ painter.drawRoundedRect(badge_rect, 5, 5);
+
+ painter.setPen(Qt::white);
+ painter.drawText(badge_rect, Qt::AlignCenter, badge);
+}
+
+}
diff --git a/UI/Qt/ContentBlockingButton.h b/UI/Qt/ContentBlockingButton.h
new file mode 100644
index 00000000000..9560d7bb686
--- /dev/null
+++ b/UI/Qt/ContentBlockingButton.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/kmalloc.h>
+#include <LibWebView/ContentBlocking.h>
+
+#include <QIcon>
+#include <QToolButton>
+
+namespace Ladybird {
+
+class ContentBlockingButton final : public QToolButton {
+ AK_ALLOC_WITH_KMALLOC;
+
+public:
+ explicit ContentBlockingButton(QWidget* parent);
+
+ void set_snapshot(WebView::ContentBlockingSnapshot const&);
+ QString badge_text() const;
+
+private:
+ virtual void paintEvent(QPaintEvent*) override;
+ virtual QSize sizeHint() const override { return { 34, 34 }; }
+
+ QIcon m_logo { ":/Icons/ladybird.png" };
+ WebView::ContentBlockingSnapshot m_snapshot;
+};
+
+}
diff --git a/UI/Qt/ContentBlockingPopover.cpp b/UI/Qt/ContentBlockingPopover.cpp
new file mode 100644
index 00000000000..6aa7b57d5c2
--- /dev/null
+++ b/UI/Qt/ContentBlockingPopover.cpp
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <UI/Qt/ChromeStyle.h>
+#include <UI/Qt/ContentBlockingPopover.h>
+#include <UI/Qt/StringUtils.h>
+
+#include <QCheckBox>
+#include <QFrame>
+#include <QHBoxLayout>
+#include <QIcon>
+#include <QKeyEvent>
+#include <QLabel>
+#include <QMouseEvent>
+#include <QScreen>
+#include <QSignalBlocker>
+#include <QStyleOptionFocusRect>
+#include <QStylePainter>
+#include <QVBoxLayout>
+
+namespace Ladybird {
+
+class ContentBlockingSwitch final : public QCheckBox {
+ AK_ALLOC_WITH_KMALLOC;
+
+public:
+ explicit ContentBlockingSwitch(QWidget* parent)
+ : QCheckBox("Block ads on this site", parent)
+ {
+ setFocusPolicy(Qt::StrongFocus);
+ }
+
+ virtual QSize sizeHint() const override
+ {
+ return { fontMetrics().horizontalAdvance(text()) + 56, qMax(28, fontMetrics().height() + 8) };
+ }
+
+private:
+ virtual bool hitButton(QPoint const& position) const override { return rect().contains(position); }
+
+ virtual void paintEvent(QPaintEvent*) override
+ {
+ QStylePainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ if (!isEnabled())
+ painter.setOpacity(0.45);
+
+ auto track = QStyle::visualRect(layoutDirection(), rect(), QRect(width() - 40, (height() - 22) / 2, 40, 22));
+ auto track_color = isChecked() ? palette().color(QPalette::Active, QPalette::Highlight) : ChromeStyle::chrome_control_border(palette());
+ if (underMouse() && isEnabled())
+ track_color = ChromeStyle::mix(track_color, Qt::white, 0.12);
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(track_color);
+ painter.drawRoundedRect(track, 11, 11);
+
+ auto thumb_offset = isChecked() != (layoutDirection() == Qt::RightToLeft) ? 21 : 3;
+ painter.setBrush(palette().color(QPalette::Active, QPalette::HighlightedText));
+ painter.drawEllipse(QRect(track.x() + thumb_offset, track.y() + 3, 16, 16));
+
+ auto text_rect = QStyle::visualRect(layoutDirection(), rect(), QRect(0, 0, width() - 56, height()));
+ painter.drawItemText(text_rect, Qt::AlignLeading | Qt::AlignVCenter, palette(), isEnabled(), text(), QPalette::WindowText);
+
+ if (hasFocus()) {
+ QStyleOptionFocusRect focus;
+ focus.initFrom(this);
+ focus.rect = rect();
+ painter.drawPrimitive(QStyle::PE_FrameFocusRect, focus);
+ }
+ }
+};
+
+ContentBlockingPopover::ContentBlockingPopover(QWidget* parent)
+ : Popover(parent)
+{
+ setAttribute(Qt::WA_NoMouseReplay);
+ setFocusPolicy(Qt::StrongFocus);
+ setAccessibleName("Ad blocking controls");
+ card().setObjectName("LadybirdContentBlockingPopover");
+
+ auto* card_layout = new QVBoxLayout(&card());
+ card_layout->setContentsMargins(0, 0, 0, 0);
+ card_layout->setSpacing(0);
+
+ auto* layout = new QVBoxLayout;
+ layout->setContentsMargins(16, 14, 16, 14);
+ layout->setSpacing(12);
+ card_layout->addLayout(layout);
+
+ auto* heading = new QHBoxLayout;
+
+ m_favicon = new QLabel(&card());
+ m_favicon->setFixedSize(24, 24);
+ m_favicon->setAlignment(Qt::AlignCenter);
+ heading->addWidget(m_favicon, 0, Qt::AlignVCenter);
+
+ m_site = new QLabel(&card());
+ m_site->setObjectName("LadybirdContentBlockingSite");
+ m_site->setTextFormat(Qt::PlainText);
+ m_site->setAlignment(Qt::AlignLeading | Qt::AlignVCenter);
+ m_site->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
+ heading->addWidget(m_site, 1);
+ layout->addLayout(heading);
+
+ m_switch = new ContentBlockingSwitch(&card());
+ m_switch->setObjectName("ContentBlockingSiteSwitch");
+ m_switch->setAccessibleName("Block ads on this site");
+ m_switch->setFocusPolicy(Qt::StrongFocus);
+ QObject::connect(m_switch, &QCheckBox::toggled, this, [this](bool enabled) {
+ if (on_toggle)
+ on_toggle(enabled);
+ });
+ layout->addWidget(m_switch);
+
+ m_count = new QLabel(&card());
+ m_count->setObjectName("LadybirdContentBlockingCount");
+ m_count->setTextFormat(Qt::PlainText);
+ m_count->setAlignment(Qt::AlignCenter);
+ layout->addWidget(m_count);
+
+ m_error = new QLabel(&card());
+ m_error->setTextFormat(Qt::PlainText);
+ m_error->hide();
+ layout->addWidget(m_error);
+
+ m_note = new QLabel(&card());
+ m_note->setObjectName("LadybirdContentBlockingNote");
+ m_note->setTextFormat(Qt::PlainText);
+ m_note->setAlignment(Qt::AlignCenter);
+ card_layout->addWidget(m_note);
+}
+
+void ContentBlockingPopover::set_favicon(QIcon const& favicon)
+{
+ m_favicon->setPixmap(favicon.pixmap(m_favicon->size(), devicePixelRatioF()));
+}
+
+void ContentBlockingPopover::set_snapshot(WebView::ContentBlockingSnapshot const& snapshot)
+{
+ auto site = snapshot.site.has_value() ? qstring_from_ak_string(*snapshot.site) : QString("This page");
+ m_site->setToolTip(site);
+ m_site->setAccessibleName(site);
+
+ QSignalBlocker blocker(m_switch);
+ m_switch->setChecked(snapshot.enabled());
+ m_switch->setEnabled(snapshot.can_toggle());
+ m_switch->setToolTip(snapshot.state == WebView::ContentBlockingState::Disabled ? "Ad blocking is disabled in Settings." : QString {});
+
+ m_count->setText(qformatted("{} request{} blocked on this page", snapshot.blocked_request_count, snapshot.blocked_request_count == 1 ? ""sv : "s"sv));
+ m_count->setVisible(snapshot.blocked_request_count > 0);
+
+ m_note->setText("If this site appears broken, try disabling ad block.");
+ m_error->hide();
+
+ update_size();
+}
+
+void ContentBlockingPopover::update_chrome_style(QPalette const& palette)
+{
+ auto active_palette = palette;
+ active_palette.setCurrentColorGroup(QPalette::Active);
+ setPalette(active_palette);
+ setStyleSheet(ChromeStyle::content_blocking_popover_style_sheet(active_palette));
+ update_size();
+}
+
+void ContentBlockingPopover::show_error(QString const& message)
+{
+ m_error->setText(message);
+ m_error->show();
+ update_size();
+}
+
+void ContentBlockingPopover::focus_switch()
+{
+ if (m_switch->isEnabled())
+ m_switch->setFocus(Qt::PopupFocusReason);
+ else
+ setFocus(Qt::PopupFocusReason);
+}
+
+void ContentBlockingPopover::mousePressEvent(QMouseEvent* event)
+{
+ // The transparent shadow margin can overlap the toolbar button. Treat it as outside the card.
+ if (!card().geometry().contains(event->position().toPoint())) {
+ close();
+ event->accept();
+ return;
+ }
+
+ Popover::mousePressEvent(event);
+}
+
+void ContentBlockingPopover::keyPressEvent(QKeyEvent* event)
+{
+ if (event->key() == Qt::Key_Escape) {
+ close();
+ if (on_keyboard_dismiss)
+ on_keyboard_dismiss();
+ event->accept();
+ return;
+ }
+
+ Popover::keyPressEvent(event);
+}
+
+void ContentBlockingPopover::update_size()
+{
+ auto count_font = m_count->font();
+ count_font.setPixelSize(16);
+ m_count->setFont(count_font);
+ m_count->ensurePolished();
+
+ auto available_width = qMax(160, screen()->availableGeometry().width() - 48);
+ auto count_width = m_count->fontMetrics().horizontalAdvance(m_count->text());
+ auto count_padding = m_count->contentsMargins().left() + m_count->contentsMargins().right();
+ auto available_count_width = available_width - 34 - count_padding;
+ if (count_width > available_count_width) {
+ // Keep the exact total on one line even on a narrow screen.
+ count_font.setPixelSize(qMax(10, 16 * available_count_width / (count_width + 1)));
+ m_count->setFont(count_font);
+ }
+
+ auto preferred_width = 340;
+ for (auto* label : { m_count, m_error }) {
+ if (label->isHidden())
+ continue;
+ label->ensurePolished();
+ preferred_width = qMax(preferred_width, label->sizeHint().width() + 34);
+ }
+ m_note->ensurePolished();
+ preferred_width = qMax(preferred_width, m_note->sizeHint().width() + 2);
+ card().setFixedWidth(qMin(available_width, preferred_width));
+
+ m_site->setText(m_site->fontMetrics().elidedText(m_site->toolTip(), Qt::ElideRight, card().width() - 80));
+
+ // Refresh the minimum sizes before resizing after rows are hidden or shown.
+ card().layout()->activate();
+ layout()->activate();
+ adjustSize();
+}
+
+}
diff --git a/UI/Qt/ContentBlockingPopover.h b/UI/Qt/ContentBlockingPopover.h
new file mode 100644
index 00000000000..6b0b1f57f83
--- /dev/null
+++ b/UI/Qt/ContentBlockingPopover.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Function.h>
+#include <LibWebView/ContentBlocking.h>
+#include <UI/Qt/Popover.h>
+
+class QCheckBox;
+class QIcon;
+class QLabel;
+class QKeyEvent;
+class QMouseEvent;
+
+namespace Ladybird {
+
+class ContentBlockingPopover final : public Popover {
+ AK_ALLOC_WITH_KMALLOC;
+
+public:
+ explicit ContentBlockingPopover(QWidget* parent);
+
+ void set_snapshot(WebView::ContentBlockingSnapshot const&);
+ void set_favicon(QIcon const&);
+ void update_chrome_style(QPalette const&);
+ void show_error(QString const&);
+ void focus_switch();
+
+ Function<void(bool)> on_toggle;
+ Function<void()> on_keyboard_dismiss;
+
+private:
+ virtual void keyPressEvent(QKeyEvent*) override;
+ virtual void mousePressEvent(QMouseEvent*) override;
+ void update_size();
+
+ QLabel* m_favicon { nullptr };
+ QLabel* m_site { nullptr };
+ QLabel* m_count { nullptr };
+ QLabel* m_note { nullptr };
+ QLabel* m_error { nullptr };
+ QCheckBox* m_switch { nullptr };
+};
+
+}
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index 18eb68809b6..f4411c02d20 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -20,6 +20,8 @@
#include <UI/Qt/BrowserWindow.h>
#include <UI/Qt/ChromeLayout.h>
#include <UI/Qt/ChromeStyle.h>
+#include <UI/Qt/ContentBlockingButton.h>
+#include <UI/Qt/ContentBlockingPopover.h>
#include <UI/Qt/Icon.h>
#include <UI/Qt/JavaScriptDialog.h>
#if defined(AK_OS_MACOS)
@@ -695,6 +697,13 @@ Tab::Tab(BrowserWindow* window, Optional<WebView::CanonicalTraversable&> travers
m_location_edit->set_zoom_action(create_application_action(*m_location_edit, view().reset_zoom_action(), IncludeActionIcon::No));
location_edit_layout->addWidget(m_location_edit);
toolbar_layout->addWidget(location_edit_container, 1);
+
+ m_content_blocking_button = new ContentBlockingButton(m_toolbar);
+ toolbar_layout->addWidget(m_content_blocking_button, 0, Qt::AlignVCenter);
+ QObject::connect(m_content_blocking_button, &QToolButton::clicked, this, [this] { show_content_blocking_popover(); });
+ view().on_content_blocking_change = [this](auto const& snapshot) { update_content_blocking_controls(snapshot); };
+ update_content_blocking_controls(view().content_blocking_snapshot());
+
m_right_toggle_vertical_tabs_expanded_button = create_toolbar_button(*m_toolbar, *m_toggle_vertical_tabs_expanded_action);
toolbar_layout->addWidget(m_right_toggle_vertical_tabs_expanded_button, 0, Qt::AlignVCenter);
@@ -747,11 +756,18 @@ Tab::Tab(BrowserWindow* window, Optional<WebView::CanonicalTraversable&> travers
};
set_loading(view().is_loading());
+ view().on_load_start = [this] {
+ if (m_content_blocking_popover)
+ m_content_blocking_popover->close();
+ };
+
view().on_load_finish = [this](auto const&) {
m_suppress_javascript_dialogs_until_navigation = false;
};
view().on_top_level_navigation_commit = [this] {
+ if (m_content_blocking_popover)
+ m_content_blocking_popover->close();
m_suppress_javascript_dialogs_until_navigation = false;
};
@@ -778,6 +794,8 @@ Tab::Tab(BrowserWindow* window, Optional<WebView::CanonicalTraversable&> travers
view().on_favicon_change = [this](auto const& bitmap) {
if (!bitmap.has_value()) {
m_favicon = {};
+ if (m_content_blocking_popover)
+ m_content_blocking_popover->set_favicon(m_favicon);
update_tab_icon();
return;
}
@@ -790,6 +808,8 @@ Tab::Tab(BrowserWindow* window, Optional<WebView::CanonicalTraversable&> travers
return;
m_favicon = qpixmap;
+ if (m_content_blocking_popover)
+ m_content_blocking_popover->set_favicon(m_favicon);
update_tab_icon();
};
@@ -1390,6 +1410,8 @@ void Tab::hideEvent(QHideEvent* event)
QWidget::hideEvent(event);
m_hover_label->hide();
+ if (m_content_blocking_popover)
+ m_content_blocking_popover->close();
}
void Tab::update_hover_label()
@@ -1437,6 +1459,8 @@ void Tab::update_chrome_style()
hover_surface, hover_text, hover_border));
if (m_downloads_popover)
m_downloads_popover->update_chrome_style(palette());
+ if (m_content_blocking_popover)
+ m_content_blocking_popover->update_chrome_style(palette());
m_is_updating_chrome_style = false;
}
@@ -1586,6 +1610,69 @@ void Tab::download_removed(u64, WebView::IsPrivate is_private)
update_downloads_popover();
}
+void Tab::update_content_blocking_controls(WebView::ContentBlockingSnapshot const& snapshot)
+{
+ m_content_blocking_button->set_snapshot(snapshot);
+ if (!m_content_blocking_popover || !m_content_blocking_popover->isVisible())
+ return;
+
+ if (snapshot.state == WebView::ContentBlockingState::Unavailable) {
+ m_content_blocking_popover->close();
+ return;
+ }
+
+ m_content_blocking_popover->set_snapshot(snapshot);
+ move_popover_below(*m_content_blocking_popover, *m_content_blocking_button);
+}
+
+void Tab::show_content_blocking_popover()
+{
+ if (m_content_blocking_popover && m_content_blocking_popover->isVisible()) {
+ m_content_blocking_popover->close();
+ m_content_blocking_button->setFocus(Qt::PopupFocusReason);
+ return;
+ }
+
+ auto snapshot = view().content_blocking_snapshot();
+ if (snapshot.state == WebView::ContentBlockingState::Unavailable)
+ return;
+
+ if (!m_content_blocking_popover) {
+ m_content_blocking_popover = new ContentBlockingPopover(this);
+ m_content_blocking_popover->on_keyboard_dismiss = [button = QPointer(m_content_blocking_button)] {
+ if (button && button->isVisible())
+ button->setFocus(Qt::PopupFocusReason);
+ };
+ }
+
+ m_content_blocking_popover->on_toggle = [this, site = snapshot.site](bool enabled) {
+ auto current = view().content_blocking_snapshot();
+ if (!site.has_value() || current.site != site || !current.can_toggle()) {
+ m_content_blocking_popover->close();
+ return;
+ }
+
+ if (auto result = WebView::Application::settings().set_content_blocker_enabled_for_site(*site, enabled); result.is_error()) {
+ m_content_blocking_popover->set_snapshot(view().content_blocking_snapshot());
+ m_content_blocking_popover->show_error("Unable to save the site preference.");
+ move_popover_below(*m_content_blocking_popover, *m_content_blocking_button);
+ return;
+ }
+
+ m_content_blocking_popover->close();
+ view().reload();
+ };
+
+ m_content_blocking_popover->update_chrome_style(palette());
+ m_content_blocking_popover->set_favicon(m_favicon);
+ m_content_blocking_popover->set_snapshot(snapshot);
+ move_popover_below(*m_content_blocking_popover, *m_content_blocking_button);
+ m_content_blocking_popover->show();
+ move_popover_below(*m_content_blocking_popover, *m_content_blocking_button);
+ m_content_blocking_popover->raise();
+ m_content_blocking_popover->focus_switch();
+}
+
void Tab::update_vertical_tabs_toolbar_button_placement()
{
auto show_left_button = m_vertical_tabs_enabled && m_vertical_tabs_position == WebView::VerticalTabsPosition::Left;
diff --git a/UI/Qt/Tab.h b/UI/Qt/Tab.h
index e23bc3f04dc..61ae5a7203b 100644
--- a/UI/Qt/Tab.h
+++ b/UI/Qt/Tab.h
@@ -41,6 +41,8 @@ namespace Ladybird {
class BrowserWindow;
enum class ChromeIcon;
class DownloadsPopover;
+class ContentBlockingButton;
+class ContentBlockingPopover;
class JavaScriptDialog;
class MessagePopover;
class WindowControlButton;
@@ -143,6 +145,8 @@ private:
void update_downloads_popover();
void show_downloads_popover();
void position_downloads_popover();
+ void show_content_blocking_popover();
+ void update_content_blocking_controls(WebView::ContentBlockingSnapshot const&);
void show_private_session_popover();
void position_private_session_popover();
void set_loading(bool);
@@ -168,6 +172,8 @@ private:
BookmarksBar* m_bookmarks_bar { nullptr };
QPushButton* m_private_badge { nullptr };
QToolButton* m_hamburger_button { nullptr };
+ ContentBlockingButton* m_content_blocking_button { nullptr };
+ QPointer<ContentBlockingPopover> m_content_blocking_popover;
QToolButton* m_downloads_button { nullptr };
QPointer<DownloadsPopover> m_downloads_popover;
QPointer<MessagePopover> m_private_session_popover;