OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_ui_manager_mac.h" | 5 #include "chrome/browser/notifications/notification_ui_manager_mac.h" |
6 | 6 |
7 #include "base/mac/cocoa_protocols.h" | 7 #include "base/mac/cocoa_protocols.h" |
8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "chrome/browser/notifications/notification.h" | 10 #include "chrome/browser/notifications/notification.h" |
11 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" | 11 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" |
12 | 12 |
| 13 #if defined(ENABLE_MESSAGE_CENTER) |
| 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/notifications/message_center_notification_manager.h" |
| 16 #include "ui/message_center/message_center_util.h" |
| 17 #endif |
| 18 |
13 @class NSUserNotificationCenter; | 19 @class NSUserNotificationCenter; |
14 | 20 |
15 // Since NSUserNotification and NSUserNotificationCenter are new classes in | 21 // Since NSUserNotification and NSUserNotificationCenter are new classes in |
16 // 10.8, they cannot simply be declared with an @interface. An @implementation | 22 // 10.8, they cannot simply be declared with an @interface. An @implementation |
17 // is needed to link, but providing one would cause a runtime conflict when | 23 // is needed to link, but providing one would cause a runtime conflict when |
18 // running on 10.8. Instead, provide the interface defined as a protocol and | 24 // running on 10.8. Instead, provide the interface defined as a protocol and |
19 // use that instead, because sizeof(id<Protocol>) == sizeof(Class*). In order to | 25 // use that instead, because sizeof(id<Protocol>) == sizeof(Class*). In order to |
20 // instantiate, use NSClassFromString and simply assign the alloc/init'd result | 26 // instantiate, use NSClassFromString and simply assign the alloc/init'd result |
21 // to an instance of the proper protocol. This way the compiler, linker, and | 27 // to an instance of the proper protocol. This way the compiler, linker, and |
22 // loader are all happy. And the code isn't full of objc_msgSend. | 28 // loader are all happy. And the code isn't full of objc_msgSend. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 93 |
88 NotificationUIManagerMac::ControllerNotification::~ControllerNotification() { | 94 NotificationUIManagerMac::ControllerNotification::~ControllerNotification() { |
89 [view release]; | 95 [view release]; |
90 delete model; | 96 delete model; |
91 } | 97 } |
92 | 98 |
93 //////////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////////// |
94 | 100 |
95 // static | 101 // static |
96 NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) { | 102 NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) { |
| 103 #if defined(ENABLE_MESSAGE_CENTER) |
| 104 // TODO(rsesek): Remove this function and merge it with the one in |
| 105 // notification_ui_manager.cc. |
| 106 if (DelegatesToMessageCenter()) { |
| 107 return new MessageCenterNotificationManager( |
| 108 g_browser_process->message_center()); |
| 109 } |
| 110 #endif |
| 111 |
97 BalloonNotificationUIManager* balloon_manager = NULL; | 112 BalloonNotificationUIManager* balloon_manager = NULL; |
98 if (base::mac::IsOSMountainLionOrLater()) | 113 if (base::mac::IsOSMountainLionOrLater()) |
99 balloon_manager = new NotificationUIManagerMac(local_state); | 114 balloon_manager = new NotificationUIManagerMac(local_state); |
100 else | 115 else |
101 balloon_manager = new BalloonNotificationUIManager(local_state); | 116 balloon_manager = new BalloonNotificationUIManager(local_state); |
102 balloon_manager->SetBalloonCollection(BalloonCollection::Create()); | 117 balloon_manager->SetBalloonCollection(BalloonCollection::Create()); |
103 return balloon_manager; | 118 return balloon_manager; |
104 } | 119 } |
105 | 120 |
106 NotificationUIManagerMac::NotificationUIManagerMac(PrefService* local_state) | 121 NotificationUIManagerMac::NotificationUIManagerMac(PrefService* local_state) |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 notification->Click(); | 313 notification->Click(); |
299 } | 314 } |
300 | 315 |
301 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center | 316 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center |
302 shouldPresentNotification:(id<CrUserNotification>)nsNotification { | 317 shouldPresentNotification:(id<CrUserNotification>)nsNotification { |
303 // Always display notifications, regardless of whether the app is foreground. | 318 // Always display notifications, regardless of whether the app is foreground. |
304 return YES; | 319 return YES; |
305 } | 320 } |
306 | 321 |
307 @end | 322 @end |
OLD | NEW |