| Index: chrome/browser/notifications/notification_platform_bridge_mac.mm
|
| diff --git a/chrome/browser/notifications/notification_platform_bridge_mac.mm b/chrome/browser/notifications/notification_platform_bridge_mac.mm
|
| index 39efa122f60a5625370714a39ef9e345542a4462..3ef0762e469636d7b115e153b1195d6c65261906 100644
|
| --- a/chrome/browser/notifications/notification_platform_bridge_mac.mm
|
| +++ b/chrome/browser/notifications/notification_platform_bridge_mac.mm
|
| @@ -11,6 +11,7 @@
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/notifications/native_notification_display_service.h"
|
| #include "chrome/browser/notifications/notification.h"
|
| #include "chrome/browser/notifications/notification_display_service_factory.h"
|
| #include "chrome/browser/notifications/persistent_notification_delegate.h"
|
| @@ -46,6 +47,32 @@
|
| // - Sound names can be implemented by setting soundName in NSUserNotification
|
| // NSUserNotificationDefaultSoundName gives you the platform default.
|
|
|
| +namespace {
|
| +// Callback to run once the profile has been loaded in order to perform a
|
| +// given |operation| in a notification.
|
| +void ProfileLoadedCallback(
|
| + notification_operation_common::NotificationOperation operation,
|
| + notification_operation_common::NotificationHandlerType notification_type,
|
| + const std::string& origin,
|
| + const std::string& notification_id,
|
| + int action_index,
|
| + Profile* profile) {
|
| + if (!profile) {
|
| + // TODO(miguelg): Add UMA for this condition.
|
| + // Perhaps propagate this through PersistentNotificationStatus.
|
| + LOG(WARNING) << "Profile not loaded correctly";
|
| + return;
|
| + }
|
| +
|
| + NotificationDisplayService* display_service =
|
| + NotificationDisplayServiceFactory::GetForProfile(profile);
|
| +
|
| + static_cast<NativeNotificationDisplayService*>(display_service)
|
| + ->ProcessNotificationOperation(operation, notification_type, origin,
|
| + notification_id, action_index);
|
| +}
|
| +
|
| +} // namespace
|
|
|
| // static
|
| NotificationPlatformBridge* NotificationPlatformBridge::Create() {
|
| @@ -76,10 +103,12 @@ NotificationPlatformBridgeMac::~NotificationPlatformBridgeMac() {
|
| [notification_center_ removeAllDeliveredNotifications];
|
| }
|
|
|
| -void NotificationPlatformBridgeMac::Display(const std::string& notification_id,
|
| - const std::string& profile_id,
|
| - bool incognito,
|
| - const Notification& notification) {
|
| +void NotificationPlatformBridgeMac::Display(
|
| + notification_operation_common::NotificationHandlerType notification_type,
|
| + const std::string& notification_id,
|
| + const std::string& profile_id,
|
| + bool incognito,
|
| + const Notification& notification) {
|
| base::scoped_nsobject<NotificationBuilder> builder(
|
| [[NotificationBuilder alloc] init]);
|
|
|
| @@ -135,6 +164,7 @@ void NotificationPlatformBridgeMac::Display(const std::string& notification_id,
|
| [builder setNotificationId:base::SysUTF8ToNSString(notification_id)];
|
| [builder setProfileId:base::SysUTF8ToNSString(profile_id)];
|
| [builder setIncognito:incognito];
|
| + [builder setNotificationType:[NSNumber numberWithInteger:notification_type]];
|
|
|
| NSUserNotification* toast = [builder buildUserNotification];
|
| [notification_center_ deliverNotification:toast];
|
| @@ -149,12 +179,11 @@ void NotificationPlatformBridgeMac::Close(const std::string& profile_id,
|
| [notification_center_ deliveredNotifications]) {
|
| NSString* toast_id =
|
| [toast.userInfo objectForKey:notification_constants::kNotificationId];
|
| -
|
| NSString* persistent_profile_id = [toast.userInfo
|
| objectForKey:notification_constants::kNotificationProfileId];
|
|
|
| - if (toast_id == candidate_id &&
|
| - persistent_profile_id == current_profile_id) {
|
| + if ([toast_id isEqualToString:candidate_id] &&
|
| + [persistent_profile_id isEqualToString:current_profile_id]) {
|
| [notification_center_ removeDeliveredNotification:toast];
|
| }
|
| }
|
| @@ -183,6 +212,57 @@ bool NotificationPlatformBridgeMac::SupportsNotificationCenter() const {
|
| return true;
|
| }
|
|
|
| +// static
|
| +bool NotificationPlatformBridgeMac::VerifyNotificationData(
|
| + NSDictionary* response) {
|
| + NSNumber* buttonIndex =
|
| + [response objectForKey:notification_constants::kNotificationButtonIndex];
|
| + NSNumber* operation =
|
| + [response objectForKey:notification_constants::kNotificationOperation];
|
| +
|
| + std::string notificationOrigin = base::SysNSStringToUTF8(
|
| + [response objectForKey:notification_constants::kNotificationOrigin]);
|
| + NSString* notificationId =
|
| + [response objectForKey:notification_constants::kNotificationId];
|
| + NSString* profileId =
|
| + [response objectForKey:notification_constants::kNotificationProfileId];
|
| + NSNumber* notificationType =
|
| + [response objectForKey:notification_constants::kNotificationType];
|
| +
|
| + if (buttonIndex.intValue < -1 ||
|
| + buttonIndex.intValue >=
|
| + static_cast<int>(blink::kWebNotificationMaxActions)) {
|
| + LOG(ERROR) << "Invalid number of buttons supplied " << buttonIndex.intValue;
|
| + return false;
|
| + }
|
| +
|
| + if (operation.unsignedIntValue >
|
| + notification_operation_common::NOTIFICATION_OPERATION_MAX) {
|
| + LOG(ERROR) << operation.unsignedIntValue
|
| + << " Does not correspond to a valid operation.";
|
| + return false;
|
| + }
|
| +
|
| + if (notificationId.length <= 0) {
|
| + LOG(ERROR) << "NotificationId not provided";
|
| + return false;
|
| + }
|
| +
|
| + if (profileId.length <= 0) {
|
| + LOG(ERROR) << "ProfileId not provided";
|
| + return false;
|
| + }
|
| +
|
| + if (notificationType.unsignedIntValue >
|
| + notification_operation_common::NOTIFICATION_HANDLER_TYPE_LAST) {
|
| + LOG(ERROR) << notificationType.unsignedIntValue
|
| + << " Does not correspond to a valid operation.";
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| // /////////////////////////////////////////////////////////////////////////////
|
|
|
| @implementation NotificationCenterDelegate
|
| @@ -191,6 +271,9 @@ bool NotificationPlatformBridgeMac::SupportsNotificationCenter() const {
|
| NSDictionary* response =
|
| [NotificationResponseBuilder buildDictionary:notification];
|
|
|
| + if (!NotificationPlatformBridgeMac::VerifyNotificationData(response))
|
| + return;
|
| +
|
| NSNumber* buttonIndex =
|
| [response objectForKey:notification_constants::kNotificationButtonIndex];
|
| NSNumber* operation =
|
| @@ -198,29 +281,29 @@ bool NotificationPlatformBridgeMac::SupportsNotificationCenter() const {
|
|
|
| std::string notificationOrigin = base::SysNSStringToUTF8(
|
| [response objectForKey:notification_constants::kNotificationOrigin]);
|
| - NSString* notificationId = [notification.userInfo
|
| - objectForKey:notification_constants::kNotificationId];
|
| + NSString* notificationId =
|
| + [response objectForKey:notification_constants::kNotificationId];
|
| std::string persistentNotificationId =
|
| base::SysNSStringToUTF8(notificationId);
|
| - int64_t persistentId;
|
| - if (!base::StringToInt64(persistentNotificationId, &persistentId)) {
|
| - LOG(ERROR) << "Unable to convert notification ID: "
|
| - << persistentNotificationId << " to integer.";
|
| - return;
|
| - }
|
| std::string profileId = base::SysNSStringToUTF8(
|
| [response objectForKey:notification_constants::kNotificationProfileId]);
|
| NSNumber* isIncognito =
|
| [response objectForKey:notification_constants::kNotificationIncognito];
|
| -
|
| - GURL origin(notificationOrigin);
|
| -
|
| - PlatformNotificationServiceImpl::GetInstance()
|
| - ->ProcessPersistentNotificationOperation(
|
| - static_cast<PlatformNotificationServiceImpl::NotificationOperation>(
|
| - operation.intValue),
|
| - profileId, [isIncognito boolValue], origin, persistentId,
|
| - buttonIndex.intValue);
|
| + NSNumber* notificationType =
|
| + [response objectForKey:notification_constants::kNotificationType];
|
| +
|
| + ProfileManager* profileManager = g_browser_process->profile_manager();
|
| + DCHECK(profileManager);
|
| +
|
| + profileManager->LoadProfile(
|
| + profileId, [isIncognito boolValue],
|
| + base::Bind(
|
| + &ProfileLoadedCallback,
|
| + static_cast<notification_operation_common::NotificationOperation>(
|
| + operation.unsignedIntValue),
|
| + static_cast<notification_operation_common::NotificationHandlerType>(
|
| + notificationType.unsignedIntValue),
|
| + notificationOrigin, persistentNotificationId, buttonIndex.intValue));
|
| }
|
|
|
| - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center
|
|
|