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 30 matching lines...) Expand all Loading... |
41 // The mapping from web notifications to NsUserNotification works as follows | 41 // The mapping from web notifications to NsUserNotification works as follows |
42 | 42 |
43 // notification#title in NSUserNotification.title | 43 // notification#title in NSUserNotification.title |
44 // notification#message in NSUserNotification.informativeText | 44 // notification#message in NSUserNotification.informativeText |
45 // notification#context_message in NSUserNotification.subtitle | 45 // notification#context_message in NSUserNotification.subtitle |
46 // notification#tag in NSUserNotification.identifier (10.9) | 46 // notification#tag in NSUserNotification.identifier (10.9) |
47 // notification#icon in NSUserNotification.contentImage (10.9) | 47 // notification#icon in NSUserNotification.contentImage (10.9) |
48 // Site settings button is implemented as NSUserNotification's action button | 48 // Site settings button is implemented as NSUserNotification's action button |
49 // Not easy to implement: | 49 // Not easy to implement: |
50 // -notification.requireInteraction | 50 // -notification.requireInteraction |
51 // -The event associated to the close button | |
52 | 51 |
53 // TODO(miguelg) implement the following features | 52 // TODO(miguelg) implement the following features |
54 // - Sound names can be implemented by setting soundName in NSUserNotification | 53 // - Sound names can be implemented by setting soundName in NSUserNotification |
55 // NSUserNotificationDefaultSoundName gives you the platform default. | 54 // NSUserNotificationDefaultSoundName gives you the platform default. |
56 | 55 |
57 namespace { | 56 namespace { |
58 | 57 |
59 // Callback to run once the profile has been loaded in order to perform a | 58 // Callback to run once the profile has been loaded in order to perform a |
60 // given |operation| in a notification. | 59 // given |operation| in a notification. |
61 void ProfileLoadedCallback(NotificationCommon::Operation operation, | 60 void ProfileLoadedCallback(NotificationCommon::Operation operation, |
(...skipping 19 matching lines...) Expand all Loading... |
81 | 80 |
82 // Loads the profile and process the Notification response | 81 // Loads the profile and process the Notification response |
83 void DoProcessNotificationResponse(NotificationCommon::Operation operation, | 82 void DoProcessNotificationResponse(NotificationCommon::Operation operation, |
84 NotificationCommon::Type type, | 83 NotificationCommon::Type type, |
85 const std::string& profile_id, | 84 const std::string& profile_id, |
86 bool incognito, | 85 bool incognito, |
87 const std::string& origin, | 86 const std::string& origin, |
88 const std::string& notification_id, | 87 const std::string& notification_id, |
89 int32_t button_index) { | 88 int32_t button_index) { |
90 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 90 |
91 ProfileManager* profileManager = g_browser_process->profile_manager(); | 91 ProfileManager* profileManager = g_browser_process->profile_manager(); |
92 DCHECK(profileManager); | 92 DCHECK(profileManager); |
93 | 93 |
94 profileManager->LoadProfile( | 94 profileManager->LoadProfile( |
95 profile_id, incognito, base::Bind(&ProfileLoadedCallback, operation, type, | 95 profile_id, incognito, base::Bind(&ProfileLoadedCallback, operation, type, |
96 origin, notification_id, button_index)); | 96 origin, notification_id, button_index)); |
97 } | 97 } |
98 | 98 |
99 } // namespace | 99 } // namespace |
100 | 100 |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 // ///////////////////////////////////////////////////////////////////////////// | 371 // ///////////////////////////////////////////////////////////////////////////// |
372 @implementation NotificationCenterDelegate | 372 @implementation NotificationCenterDelegate |
373 - (void)userNotificationCenter:(NSUserNotificationCenter*)center | 373 - (void)userNotificationCenter:(NSUserNotificationCenter*)center |
374 didActivateNotification:(NSUserNotification*)notification { | 374 didActivateNotification:(NSUserNotification*)notification { |
375 NSDictionary* notificationResponse = | 375 NSDictionary* notificationResponse = |
376 [NotificationResponseBuilder buildDictionary:notification]; | 376 [NotificationResponseBuilder buildDictionary:notification]; |
377 NotificationPlatformBridgeMac::ProcessNotificationResponse( | 377 NotificationPlatformBridgeMac::ProcessNotificationResponse( |
378 notificationResponse); | 378 notificationResponse); |
379 } | 379 } |
380 | 380 |
| 381 // Overriden from _NSUserNotificationCenterDelegatePrivate. |
| 382 // Emitted when a user clicks the "Close" button in the notification. |
| 383 // It not is emitted if the notification is closed from the notification |
| 384 // center or if the app is not running at the time the Close button is |
| 385 // pressed so it's essentially just a best effort way to detect |
| 386 // notifications closed by the user. |
| 387 - (void)userNotificationCenter:(NSUserNotificationCenter*)center |
| 388 didDismissAlert:(NSUserNotification*)notification { |
| 389 NSDictionary* notificationResponse = |
| 390 [NotificationResponseBuilder buildDictionary:notification]; |
| 391 NotificationPlatformBridgeMac::ProcessNotificationResponse( |
| 392 notificationResponse); |
| 393 } |
| 394 |
381 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center | 395 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center |
382 shouldPresentNotification:(NSUserNotification*)nsNotification { | 396 shouldPresentNotification:(NSUserNotification*)nsNotification { |
383 // Always display notifications, regardless of whether the app is foreground. | 397 // Always display notifications, regardless of whether the app is foreground. |
384 return YES; | 398 return YES; |
385 } | 399 } |
386 | 400 |
387 @end | 401 @end |
388 | 402 |
389 @implementation NotificationRemoteDispatcher { | 403 @implementation NotificationRemoteDispatcher { |
390 // The connection to the XPC server in charge of delivering alerts. | 404 // The connection to the XPC server in charge of delivering alerts. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 [[xpcConnection_ remoteObjectProxy] deliverNotification:data]; | 441 [[xpcConnection_ remoteObjectProxy] deliverNotification:data]; |
428 } | 442 } |
429 | 443 |
430 // NotificationReply implementation | 444 // NotificationReply implementation |
431 - (void)notificationClick:(NSDictionary*)notificationResponseData { | 445 - (void)notificationClick:(NSDictionary*)notificationResponseData { |
432 NotificationPlatformBridgeMac::ProcessNotificationResponse( | 446 NotificationPlatformBridgeMac::ProcessNotificationResponse( |
433 notificationResponseData); | 447 notificationResponseData); |
434 } | 448 } |
435 | 449 |
436 @end | 450 @end |
OLD | NEW |