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

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

Issue 2827543003: Display ETLD+1 instead of the full domain in MacOSX native notifications (Closed)
Patch Set: format Created 3 years, 8 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 18 matching lines...) Expand all
29 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/profiles/profile_manager.h" 30 #include "chrome/browser/profiles/profile_manager.h"
31 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" 31 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h"
32 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" 32 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h"
33 #import "chrome/browser/ui/cocoa/notifications/notification_delivery.h" 33 #import "chrome/browser/ui/cocoa/notifications/notification_delivery.h"
34 #import "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac .h" 34 #import "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac .h"
35 #include "chrome/common/features.h" 35 #include "chrome/common/features.h"
36 #include "chrome/grit/generated_resources.h" 36 #include "chrome/grit/generated_resources.h"
37 #include "components/crash/content/app/crashpad.h" 37 #include "components/crash/content/app/crashpad.h"
38 #include "components/url_formatter/elide_url.h" 38 #include "components/url_formatter/elide_url.h"
39 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
39 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onConstants.h" 40 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onConstants.h"
40 #include "third_party/crashpad/crashpad/client/crashpad_client.h" 41 #include "third_party/crashpad/crashpad/client/crashpad_client.h"
41 #include "ui/base/l10n/l10n_util_mac.h" 42 #include "ui/base/l10n/l10n_util_mac.h"
42 #include "url/gurl.h" 43 #include "url/gurl.h"
43 #include "url/origin.h" 44 #include "url/origin.h"
44 45
45 @class NSUserNotification; 46 @class NSUserNotification;
46 @class NSUserNotificationCenter; 47 @class NSUserNotificationCenter;
47 48
48 // The mapping from web notifications to NsUserNotification works as follows 49 // The mapping from web notifications to NsUserNotification works as follows
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 base::string16 CreateNotificationTitle(const Notification& notification) { 120 base::string16 CreateNotificationTitle(const Notification& notification) {
120 base::string16 title; 121 base::string16 title;
121 if (notification.progress() > 0) { 122 if (notification.progress() > 0) {
122 title += base::FormatPercent(notification.progress()); 123 title += base::FormatPercent(notification.progress());
123 title += base::UTF8ToUTF16(" - "); 124 title += base::UTF8ToUTF16(" - ");
124 } 125 }
125 title += notification.title(); 126 title += notification.title();
126 return title; 127 return title;
127 } 128 }
128 129
130 base::string16 CreateNotificationContext(const Notification& notification,
131 bool requires_attribution) {
132 if (!requires_attribution)
133 return notification.context_message();
134
135 base::string16 context =
136 base::UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry(
137 notification.origin_url(),
138 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
139
140 // localhost, raw IPs etc. are not handled by GetDomainAndRegistry.
141 if (context.empty()) {
142 context = url_formatter::FormatOriginForSecurityDisplay(
143 url::Origin(notification.origin_url()),
144 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
145 }
146
147 return context;
148 }
129 } // namespace 149 } // namespace
130 150
131 // A Cocoa class that represents the delegate of NSUserNotificationCenter and 151 // A Cocoa class that represents the delegate of NSUserNotificationCenter and
132 // can forward commands to C++. 152 // can forward commands to C++.
133 @interface NotificationCenterDelegate 153 @interface NotificationCenterDelegate
134 : NSObject<NSUserNotificationCenterDelegate> { 154 : NSObject<NSUserNotificationCenterDelegate> {
135 } 155 }
136 @end 156 @end
137 157
138 // Interface to communicate with the Alert XPC service. 158 // Interface to communicate with the Alert XPC service.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 notification.items().empty() 207 notification.items().empty()
188 ? notification.message() 208 ? notification.message()
189 : (notification.items().at(0).title + base::UTF8ToUTF16(" - ") + 209 : (notification.items().at(0).title + base::UTF8ToUTF16(" - ") +
190 notification.items().at(0).message); 210 notification.items().at(0).message);
191 211
192 [builder setContextMessage:base::SysUTF16ToNSString(context_message)]; 212 [builder setContextMessage:base::SysUTF16ToNSString(context_message)];
193 213
194 bool requires_attribution = 214 bool requires_attribution =
195 notification.context_message().empty() && 215 notification.context_message().empty() &&
196 notification_type != NotificationCommon::EXTENSION; 216 notification_type != NotificationCommon::EXTENSION;
217 [builder setSubTitle:base::SysUTF16ToNSString(CreateNotificationContext(
218 notification, requires_attribution))];
197 219
198 base::string16 subtitle =
199 requires_attribution
200 ? url_formatter::FormatOriginForSecurityDisplay(
201 url::Origin(notification.origin_url()),
202 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS)
203 : notification.context_message();
204
205 [builder setSubTitle:base::SysUTF16ToNSString(subtitle)];
206 if (!notification.icon().IsEmpty()) { 220 if (!notification.icon().IsEmpty()) {
207 [builder setIcon:notification.icon().ToNSImage()]; 221 [builder setIcon:notification.icon().ToNSImage()];
208 } 222 }
209 223
210 [builder setShowSettingsButton:(notification_type != 224 [builder setShowSettingsButton:(notification_type !=
211 NotificationCommon::EXTENSION)]; 225 NotificationCommon::EXTENSION)];
212 std::vector<message_center::ButtonInfo> buttons = notification.buttons(); 226 std::vector<message_center::ButtonInfo> buttons = notification.buttons();
213 if (!buttons.empty()) { 227 if (!buttons.empty()) {
214 DCHECK_LE(buttons.size(), blink::kWebNotificationMaxActions); 228 DCHECK_LE(buttons.size(), blink::kWebNotificationMaxActions);
215 NSString* buttonOne = SysUTF16ToNSString(buttons[0].title); 229 NSString* buttonOne = SysUTF16ToNSString(buttons[0].title);
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 base::scoped_nsobject<CrXPCMachPort> xpcPort( 569 base::scoped_nsobject<CrXPCMachPort> xpcPort(
556 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]); 570 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]);
557 [proxy setMachExceptionPort:xpcPort]; 571 [proxy setMachExceptionPort:xpcPort];
558 setExceptionPort_ = YES; 572 setExceptionPort_ = YES;
559 } 573 }
560 574
561 return proxy; 575 return proxy;
562 } 576 }
563 577
564 @end 578 @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