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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 // Deliver a notification to the XPC service to be displayed as an alert. | 113 // Deliver a notification to the XPC service to be displayed as an alert. |
114 - (void)dispatchNotification:(NSDictionary*)data; | 114 - (void)dispatchNotification:(NSDictionary*)data; |
115 | 115 |
116 // Close a notification for a given |notificationId| and |profileId|. | 116 // Close a notification for a given |notificationId| and |profileId|. |
117 - (void)closeNotificationWithId:(NSString*)notificationId | 117 - (void)closeNotificationWithId:(NSString*)notificationId |
118 withProfileId:(NSString*)profileId; | 118 withProfileId:(NSString*)profileId; |
119 | 119 |
120 // Close all notifications. | 120 // Close all notifications. |
121 - (void)closeAllNotifications; | 121 - (void)closeAllNotifications; |
122 | 122 |
123 // Retrieves all the alerts currenlty displayed by the XPC server | |
124 // They are subsequently merged with the local ones (passed in | |
125 // |localNotifications| | |
126 // and included in |callback|. | |
Peter Beverloo
2017/02/24 16:12:24
nit: weird line break
Miguel Garcia
2017/03/22 22:00:07
Done.
| |
127 - (void)getDisplayedAlertIds:(NSString*)profileId | |
128 withLocalNotifications:(NSArray*)localNotifications | |
129 withCallback: | |
130 (NotificationCommon::NotificationResultCallback)callback; | |
131 | |
123 @end | 132 @end |
124 | 133 |
125 // ///////////////////////////////////////////////////////////////////////////// | 134 // ///////////////////////////////////////////////////////////////////////////// |
126 NotificationPlatformBridgeMac::NotificationPlatformBridgeMac( | 135 NotificationPlatformBridgeMac::NotificationPlatformBridgeMac( |
127 NSUserNotificationCenter* notification_center, | 136 NSUserNotificationCenter* notification_center, |
128 id<AlertDispatcher> alert_dispatcher) | 137 id<AlertDispatcher> alert_dispatcher) |
129 : delegate_([NotificationCenterDelegate alloc]), | 138 : delegate_([NotificationCenterDelegate alloc]), |
130 notification_center_([notification_center retain]), | 139 notification_center_([notification_center retain]), |
131 alert_dispatcher_([alert_dispatcher retain]) { | 140 alert_dispatcher_([alert_dispatcher retain]) { |
132 [notification_center_ setDelegate:delegate_.get()]; | 141 [notification_center_ setDelegate:delegate_.get()]; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); | 291 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); |
283 for (NSUserNotification* toast in | 292 for (NSUserNotification* toast in |
284 [notification_center_ deliveredNotifications]) { | 293 [notification_center_ deliveredNotifications]) { |
285 NSString* toast_profile_id = [toast.userInfo | 294 NSString* toast_profile_id = [toast.userInfo |
286 objectForKey:notification_constants::kNotificationProfileId]; | 295 objectForKey:notification_constants::kNotificationProfileId]; |
287 if ([toast_profile_id isEqualToString:current_profile_id]) { | 296 if ([toast_profile_id isEqualToString:current_profile_id]) { |
288 notifications->insert(base::SysNSStringToUTF8([toast.userInfo | 297 notifications->insert(base::SysNSStringToUTF8([toast.userInfo |
289 objectForKey:notification_constants::kNotificationId])); | 298 objectForKey:notification_constants::kNotificationId])); |
290 } | 299 } |
291 } | 300 } |
301 | |
292 return true; | 302 return true; |
293 } | 303 } |
294 | 304 |
305 void NotificationPlatformBridgeMac::GetDisplayedAsync( | |
306 const std::string& profile_id, | |
307 bool incognito, | |
308 const NotificationCommon::NotificationResultCallback& callback) const { | |
309 #if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS) | |
310 [alert_dispatcher_ | |
311 getDisplayedAlertIds:base::SysUTF8ToNSString(profile_id) | |
312 withLocalNotifications:[notification_center_ deliveredNotifications] | |
313 withCallback:callback]; | |
314 | |
315 #endif // ENABLE_XPC_NOTIFICATIONS | |
316 } | |
317 | |
295 // static | 318 // static |
296 void NotificationPlatformBridgeMac::ProcessNotificationResponse( | 319 void NotificationPlatformBridgeMac::ProcessNotificationResponse( |
297 NSDictionary* response) { | 320 NSDictionary* response) { |
298 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response)) | 321 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response)) |
299 return; | 322 return; |
300 | 323 |
301 NSNumber* button_index = | 324 NSNumber* button_index = |
302 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 325 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
303 NSNumber* operation = | 326 NSNumber* operation = |
304 [response objectForKey:notification_constants::kNotificationOperation]; | 327 [response objectForKey:notification_constants::kNotificationOperation]; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 - (void)closeNotificationWithId:(NSString*)notificationId | 492 - (void)closeNotificationWithId:(NSString*)notificationId |
470 withProfileId:(NSString*)profileId { | 493 withProfileId:(NSString*)profileId { |
471 [[xpcConnection_ remoteObjectProxy] closeNotificationWithId:notificationId | 494 [[xpcConnection_ remoteObjectProxy] closeNotificationWithId:notificationId |
472 withProfileId:profileId]; | 495 withProfileId:profileId]; |
473 } | 496 } |
474 | 497 |
475 - (void)closeAllNotifications { | 498 - (void)closeAllNotifications { |
476 [[xpcConnection_ remoteObjectProxy] closeAllNotifications]; | 499 [[xpcConnection_ remoteObjectProxy] closeAllNotifications]; |
477 } | 500 } |
478 | 501 |
502 - (void)getDisplayedAlertIds:(NSString*)profileId | |
503 withLocalNotifications:(NSArray*)localNotifications | |
504 withCallback: | |
505 (NotificationCommon::NotificationResultCallback)callback { | |
506 [[xpcConnection_ remoteObjectProxy] | |
507 getDisplayedAlertIds:profileId | |
508 withReply:^(NSArray* alerts) { | |
Robert Sesek
2017/02/24 22:38:05
This is hard to read due to the amount of indent n
Miguel Garcia
2017/03/22 22:00:07
Done.
| |
509 std::unique_ptr<std::set<std::string>> | |
510 displayedNotifications = | |
511 base::MakeUnique<std::set<std::string>>(); | |
Peter Beverloo
2017/02/24 16:12:24
nit {}
Miguel Garcia
2017/03/22 22:00:07
Done.
| |
512 | |
513 for (NSUserNotification* toast in localNotifications) { | |
Peter Beverloo
2017/02/24 16:12:24
Can it happen that the XPC service does not reply,
Robert Sesek
2017/02/24 22:38:05
Yes this is possible.
Miguel Garcia
2017/03/22 22:00:07
I have changed the flow now so that the xpc alerts
| |
514 NSString* toast_profile_id = [toast.userInfo | |
Peter Beverloo
2017/02/24 16:12:24
nit: toastProfileId
Miguel Garcia
2017/03/22 22:00:07
Done.
| |
515 objectForKey:notification_constants:: | |
516 kNotificationProfileId]; | |
517 if ([toast_profile_id isEqualToString:profileId]) { | |
518 displayedNotifications->insert(base::SysNSStringToUTF8( | |
519 [toast.userInfo objectForKey:notification_constants:: | |
520 kNotificationId])); | |
521 } | |
522 } | |
523 | |
524 for (NSString* alert in alerts) | |
525 displayedNotifications->insert( | |
526 base::SysNSStringToUTF8(alert)); | |
Peter Beverloo
2017/02/24 16:12:24
nit: {}
Miguel Garcia
2017/03/22 22:00:07
Done.
| |
527 | |
528 content::BrowserThread::PostTask( | |
529 content::BrowserThread::IO, FROM_HERE, | |
530 base::Bind(callback, | |
531 base::Passed(&displayedNotifications), | |
532 true /* supports sync */)); | |
533 }]; | |
534 } | |
535 | |
479 // NotificationReply implementation | 536 // NotificationReply implementation |
480 - (void)notificationClick:(NSDictionary*)notificationResponseData { | 537 - (void)notificationClick:(NSDictionary*)notificationResponseData { |
481 NotificationPlatformBridgeMac::ProcessNotificationResponse( | 538 NotificationPlatformBridgeMac::ProcessNotificationResponse( |
482 notificationResponseData); | 539 notificationResponseData); |
483 } | 540 } |
484 | 541 |
485 @end | 542 @end |
OLD | NEW |