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

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: 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
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 title += notification.title(); 127 title += notification.title();
128 return title; 128 return title;
129 } 129 }
130 130
131 base::string16 CreateNotificationContext(const Notification& notification, 131 base::string16 CreateNotificationContext(const Notification& notification,
132 bool requires_attribution) { 132 bool requires_attribution) {
133 if (!requires_attribution) 133 if (!requires_attribution)
134 return notification.context_message(); 134 return notification.context_message();
135 135
136 base::string16 context = 136 // OSX notifications don't provide a good way to elide the domain (or tell you
Peter Beverloo 2017/05/05 14:55:51 nit: OSX -> Mac OS
Miguel Garcia 2017/05/08 10:20:11 Done.
137 // the maximum widh of the subtitle field) Therefore we use a bit of a mixed
Peter Beverloo 2017/05/05 14:55:51 nit: widh -> width nit: period after the closing p
Miguel Garcia 2017/05/08 10:20:11 Done.
138 // approach We have experimentally determined the maximum number of characters
Peter Beverloo 2017/05/05 14:55:51 nit: period after "approach". Or just remove "Ther
Miguel Garcia 2017/05/08 10:20:11 Done.
139 // that fit using the widest possible character (m) If the domain fits in
Peter Beverloo 2017/05/05 14:55:51 nit: period after (m)
Miguel Garcia 2017/05/08 10:20:11 Done.
140 // those character we show it completely Otherwise we use etld+1
Peter Beverloo 2017/05/05 14:55:51 nit: period after "completely" nit: etld+1 -> eTLD
Miguel Garcia 2017/05/08 10:20:11 Done.
141
142 // These numbers have been obtained through experimentation on various
143 // android platforms.
Peter Beverloo 2017/05/05 14:55:51 ???????????????????????
Miguel Garcia 2017/05/08 10:20:11 Acknowledged.
144
145 // Corresponds to the string "mmmmmmmmmmmmmm"
146 const uint kMaxDomainLenghtAlert = 14;
147
148 // Corresponds to the string "mmmmmmmmmmmmmmmmmmmmm"
149 const uint kMaxDomainLenghtBanner = 21;
Peter Beverloo 2017/05/05 14:55:51 constexpr size_t kMaxDomainLength{Alert,Banner}
Miguel Garcia 2017/05/08 10:20:11 For variables I think const and constexpr are the
150
151 uint max_characters = notification.never_timeout() ? kMaxDomainLenghtAlert
Peter Beverloo 2017/05/05 14:55:50 size_t here too (we don't use the "uint" type w/o
Peter Beverloo 2017/05/05 14:55:51 Do we have to consider progress notifications here
Miguel Garcia 2017/05/08 10:20:11 Done.
Miguel Garcia 2017/05/08 10:20:11 Let's add it just for safety although since progre
152 : kMaxDomainLenghtBanner;
153
154 base::string16 origin = url_formatter::FormatOriginForSecurityDisplay(
155 url::Origin(notification.origin_url()),
156 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
157
158 if (origin.size() <= max_characters)
159 return origin;
160
161 // Too long, use etld+1
162 base::string16 etldplusone =
137 base::UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry( 163 base::UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry(
138 notification.origin_url(), 164 notification.origin_url(),
139 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)); 165 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
140 166
141 // localhost, raw IPs etc. are not handled by GetDomainAndRegistry. 167 // localhost, raw IPs etc. are not handled by GetDomainAndRegistry.
142 if (context.empty()) { 168 if (etldplusone.empty())
143 context = url_formatter::FormatOriginForSecurityDisplay( 169 return origin;
144 url::Origin(notification.origin_url()),
145 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
146 }
147 170
148 return context; 171 return etldplusone;
149 } 172 }
150 } // namespace 173 } // namespace
151 174
152 // A Cocoa class that represents the delegate of NSUserNotificationCenter and 175 // A Cocoa class that represents the delegate of NSUserNotificationCenter and
153 // can forward commands to C++. 176 // can forward commands to C++.
154 @interface NotificationCenterDelegate 177 @interface NotificationCenterDelegate
155 : NSObject<NSUserNotificationCenterDelegate> { 178 : NSObject<NSUserNotificationCenterDelegate> {
156 } 179 }
157 @end 180 @end
158 181
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 base::scoped_nsobject<CrXPCMachPort> xpcPort( 599 base::scoped_nsobject<CrXPCMachPort> xpcPort(
577 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]); 600 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]);
578 [proxy setMachExceptionPort:xpcPort]; 601 [proxy setMachExceptionPort:xpcPort];
579 setExceptionPort_ = YES; 602 setExceptionPort_ = YES;
580 } 603 }
581 604
582 return proxy; 605 return proxy;
583 } 606 }
584 607
585 @end 608 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698