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 |
51 | 52 |
52 // TODO(miguelg) implement the following features | 53 // TODO(miguelg) implement the following features |
53 // - Sound names can be implemented by setting soundName in NSUserNotification | 54 // - Sound names can be implemented by setting soundName in NSUserNotification |
54 // NSUserNotificationDefaultSoundName gives you the platform default. | 55 // NSUserNotificationDefaultSoundName gives you the platform default. |
55 | 56 |
56 namespace { | 57 namespace { |
57 | 58 |
58 // Callback to run once the profile has been loaded in order to perform a | 59 // Callback to run once the profile has been loaded in order to perform a |
59 // given |operation| in a notification. | 60 // given |operation| in a notification. |
60 void ProfileLoadedCallback(NotificationCommon::Operation operation, | 61 void ProfileLoadedCallback(NotificationCommon::Operation operation, |
(...skipping 19 matching lines...) Expand all Loading... |
80 | 81 |
81 // Loads the profile and process the Notification response | 82 // Loads the profile and process the Notification response |
82 void DoProcessNotificationResponse(NotificationCommon::Operation operation, | 83 void DoProcessNotificationResponse(NotificationCommon::Operation operation, |
83 NotificationCommon::Type type, | 84 NotificationCommon::Type type, |
84 const std::string& profile_id, | 85 const std::string& profile_id, |
85 bool incognito, | 86 bool incognito, |
86 const std::string& origin, | 87 const std::string& origin, |
87 const std::string& notification_id, | 88 const std::string& notification_id, |
88 int32_t button_index) { | 89 int32_t button_index) { |
89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 90 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 | |
395 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center | 381 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center |
396 shouldPresentNotification:(NSUserNotification*)nsNotification { | 382 shouldPresentNotification:(NSUserNotification*)nsNotification { |
397 // Always display notifications, regardless of whether the app is foreground. | 383 // Always display notifications, regardless of whether the app is foreground. |
398 return YES; | 384 return YES; |
399 } | 385 } |
400 | 386 |
401 @end | 387 @end |
402 | 388 |
403 @implementation NotificationRemoteDispatcher { | 389 @implementation NotificationRemoteDispatcher { |
404 // The connection to the XPC server in charge of delivering alerts. | 390 // The connection to the XPC server in charge of delivering alerts. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 [[xpcConnection_ remoteObjectProxy] deliverNotification:data]; | 427 [[xpcConnection_ remoteObjectProxy] deliverNotification:data]; |
442 } | 428 } |
443 | 429 |
444 // NotificationReply implementation | 430 // NotificationReply implementation |
445 - (void)notificationClick:(NSDictionary*)notificationResponseData { | 431 - (void)notificationClick:(NSDictionary*)notificationResponseData { |
446 NotificationPlatformBridgeMac::ProcessNotificationResponse( | 432 NotificationPlatformBridgeMac::ProcessNotificationResponse( |
447 notificationResponseData); | 433 notificationResponseData); |
448 } | 434 } |
449 | 435 |
450 @end | 436 @end |
OLD | NEW |