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

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_mac.mm

Issue 2861133003: Only resort to etl+1 when the full domain does not fit. (Closed)
Patch Set: review 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/notifications/notification_platform_bridge_mac.h" 5 #include "chrome/browser/notifications/notification_platform_bridge_mac.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 base::string16 CreateNotificationTitle(const Notification& notification) { 121 base::string16 CreateNotificationTitle(const Notification& notification) {
122 base::string16 title; 122 base::string16 title;
123 if (notification.type() == message_center::NOTIFICATION_TYPE_PROGRESS) { 123 if (notification.type() == message_center::NOTIFICATION_TYPE_PROGRESS) {
124 title += base::FormatPercent(notification.progress()); 124 title += base::FormatPercent(notification.progress());
125 title += base::UTF8ToUTF16(" - "); 125 title += base::UTF8ToUTF16(" - ");
126 } 126 }
127 title += notification.title(); 127 title += notification.title();
128 return title; 128 return title;
129 } 129 }
130 130
131 bool IsPersistentNotification(const Notification& notification) {
132 return notification.never_timeout() ||
133 notification.type() == message_center::NOTIFICATION_TYPE_PROGRESS;
134 }
135
131 base::string16 CreateNotificationContext(const Notification& notification, 136 base::string16 CreateNotificationContext(const Notification& notification,
132 bool requires_attribution) { 137 bool requires_attribution) {
133 if (!requires_attribution) 138 if (!requires_attribution)
134 return notification.context_message(); 139 return notification.context_message();
135 140
136 base::string16 context = 141 // Mac OS notifications don't provide a good way to elide the domain (or tell
142 // you the maximum width of the subtitle field). We have experimentally
143 // determined the maximum number of characters that fit using the widest
144 // possible character (m). If the domain fits in those character we show it
145 // completely. Otherwise we use eTLD + 1.
146
147 // These numbers have been obtained through experimentation on various
148 // Mac OS platforms.
149
150 // Corresponds to the string "mmmmmmmmmmmmmm"
151 constexpr size_t kMaxDomainLenghtAlert = 14;
152
153 // Corresponds to the string "mmmmmmmmmmmmmmmmmmmmm"
154 constexpr size_t kMaxDomainLenghtBanner = 21;
155
156 size_t max_characters = IsPersistentNotification(notification)
157 ? kMaxDomainLenghtAlert
158 : kMaxDomainLenghtBanner;
159
160 base::string16 origin = url_formatter::FormatOriginForSecurityDisplay(
161 url::Origin(notification.origin_url()),
162 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
163
164 if (origin.size() <= max_characters)
165 return origin;
166
167 // Too long, use etld+1
168 base::string16 etldplusone =
137 base::UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry( 169 base::UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry(
138 notification.origin_url(), 170 notification.origin_url(),
139 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)); 171 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
140 172
141 // localhost, raw IPs etc. are not handled by GetDomainAndRegistry. 173 // localhost, raw IPs etc. are not handled by GetDomainAndRegistry.
142 if (context.empty()) { 174 if (etldplusone.empty())
143 context = url_formatter::FormatOriginForSecurityDisplay( 175 return origin;
144 url::Origin(notification.origin_url()),
145 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
146 }
147 176
148 return context; 177 return etldplusone;
149 } 178 }
150 } // namespace 179 } // namespace
151 180
152 // A Cocoa class that represents the delegate of NSUserNotificationCenter and 181 // A Cocoa class that represents the delegate of NSUserNotificationCenter and
153 // can forward commands to C++. 182 // can forward commands to C++.
154 @interface NotificationCenterDelegate 183 @interface NotificationCenterDelegate
155 : NSObject<NSUserNotificationCenterDelegate> { 184 : NSObject<NSUserNotificationCenterDelegate> {
156 } 185 }
157 @end 186 @end
158 187
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 290
262 [builder setOrigin:base::SysUTF8ToNSString(notification.origin_url().spec())]; 291 [builder setOrigin:base::SysUTF8ToNSString(notification.origin_url().spec())];
263 [builder setNotificationId:base::SysUTF8ToNSString(notification_id)]; 292 [builder setNotificationId:base::SysUTF8ToNSString(notification_id)];
264 [builder setProfileId:base::SysUTF8ToNSString(profile_id)]; 293 [builder setProfileId:base::SysUTF8ToNSString(profile_id)];
265 [builder setIncognito:incognito]; 294 [builder setIncognito:incognito];
266 [builder setNotificationType:[NSNumber numberWithInteger:notification_type]]; 295 [builder setNotificationType:[NSNumber numberWithInteger:notification_type]];
267 296
268 // Send persistent notifications to the XPC service so they 297 // Send persistent notifications to the XPC service so they
269 // can be displayed as alerts. Chrome itself can only display 298 // can be displayed as alerts. Chrome itself can only display
270 // banners. 299 // banners.
271 // Progress Notifications are always considered persistent. 300 if (IsPersistentNotification(notification)) {
272 if (notification.never_timeout() ||
273 notification.type() == message_center::NOTIFICATION_TYPE_PROGRESS) {
274 NSDictionary* dict = [builder buildDictionary]; 301 NSDictionary* dict = [builder buildDictionary];
275 [alert_dispatcher_ dispatchNotification:dict]; 302 [alert_dispatcher_ dispatchNotification:dict];
276 } else { 303 } else {
277 NSUserNotification* toast = [builder buildUserNotification]; 304 NSUserNotification* toast = [builder buildUserNotification];
278 [notification_center_ deliverNotification:toast]; 305 [notification_center_ deliverNotification:toast];
279 } 306 }
280 } 307 }
281 308
282 void NotificationPlatformBridgeMac::Close(const std::string& profile_id, 309 void NotificationPlatformBridgeMac::Close(const std::string& profile_id,
283 const std::string& notification_id) { 310 const std::string& notification_id) {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 base::scoped_nsobject<CrXPCMachPort> xpcPort( 603 base::scoped_nsobject<CrXPCMachPort> xpcPort(
577 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]); 604 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]);
578 [proxy setMachExceptionPort:xpcPort]; 605 [proxy setMachExceptionPort:xpcPort];
579 setExceptionPort_ = YES; 606 setExceptionPort_ = YES;
580 } 607 }
581 608
582 return proxy; 609 return proxy;
583 } 610 }
584 611
585 @end 612 @end
OLDNEW
« 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