| 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" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 instance = impl = new NotificationUIManagerImpl(local_state); | 92 instance = impl = new NotificationUIManagerImpl(local_state); |
| 93 } | 93 } |
| 94 | 94 |
| 95 impl->Initialize(balloons); | 95 impl->Initialize(balloons); |
| 96 balloons->set_space_change_listener(impl); | 96 balloons->set_space_change_listener(impl); |
| 97 | 97 |
| 98 return instance; | 98 return instance; |
| 99 } | 99 } |
| 100 | 100 |
| 101 NotificationUIManagerMac::ControllerNotification::ControllerNotification( | 101 NotificationUIManagerMac::ControllerNotification::ControllerNotification( |
| 102 id<CrUserNotification> a_view, Notification* a_model) | 102 Profile* a_profile, |
| 103 : view(a_view), | 103 id<CrUserNotification> a_view, |
| 104 Notification* a_model) |
| 105 : profile(a_profile), |
| 106 view(a_view), |
| 104 model(a_model) { | 107 model(a_model) { |
| 105 } | 108 } |
| 106 | 109 |
| 107 NotificationUIManagerMac::ControllerNotification::~ControllerNotification() { | 110 NotificationUIManagerMac::ControllerNotification::~ControllerNotification() { |
| 108 [view release]; | 111 [view release]; |
| 109 delete model; | 112 delete model; |
| 110 } | 113 } |
| 111 | 114 |
| 112 //////////////////////////////////////////////////////////////////////////////// | 115 //////////////////////////////////////////////////////////////////////////////// |
| 113 | 116 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 143 ns_notification.subtitle = | 146 ns_notification.subtitle = |
| 144 base::SysUTF16ToNSString(notification.display_source()); | 147 base::SysUTF16ToNSString(notification.display_source()); |
| 145 ns_notification.informativeText = | 148 ns_notification.informativeText = |
| 146 base::SysUTF16ToNSString(notification.body()); | 149 base::SysUTF16ToNSString(notification.body()); |
| 147 ns_notification.userInfo = | 150 ns_notification.userInfo = |
| 148 [NSDictionary dictionaryWithObject:base::SysUTF8ToNSString( | 151 [NSDictionary dictionaryWithObject:base::SysUTF8ToNSString( |
| 149 notification.notification_id()) | 152 notification.notification_id()) |
| 150 forKey:kNotificationIDKey]; | 153 forKey:kNotificationIDKey]; |
| 151 ns_notification.hasActionButton = NO; | 154 ns_notification.hasActionButton = NO; |
| 152 | 155 |
| 153 notification_map_.insert( | 156 notification_map_.insert(std::make_pair( |
| 154 std::make_pair(notification.notification_id(), | 157 notification.notification_id(), |
| 155 new ControllerNotification(ns_notification, | 158 new ControllerNotification(profile, |
| 156 new Notification(notification)))); | 159 ns_notification, |
| 160 new Notification(notification)))); |
| 157 | 161 |
| 158 [GetNotificationCenter() deliverNotification:ns_notification]; | 162 [GetNotificationCenter() deliverNotification:ns_notification]; |
| 159 } | 163 } |
| 160 } | 164 } |
| 161 | 165 |
| 162 bool NotificationUIManagerMac::CancelById(const std::string& notification_id) { | 166 bool NotificationUIManagerMac::CancelById(const std::string& notification_id) { |
| 163 NotificationMap::iterator it = notification_map_.find(notification_id); | 167 NotificationMap::iterator it = notification_map_.find(notification_id); |
| 164 if (it == notification_map_.end()) | 168 if (it == notification_map_.end()) |
| 165 return builtin_manager_->CancelById(notification_id); | 169 return builtin_manager_->CancelById(notification_id); |
| 166 | 170 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 178 // references to the removed element. | 182 // references to the removed element. |
| 179 success |= RemoveNotification((it++)->second->view); | 183 success |= RemoveNotification((it++)->second->view); |
| 180 } else { | 184 } else { |
| 181 ++it; | 185 ++it; |
| 182 } | 186 } |
| 183 } | 187 } |
| 184 | 188 |
| 185 return success; | 189 return success; |
| 186 } | 190 } |
| 187 | 191 |
| 192 bool NotificationUIManagerMac::CancelAllByProfile(Profile* profile) { |
| 193 bool success = builtin_manager_->CancelAllByProfile(profile); |
| 194 |
| 195 for (NotificationMap::iterator it = notification_map_.begin(); |
| 196 it != notification_map_.end();) { |
| 197 if (it->second->profile == profile) { |
| 198 // RemoveNotification will erase from the map, invalidating iterator |
| 199 // references to the removed element. |
| 200 success |= RemoveNotification((it++)->second->view); |
| 201 } else { |
| 202 ++it; |
| 203 } |
| 204 } |
| 205 |
| 206 return success; |
| 207 } |
| 208 |
| 188 void NotificationUIManagerMac::CancelAll() { | 209 void NotificationUIManagerMac::CancelAll() { |
| 189 id<CrUserNotificationCenter> center = GetNotificationCenter(); | 210 id<CrUserNotificationCenter> center = GetNotificationCenter(); |
| 190 | 211 |
| 191 // Calling RemoveNotification would loop many times over, so just replicate | 212 // Calling RemoveNotification would loop many times over, so just replicate |
| 192 // a small bit of its logic here. | 213 // a small bit of its logic here. |
| 193 for (NotificationMap::iterator it = notification_map_.begin(); | 214 for (NotificationMap::iterator it = notification_map_.begin(); |
| 194 it != notification_map_.end(); | 215 it != notification_map_.end(); |
| 195 ++it) { | 216 ++it) { |
| 196 it->second->model->Close(false); | 217 it->second->model->Close(false); |
| 197 delete it->second; | 218 delete it->second; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 notification->Click(); | 321 notification->Click(); |
| 301 } | 322 } |
| 302 | 323 |
| 303 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center | 324 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center |
| 304 shouldPresentNotification:(id<CrUserNotification>)nsNotification { | 325 shouldPresentNotification:(id<CrUserNotification>)nsNotification { |
| 305 // Always display notifications, regardless of whether the app is foreground. | 326 // Always display notifications, regardless of whether the app is foreground. |
| 306 return YES; | 327 return YES; |
| 307 } | 328 } |
| 308 | 329 |
| 309 @end | 330 @end |
| OLD | NEW |