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/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 // from the notification center before displaying this one. | 115 // from the notification center before displaying this one. |
116 // TODO(miguelg): This will need to work for alerts as well via XPC | 116 // TODO(miguelg): This will need to work for alerts as well via XPC |
117 // once supported. | 117 // once supported. |
118 if (notification.renotify()) { | 118 if (notification.renotify()) { |
119 NSUserNotificationCenter* notification_center = | 119 NSUserNotificationCenter* notification_center = |
120 [NSUserNotificationCenter defaultUserNotificationCenter]; | 120 [NSUserNotificationCenter defaultUserNotificationCenter]; |
121 for (NSUserNotification* existing_notification in | 121 for (NSUserNotification* existing_notification in |
122 [notification_center deliveredNotifications]) { | 122 [notification_center deliveredNotifications]) { |
123 NSString* identifier = | 123 NSString* identifier = |
124 [existing_notification valueForKey:@"identifier"]; | 124 [existing_notification valueForKey:@"identifier"]; |
125 if ([identifier isEqual:base::SysUTF8ToNSString(notification.tag())]) { | 125 if ([identifier |
126 isEqualToString:base::SysUTF8ToNSString(notification.tag())]) { | |
126 [notification_center | 127 [notification_center |
127 removeDeliveredNotification:existing_notification]; | 128 removeDeliveredNotification:existing_notification]; |
128 break; | 129 break; |
129 } | 130 } |
130 } | 131 } |
131 } | 132 } |
132 } | 133 } |
133 | 134 |
134 [builder setOrigin:base::SysUTF8ToNSString(notification.origin_url().spec())]; | 135 [builder setOrigin:base::SysUTF8ToNSString(notification.origin_url().spec())]; |
135 [builder setNotificationId:base::SysUTF8ToNSString(notification_id)]; | 136 [builder setNotificationId:base::SysUTF8ToNSString(notification_id)]; |
136 [builder setProfileId:base::SysUTF8ToNSString(profile_id)]; | 137 [builder setProfileId:base::SysUTF8ToNSString(profile_id)]; |
137 [builder setIncognito:incognito]; | 138 [builder setIncognito:incognito]; |
138 | 139 |
139 NSUserNotification* toast = [builder buildUserNotification]; | 140 NSUserNotification* toast = [builder buildUserNotification]; |
140 [notification_center_ deliverNotification:toast]; | 141 [notification_center_ deliverNotification:toast]; |
141 } | 142 } |
142 | 143 |
143 void NotificationPlatformBridgeMac::Close(const std::string& profile_id, | 144 void NotificationPlatformBridgeMac::Close(const std::string& profile_id, |
144 const std::string& notification_id) { | 145 const std::string& notification_id) { |
145 NSString* candidate_id = base::SysUTF8ToNSString(notification_id); | 146 NSString* candidate_id = base::SysUTF8ToNSString(notification_id); |
146 | 147 |
147 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); | 148 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); |
148 for (NSUserNotification* toast in | 149 for (NSUserNotification* toast in |
149 [notification_center_ deliveredNotifications]) { | 150 [notification_center_ deliveredNotifications]) { |
150 NSString* toast_id = | 151 NSString* toast_id = |
151 [toast.userInfo objectForKey:notification_constants::kNotificationId]; | 152 [toast.userInfo objectForKey:notification_constants::kNotificationId]; |
152 | 153 |
153 NSString* persistent_profile_id = [toast.userInfo | 154 NSString* persistent_profile_id = [toast.userInfo |
154 objectForKey:notification_constants::kNotificationProfileId]; | 155 objectForKey:notification_constants::kNotificationProfileId]; |
155 | 156 if ([toast_id isEqualToString:candidate_id] && |
156 if (toast_id == candidate_id && | 157 [persistent_profile_id isEqualToString:current_profile_id]) { |
Peter Beverloo
2016/06/26 20:46:26
This seems like the kind of bug that would easily
Miguel Garcia
2016/06/28 08:17:20
You'd thing but in the tests all strings would be
| |
157 persistent_profile_id == current_profile_id) { | |
158 [notification_center_ removeDeliveredNotification:toast]; | 158 [notification_center_ removeDeliveredNotification:toast]; |
159 } | 159 } |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 bool NotificationPlatformBridgeMac::GetDisplayed( | 163 bool NotificationPlatformBridgeMac::GetDisplayed( |
164 const std::string& profile_id, | 164 const std::string& profile_id, |
165 bool incognito, | 165 bool incognito, |
166 std::set<std::string>* notifications) const { | 166 std::set<std::string>* notifications) const { |
167 DCHECK(notifications); | 167 DCHECK(notifications); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 buttonIndex.intValue); | 223 buttonIndex.intValue); |
224 } | 224 } |
225 | 225 |
226 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center | 226 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center |
227 shouldPresentNotification:(NSUserNotification*)nsNotification { | 227 shouldPresentNotification:(NSUserNotification*)nsNotification { |
228 // Always display notifications, regardless of whether the app is foreground. | 228 // Always display notifications, regardless of whether the app is foreground. |
229 return YES; | 229 return YES; |
230 } | 230 } |
231 | 231 |
232 @end | 232 @end |
OLD | NEW |