| 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" |
| 11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
| 12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
| 13 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
| 14 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/notifications/native_notification_display_service.h" | 18 #include "chrome/browser/notifications/native_notification_display_service.h" |
| 19 #include "chrome/browser/notifications/notification.h" | 19 #include "chrome/browser/notifications/notification.h" |
| 20 #include "chrome/browser/notifications/notification_common.h" | 20 #include "chrome/browser/notifications/notification_common.h" |
| 21 #include "chrome/browser/notifications/notification_display_service_factory.h" | 21 #include "chrome/browser/notifications/notification_display_service_factory.h" |
| 22 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 22 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
| 23 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 23 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" | 26 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" |
| 27 #import "chrome/browser/ui/cocoa/notifications/notification_delivery.h" | 27 #import "chrome/browser/ui/cocoa/notifications/notification_delivery.h" |
| 28 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" | 28 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" |
| 29 #import "chrome/browser/ui/cocoa/notifications/notification_private_mac.h" |
| 29 #import "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac
.h" | 30 #import "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac
.h" |
| 30 #include "chrome/common/features.h" | 31 #include "chrome/common/features.h" |
| 31 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
| 32 #include "components/url_formatter/elide_url.h" | 33 #include "components/url_formatter/elide_url.h" |
| 33 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onConstants.h" | 34 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onConstants.h" |
| 34 #include "ui/base/l10n/l10n_util_mac.h" | 35 #include "ui/base/l10n/l10n_util_mac.h" |
| 35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 36 #include "url/origin.h" | 37 #include "url/origin.h" |
| 37 | 38 |
| 38 @class NSUserNotification; | 39 @class NSUserNotification; |
| 39 @class NSUserNotificationCenter; | 40 @class NSUserNotificationCenter; |
| 40 | 41 |
| 41 // The mapping from web notifications to NsUserNotification works as follows | 42 // The mapping from web notifications to NsUserNotification works as follows |
| 42 | 43 |
| 43 // notification#title in NSUserNotification.title | 44 // notification#title in NSUserNotification.title |
| 44 // notification#message in NSUserNotification.informativeText | 45 // notification#message in NSUserNotification.informativeText |
| 45 // notification#context_message in NSUserNotification.subtitle | 46 // notification#context_message in NSUserNotification.subtitle |
| 46 // notification#tag in NSUserNotification.identifier (10.9) | 47 // notification#tag in NSUserNotification.identifier (10.9) |
| 47 // notification#icon in NSUserNotification.contentImage (10.9) | 48 // notification#icon in NSUserNotification.contentImage (10.9) |
| 48 // Site settings button is implemented as NSUserNotification's action button | 49 // Site settings button is implemented as NSUserNotification's action button |
| 49 // Not easy to implement: | 50 // Not easy to implement: |
| 50 // -notification.requireInteraction | 51 // -notification.requireInteraction |
| 51 // -The event associated to the close button | |
| 52 | 52 |
| 53 // TODO(miguelg) implement the following features | 53 // TODO(miguelg) implement the following features |
| 54 // - Sound names can be implemented by setting soundName in NSUserNotification | 54 // - Sound names can be implemented by setting soundName in NSUserNotification |
| 55 // NSUserNotificationDefaultSoundName gives you the platform default. | 55 // NSUserNotificationDefaultSoundName gives you the platform default. |
| 56 | 56 |
| 57 namespace { | 57 namespace { |
| 58 | 58 |
| 59 // 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 |
| 60 // given |operation| in a notification. | 60 // given |operation| in a notification. |
| 61 void ProfileLoadedCallback(NotificationCommon::Operation operation, | 61 void ProfileLoadedCallback(NotificationCommon::Operation operation, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 81 | 81 |
| 82 // Loads the profile and process the Notification response | 82 // Loads the profile and process the Notification response |
| 83 void DoProcessNotificationResponse(NotificationCommon::Operation operation, | 83 void DoProcessNotificationResponse(NotificationCommon::Operation operation, |
| 84 NotificationCommon::Type type, | 84 NotificationCommon::Type type, |
| 85 const std::string& profile_id, | 85 const std::string& profile_id, |
| 86 bool incognito, | 86 bool incognito, |
| 87 const std::string& origin, | 87 const std::string& origin, |
| 88 const std::string& notification_id, | 88 const std::string& notification_id, |
| 89 int32_t button_index) { | 89 int32_t button_index) { |
| 90 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 90 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 91 |
| 91 ProfileManager* profileManager = g_browser_process->profile_manager(); | 92 ProfileManager* profileManager = g_browser_process->profile_manager(); |
| 92 DCHECK(profileManager); | 93 DCHECK(profileManager); |
| 93 | 94 |
| 94 profileManager->LoadProfile( | 95 profileManager->LoadProfile( |
| 95 profile_id, incognito, base::Bind(&ProfileLoadedCallback, operation, type, | 96 profile_id, incognito, base::Bind(&ProfileLoadedCallback, operation, type, |
| 96 origin, notification_id, button_index)); | 97 origin, notification_id, button_index)); |
| 97 } | 98 } |
| 98 | 99 |
| 99 } // namespace | 100 } // namespace |
| 100 | 101 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 // ///////////////////////////////////////////////////////////////////////////// | 372 // ///////////////////////////////////////////////////////////////////////////// |
| 372 @implementation NotificationCenterDelegate | 373 @implementation NotificationCenterDelegate |
| 373 - (void)userNotificationCenter:(NSUserNotificationCenter*)center | 374 - (void)userNotificationCenter:(NSUserNotificationCenter*)center |
| 374 didActivateNotification:(NSUserNotification*)notification { | 375 didActivateNotification:(NSUserNotification*)notification { |
| 375 NSDictionary* notificationResponse = | 376 NSDictionary* notificationResponse = |
| 376 [NotificationResponseBuilder buildDictionary:notification]; | 377 [NotificationResponseBuilder buildDictionary:notification]; |
| 377 NotificationPlatformBridgeMac::ProcessNotificationResponse( | 378 NotificationPlatformBridgeMac::ProcessNotificationResponse( |
| 378 notificationResponse); | 379 notificationResponse); |
| 379 } | 380 } |
| 380 | 381 |
| 382 - (void)userNotificationCenter:(NSUserNotificationCenter*)center |
| 383 didDismissAlert:(NSUserNotification*)notification { |
| 384 NSDictionary* notificationResponse = |
| 385 [NotificationResponseBuilder buildDictionary:notification]; |
| 386 NotificationPlatformBridgeMac::ProcessNotificationResponse( |
| 387 notificationResponse); |
| 388 } |
| 389 |
| 381 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center | 390 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center |
| 382 shouldPresentNotification:(NSUserNotification*)nsNotification { | 391 shouldPresentNotification:(NSUserNotification*)nsNotification { |
| 383 // Always display notifications, regardless of whether the app is foreground. | 392 // Always display notifications, regardless of whether the app is foreground. |
| 384 return YES; | 393 return YES; |
| 385 } | 394 } |
| 386 | 395 |
| 387 @end | 396 @end |
| 388 | 397 |
| 389 @implementation NotificationRemoteDispatcher { | 398 @implementation NotificationRemoteDispatcher { |
| 390 // The connection to the XPC server in charge of delivering alerts. | 399 // 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]; | 436 [[xpcConnection_ remoteObjectProxy] deliverNotification:data]; |
| 428 } | 437 } |
| 429 | 438 |
| 430 // NotificationReply implementation | 439 // NotificationReply implementation |
| 431 - (void)notificationClick:(NSDictionary*)notificationResponseData { | 440 - (void)notificationClick:(NSDictionary*)notificationResponseData { |
| 432 NotificationPlatformBridgeMac::ProcessNotificationResponse( | 441 NotificationPlatformBridgeMac::ProcessNotificationResponse( |
| 433 notificationResponseData); | 442 notificationResponseData); |
| 434 } | 443 } |
| 435 | 444 |
| 436 @end | 445 @end |
| OLD | NEW |