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/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 objectForKey:notification_constants::kNotificationId])); | 177 objectForKey:notification_constants::kNotificationId])); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 return true; | 180 return true; |
| 181 } | 181 } |
| 182 | 182 |
| 183 bool NotificationPlatformBridgeMac::SupportsNotificationCenter() const { | 183 bool NotificationPlatformBridgeMac::SupportsNotificationCenter() const { |
| 184 return true; | 184 return true; |
| 185 } | 185 } |
| 186 | 186 |
| 187 // static | |
| 188 bool NotificationPlatformBridgeMac::VerifyNotificationData( | |
| 189 NSDictionary* response) { | |
| 190 if (![response | |
| 191 objectForKey:notification_constants::kNotificationButtonIndex] || | |
| 192 ![response objectForKey:notification_constants::kNotificationOperation] || | |
| 193 ![response objectForKey:notification_constants::kNotificationId] || | |
| 194 ![response objectForKey:notification_constants::kNotificationProfileId]) { | |
|
Peter Beverloo
2016/07/01 13:31:43
+kNotificationIncognito
Miguel Garcia
2016/07/04 15:18:56
Done.
| |
| 195 LOG(ERROR) << "Missing required key"; | |
|
Robert Sesek
2016/07/01 15:35:57
Should we ship this log information, or should it
Miguel Garcia
2016/07/04 15:18:56
Yeah I think we should ship it, it's a pretty bad
| |
| 196 return false; | |
| 197 } | |
| 198 | |
| 199 NSNumber* buttonIndex = | |
|
Robert Sesek
2016/07/01 15:35:57
naming: under_scores since this is in C++
Miguel Garcia
2016/07/04 15:18:56
Done.
| |
| 200 [response objectForKey:notification_constants::kNotificationButtonIndex]; | |
| 201 NSNumber* operation = | |
| 202 [response objectForKey:notification_constants::kNotificationOperation]; | |
| 203 NSString* notificationId = | |
| 204 [response objectForKey:notification_constants::kNotificationId]; | |
| 205 NSString* profileId = | |
| 206 [response objectForKey:notification_constants::kNotificationProfileId]; | |
| 207 | |
| 208 if (buttonIndex.intValue < -1 || | |
| 209 buttonIndex.intValue >= | |
| 210 static_cast<int>(blink::kWebNotificationMaxActions)) { | |
| 211 LOG(ERROR) << "Invalid number of buttons supplied " << buttonIndex.intValue; | |
| 212 return false; | |
| 213 } | |
| 214 | |
| 215 if (operation.unsignedIntValue > NotificationCommon::OPERATION_MAX) { | |
| 216 LOG(ERROR) << operation.unsignedIntValue | |
| 217 << " does not correspond to a valid operation."; | |
| 218 return false; | |
| 219 } | |
| 220 | |
| 221 if (notificationId.length <= 0) { | |
| 222 LOG(ERROR) << "NotificationId not provided"; | |
|
Peter Beverloo
2016/07/01 13:31:43
"not provided" -> "is empty" perhaps, since we now
Miguel Garcia
2016/07/04 15:18:56
Done.
| |
| 223 return false; | |
| 224 } | |
| 225 | |
| 226 if (profileId.length <= 0) { | |
| 227 LOG(ERROR) << "ProfileId not provided"; | |
| 228 return false; | |
| 229 } | |
| 230 | |
| 231 // Origin is not actually required but if it's there it should be a valid one. | |
| 232 NSString* origin = | |
| 233 [response objectForKey:notification_constants::kNotificationOrigin]; | |
| 234 if (origin) { | |
| 235 std::string notificationOrigin = base::SysNSStringToUTF8(origin); | |
| 236 GURL url(notificationOrigin); | |
| 237 if (!url.is_valid()) | |
| 238 return false; | |
| 239 } | |
| 240 | |
| 241 return true; | |
| 242 } | |
| 243 | |
| 187 // ///////////////////////////////////////////////////////////////////////////// | 244 // ///////////////////////////////////////////////////////////////////////////// |
| 188 | 245 |
| 189 @implementation NotificationCenterDelegate | 246 @implementation NotificationCenterDelegate |
| 190 - (void)userNotificationCenter:(NSUserNotificationCenter*)center | 247 - (void)userNotificationCenter:(NSUserNotificationCenter*)center |
| 191 didActivateNotification:(NSUserNotification*)notification { | 248 didActivateNotification:(NSUserNotification*)notification { |
| 192 NSDictionary* response = | 249 NSDictionary* response = |
| 193 [NotificationResponseBuilder buildDictionary:notification]; | 250 [NotificationResponseBuilder buildDictionary:notification]; |
| 251 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response)) | |
| 252 return; | |
| 194 | 253 |
| 195 NSNumber* buttonIndex = | 254 NSNumber* buttonIndex = |
| 196 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 255 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
| 197 NSNumber* operation = | 256 NSNumber* operation = |
| 198 [response objectForKey:notification_constants::kNotificationOperation]; | 257 [response objectForKey:notification_constants::kNotificationOperation]; |
| 199 | 258 |
| 200 std::string notificationOrigin = base::SysNSStringToUTF8( | 259 std::string notificationOrigin = base::SysNSStringToUTF8( |
| 201 [response objectForKey:notification_constants::kNotificationOrigin]); | 260 [response objectForKey:notification_constants::kNotificationOrigin]); |
| 202 NSString* notificationId = [notification.userInfo | 261 NSString* notificationId = |
| 203 objectForKey:notification_constants::kNotificationId]; | 262 [response objectForKey:notification_constants::kNotificationId]; |
| 204 std::string persistentNotificationId = | 263 std::string persistentNotificationId = |
| 205 base::SysNSStringToUTF8(notificationId); | 264 base::SysNSStringToUTF8(notificationId); |
| 206 int64_t persistentId; | 265 int64_t persistentId; |
| 207 if (!base::StringToInt64(persistentNotificationId, &persistentId)) { | 266 if (!base::StringToInt64(persistentNotificationId, &persistentId)) { |
| 208 LOG(ERROR) << "Unable to convert notification ID: " | 267 LOG(ERROR) << "Unable to convert notification ID: " |
| 209 << persistentNotificationId << " to integer."; | 268 << persistentNotificationId << " to integer."; |
| 210 return; | 269 return; |
| 211 } | 270 } |
| 212 std::string profileId = base::SysNSStringToUTF8( | 271 std::string profileId = base::SysNSStringToUTF8( |
| 213 [response objectForKey:notification_constants::kNotificationProfileId]); | 272 [response objectForKey:notification_constants::kNotificationProfileId]); |
| 214 NSNumber* isIncognito = | 273 NSNumber* isIncognito = |
| 215 [response objectForKey:notification_constants::kNotificationIncognito]; | 274 [response objectForKey:notification_constants::kNotificationIncognito]; |
| 216 | 275 |
| 217 GURL origin(notificationOrigin); | 276 GURL origin(notificationOrigin); |
| 218 | 277 |
| 219 PlatformNotificationServiceImpl::GetInstance() | 278 PlatformNotificationServiceImpl::GetInstance() |
| 220 ->ProcessPersistentNotificationOperation( | 279 ->ProcessPersistentNotificationOperation( |
| 221 static_cast<NotificationCommon::Operation>(operation.intValue), | 280 static_cast<NotificationCommon::Operation>(operation.intValue), |
| 222 profileId, [isIncognito boolValue], origin, persistentId, | 281 profileId, [isIncognito boolValue], origin, persistentId, |
| 223 buttonIndex.intValue); | 282 buttonIndex.intValue); |
| 224 } | 283 } |
| 225 | 284 |
| 226 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center | 285 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center |
| 227 shouldPresentNotification:(NSUserNotification*)nsNotification { | 286 shouldPresentNotification:(NSUserNotification*)nsNotification { |
| 228 // Always display notifications, regardless of whether the app is foreground. | 287 // Always display notifications, regardless of whether the app is foreground. |
| 229 return YES; | 288 return YES; |
| 230 } | 289 } |
| 231 | 290 |
| 232 @end | 291 @end |
| OLD | NEW |