Skip to content

Truly independent web browser

UI/Qt: Show and change a site’s permissions from the location bar

sideshowbarker65f5ff1b5d5b
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index d8ab7c4c264..c71a7a3d0f1 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -324,6 +324,7 @@ void ViewImplementation::did_change_active_document(Badge<CanonicalTraversable>)
// A prompt the document that asked has left behind goes unanswered: the user ignored it.
ignore_pending_permission_prompts();
report_permission_presence();
+ m_permissions_requested_by_page.clear();
set_title(Utf16String::from_utf8(url().serialize()));
set_favicon({});
did_update_url();
@@ -3069,6 +3070,7 @@ void ViewImplementation::initialize_tab(Web::HTML::VisibilityState system_visibi
auto* view = weak_this.ptr();
if (!view || !request_page->is_open())
return;
+ ScopeGuard update_location_in_use = [view] { view->update_location_in_use(); };
if (is_watch) {
if (!view->m_geolocation_watch_ids.contains(key))
@@ -3098,6 +3100,7 @@ void ViewImplementation::initialize_tab(Web::HTML::VisibilityState system_visibi
auto* view = weak_this.ptr();
if (!view || !request_page->is_open())
return;
+ ScopeGuard update_location_in_use = [view] { view->update_location_in_use(); };
if (is_watch) {
if (!view->m_geolocation_watch_ids.contains(key))
@@ -3118,6 +3121,7 @@ void ViewImplementation::initialize_tab(Web::HTML::VisibilityState system_visibi
};
on_request_geolocation_position = [this, geolocation_error_code, make_geolocation_success_handler, make_geolocation_error_handler](WebContentPage& requesting_page, u64 request_id, Web::HTML::CrossProcessId document_id) {
+ ScopeGuard update_location_in_use = [this] { this->update_location_in_use(); };
if (!Application::the().sites_can_ask_for_location()) {
requesting_page.async_geolocation_position_response(request_id, {}, to_underlying(GeolocationErrorCode::PermissionDenied));
return;
@@ -3139,12 +3143,14 @@ void ViewImplementation::initialize_tab(Web::HTML::VisibilityState system_visibi
};
on_cancel_geolocation_position_request = [this](WebContentPage& requesting_page, u64 request_id) {
+ ScopeGuard update_location_in_use = [this] { this->update_location_in_use(); };
auto provider_request_id = m_geolocation_position_request_ids.take({ requesting_page, request_id });
if (provider_request_id.has_value())
Application::the().cancel_geolocation_position_request(*provider_request_id);
};
on_start_geolocation_position_watch = [this, geolocation_error_code, make_geolocation_success_handler, make_geolocation_error_handler](WebContentPage& requesting_page, u64 request_id, Web::HTML::CrossProcessId document_id) {
+ ScopeGuard update_location_in_use = [this] { this->update_location_in_use(); };
if (!Application::the().sites_can_ask_for_location()) {
requesting_page.async_geolocation_position_response(request_id, {}, to_underlying(GeolocationErrorCode::PermissionDenied));
return;
@@ -3167,6 +3173,7 @@ void ViewImplementation::initialize_tab(Web::HTML::VisibilityState system_visibi
};
on_stop_geolocation_position_watch = [this](WebContentPage& requesting_page, u64 request_id) {
+ ScopeGuard update_location_in_use = [this] { this->update_location_in_use(); };
auto provider_watch_id = m_geolocation_watch_ids.take({ requesting_page, request_id });
if (!provider_watch_id.has_value())
return;
@@ -3184,6 +3191,7 @@ void ViewImplementation::cancel_all_native_geolocation_requests()
auto geolocation_watch_ids = move(m_geolocation_watch_ids);
for (auto const& watch : geolocation_watch_ids)
Application::the().stop_watching_geolocation_position(watch.value);
+ update_location_in_use();
}
void ViewImplementation::did_start_navigation()
@@ -4329,6 +4337,50 @@ void ViewImplementation::global_privacy_control_changed()
traversable().for_each_hosting_page(send_global_privacy_control);
}
+Vector<SitePermissionRow> ViewImplementation::site_permission_rows() const
+{
+ auto origin = url().origin();
+ auto const& manager = *session().permission_manager;
+
+ Vector<SitePermissionRow> rows;
+ for (auto name : { Web::Permissions::PermissionName::Geolocation, Web::Permissions::PermissionName::Microphone }) {
+ auto decision = manager.decision(name, origin);
+ rows.append({
+ .name = name,
+ .decision = decision,
+ .one_time_grant_is_live = decision == PermissionDecision::AllowOnce,
+ .requested_by_page = m_permissions_requested_by_page.contains_slow(name),
+ });
+ }
+ return rows;
+}
+
+void ViewImplementation::set_site_permission(URL::Origin const& origin, Web::Permissions::PermissionName name, Optional<PermissionDecision> decision)
+{
+ session().permission_manager->set_decision(name, origin, decision);
+}
+
+void ViewImplementation::reset_site_permissions(URL::Origin const& origin)
+{
+ session().permission_manager->reset_origin(origin);
+}
+
+void ViewImplementation::did_request_permission(Badge<WebContentPage>, Web::Permissions::PermissionName name)
+{
+ if (!m_permissions_requested_by_page.contains_slow(name))
+ m_permissions_requested_by_page.append(name);
+}
+
+void ViewImplementation::update_location_in_use()
+{
+ auto in_use = !m_geolocation_position_request_ids.is_empty() || !m_geolocation_watch_ids.is_empty();
+ if (in_use == m_location_in_use)
+ return;
+ m_location_in_use = in_use;
+ if (on_location_in_use_change)
+ on_location_in_use_change(in_use);
+}
+
void ViewImplementation::revoke_geolocation_without_permission()
{
using ErrorCode = Web::Geolocation::GeolocationPositionErrorCode;
@@ -4351,6 +4403,7 @@ void ViewImplementation::revoke_geolocation_without_permission()
Application::the().stop_watching_geolocation_position(*provider_watch_id);
key.page->async_geolocation_position_response(key.request_id, {}, to_underlying(ErrorCode::PermissionDenied));
}
+ update_location_in_use();
}
void ViewImplementation::geolocation_settings_changed()
@@ -4376,6 +4429,7 @@ void ViewImplementation::geolocation_settings_changed()
if (&page != &this->page())
send_geolocation_emulated_position(page);
});
+ update_location_in_use();
}
void ViewImplementation::send_geolocation_emulated_position(WebContentPage& page)
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index aa4c58a837c..11ce555dba6 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -76,6 +76,7 @@
#include <LibWebView/ExternalURLHandler.h>
#include <LibWebView/Forward.h>
#include <LibWebView/HistoryVisitTransition.h>
+#include <LibWebView/PermissionManager.h>
#include <LibWebView/SessionHistory.h>
#include <LibWebView/SessionStore.h>
#include <LibWebView/Settings.h>
@@ -110,6 +111,14 @@ struct PermissionPromptRequest {
using PermissionPromptCallback = Function<void(Web::Permissions::PromptOutcome)>;
+// One permission as the site information panel shows it for the site a view shows.
+struct SitePermissionRow {
+ Web::Permissions::PermissionName name;
+ Optional<PermissionDecision> decision;
+ bool one_time_grant_is_live { false };
+ bool requested_by_page { false };
+};
+
class WEBVIEW_API ViewImplementation
: public SettingsObserver
, public BookmarkStoreObserver
@@ -134,6 +143,15 @@ public:
void release_held_permission_prompt_for_testing(u32 waiters);
void reset_permission_prompts_for_testing();
+ // The site information panel's view of, and changes to, the permissions of the site this view shows.
+ Vector<SitePermissionRow> site_permission_rows() const;
+ // These act on the site given, which a panel showing it keeps even after the view moves on to another site.
+ void set_site_permission(URL::Origin const&, Web::Permissions::PermissionName, Optional<PermissionDecision>);
+ void reset_site_permissions(URL::Origin const&);
+ void did_request_permission(Badge<WebContentPage>, Web::Permissions::PermissionName);
+
+ bool location_in_use() const { return m_location_in_use; }
+
// Ends every location request and watch whose document the user has since taken the permission away from.
void revoke_geolocation_without_permission();
@@ -603,6 +621,7 @@ public:
Function<void(WebContentPage& requesting_page, u64 request_id)> on_stop_geolocation_position_watch;
Function<void(PermissionPromptRequest const&, PermissionPromptCallback)> on_request_permission;
Function<void(PermissionPromptRequest const&)> on_cancel_permission_prompt;
+ Function<void(bool)> on_location_in_use_change;
Function<void(Web::HTML::FileFilter const& accepted_file_types, Web::HTML::AllowMultipleFiles)> on_request_file_picker;
Function<void(Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> items)> on_request_select_dropdown;
Function<void(Web::KeyEvent const&)> on_finish_handling_key_event;
@@ -691,6 +710,7 @@ protected:
void did_update_url();
void settle_permission_prompt(PermissionPromptRequest const&, Web::Permissions::PromptOutcome);
void report_permission_presence();
+ void update_location_in_use();
void ignore_pending_permission_prompts();
void set_title(Utf16String);
void set_favicon(Optional<Gfx::Bitmap const&>);
@@ -1130,6 +1150,8 @@ protected:
HashMap<GeolocationRequestKey, Core::GeolocationProvider::RequestId> m_geolocation_position_request_ids;
HashMap<GeolocationRequestKey, Core::GeolocationProvider::WatchId> m_geolocation_watch_ids;
HashMap<GeolocationRequestKey, Web::HTML::CrossProcessId> m_geolocation_request_documents;
+ bool m_location_in_use { false };
+ Vector<Web::Permissions::PermissionName> m_permissions_requested_by_page;
struct PendingPermissionPrompt {
PermissionPromptRequest request;
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index a7a66e8a316..b8438e7aa1c 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -1682,6 +1682,8 @@ void WebContentPage::did_request_permission(u64 request_id, Web::HTML::CrossProc
auto deny = [&] { async_permission_request_completed(request_id, Web::Permissions::EffectiveState::Denied); };
+ view().did_request_permission({}, *permission_name);
+
// The UI process decides from what it knows of the requesting document, never from what the renderer says of it.
auto document = hosted_document_with_id(document_id);
if (!document) {
diff --git a/UI/Qt/ChromeStyle.cpp b/UI/Qt/ChromeStyle.cpp
index 9e1c16c1160..69a4379aa57 100644
--- a/UI/Qt/ChromeStyle.cpp
+++ b/UI/Qt/ChromeStyle.cpp
@@ -544,6 +544,23 @@ QToolButton#LadybirdLocationZoomIndicator:pressed {{
background: {16};
}}
+QToolButton#LadybirdLocationInUse {{
+ color: {13};
+ background: {14};
+ border: 0;
+ border-radius: 5px;
+ padding: 0 8px;
+ font-size: 12px;
+}}
+
+QToolButton#LadybirdLocationInUse:hover {{
+ background: {15};
+}}
+
+QToolButton#LadybirdLocationInUse:pressed {{
+ background: {16};
+}}
+
QToolButton#LadybirdLocationAction {{
background: transparent;
border: 0;
diff --git a/UI/Qt/LocationEdit.cpp b/UI/Qt/LocationEdit.cpp
index a26e066105a..9209ecbe97f 100644
--- a/UI/Qt/LocationEdit.cpp
+++ b/UI/Qt/LocationEdit.cpp
@@ -188,6 +188,9 @@ static constexpr int LOCATION_PILL_HORIZONTAL_PADDING = 16;
// The zoom chip is at least wide enough for any zoom level up to 999%, so it keeps its width as the level changes.
static constexpr int LOCATION_ZOOM_CHIP_MIN_WIDTH = 54;
static constexpr int LOCATION_ZOOM_CHIP_GAP = 3;
+// The location chip says what it means at first, then shrinks to its icon.
+static constexpr int LOCATION_IN_USE_CHIP_COLLAPSE_DELAY_MS = 4000;
+static constexpr int LOCATION_IN_USE_CHIP_ICON_ONLY_WIDTH = 30;
LocationEdit::LocationEdit(QWidget* parent, WebView::IsPrivate is_private)
: NativeTextEditingLineEdit(parent)
@@ -269,7 +272,32 @@ LocationEdit::LocationEdit(QWidget* parent, WebView::IsPrivate is_private)
on_zoom_requested();
});
- for (auto* button : { m_leading_icon_button, m_trailing_action_button, m_zoom_indicator_button })
+ m_location_in_use_button = new QToolButton(this);
+ m_location_in_use_button->setObjectName("LadybirdLocationInUse");
+ m_location_in_use_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ m_location_in_use_button->setIconSize({ 16, 16 });
+ m_location_in_use_button->setText("Using your location");
+ m_location_in_use_button->setToolTip("This page is using your location");
+ m_location_in_use_button->setFixedHeight(LOCATION_PILL_HEIGHT);
+ m_location_in_use_button->setAutoRaise(true);
+ m_location_in_use_button->setFocusPolicy(Qt::NoFocus);
+ m_location_in_use_button->setCursor(Qt::ArrowCursor);
+ m_location_in_use_button->hide();
+ connect(m_location_in_use_button, &QToolButton::clicked, this, [this] {
+ if (on_site_settings_requested)
+ on_site_settings_requested();
+ });
+ m_location_in_use_collapse_timer = new QTimer(this);
+ m_location_in_use_collapse_timer->setSingleShot(true);
+ m_location_in_use_collapse_timer->setInterval(LOCATION_IN_USE_CHIP_COLLAPSE_DELAY_MS);
+ connect(m_location_in_use_collapse_timer, &QTimer::timeout, this, [this] {
+ m_location_in_use_button->setToolButtonStyle(Qt::ToolButtonIconOnly);
+ update_location_in_use_chip();
+ update_text_margins();
+ update_trailing_item_positions();
+ });
+
+ for (auto* button : { m_leading_icon_button, m_trailing_action_button, m_zoom_indicator_button, m_location_in_use_button })
button->installEventFilter(this);
update_text_margins();
@@ -863,6 +891,14 @@ void LocationEdit::update_trailing_item_positions()
auto zoom_y = (height() - zoom_button_size.height()) / 2;
m_zoom_indicator_button->move(items_x - LOCATION_ZOOM_CHIP_GAP - zoom_button_size.width(), zoom_y);
m_zoom_indicator_button->raise();
+
+ // The location chip stands before the zoom chip, when there is one.
+ auto location_chip_x = items_x;
+ if (!m_zoom_indicator_button->isHidden())
+ location_chip_x -= LOCATION_ZOOM_CHIP_GAP + zoom_button_size.width();
+ auto location_chip_size = m_location_in_use_button->size();
+ m_location_in_use_button->move(location_chip_x - LOCATION_ZOOM_CHIP_GAP - location_chip_size.width(), (height() - location_chip_size.height()) / 2);
+ m_location_in_use_button->raise();
m_trailing_action_button->raise();
}
@@ -884,6 +920,8 @@ int LocationEdit::trailing_text_margin() const
if (m_zoom_indicator_button && !m_zoom_indicator_button->isHidden())
margin += m_zoom_indicator_button->width() + LOCATION_ZOOM_CHIP_GAP;
+ if (m_location_in_use_button && !m_location_in_use_button->isHidden())
+ margin += m_location_in_use_button->width() + LOCATION_ZOOM_CHIP_GAP;
return margin;
}
@@ -898,6 +936,7 @@ void LocationEdit::update_chrome_style()
setStyleSheet(ChromeStyle::location_edit_style_sheet(Theme::chrome_palette(*this)));
m_is_updating_chrome_style = false;
update_zoom_indicator();
+ update_location_in_use_chip();
}
void LocationEdit::schedule_chrome_style_update()
@@ -1047,6 +1086,39 @@ void LocationEdit::update_zoom_indicator()
update_trailing_item_positions();
}
+void LocationEdit::set_location_in_use(bool in_use)
+{
+ if (in_use == !m_location_in_use_button->isHidden())
+ return;
+
+ if (in_use) {
+ m_location_in_use_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ update_location_in_use_chip();
+ m_location_in_use_button->show();
+ m_location_in_use_collapse_timer->start();
+ } else {
+ m_location_in_use_collapse_timer->stop();
+ m_location_in_use_button->hide();
+ }
+
+ update_text_margins();
+ update_trailing_item_positions();
+}
+
+void LocationEdit::update_location_in_use_chip()
+{
+ if (!m_location_in_use_button)
+ return;
+
+ m_location_in_use_button->setIcon(create_chrome_icon(ChromeIcon::Location, Theme::chrome_palette(*this)));
+ if (m_location_in_use_button->toolButtonStyle() == Qt::ToolButtonIconOnly) {
+ m_location_in_use_button->setFixedWidth(LOCATION_IN_USE_CHIP_ICON_ONLY_WIDTH);
+ return;
+ }
+ auto width = m_location_in_use_button->fontMetrics().horizontalAdvance(m_location_in_use_button->text()) + 16 + 4 + LOCATION_PILL_HORIZONTAL_PADDING;
+ m_location_in_use_button->setFixedWidth(width);
+}
+
void LocationEdit::highlight_location()
{
auto url = ak_string_from_qstring(text());
diff --git a/UI/Qt/LocationEdit.h b/UI/Qt/LocationEdit.h
index e4b9482277d..052e84400a5 100644
--- a/UI/Qt/LocationEdit.h
+++ b/UI/Qt/LocationEdit.h
@@ -24,6 +24,7 @@ class QGraphicsOpacityEffect;
class QLabel;
class QMouseEvent;
class QResizeEvent;
+class QTimer;
class QToolButton;
class QVariantAnimation;
@@ -54,6 +55,8 @@ public:
// The knobs of the site settings icon slide past each other while the given popover is open.
void follow_site_settings_popover(QWidget&);
void set_zoom_action(QAction*);
+ // Shows, while the page uses the user's location, a chip that says so.
+ void set_location_in_use(bool);
Optional<URL::URL const&> url() const { return m_url; }
void set_url(Optional<URL::URL>);
@@ -99,6 +102,7 @@ private:
void update_chrome_style();
void update_location_icon();
void update_zoom_indicator();
+ void update_location_in_use_chip();
void update_focus_ring(qreal opacity);
void set_field_hovered(bool);
void schedule_chrome_style_update();
@@ -125,6 +129,8 @@ private:
QToolButton* m_zoom_indicator_button { nullptr };
QGraphicsOpacityEffect* m_zoom_indicator_opacity { nullptr };
QVariantAnimation* m_zoom_indicator_fade { nullptr };
+ QToolButton* m_location_in_use_button { nullptr };
+ QTimer* m_location_in_use_collapse_timer { nullptr };
QLabel* m_completion_title { nullptr };
QVariantAnimation* m_focus_ring_animation { nullptr };
QGraphicsEffect* m_focus_ring_effect { nullptr };
diff --git a/UI/Qt/SiteSettingsPopover.cpp b/UI/Qt/SiteSettingsPopover.cpp
index ad0d8de0228..11b2be3272c 100644
--- a/UI/Qt/SiteSettingsPopover.cpp
+++ b/UI/Qt/SiteSettingsPopover.cpp
@@ -72,6 +72,56 @@ static QString autoplay_policy_name(Web::HTML::AutoplayPolicy policy)
VERIFY_NOT_REACHED();
}
+static QString permission_label(Web::Permissions::PermissionName name)
+{
+ switch (name) {
+ case Web::Permissions::PermissionName::Geolocation:
+ return QStringLiteral("Location");
+ case Web::Permissions::PermissionName::Microphone:
+ return QStringLiteral("Microphone");
+ }
+ VERIFY_NOT_REACHED();
+}
+
+static ChromeIcon permission_icon(Web::Permissions::PermissionName name)
+{
+ switch (name) {
+ case Web::Permissions::PermissionName::Geolocation:
+ return ChromeIcon::Location;
+ case Web::Permissions::PermissionName::Microphone:
+ return ChromeIcon::Microphone;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+// The value a permission row shows for the site's decision; a site with none is asked.
+static QString permission_decision_name(Optional<WebView::PermissionDecision> decision)
+{
+ if (!decision.has_value())
+ return QStringLiteral("Ask");
+ switch (*decision) {
+ case WebView::PermissionDecision::Allow:
+ return QStringLiteral("Allow");
+ case WebView::PermissionDecision::AllowOnce:
+ return QStringLiteral("Allow this time");
+ case WebView::PermissionDecision::Block:
+ return QStringLiteral("Block");
+ }
+ VERIFY_NOT_REACHED();
+}
+
+static QPushButton* create_value_button(QWidget& parent)
+{
+ auto* button = new QPushButton(&parent);
+ button->setObjectName("LadybirdPopoverValueButton");
+ button->setCursor(Qt::PointingHandCursor);
+ button->setAttribute(Qt::WA_LayoutUsesWidgetRect);
+ // NB: The chevron follows the value.
+ button->setLayoutDirection(Qt::RightToLeft);
+ button->setIconSize({ 12, 12 });
+ return button;
+}
+
SiteSettingsPopover::SiteSettingsPopover(QWidget* parent)
: Popover(parent)
{
@@ -112,6 +162,13 @@ SiteSettingsPopover::SiteSettingsPopover(QWidget* parent)
add_separator(*m_site_page, *layout, 12, 6);
+ // The permissions the user decided for the site, or the page asked for. The rows are made for each site shown.
+ m_permission_rows = new QWidget(m_site_page);
+ auto* permission_rows_layout = new QVBoxLayout(m_permission_rows);
+ permission_rows_layout->setContentsMargins(0, 0, 0, 0);
+ permission_rows_layout->setSpacing(0);
+ layout->addWidget(m_permission_rows);
+
// Whether media may play on its own.
auto* autoplay_row = new QHBoxLayout;
autoplay_row->setContentsMargins(10, 0, 10, 0);
@@ -121,13 +178,7 @@ SiteSettingsPopover::SiteSettingsPopover(QWidget* parent)
auto* autoplay_label = new QLabel("Autoplay", m_site_page);
autoplay_label->setFixedHeight(ROW_HEIGHT);
autoplay_row->addWidget(autoplay_label, 1);
- m_autoplay_button = new QPushButton(m_site_page);
- m_autoplay_button->setObjectName("LadybirdPopoverValueButton");
- m_autoplay_button->setCursor(Qt::PointingHandCursor);
- m_autoplay_button->setAttribute(Qt::WA_LayoutUsesWidgetRect);
- // NB: The chevron follows the value.
- m_autoplay_button->setLayoutDirection(Qt::RightToLeft);
- m_autoplay_button->setIconSize({ 12, 12 });
+ m_autoplay_button = create_value_button(*m_site_page);
QObject::connect(m_autoplay_button, &QPushButton::clicked, this, [this] {
// A site is either allowed to autoplay, or follows the default, which the menu names so that the choice it shows
// on the button is always one of those in the menu.
@@ -203,6 +254,8 @@ SiteSettingsPopover::SiteSettingsPopover(QWidget* parent)
QObject::connect(m_reset_permissions_link, &QPushButton::clicked, this, [this] {
WebView::Application::settings().remove_autoplay_site_filter(m_host);
update_autoplay();
+ if (on_reset_permissions)
+ on_reset_permissions();
});
links->addWidget(m_reset_permissions_link);
links->addStretch(1);
@@ -285,11 +338,72 @@ void SiteSettingsPopover::set_site(Site site)
m_favicon->setPixmap(site.favicon.isNull() ? create_chrome_icon(ChromeIcon::Globe, Theme::panel().muted).pixmap(QSize(16, 16), devicePixelRatioF()) : site.favicon.pixmap(QSize(16, 16), devicePixelRatioF()));
+ set_permissions(site.permissions);
update_autoplay();
show_blocked_resources(false);
set_content_blocking(site.content_blocking);
}
+// A permission the user never decided and the page never asked for has no row.
+void SiteSettingsPopover::set_permissions(Vector<WebView::SitePermissionRow> const& permissions)
+{
+ auto* rows_layout = m_permission_rows->layout();
+ while (auto* item = rows_layout->takeAt(0)) {
+ delete item->widget();
+ delete item;
+ }
+ m_permissions.clear();
+ m_has_decided_permissions = false;
+
+ for (auto const& permission : permissions) {
+ if (!permission.decision.has_value() && !permission.requested_by_page)
+ continue;
+ m_has_decided_permissions |= permission.decision.has_value();
+
+ auto* row = new QWidget(m_permission_rows);
+ auto* row_layout = new QHBoxLayout(row);
+ row_layout->setContentsMargins(10, 0, 10, 0);
+ row_layout->setSpacing(10);
+ auto* icon = create_icon(*row);
+ row_layout->addWidget(icon);
+ auto* label = new QLabel(permission_label(permission.name), row);
+ label->setFixedHeight(ROW_HEIGHT);
+ row_layout->addWidget(label, 1);
+ auto* button = create_value_button(*row);
+ button->setObjectName(QStringLiteral("LadybirdSiteSettingsPermission-%1").arg(qstring_from_ak_string(Web::Permissions::to_string(permission.name))));
+ button->setText(permission_decision_name(permission.decision));
+ QObject::connect(button, &QPushButton::clicked, this, [this, button, name = permission.name, decision = permission.decision, one_time_grant_is_live = permission.one_time_grant_is_live] {
+ QMenu menu(this);
+ Vector<QAction*> actions;
+ Vector<Optional<WebView::PermissionDecision>> choices;
+ auto add_choice = [&](QString const& text, Optional<WebView::PermissionDecision> choice) {
+ auto* action = menu.addAction(text);
+ action->setCheckable(true);
+ action->setChecked(choice == decision);
+ actions.append(action);
+ choices.append(choice);
+ };
+ add_choice("Allow", WebView::PermissionDecision::Allow);
+ // A one-time grant can be kept while it lasts, but not given from here.
+ if (one_time_grant_is_live)
+ add_choice("Allow this time", WebView::PermissionDecision::AllowOnce);
+ add_choice("Ask", {});
+ add_choice("Block", WebView::PermissionDecision::Block);
+ auto* chosen = menu.exec(button->mapToGlobal(QPoint(0, button->height())));
+ if (auto index = actions.find_first_index(chosen); index.has_value() && on_permission_change)
+ on_permission_change(name, choices[*index]);
+ });
+ row_layout->addWidget(button);
+ rows_layout->addWidget(row);
+ m_permissions.append({ .name = permission.name, .icon = icon, .button = button });
+ }
+
+ m_permission_rows->setVisible(!m_permissions.is_empty());
+ update_icons();
+ update_reset_link();
+ fit_to_page();
+}
+
void SiteSettingsPopover::set_content_blocking(WebView::ContentBlockingSnapshot const& blocking)
{
QSignalBlocker blocker(m_content_blocking_switch);
@@ -359,8 +473,16 @@ void SiteSettingsPopover::update_autoplay()
auto name = autoplay.site_filters.contains(m_host) ? QStringLiteral("Allow") : autoplay_policy_name(autoplay.policy);
m_autoplay_button->setText(name);
m_autoplay_button->setIcon(create_chrome_icon(ChromeIcon::ChevronDown, Theme::panel().muted));
- if (m_reset_permissions_link)
- m_reset_permissions_link->setEnabled(autoplay.site_filters.contains(m_host));
+ update_reset_link();
+}
+
+// There is something to reset once the site has a decision of its own, for a permission or for autoplay.
+void SiteSettingsPopover::update_reset_link()
+{
+ if (!m_reset_permissions_link)
+ return;
+ auto const& autoplay = WebView::Application::settings().autoplay_settings();
+ m_reset_permissions_link->setEnabled(m_has_decided_permissions || autoplay.site_filters.contains(m_host));
}
void SiteSettingsPopover::update_chrome_style(QPalette const& palette)
@@ -374,6 +496,10 @@ void SiteSettingsPopover::update_chrome_style(QPalette const& palette)
void SiteSettingsPopover::update_icons()
{
auto const& panel = Theme::panel();
+ for (auto& permission : m_permissions) {
+ permission.icon->setPixmap(create_chrome_icon(permission_icon(permission.name), panel.body).pixmap(QSize(16, 16), devicePixelRatioF()));
+ permission.button->setIcon(create_chrome_icon(ChromeIcon::ChevronDown, panel.muted));
+ }
m_autoplay_icon->setPixmap(create_chrome_icon(ChromeIcon::Volume, panel.body).pixmap(QSize(16, 16), devicePixelRatioF()));
m_content_blocking_icon->setPixmap(create_chrome_icon(ChromeIcon::ContentBlocking, panel.body).pixmap(QSize(16, 16), devicePixelRatioF()));
m_blocked_row_chevron->setPixmap(create_chrome_icon(ChromeIcon::Forward, panel.muted).pixmap(QSize(12, 12), devicePixelRatioF()));
diff --git a/UI/Qt/SiteSettingsPopover.h b/UI/Qt/SiteSettingsPopover.h
index 20f307e6383..7a5335b1b07 100644
--- a/UI/Qt/SiteSettingsPopover.h
+++ b/UI/Qt/SiteSettingsPopover.h
@@ -7,8 +7,14 @@
#pragma once
#include <AK/Function.h>
+#include <AK/Optional.h>
#include <AK/String.h>
+#include <AK/Vector.h>
+#include <LibWebCommon/Permissions/Permissions.h>
#include <LibWebView/ContentBlocking.h>
+#include <LibWebView/PermissionManager.h>
+#include <LibWebView/ViewImplementation.h>
+#include <UI/Qt/Icon.h>
#include <UI/Qt/Popover.h>
class QLabel;
@@ -30,28 +36,43 @@ public:
bool is_secure { false };
QIcon favicon;
WebView::ContentBlockingSnapshot content_blocking;
+ Vector<WebView::SitePermissionRow> permissions;
};
void set_site(Site);
void set_content_blocking(WebView::ContentBlockingSnapshot const&);
+ void set_permissions(Vector<WebView::SitePermissionRow> const&);
void update_chrome_style(QPalette const&);
Function<void(bool)> on_content_blocking_toggle;
+ // Changes one of the site's permissions, to the decision given, or back to asking when there is none.
+ Function<void(Web::Permissions::PermissionName, Optional<WebView::PermissionDecision>)> on_permission_change;
+ Function<void()> on_reset_permissions;
Function<void()> on_open_all_site_settings;
Function<void()> on_report_broken_site;
Function<void()> on_open_filter_lists;
private:
void update_autoplay();
+ void update_reset_link();
void update_icons();
void show_blocked_resources(bool);
void fit_to_page();
+ struct PermissionRow {
+ Web::Permissions::PermissionName name;
+ QLabel* icon { nullptr };
+ QPushButton* button { nullptr };
+ };
+
String m_host;
QWidget* m_site_page { nullptr };
QWidget* m_blocked_page { nullptr };
QLabel* m_favicon { nullptr };
QLabel* m_host_label { nullptr };
QLabel* m_security_label { nullptr };
+ QWidget* m_permission_rows { nullptr };
+ Vector<PermissionRow> m_permissions;
+ bool m_has_decided_permissions { false };
QLabel* m_autoplay_icon { nullptr };
QPushButton* m_autoplay_button { nullptr };
QPushButton* m_reset_permissions_link { nullptr };
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index 33f11961916..0905931cda3 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -1638,6 +1638,10 @@ void Tab::initialize(Optional<WebView::CanonicalTraversable&> traversable)
m_permission_prompts.cancel(request);
};
+ view().on_location_in_use_change = [this](bool in_use) {
+ m_location_edit->set_location_in_use(in_use);
+ };
+
view().on_request_accept_dialog = [this]() {
m_javascript_dialog->accept();
};
@@ -2714,6 +2718,15 @@ void Tab::show_site_settings_popover()
m_site_settings_popover->on_open_filter_lists = [this] {
m_window->new_tab_from_url(URL::Parser::basic_parse("about:settings#blocking"sv).release_value(), Web::HTML::ActivateTab::Yes, BrowserWindow::TabLocation::after_current_tab());
};
+ // A change reaches every page of the site at once, and the panel shows it right away.
+ m_site_settings_popover->on_permission_change = [this](Web::Permissions::PermissionName name, Optional<WebView::PermissionDecision> decision) {
+ view().set_site_permission(view().url().origin(), name, decision);
+ m_site_settings_popover->set_permissions(view().site_permission_rows());
+ };
+ m_site_settings_popover->on_reset_permissions = [this] {
+ view().reset_site_permissions(view().url().origin());
+ m_site_settings_popover->set_permissions(view().site_permission_rows());
+ };
}
m_site_settings_popover->update_chrome_style(palette());
@@ -2722,6 +2735,7 @@ void Tab::show_site_settings_popover()
.is_secure = url.scheme() == "https"sv,
.favicon = m_favicon,
.content_blocking = view().content_blocking_snapshot(),
+ .permissions = view().site_permission_rows(),
});
auto& anchor = m_location_edit->site_settings_button();
move_popover_below(*m_site_settings_popover, anchor, PopoverAlignment::Leading);