Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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( | |
| 131 const Notification& notification, | |
| 132 NotificationCommon::Type notification_type) { | |
|
Peter Beverloo
2017/04/18 14:48:54
nit: I'd prefer to pass in `requires_attribution`
Miguel Garcia
2017/04/18 14:59:10
Done.
| |
| 133 bool requires_attribution = | |
| 134 notification.context_message().empty() && | |
| 135 notification_type != NotificationCommon::EXTENSION; | |
| 136 if (!requires_attribution) | |
| 137 return notification.context_message(); | |
| 138 | |
| 139 base::string16 context = | |
| 140 base::UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry( | |
| 141 notification.origin_url(), | |
| 142 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)); | |
| 143 | |
| 144 // localhost, raw IPs etc. are not handled by GetDomainAndRegistry | |
|
Peter Beverloo
2017/04/18 14:48:54
Maybe explicitly refer the reader to the GetDomain
Miguel Garcia
2017/04/18 14:59:10
Added the period at the end. I kind of like havin
| |
| 145 if (context.empty()) { | |
| 146 context = url_formatter::FormatOriginForSecurityDisplay( | |
| 147 url::Origin(notification.origin_url()), | |
| 148 url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS); | |
| 149 } | |
| 150 | |
| 151 return context; | |
| 152 } | |
| 129 } // namespace | 153 } // namespace |
| 130 | 154 |
| 131 // A Cocoa class that represents the delegate of NSUserNotificationCenter and | 155 // A Cocoa class that represents the delegate of NSUserNotificationCenter and |
| 132 // can forward commands to C++. | 156 // can forward commands to C++. |
| 133 @interface NotificationCenterDelegate | 157 @interface NotificationCenterDelegate |
| 134 : NSObject<NSUserNotificationCenterDelegate> { | 158 : NSObject<NSUserNotificationCenterDelegate> { |
| 135 } | 159 } |
| 136 @end | 160 @end |
| 137 | 161 |
| 138 // Interface to communicate with the Alert XPC service. | 162 // Interface to communicate with the Alert XPC service. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 setTitle:base::SysUTF16ToNSString(CreateNotificationTitle(notification))]; | 208 setTitle:base::SysUTF16ToNSString(CreateNotificationTitle(notification))]; |
| 185 | 209 |
| 186 base::string16 context_message = | 210 base::string16 context_message = |
| 187 notification.items().empty() | 211 notification.items().empty() |
| 188 ? notification.message() | 212 ? notification.message() |
| 189 : (notification.items().at(0).title + base::UTF8ToUTF16(" - ") + | 213 : (notification.items().at(0).title + base::UTF8ToUTF16(" - ") + |
| 190 notification.items().at(0).message); | 214 notification.items().at(0).message); |
| 191 | 215 |
| 192 [builder setContextMessage:base::SysUTF16ToNSString(context_message)]; | 216 [builder setContextMessage:base::SysUTF16ToNSString(context_message)]; |
| 193 | 217 |
| 194 bool requires_attribution = | 218 [builder setSubTitle:base::SysUTF16ToNSString(CreateNotificationContext( |
| 195 notification.context_message().empty() && | 219 notification, notification_type))]; |
| 196 notification_type != NotificationCommon::EXTENSION; | |
| 197 | 220 |
| 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()) { | 221 if (!notification.icon().IsEmpty()) { |
| 207 [builder setIcon:notification.icon().ToNSImage()]; | 222 [builder setIcon:notification.icon().ToNSImage()]; |
| 208 } | 223 } |
| 209 | 224 |
| 210 [builder setShowSettingsButton:(notification_type != | 225 [builder setShowSettingsButton:(notification_type != |
| 211 NotificationCommon::EXTENSION)]; | 226 NotificationCommon::EXTENSION)]; |
| 212 std::vector<message_center::ButtonInfo> buttons = notification.buttons(); | 227 std::vector<message_center::ButtonInfo> buttons = notification.buttons(); |
| 213 if (!buttons.empty()) { | 228 if (!buttons.empty()) { |
| 214 DCHECK_LE(buttons.size(), blink::kWebNotificationMaxActions); | 229 DCHECK_LE(buttons.size(), blink::kWebNotificationMaxActions); |
| 215 NSString* buttonOne = SysUTF16ToNSString(buttons[0].title); | 230 NSString* buttonOne = SysUTF16ToNSString(buttons[0].title); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 base::scoped_nsobject<CrXPCMachPort> xpcPort( | 570 base::scoped_nsobject<CrXPCMachPort> xpcPort( |
| 556 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]); | 571 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]); |
| 557 [proxy setMachExceptionPort:xpcPort]; | 572 [proxy setMachExceptionPort:xpcPort]; |
| 558 setExceptionPort_ = YES; | 573 setExceptionPort_ = YES; |
| 559 } | 574 } |
| 560 | 575 |
| 561 return proxy; | 576 return proxy; |
| 562 } | 577 } |
| 563 | 578 |
| 564 @end | 579 @end |
| OLD | NEW |