Add keyboard lock and pointer lock to the page info UI
When the permissions are approved/denied, they will show up in the
page info bubble.
Bug: 347856722
Change-Id: I90d43d9bb7928669aba04779526d1e29b7d255c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5633065
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Reviewed-by: Elias Klim <elklm@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1316709}
diff --git a/components/BUILD.gn b/components/BUILD.gn
index 57cead0..f0f650c 100644
--- a/components/BUILD.gn
+++ b/components/BUILD.gn
@@ -569,6 +569,7 @@
"//components/media_router/browser:unit_tests",
"//components/media_router/common:unit_tests",
"//components/media_router/common/providers/cast/channel:unit_tests",
+ "//components/page_info:unit_tests",
"//components/permissions:unit_tests",
"//components/permissions/prediction_service:unit_tests",
"//components/privacy_sandbox:unit_tests",
diff --git a/components/page_info/BUILD.gn b/components/page_info/BUILD.gn
index 0c31c65..d85a1b75 100644
--- a/components/page_info/BUILD.gn
+++ b/components/page_info/BUILD.gn
@@ -56,3 +56,19 @@
deps += [ "//ui/native_theme" ]
}
}
+
+source_set("unit_tests") {
+ testonly = true
+
+ sources = [ "page_info_ui_unittest.cc" ]
+
+ deps = [
+ ":page_info",
+ "//base",
+ "//build:chromeos_buildflags",
+ "//components/strings:components_strings_grit",
+ "//testing/gmock",
+ "//testing/gtest",
+ "//ui/base:base",
+ ]
+}
diff --git a/components/page_info/page_info.cc b/components/page_info/page_info.cc
index 4778808a..e8160b1 100644
--- a/components/page_info/page_info.cc
+++ b/components/page_info/page_info.cc
@@ -138,6 +138,10 @@
ContentSettingsType::CAPTURED_SURFACE_CONTROL,
#endif // !BUILDFLAG(IS_ANDROID)
ContentSettingsType::AUTOMATIC_FULLSCREEN,
+#if !BUILDFLAG(IS_ANDROID)
+ ContentSettingsType::KEYBOARD_LOCK,
+ ContentSettingsType::POINTER_LOCK,
+#endif // !BUILDFLAG(IS_ANDROID)
};
// The list of setting types which request permission for a pair of requesting
diff --git a/components/page_info/page_info_ui.cc b/components/page_info/page_info_ui.cc
index fcbd39fc..851919e 100644
--- a/components/page_info/page_info_ui.cc
+++ b/components/page_info/page_info_ui.cc
@@ -224,12 +224,16 @@
{ContentSettingsType::FILE_SYSTEM_WRITE_GUARD,
IDS_SITE_SETTINGS_TYPE_FILE_SYSTEM_ACCESS_WRITE,
IDS_SITE_SETTINGS_TYPE_FILE_SYSTEM_ACCESS_WRITE_MID_SENTENCE},
+ {ContentSettingsType::KEYBOARD_LOCK, IDS_SITE_SETTINGS_TYPE_KEYBOARD_LOCK,
+ IDS_SITE_SETTINGS_TYPE_KEYBOARD_LOCK_MID_SENTENCE},
{ContentSettingsType::LOCAL_FONTS, IDS_SITE_SETTINGS_TYPE_FONT_ACCESS,
IDS_SITE_SETTINGS_TYPE_FONT_ACCESS_MID_SENTENCE},
{ContentSettingsType::HID_GUARD, IDS_SITE_SETTINGS_TYPE_HID_DEVICES,
IDS_SITE_SETTINGS_TYPE_HID_DEVICES_MID_SENTENCE},
{ContentSettingsType::IMAGES, IDS_SITE_SETTINGS_TYPE_IMAGES,
IDS_SITE_SETTINGS_TYPE_IMAGES_MID_SENTENCE},
+ {ContentSettingsType::POINTER_LOCK, IDS_SITE_SETTINGS_TYPE_POINTER_LOCK,
+ IDS_SITE_SETTINGS_TYPE_POINTER_LOCK_MID_SENTENCE},
{ContentSettingsType::SERIAL_GUARD, IDS_SITE_SETTINGS_TYPE_SERIAL_PORTS,
IDS_SITE_SETTINGS_TYPE_SERIAL_PORTS_MID_SENTENCE},
{ContentSettingsType::WEB_PRINTING, IDS_SITE_SETTINGS_TYPE_WEB_PRINTING,
@@ -394,6 +398,12 @@
case ContentSettingsType::AUTO_PICTURE_IN_PICTURE:
message_id = IDS_PAGE_INFO_STATE_TEXT_AUTO_PICTURE_IN_PICTURE_ASK;
break;
+ case ContentSettingsType::KEYBOARD_LOCK:
+ message_id = IDS_PAGE_INFO_STATE_TEXT_KEYBOARD_LOCK_ASK;
+ break;
+ case ContentSettingsType::POINTER_LOCK:
+ message_id = IDS_PAGE_INFO_STATE_TEXT_POINTER_LOCK_ASK;
+ break;
default:
NOTREACHED_IN_MIGRATION();
}
diff --git a/components/page_info/page_info_ui_unittest.cc b/components/page_info/page_info_ui_unittest.cc
new file mode 100644
index 0000000..5f003284
--- /dev/null
+++ b/components/page_info/page_info_ui_unittest.cc
@@ -0,0 +1,50 @@
+// Copyright 2024 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/page_info/page_info_ui.h"
+
+#include "build/buildflag.h"
+#include "components/page_info/page_info_ui_delegate.h"
+#include "components/strings/grit/components_strings.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/l10n/l10n_util.h"
+
+namespace {
+
+class MockPageInfoUiDelegate : public PageInfoUiDelegate {
+ public:
+#if !BUILDFLAG(IS_ANDROID)
+ MOCK_METHOD(bool, IsBlockAutoPlayEnabled, (), (override));
+ MOCK_METHOD(bool, IsMultipleTabsOpen, (), (override));
+ MOCK_METHOD(void, OpenSiteSettingsFileSystem, (), (override));
+#endif
+ MOCK_METHOD(bool, IsTrackingProtection3pcdEnabled, (), (override));
+ MOCK_METHOD(content::PermissionResult,
+ GetPermissionResult,
+ (blink::PermissionType permission),
+ (override));
+ MOCK_METHOD(std::optional<content::PermissionResult>,
+ GetEmbargoResult,
+ (ContentSettingsType type),
+ (override));
+};
+
+} // namespace
+
+TEST(PageInfoUITest, PermissionStateToUIString) {
+ MockPageInfoUiDelegate delegate;
+ PageInfo::PermissionInfo permission_info;
+ permission_info.setting = CONTENT_SETTING_ASK;
+
+ permission_info.type = ContentSettingsType::KEYBOARD_LOCK;
+ EXPECT_EQ(
+ l10n_util::GetStringUTF16(IDS_PAGE_INFO_STATE_TEXT_KEYBOARD_LOCK_ASK),
+ PageInfoUI::PermissionStateToUIString(&delegate, permission_info));
+
+ permission_info.type = ContentSettingsType::POINTER_LOCK;
+ EXPECT_EQ(
+ l10n_util::GetStringUTF16(IDS_PAGE_INFO_STATE_TEXT_POINTER_LOCK_ASK),
+ PageInfoUI::PermissionStateToUIString(&delegate, permission_info));
+}
diff --git a/components/page_info_strings.grdp b/components/page_info_strings.grdp
index 7794e2bf..3dd4def 100644
--- a/components/page_info_strings.grdp
+++ b/components/page_info_strings.grdp
@@ -415,6 +415,9 @@
<message name="IDS_PAGE_INFO_STATE_TEXT_HID_DEVICES_ASK" desc="The Page Info permission subpage and the main page info page contain a label which shows the state of the site permission. This is the text shown if the HID permission is in the ask state and the site can prompt the user to ask if they allow the site to connect to HID devices.">
Can ask to connect to HID devices
</message>
+ <message name="IDS_PAGE_INFO_STATE_TEXT_KEYBOARD_LOCK_ASK" desc="The Page Info permission subpage and the main page info page contain a label which shows the state of the site permission. This is the text shown if the keyboard lock permission is in the ask state and the site can prompt the user to ask if they allow the site to lock and use the input from their keyboard.">
+ Can ask to lock and use your keyboard
+ </message>
<message name="IDS_PAGE_INFO_STATE_TEXT_LOCATION_ASK" desc="The Page Info permission subpage and the main page info page contain a label which shows the state of the site permission. This is the text shown if the location permission is in the ask state and the site can prompt the user to ask if they allow the site to use your location.">
Can ask for your location
</message>
@@ -427,6 +430,9 @@
<message name="IDS_PAGE_INFO_STATE_TEXT_NOTIFICATIONS_ASK" desc="The Page Info permission subpage and the main page info page contain a label which shows the state of the site permission. This is the text shown if the notification permission is in the ask state and the site can prompt the user to ask if they want to receive notifications.">
Can ask to send notifications
</message>
+ <message name="IDS_PAGE_INFO_STATE_TEXT_POINTER_LOCK_ASK" desc="The Page Info permission subpage and the main page info page contain a label which shows the state of the site permission. This is the text shown if the pointer lock permission is in the ask state and the site can prompt the user to ask if they allow the site to lock and use the input from their mouse pointer.">
+ Can ask to lock and use your mouse
+ </message>
<message name="IDS_PAGE_INFO_STATE_TEXT_USB_ASK" desc="The Page Info permission subpage and the main page info page contain a label which shows the state of the site permission. This is the text shown if the USB permission is in the ask state and the site can prompt the user to ask if they allow the site to connect to USB devices.">
Can ask to connect to USB devices
</message>
diff --git a/components/page_info_strings_grdp/IDS_PAGE_INFO_STATE_TEXT_KEYBOARD_LOCK_ASK.png.sha1 b/components/page_info_strings_grdp/IDS_PAGE_INFO_STATE_TEXT_KEYBOARD_LOCK_ASK.png.sha1
new file mode 100644
index 0000000..eea5865
--- /dev/null
+++ b/components/page_info_strings_grdp/IDS_PAGE_INFO_STATE_TEXT_KEYBOARD_LOCK_ASK.png.sha1
@@ -0,0 +1 @@
+fc6e69ae488f79c3f43aa63898ba9a0adbe1d765
\ No newline at end of file
diff --git a/components/page_info_strings_grdp/IDS_PAGE_INFO_STATE_TEXT_POINTER_LOCK_ASK.png.sha1 b/components/page_info_strings_grdp/IDS_PAGE_INFO_STATE_TEXT_POINTER_LOCK_ASK.png.sha1
new file mode 100644
index 0000000..eea5865
--- /dev/null
+++ b/components/page_info_strings_grdp/IDS_PAGE_INFO_STATE_TEXT_POINTER_LOCK_ASK.png.sha1
@@ -0,0 +1 @@
+fc6e69ae488f79c3f43aa63898ba9a0adbe1d765
\ No newline at end of file