[Snooping protection] Use human-readable notifier names.
The sources of blocked notifications are surfaced to the user. This CL replaces the placeholder source title with platform- and app-specific titles. The image provided to translators can be seen at http://go/strpic/edec4cad3e1839f2ad641cebbeb7970ea0029171 Change-Id: I83486dd315eeee1b04e56e825d428adb834aef1d Bug: 1298327 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3511920 Reviewed-by: Alex Newcomer <newcomer@chromium.org> Commit-Queue: Michael Martis <martis@chromium.org> Cr-Commit-Position: refs/heads/main@{#981492}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
392eb19eaa
commit
a5a714e6cc
ash
ash_strings.grd
ash_strings_grd
IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_APP_TITLE.png.sha1IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_ARC_TITLE.png.sha1IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_CROSTINI_TITLE.png.sha1IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_PHONE_HUB_TITLE.png.sha1IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_SYSTEM_TITLE.png.sha1IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_WEB_TITLE.png.sha1
system
@ -4888,6 +4888,24 @@ New install
|
||||
<message name="IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_MESSAGE_3_PLUS" desc="Notification message explaining that a popup from three or more applications have been blocked.">
|
||||
<ph name="APP_1_TITLE">$1<ex>Google Chat</ex></ph>, <ph name="APP_2_TITLE">$2<ex>Chrome</ex></ph> and other notifications are hidden because viewing protection is on
|
||||
</message>
|
||||
<message name="IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_SYSTEM_TITLE" desc="Title used for the OS when listing blocked notification sources.">
|
||||
System
|
||||
</message>
|
||||
<message name="IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_APP_TITLE" desc="Title used for a generic application when listing blocked notification sources.">
|
||||
App
|
||||
</message>
|
||||
<message name="IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_ARC_TITLE" desc="Title used for an Android application when listing blocked notification sources.">
|
||||
Android
|
||||
</message>
|
||||
<message name="IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_CROSTINI_TITLE" desc="Title used for a Linux application when listing blocked notification sources.">
|
||||
Linux
|
||||
</message>
|
||||
<message name="IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_WEB_TITLE" desc="Title used for the web browser when listing blocked notification sources.">
|
||||
Web
|
||||
</message>
|
||||
<message name="IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_PHONE_HUB_TITLE" desc="Title used for the Phone Hub feature when listing blocked notification sources.">
|
||||
Phone Hub
|
||||
</message>
|
||||
<message name="IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_SHOW_BUTTON_TEXT" desc="Text in notification button to show previously-blocked notifications.">
|
||||
Show
|
||||
</message>
|
||||
|
@ -0,0 +1 @@
|
||||
edec4cad3e1839f2ad641cebbeb7970ea0029171
|
@ -0,0 +1 @@
|
||||
edec4cad3e1839f2ad641cebbeb7970ea0029171
|
1
ash/ash_strings_grd/IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_CROSTINI_TITLE.png.sha1
Normal file
1
ash/ash_strings_grd/IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_CROSTINI_TITLE.png.sha1
Normal file
@ -0,0 +1 @@
|
||||
edec4cad3e1839f2ad641cebbeb7970ea0029171
|
1
ash/ash_strings_grd/IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_PHONE_HUB_TITLE.png.sha1
Normal file
1
ash/ash_strings_grd/IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_PHONE_HUB_TITLE.png.sha1
Normal file
@ -0,0 +1 @@
|
||||
edec4cad3e1839f2ad641cebbeb7970ea0029171
|
@ -0,0 +1 @@
|
||||
edec4cad3e1839f2ad641cebbeb7970ea0029171
|
@ -0,0 +1 @@
|
||||
edec4cad3e1839f2ad641cebbeb7970ea0029171
|
@ -28,6 +28,8 @@
|
||||
#include "chromeos/dbus/hps/hps_service.pb.h"
|
||||
#include "components/prefs/pref_change_registrar.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/services/app_service/public/cpp/app_registry_cache.h"
|
||||
#include "components/services/app_service/public/cpp/app_registry_cache_wrapper.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/message_center/message_center.h"
|
||||
#include "ui/message_center/public/cpp/notification.h"
|
||||
@ -40,8 +42,74 @@ namespace {
|
||||
|
||||
constexpr char kNotifierId[] = "hps-notify";
|
||||
|
||||
// Returns a human-readable title for the given notification source.
|
||||
std::u16string GetNotifierTitle(const message_center::NotifierId& id) {
|
||||
std::u16string title = l10n_util::GetStringUTF16(
|
||||
IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_SYSTEM_TITLE);
|
||||
|
||||
// Assign default title based on notifier type.
|
||||
switch (id.type) {
|
||||
case message_center::NotifierType::APPLICATION:
|
||||
title = l10n_util::GetStringUTF16(
|
||||
IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_APP_TITLE);
|
||||
break;
|
||||
|
||||
case message_center::NotifierType::ARC_APPLICATION:
|
||||
title = l10n_util::GetStringUTF16(
|
||||
IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_ARC_TITLE);
|
||||
break;
|
||||
|
||||
case message_center::NotifierType::CROSTINI_APPLICATION:
|
||||
title = l10n_util::GetStringUTF16(
|
||||
IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_CROSTINI_TITLE);
|
||||
break;
|
||||
|
||||
case message_center::NotifierType::WEB_PAGE:
|
||||
title = id.title.value_or(l10n_util::GetStringUTF16(
|
||||
IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_WEB_TITLE));
|
||||
break;
|
||||
|
||||
case message_center::NotifierType::SYSTEM_COMPONENT:
|
||||
// Handled by initial value.
|
||||
break;
|
||||
|
||||
case message_center::NotifierType::PHONE_HUB:
|
||||
title = l10n_util::GetStringUTF16(
|
||||
IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_PHONE_HUB_TITLE);
|
||||
break;
|
||||
}
|
||||
|
||||
// If we can access a more-specific app title, assign it here.
|
||||
if (id.type == message_center::NotifierType::APPLICATION ||
|
||||
id.type == message_center::NotifierType::ARC_APPLICATION ||
|
||||
id.type == message_center::NotifierType::CROSTINI_APPLICATION) {
|
||||
// Access the registry of human-readable app names.
|
||||
const AccountId account_id =
|
||||
Shell::Get()->session_controller()->GetActiveAccountId();
|
||||
apps::AppRegistryCache* app_cache =
|
||||
apps::AppRegistryCacheWrapper::Get().GetAppRegistryCache(account_id);
|
||||
|
||||
if (!app_cache) {
|
||||
LOG(ERROR) << "Couldn't find app registry cache for user";
|
||||
return title;
|
||||
}
|
||||
|
||||
const bool found =
|
||||
app_cache->ForApp(id.id, [&](const apps::AppUpdate& update) {
|
||||
const std::string& short_name = update.ShortName();
|
||||
title = std::u16string(short_name.begin(), short_name.end());
|
||||
});
|
||||
|
||||
if (!found)
|
||||
LOG(WARNING) << "No matching notifier found for ID " << id.id;
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
// Returns the right message for the number of titles.
|
||||
std::u16string TitlesBlockedMessage(const std::vector<std::u16string>& titles) {
|
||||
std::u16string GetTitlesBlockedMessage(
|
||||
const std::vector<std::u16string>& titles) {
|
||||
switch (titles.size()) {
|
||||
case 0:
|
||||
return u"";
|
||||
@ -239,11 +307,8 @@ HpsNotifyNotificationBlocker::CreateInfoNotification() const {
|
||||
if (blocked_popups_.find(id) == blocked_popups_.end())
|
||||
continue;
|
||||
|
||||
// Websites have long URL titles; we use Web here for cleaner messages.
|
||||
// TODO(1294649): deduce the right title to use in this case and replace raw
|
||||
// literal with a localized string.
|
||||
const std::u16string& title =
|
||||
notification->notifier_id().title.value_or(u"Web");
|
||||
// Use a human readable-title (e.g. "Web" vs "https://somesite.com:443").
|
||||
const std::u16string& title = GetNotifierTitle(notification->notifier_id());
|
||||
if (seen_titles.find(title) != seen_titles.end())
|
||||
continue;
|
||||
|
||||
@ -264,7 +329,7 @@ HpsNotifyNotificationBlocker::CreateInfoNotification() const {
|
||||
message_center::NOTIFICATION_TYPE_SIMPLE, kInfoNotificationId,
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_ASH_SMART_PRIVACY_SNOOPING_NOTIFICATION_TITLE),
|
||||
TitlesBlockedMessage(titles),
|
||||
GetTitlesBlockedMessage(titles),
|
||||
/*display_source=*/std::u16string(), /*origin_url=*/GURL(),
|
||||
message_center::NotifierId(message_center::NotifierType::SYSTEM_COMPONENT,
|
||||
kNotifierId),
|
||||
|
@ -303,8 +303,8 @@ TEST_F(HpsNotifyNotificationBlockerTest, SystemNotification) {
|
||||
// Regular notification disappears because it was already shown before the
|
||||
// snooper arrived.
|
||||
EXPECT_EQ(PositionInInfoPopupMessage(u"notifier-1"), std::u16string::npos);
|
||||
// Title used for system popups is currently Web.
|
||||
EXPECT_NE(PositionInInfoPopupMessage(u"Web"), std::u16string::npos);
|
||||
// Check that the system notification is labled as such.
|
||||
EXPECT_NE(PositionInInfoPopupMessage(u"System"), std::u16string::npos);
|
||||
EXPECT_EQ(VisibleNotificationCount(), 4u);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user