Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2088)

Unified Diff: chrome/browser/notifications/notification_platform_bridge_mac.mm

Issue 2882663002: Only resort to etl+1 when the full domain does not fit. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/notifications/notification_platform_bridge_mac.mm
diff --git a/chrome/browser/notifications/notification_platform_bridge_mac.mm b/chrome/browser/notifications/notification_platform_bridge_mac.mm
index ead5b76a5f5bc2babd2bf6f46f215422eed6904e..0cf42092190e69cab13c60048e17494499f52bf8 100644
--- a/chrome/browser/notifications/notification_platform_bridge_mac.mm
+++ b/chrome/browser/notifications/notification_platform_bridge_mac.mm
@@ -128,24 +128,53 @@ base::string16 CreateNotificationTitle(const Notification& notification) {
return title;
}
+bool IsPersistentNotification(const Notification& notification) {
+ return notification.never_timeout() ||
+ notification.type() == message_center::NOTIFICATION_TYPE_PROGRESS;
+}
+
base::string16 CreateNotificationContext(const Notification& notification,
bool requires_attribution) {
if (!requires_attribution)
return notification.context_message();
- base::string16 context =
+ // Mac OS notifications don't provide a good way to elide the domain (or tell
+ // you the maximum width of the subtitle field). We have experimentally
+ // determined the maximum number of characters that fit using the widest
+ // possible character (m). If the domain fits in those character we show it
+ // completely. Otherwise we use eTLD + 1.
+
+ // These numbers have been obtained through experimentation on various
+ // Mac OS platforms.
+
+ // Corresponds to the string "mmmmmmmmmmmmmm"
+ constexpr size_t kMaxDomainLenghtAlert = 14;
+
+ // Corresponds to the string "mmmmmmmmmmmmmmmmmmmmm"
+ constexpr size_t kMaxDomainLenghtBanner = 21;
+
+ size_t max_characters = IsPersistentNotification(notification)
+ ? kMaxDomainLenghtAlert
+ : kMaxDomainLenghtBanner;
+
+ base::string16 origin = url_formatter::FormatOriginForSecurityDisplay(
+ url::Origin(notification.origin_url()),
+ url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
+
+ if (origin.size() <= max_characters)
+ return origin;
+
+ // Too long, use etld+1
+ base::string16 etldplusone =
base::UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry(
notification.origin_url(),
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
// localhost, raw IPs etc. are not handled by GetDomainAndRegistry.
- if (context.empty()) {
- context = url_formatter::FormatOriginForSecurityDisplay(
- url::Origin(notification.origin_url()),
- url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
- }
+ if (etldplusone.empty())
+ return origin;
- return context;
+ return etldplusone;
}
} // namespace
@@ -268,9 +297,7 @@ void NotificationPlatformBridgeMac::Display(
// Send persistent notifications to the XPC service so they
// can be displayed as alerts. Chrome itself can only display
// banners.
- // Progress Notifications are always considered persistent.
- if (notification.never_timeout() ||
- notification.type() == message_center::NOTIFICATION_TYPE_PROGRESS) {
+ if (IsPersistentNotification(notification)) {
NSDictionary* dict = [builder buildDictionary];
[alert_dispatcher_ dispatchNotification:dict];
} else {
« no previous file with comments | « no previous file | chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698