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

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

Issue 2835113002: Display ETLD+1 instead of the full domain in MacOSX native notifications (Closed)
Patch Set: 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 "ui/message_center/notification_types.h" 43 #include "ui/message_center/notification_types.h"
43 #include "url/gurl.h" 44 #include "url/gurl.h"
44 #include "url/origin.h" 45 #include "url/origin.h"
45 46
46 @class NSUserNotification; 47 @class NSUserNotification;
47 @class NSUserNotificationCenter; 48 @class NSUserNotificationCenter;
48 49
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 base::string16 CreateNotificationTitle(const Notification& notification) { 121 base::string16 CreateNotificationTitle(const Notification& notification) {
121 base::string16 title; 122 base::string16 title;
122 if (notification.type() == message_center::NOTIFICATION_TYPE_PROGRESS) { 123 if (notification.type() == message_center::NOTIFICATION_TYPE_PROGRESS) {
123 title += base::FormatPercent(notification.progress()); 124 title += base::FormatPercent(notification.progress());
124 title += base::UTF8ToUTF16(" - "); 125 title += base::UTF8ToUTF16(" - ");
125 } 126 }
126 title += notification.title(); 127 title += notification.title();
127 return title; 128 return title;
128 } 129 }
129 130
131 base::string16 CreateNotificationContext(const Notification& notification,
132 bool requires_attribution) {
133 if (!requires_attribution)
134 return notification.context_message();
135
136 base::string16 context =
137 base::UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry(
138 notification.origin_url(),
139 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
140
141 // localhost, raw IPs etc. are not handled by GetDomainAndRegistry.
142 if (context.empty()) {
143 context = url_formatter::FormatOriginForSecurityDisplay(
144 url::Origin(notification.origin_url()),
145 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
146 }
147
148 return context;
149 }
130 } // namespace 150 } // namespace
131 151
132 // A Cocoa class that represents the delegate of NSUserNotificationCenter and 152 // A Cocoa class that represents the delegate of NSUserNotificationCenter and
133 // can forward commands to C++. 153 // can forward commands to C++.
134 @interface NotificationCenterDelegate 154 @interface NotificationCenterDelegate
135 : NSObject<NSUserNotificationCenterDelegate> { 155 : NSObject<NSUserNotificationCenterDelegate> {
136 } 156 }
137 @end 157 @end
138 158
139 // Interface to communicate with the Alert XPC service. 159 // Interface to communicate with the Alert XPC service.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 notification.items().empty() 208 notification.items().empty()
189 ? notification.message() 209 ? notification.message()
190 : (notification.items().at(0).title + base::UTF8ToUTF16(" - ") + 210 : (notification.items().at(0).title + base::UTF8ToUTF16(" - ") +
191 notification.items().at(0).message); 211 notification.items().at(0).message);
192 212
193 [builder setContextMessage:base::SysUTF16ToNSString(context_message)]; 213 [builder setContextMessage:base::SysUTF16ToNSString(context_message)];
194 214
195 bool requires_attribution = 215 bool requires_attribution =
196 notification.context_message().empty() && 216 notification.context_message().empty() &&
197 notification_type != NotificationCommon::EXTENSION; 217 notification_type != NotificationCommon::EXTENSION;
218 [builder setSubTitle:base::SysUTF16ToNSString(CreateNotificationContext(
219 notification, requires_attribution))];
198 220
199 base::string16 subtitle =
200 requires_attribution
201 ? url_formatter::FormatOriginForSecurityDisplay(
202 url::Origin(notification.origin_url()),
203 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS)
204 : notification.context_message();
205
206 [builder setSubTitle:base::SysUTF16ToNSString(subtitle)];
207 if (!notification.icon().IsEmpty()) { 221 if (!notification.icon().IsEmpty()) {
208 [builder setIcon:notification.icon().ToNSImage()]; 222 [builder setIcon:notification.icon().ToNSImage()];
209 } 223 }
210 224
211 [builder setShowSettingsButton:(notification_type != 225 [builder setShowSettingsButton:(notification_type !=
212 NotificationCommon::EXTENSION)]; 226 NotificationCommon::EXTENSION)];
213 std::vector<message_center::ButtonInfo> buttons = notification.buttons(); 227 std::vector<message_center::ButtonInfo> buttons = notification.buttons();
214 if (!buttons.empty()) { 228 if (!buttons.empty()) {
215 DCHECK_LE(buttons.size(), blink::kWebNotificationMaxActions); 229 DCHECK_LE(buttons.size(), blink::kWebNotificationMaxActions);
216 NSString* buttonOne = SysUTF16ToNSString(buttons[0].title); 230 NSString* buttonOne = SysUTF16ToNSString(buttons[0].title);
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 base::scoped_nsobject<CrXPCMachPort> xpcPort( 571 base::scoped_nsobject<CrXPCMachPort> xpcPort(
558 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]); 572 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]);
559 [proxy setMachExceptionPort:xpcPort]; 573 [proxy setMachExceptionPort:xpcPort];
560 setExceptionPort_ = YES; 574 setExceptionPort_ = YES;
561 } 575 }
562 576
563 return proxy; 577 return proxy;
564 } 578 }
565 579
566 @end 580 @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