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/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/notifications/notification.h" | 11 #include "chrome/browser/notifications/notification.h" |
12 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" | 12 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" |
13 #include "chrome/browser/notifications/message_center_notification_manager.h" | 13 #include "chrome/browser/notifications/message_center_notification_manager.h" |
14 #include "chrome/browser/profiles/profile.h" | |
14 #include "ui/message_center/message_center_util.h" | 15 #include "ui/message_center/message_center_util.h" |
15 | 16 |
16 @class NSUserNotificationCenter; | 17 @class NSUserNotificationCenter; |
17 | 18 |
18 // Since NSUserNotification and NSUserNotificationCenter are new classes in | 19 // Since NSUserNotification and NSUserNotificationCenter are new classes in |
19 // 10.8, they cannot simply be declared with an @interface. An @implementation | 20 // 10.8, they cannot simply be declared with an @interface. An @implementation |
20 // is needed to link, but providing one would cause a runtime conflict when | 21 // is needed to link, but providing one would cause a runtime conflict when |
21 // running on 10.8. Instead, provide the interface defined as a protocol and | 22 // running on 10.8. Instead, provide the interface defined as a protocol and |
22 // use that instead, because sizeof(id<Protocol>) == sizeof(Class*). In order to | 23 // use that instead, because sizeof(id<Protocol>) == sizeof(Class*). In order to |
23 // instantiate, use NSClassFromString and simply assign the alloc/init'd result | 24 // instantiate, use NSClassFromString and simply assign the alloc/init'd result |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 notification_map_.insert(std::make_pair( | 155 notification_map_.insert(std::make_pair( |
155 notification.notification_id(), | 156 notification.notification_id(), |
156 new ControllerNotification(profile, | 157 new ControllerNotification(profile, |
157 ns_notification, | 158 ns_notification, |
158 new Notification(notification)))); | 159 new Notification(notification)))); |
159 | 160 |
160 [GetNotificationCenter() deliverNotification:ns_notification]; | 161 [GetNotificationCenter() deliverNotification:ns_notification]; |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
165 std::set<std::string> | |
166 NotificationUIManagerMac::GetAllIdsByProfileAndSourceOrigin( | |
167 Profile* profile, | |
jianli
2013/05/24 21:51:20
nit: 4-space indentation
dewittj
2013/05/24 23:03:22
wow, clang-format-diff has made me lazy. Done.
| |
168 const GURL& source_origin) { | |
169 std::set<std::string> notification_ids = | |
170 BalloonNotificationUIManager::GetAllIdsByProfileAndSourceOrigin( | |
171 profile, source_origin); | |
172 | |
173 for (NotificationMap::iterator it = notification_map_.begin(); | |
174 it != notification_map_.end(); it++) { | |
jianli
2013/05/24 21:51:20
nit: ++it
dewittj
2013/05/24 23:03:22
Done.
| |
175 if (it->second->model->origin_url() == source_origin && | |
jianli
2013/05/24 21:51:20
It might be better to use a temp variable to hold
dewittj
2013/05/24 23:03:22
Done.
| |
176 profile->IsSameProfile(it->second->profile)) { | |
177 // RemoveNotification will erase from the map, invalidating iterator | |
jianli
2013/05/24 21:51:20
Not sure I understand this comment. RemoveNotifica
dewittj
2013/05/24 23:03:22
Done.
| |
178 // references to the removed element. | |
179 notification_ids.insert(it->second->model->notification_id()); | |
180 } | |
181 } | |
182 | |
183 return notification_ids; | |
184 } | |
jianli
2013/05/24 21:51:20
nit: empty line
dewittj
2013/05/24 23:03:22
Done.
| |
164 bool NotificationUIManagerMac::CancelById(const std::string& notification_id) { | 185 bool NotificationUIManagerMac::CancelById(const std::string& notification_id) { |
165 NotificationMap::iterator it = notification_map_.find(notification_id); | 186 NotificationMap::iterator it = notification_map_.find(notification_id); |
166 if (it == notification_map_.end()) | 187 if (it == notification_map_.end()) |
167 return BalloonNotificationUIManager::CancelById(notification_id); | 188 return BalloonNotificationUIManager::CancelById(notification_id); |
168 | 189 |
169 return RemoveNotification(it->second->view); | 190 return RemoveNotification(it->second->view); |
170 } | 191 } |
171 | 192 |
172 bool NotificationUIManagerMac::CancelAllBySourceOrigin( | 193 bool NotificationUIManagerMac::CancelAllBySourceOrigin( |
173 const GURL& source_origin) { | 194 const GURL& source_origin) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 notification->Click(); | 328 notification->Click(); |
308 } | 329 } |
309 | 330 |
310 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center | 331 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center |
311 shouldPresentNotification:(id<CrUserNotification>)nsNotification { | 332 shouldPresentNotification:(id<CrUserNotification>)nsNotification { |
312 // Always display notifications, regardless of whether the app is foreground. | 333 // Always display notifications, regardless of whether the app is foreground. |
313 return YES; | 334 return YES; |
314 } | 335 } |
315 | 336 |
316 @end | 337 @end |
OLD | NEW |