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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 // Deliver a notification to the XPC service to be displayed as an alert. | 130 // Deliver a notification to the XPC service to be displayed as an alert. |
131 - (void)dispatchNotification:(NSDictionary*)data; | 131 - (void)dispatchNotification:(NSDictionary*)data; |
132 | 132 |
133 // Close a notification for a given |notificationId| and |profileId|. | 133 // Close a notification for a given |notificationId| and |profileId|. |
134 - (void)closeNotificationWithId:(NSString*)notificationId | 134 - (void)closeNotificationWithId:(NSString*)notificationId |
135 withProfileId:(NSString*)profileId; | 135 withProfileId:(NSString*)profileId; |
136 | 136 |
137 // Close all notifications. | 137 // Close all notifications. |
138 - (void)closeAllNotifications; | 138 - (void)closeAllNotifications; |
139 | 139 |
140 // Get displayed alerts for |profileId| merge them with |localNotifications| | |
Peter Beverloo
2017/04/03 12:33:28
nit: no double space
Robert Sesek
2017/04/03 16:51:24
I missed this earlier, but you can omit re-declari
Miguel Garcia
2017/04/04 12:21:26
Done.
Miguel Garcia
2017/04/04 12:21:26
Done.
| |
141 // and post |callback| to the IO thread. | |
Peter Beverloo
2017/04/03 12:33:29
IO -> UI?
Miguel Garcia
2017/04/04 12:21:26
Done.
| |
142 - (void)getDisplayedAlertsForProfileId:(NSString*)profileId | |
143 withNotificationCenter: | |
144 (NSUserNotificationCenter*)notificationCenter | |
145 callback:(DisplayedNotificationsCallback)callback; | |
146 | |
140 @end | 147 @end |
141 | 148 |
142 // ///////////////////////////////////////////////////////////////////////////// | 149 // ///////////////////////////////////////////////////////////////////////////// |
143 NotificationPlatformBridgeMac::NotificationPlatformBridgeMac( | 150 NotificationPlatformBridgeMac::NotificationPlatformBridgeMac( |
144 NSUserNotificationCenter* notification_center, | 151 NSUserNotificationCenter* notification_center, |
145 id<AlertDispatcher> alert_dispatcher) | 152 id<AlertDispatcher> alert_dispatcher) |
146 : delegate_([NotificationCenterDelegate alloc]), | 153 : delegate_([NotificationCenterDelegate alloc]), |
147 notification_center_([notification_center retain]), | 154 notification_center_([notification_center retain]), |
148 alert_dispatcher_([alert_dispatcher retain]) { | 155 alert_dispatcher_([alert_dispatcher retain]) { |
149 [notification_center_ setDelegate:delegate_.get()]; | 156 [notification_center_ setDelegate:delegate_.get()]; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 [alert_dispatcher_ closeNotificationWithId:candidate_id | 294 [alert_dispatcher_ closeNotificationWithId:candidate_id |
288 withProfileId:current_profile_id]; | 295 withProfileId:current_profile_id]; |
289 } | 296 } |
290 #endif // ENABLE_XPC_NOTIFICATIONS | 297 #endif // ENABLE_XPC_NOTIFICATIONS |
291 } | 298 } |
292 | 299 |
293 void NotificationPlatformBridgeMac::GetDisplayed( | 300 void NotificationPlatformBridgeMac::GetDisplayed( |
294 const std::string& profile_id, | 301 const std::string& profile_id, |
295 bool incognito, | 302 bool incognito, |
296 const DisplayedNotificationsCallback& callback) const { | 303 const DisplayedNotificationsCallback& callback) const { |
304 #if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS) | |
305 [alert_dispatcher_ | |
306 getDisplayedAlertsForProfileId:base::SysUTF8ToNSString(profile_id) | |
307 withNotificationCenter:notification_center_ | |
Peter Beverloo
2017/04/03 12:33:28
Shouldn't this call understand |incognito|?
Miguel Garcia
2017/04/04 12:21:26
Well I guess but since we don't support notificati
Peter Beverloo
2017/04/04 13:16:25
We absolutely do. Not Web Notifications, but exten
| |
308 callback:callback]; | |
309 | |
310 #else | |
311 | |
297 auto displayed_notifications = base::MakeUnique<std::set<std::string>>(); | 312 auto displayed_notifications = base::MakeUnique<std::set<std::string>>(); |
298 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); | 313 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); |
299 for (NSUserNotification* toast in | 314 for (NSUserNotification* toast in |
300 [notification_center_ deliveredNotifications]) { | 315 [notification_center_ deliveredNotifications]) { |
301 NSString* toast_profile_id = [toast.userInfo | 316 NSString* toast_profile_id = [toast.userInfo |
302 objectForKey:notification_constants::kNotificationProfileId]; | 317 objectForKey:notification_constants::kNotificationProfileId]; |
303 if ([toast_profile_id isEqualToString:current_profile_id]) { | 318 if ([toast_profile_id isEqualToString:current_profile_id]) { |
304 displayed_notifications->insert(base::SysNSStringToUTF8([toast.userInfo | 319 displayed_notifications->insert(base::SysNSStringToUTF8([toast.userInfo |
305 objectForKey:notification_constants::kNotificationId])); | 320 objectForKey:notification_constants::kNotificationId])); |
306 } | 321 } |
307 } | 322 } |
308 content::BrowserThread::PostTask( | 323 content::BrowserThread::PostTask( |
309 content::BrowserThread::UI, FROM_HERE, | 324 content::BrowserThread::UI, FROM_HERE, |
310 base::Bind(callback, base::Passed(&displayed_notifications), | 325 base::Bind(callback, base::Passed(&displayed_notifications), |
311 true /* supports_synchronization */)); | 326 true /* supports_synchronization */)); |
327 | |
328 #endif // ENABLE_XPC_NOTIFICATIONS | |
312 } | 329 } |
313 | 330 |
314 // static | 331 // static |
315 void NotificationPlatformBridgeMac::ProcessNotificationResponse( | 332 void NotificationPlatformBridgeMac::ProcessNotificationResponse( |
316 NSDictionary* response) { | 333 NSDictionary* response) { |
317 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response)) | 334 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response)) |
318 return; | 335 return; |
319 | 336 |
320 NSNumber* button_index = | 337 NSNumber* button_index = |
321 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 338 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 }; | 500 }; |
484 | 501 |
485 xpcConnection_.get().exportedInterface = | 502 xpcConnection_.get().exportedInterface = |
486 [NSXPCInterface interfaceWithProtocol:@protocol(NotificationReply)]; | 503 [NSXPCInterface interfaceWithProtocol:@protocol(NotificationReply)]; |
487 xpcConnection_.get().exportedObject = self; | 504 xpcConnection_.get().exportedObject = self; |
488 [xpcConnection_ resume]; | 505 [xpcConnection_ resume]; |
489 } | 506 } |
490 | 507 |
491 return self; | 508 return self; |
492 } | 509 } |
493 | 510 |
Robert Sesek
2017/04/03 16:51:24
Just mark the protocol's methods:
// AlertDispatc
Miguel Garcia
2017/04/04 12:21:26
Done.
| |
494 - (void)dispatchNotification:(NSDictionary*)data { | 511 - (void)dispatchNotification:(NSDictionary*)data { |
495 [[self serviceProxy] deliverNotification:data]; | 512 [[self serviceProxy] deliverNotification:data]; |
496 } | 513 } |
497 | 514 |
498 - (void)closeNotificationWithId:(NSString*)notificationId | 515 - (void)closeNotificationWithId:(NSString*)notificationId |
499 withProfileId:(NSString*)profileId { | 516 withProfileId:(NSString*)profileId { |
500 [[self serviceProxy] closeNotificationWithId:notificationId | 517 [[self serviceProxy] closeNotificationWithId:notificationId |
501 withProfileId:profileId]; | 518 withProfileId:profileId]; |
502 } | 519 } |
503 | 520 |
504 - (void)closeAllNotifications { | 521 - (void)closeAllNotifications { |
505 [[self serviceProxy] closeAllNotifications]; | 522 [[self serviceProxy] closeAllNotifications]; |
506 } | 523 } |
507 | 524 |
525 - (void) | |
526 getDisplayedAlertsForProfileId:(NSString*)profileId | |
527 withNotificationCenter:(NSUserNotificationCenter*)notificationCenter | |
528 callback:(DisplayedNotificationsCallback)callback { | |
529 auto reply = ^(NSArray* alerts) { | |
530 std::unique_ptr<std::set<std::string>> displayedNotifications = | |
531 base::MakeUnique<std::set<std::string>>(); | |
532 | |
533 for (NSUserNotification* toast in | |
534 [notificationCenter deliveredNotifications]) { | |
535 NSString* toastProfileId = [toast.userInfo | |
536 objectForKey:notification_constants::kNotificationProfileId]; | |
537 if ([toastProfileId isEqualToString:profileId]) { | |
538 displayedNotifications->insert(base::SysNSStringToUTF8([toast.userInfo | |
539 objectForKey:notification_constants::kNotificationId])); | |
540 } | |
541 } | |
542 | |
543 for (NSString* alert in alerts) { | |
544 displayedNotifications->insert(base::SysNSStringToUTF8(alert)); | |
545 } | |
Peter Beverloo
2017/04/03 12:33:28
nit: no {}
Miguel Garcia
2017/04/04 12:21:26
Done.
| |
546 | |
547 content::BrowserThread::PostTask( | |
548 content::BrowserThread::UI, FROM_HERE, | |
549 base::Bind(callback, base::Passed(&displayedNotifications), | |
550 true /* supports_synchronization */)); | |
551 }; | |
552 | |
553 [[self serviceProxy] getDisplayedAlertsForProfileId:profileId | |
554 withReply:reply]; | |
555 } | |
556 | |
508 // NotificationReply: | 557 // NotificationReply: |
509 - (void)notificationClick:(NSDictionary*)notificationResponseData { | 558 - (void)notificationClick:(NSDictionary*)notificationResponseData { |
510 NotificationPlatformBridgeMac::ProcessNotificationResponse( | 559 NotificationPlatformBridgeMac::ProcessNotificationResponse( |
511 notificationResponseData); | 560 notificationResponseData); |
512 } | 561 } |
513 | 562 |
514 // Private methods: | 563 // Private methods: |
515 | 564 |
516 // Retrieves the connection's remoteObjectProxy. Always use this as opposed | 565 // Retrieves the connection's remoteObjectProxy. Always use this as opposed |
517 // to going directly through the connection, since this will ensure that the | 566 // to going directly through the connection, since this will ensure that the |
518 // service has its exception port configured for crash reporting. | 567 // service has its exception port configured for crash reporting. |
519 - (id<NotificationDelivery>)serviceProxy { | 568 - (id<NotificationDelivery>)serviceProxy { |
520 id<NotificationDelivery> proxy = [xpcConnection_ remoteObjectProxy]; | 569 id<NotificationDelivery> proxy = [xpcConnection_ remoteObjectProxy]; |
521 | 570 |
522 if (!setExceptionPort_) { | 571 if (!setExceptionPort_) { |
523 base::mac::ScopedMachSendRight exceptionPort( | 572 base::mac::ScopedMachSendRight exceptionPort( |
524 crash_reporter::GetCrashpadClient().GetHandlerMachPort()); | 573 crash_reporter::GetCrashpadClient().GetHandlerMachPort()); |
525 base::scoped_nsobject<CrXPCMachPort> xpcPort( | 574 base::scoped_nsobject<CrXPCMachPort> xpcPort( |
526 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]); | 575 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]); |
527 [proxy setMachExceptionPort:xpcPort]; | 576 [proxy setMachExceptionPort:xpcPort]; |
528 setExceptionPort_ = YES; | 577 setExceptionPort_ = YES; |
529 } | 578 } |
530 | 579 |
531 return proxy; | 580 return proxy; |
532 } | 581 } |
533 | 582 |
534 @end | 583 @end |
OLD | NEW |