Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac .h" | 5 #import "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac .h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" | 8 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 objectForKey:notification_constants::kNotificationProfileId]); | 38 objectForKey:notification_constants::kNotificationProfileId]); |
| 39 NSString* profileId = [[notification userInfo] | 39 NSString* profileId = [[notification userInfo] |
| 40 objectForKey:notification_constants::kNotificationProfileId]; | 40 objectForKey:notification_constants::kNotificationProfileId]; |
| 41 | 41 |
| 42 DCHECK([[notification userInfo] | 42 DCHECK([[notification userInfo] |
| 43 objectForKey:notification_constants::kNotificationIncognito]); | 43 objectForKey:notification_constants::kNotificationIncognito]); |
| 44 NSNumber* incognito = [[notification userInfo] | 44 NSNumber* incognito = [[notification userInfo] |
| 45 objectForKey:notification_constants::kNotificationIncognito]; | 45 objectForKey:notification_constants::kNotificationIncognito]; |
| 46 NSNumber* notificationType = [[notification userInfo] | 46 NSNumber* notificationType = [[notification userInfo] |
| 47 objectForKey:notification_constants::kNotificationType]; | 47 objectForKey:notification_constants::kNotificationType]; |
| 48 NSNumber* hasSettingsButton = [[notification userInfo] | |
| 49 objectForKey:notification_constants::kNotificationHasSettingsButton]; | |
| 48 | 50 |
| 49 // Closed notifications are not activated. | 51 // Closed notifications are not activated. |
| 50 NotificationOperation operation = | 52 NotificationOperation operation = |
| 51 notification.activationType == NSUserNotificationActivationTypeNone | 53 notification.activationType == NSUserNotificationActivationTypeNone |
| 52 ? NOTIFICATION_CLOSE | 54 ? NOTIFICATION_CLOSE |
| 53 : NOTIFICATION_CLICK; | 55 : NOTIFICATION_CLICK; |
| 54 int buttonIndex = -1; | 56 int buttonIndex = -1; |
| 55 | 57 |
| 56 // Determine whether the user clicked on a button, and if they did, whether it | 58 // Determine whether the user clicked on a button, and if they did, whether it |
| 57 // was a developer-provided button or the mandatory Settings button. | 59 // was a developer-provided button or the Settings button. |
| 58 if (notification.activationType == | 60 if (notification.activationType == |
| 59 NSUserNotificationActivationTypeActionButtonClicked) { | 61 NSUserNotificationActivationTypeActionButtonClicked) { |
| 60 NSArray* alternateButtons = @[]; | 62 NSArray* alternateButtons = @[]; |
| 61 if ([notification | 63 if ([notification |
| 62 respondsToSelector:@selector(_alternateActionButtonTitles)]) { | 64 respondsToSelector:@selector(_alternateActionButtonTitles)]) { |
| 63 alternateButtons = | 65 alternateButtons = |
| 64 [notification valueForKey:@"_alternateActionButtonTitles"]; | 66 [notification valueForKey:@"_alternateActionButtonTitles"]; |
| 65 } | 67 } |
| 66 | 68 |
| 67 bool multipleButtons = (alternateButtons.count > 0); | 69 BOOL settingsButtonRequired = [hasSettingsButton boolValue]; |
| 70 BOOL multipleButtons = (alternateButtons.count > 0); | |
| 68 | 71 |
| 69 // No developer actions, just the settings button. | 72 // No developer actions, just the settings button. |
| 70 if (!multipleButtons) { | 73 if (!multipleButtons) { |
| 74 DCHECK(settingsButtonRequired); | |
| 71 operation = NOTIFICATION_SETTINGS; | 75 operation = NOTIFICATION_SETTINGS; |
| 72 buttonIndex = -1; | 76 buttonIndex = -1; |
| 73 } else { | 77 } else { |
| 74 // 0 based array containing. | 78 // 0 based array containing. |
| 75 // Button 1 | 79 // Button 1 |
| 76 // Button 2 (optional) | 80 // Button 2 (optional) |
| 77 // Settings | 81 // Settings (if required) |
| 78 NSNumber* actionIndex = | 82 NSNumber* actionIndex = |
| 79 [notification valueForKey:@"_alternateActionIndex"]; | 83 [notification valueForKey:@"_alternateActionIndex"]; |
| 80 operation = (actionIndex.unsignedLongValue == alternateButtons.count - 1) | 84 operation = settingsButtonRequired && (actionIndex.unsignedLongValue == |
| 85 alternateButtons.count - 1) | |
| 81 ? NOTIFICATION_SETTINGS | 86 ? NOTIFICATION_SETTINGS |
| 82 : NOTIFICATION_CLICK; | 87 : NOTIFICATION_CLICK; |
| 83 buttonIndex = | 88 buttonIndex = settingsButtonRequired && (actionIndex.unsignedLongValue == |
| 84 (actionIndex.unsignedLongValue == alternateButtons.count - 1) | 89 alternateButtons.count - 1) |
|
Peter Beverloo
2017/04/07 16:19:05
nit: this would become a lot easier to read if you
| |
| 85 ? -1 | 90 ? -1 |
| 86 : actionIndex.intValue; | 91 : actionIndex.intValue; |
| 87 } | 92 } |
| 88 } | 93 } |
| 89 | 94 |
| 90 return @{ | 95 return @{ |
| 91 notification_constants::kNotificationOrigin : origin, | 96 notification_constants::kNotificationOrigin : origin, |
| 92 notification_constants::kNotificationId : notificationId, | 97 notification_constants::kNotificationId : notificationId, |
| 93 notification_constants::kNotificationProfileId : profileId, | 98 notification_constants::kNotificationProfileId : profileId, |
| 94 notification_constants::kNotificationIncognito : incognito, | 99 notification_constants::kNotificationIncognito : incognito, |
| 95 notification_constants::kNotificationType : notificationType, | 100 notification_constants::kNotificationType : notificationType, |
| 96 notification_constants:: | 101 notification_constants:: |
| 97 kNotificationOperation : [NSNumber numberWithInt:operation], | 102 kNotificationOperation : [NSNumber numberWithInt:operation], |
| 98 notification_constants:: | 103 notification_constants:: |
| 99 kNotificationButtonIndex : [NSNumber numberWithInt:buttonIndex], | 104 kNotificationButtonIndex : [NSNumber numberWithInt:buttonIndex], |
| 100 }; | 105 }; |
| 101 } | 106 } |
| 102 | 107 |
| 103 @end | 108 @end |
| OLD | NEW |