Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_mac.mm

Issue 1925803002: Rename NotificationUIManagerMac to NotificationPlatformBridgeMac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_ui_manager_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"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/notifications/notification.h" 14 #include "chrome/browser/notifications/notification.h"
15 #include "chrome/browser/notifications/notification_display_service_factory.h" 15 #include "chrome/browser/notifications/notification_display_service_factory.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 NSString* const kNotificationPersistentIdKey = @"notification_persistent_id"; 48 NSString* const kNotificationPersistentIdKey = @"notification_persistent_id";
49 49
50 NSString* const kNotificationProfilePersistentIdKey = 50 NSString* const kNotificationProfilePersistentIdKey =
51 @"notification_profile_persistent_id"; 51 @"notification_profile_persistent_id";
52 NSString* const kNotificationIncognitoKey = @"notification_incognito"; 52 NSString* const kNotificationIncognitoKey = @"notification_incognito";
53 53
54 } // namespace 54 } // namespace
55 55
56 // static 56 // static
57 NotificationPlatformBridge* NotificationPlatformBridge::Create() { 57 NotificationPlatformBridge* NotificationPlatformBridge::Create() {
58 return new NotificationUIManagerMac( 58 return new NotificationPlatformBridgeMac(
59 [NSUserNotificationCenter defaultUserNotificationCenter]); 59 [NSUserNotificationCenter defaultUserNotificationCenter]);
60 } 60 }
61 61
62 // A Cocoa class that represents the delegate of NSUserNotificationCenter and 62 // A Cocoa class that represents the delegate of NSUserNotificationCenter and
63 // can forward commands to C++. 63 // can forward commands to C++.
64 @interface NotificationCenterDelegate 64 @interface NotificationCenterDelegate
65 : NSObject<NSUserNotificationCenterDelegate> { 65 : NSObject<NSUserNotificationCenterDelegate> {
66 } 66 }
67 @end 67 @end
68 68
69 // ///////////////////////////////////////////////////////////////////////////// 69 // /////////////////////////////////////////////////////////////////////////////
70 70
71 NotificationUIManagerMac::NotificationUIManagerMac( 71 NotificationPlatformBridgeMac::NotificationPlatformBridgeMac(
72 NSUserNotificationCenter* notification_center) 72 NSUserNotificationCenter* notification_center)
73 : delegate_([NotificationCenterDelegate alloc]), 73 : delegate_([NotificationCenterDelegate alloc]),
74 notification_center_(notification_center) { 74 notification_center_(notification_center) {
75 [notification_center_ setDelegate:delegate_.get()]; 75 [notification_center_ setDelegate:delegate_.get()];
76 } 76 }
77 77
78 NotificationUIManagerMac::~NotificationUIManagerMac() { 78 NotificationPlatformBridgeMac::~NotificationPlatformBridgeMac() {
79 [notification_center_ setDelegate:nil]; 79 [notification_center_ setDelegate:nil];
80 80
81 // TODO(miguelg) lift this restriction if possible. 81 // TODO(miguelg) lift this restriction if possible.
82 [notification_center_ removeAllDeliveredNotifications]; 82 [notification_center_ removeAllDeliveredNotifications];
83 } 83 }
84 84
85 void NotificationUIManagerMac::Display(const std::string& notification_id, 85 void NotificationPlatformBridgeMac::Display(const std::string& notification_id,
86 const std::string& profile_id, 86 const std::string& profile_id,
Peter Beverloo 2016/04/27 21:26:58 nit: alignment
Miguel Garcia 2016/04/27 21:35:41 Done.
87 bool incognito, 87 bool incognito,
88 const Notification& notification) { 88 const Notification& notification) {
89 base::scoped_nsobject<NSUserNotification> toast( 89 base::scoped_nsobject<NSUserNotification> toast(
90 [[NSUserNotification alloc] init]); 90 [[NSUserNotification alloc] init]);
91 [toast setTitle:base::SysUTF16ToNSString(notification.title())]; 91 [toast setTitle:base::SysUTF16ToNSString(notification.title())];
92 [toast setSubtitle:base::SysUTF16ToNSString(notification.message())]; 92 [toast setSubtitle:base::SysUTF16ToNSString(notification.message())];
93 93
94 // TODO(miguelg): try to elide the origin perhaps See NSString 94 // TODO(miguelg): try to elide the origin perhaps See NSString
95 // stringWithFormat. It seems that the informativeText font is constant. 95 // stringWithFormat. It seems that the informativeText font is constant.
96 NSString* informative_text = 96 NSString* informative_text =
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 toast.get().userInfo = @{ 173 toast.get().userInfo = @{
174 kNotificationOriginKey : 174 kNotificationOriginKey :
175 base::SysUTF8ToNSString(notification.origin_url().spec()), 175 base::SysUTF8ToNSString(notification.origin_url().spec()),
176 kNotificationPersistentIdKey : base::SysUTF8ToNSString(notification_id), 176 kNotificationPersistentIdKey : base::SysUTF8ToNSString(notification_id),
177 kNotificationProfilePersistentIdKey : base::SysUTF8ToNSString(profile_id), 177 kNotificationProfilePersistentIdKey : base::SysUTF8ToNSString(profile_id),
178 kNotificationIncognitoKey : [NSNumber numberWithBool:incognito] 178 kNotificationIncognitoKey : [NSNumber numberWithBool:incognito]
179 }; 179 };
180 180
181 [notification_center_ deliverNotification:toast]; 181 [notification_center_ deliverNotification:toast];
182 notification.delegate()->Display();
Peter Beverloo 2016/04/27 21:26:58 Merge conflict? You unified this in the display ma
Miguel Garcia 2016/04/27 21:35:41 mm yes I don't know how this one sneaked in. Will
182 } 183 }
183 184
184 void NotificationUIManagerMac::Close(const std::string& profile_id, 185 void NotificationPlatformBridgeMac::Close(const std::string& profile_id,
185 const std::string& notification_id) { 186 const std::string& notification_id) {
Peter Beverloo 2016/04/27 21:26:58 nit: alignment
Miguel Garcia 2016/04/27 21:35:41 Done.
186 NSString* candidate_id = base::SysUTF8ToNSString(notification_id); 187 NSString* candidate_id = base::SysUTF8ToNSString(notification_id);
187 188
188 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); 189 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id);
189 for (NSUserNotification* toast in 190 for (NSUserNotification* toast in
190 [notification_center_ deliveredNotifications]) { 191 [notification_center_ deliveredNotifications]) {
191 NSString* toast_id = 192 NSString* toast_id =
192 [toast.userInfo objectForKey:kNotificationPersistentIdKey]; 193 [toast.userInfo objectForKey:kNotificationPersistentIdKey];
193 194
194 NSString* persistent_profile_id = 195 NSString* persistent_profile_id =
195 [toast.userInfo objectForKey:kNotificationProfilePersistentIdKey]; 196 [toast.userInfo objectForKey:kNotificationProfilePersistentIdKey];
196 197
197 if (toast_id == candidate_id && 198 if (toast_id == candidate_id &&
198 persistent_profile_id == current_profile_id) { 199 persistent_profile_id == current_profile_id) {
199 [notification_center_ removeDeliveredNotification:toast]; 200 [notification_center_ removeDeliveredNotification:toast];
200 } 201 }
201 } 202 }
202 } 203 }
203 204
204 bool NotificationUIManagerMac::GetDisplayed( 205 bool NotificationPlatformBridgeMac::GetDisplayed(
205 const std::string& profile_id, 206 const std::string& profile_id,
206 bool incognito, 207 bool incognito,
207 std::set<std::string>* notifications) const { 208 std::set<std::string>* notifications) const {
208 DCHECK(notifications); 209 DCHECK(notifications);
209 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); 210 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id);
210 for (NSUserNotification* toast in 211 for (NSUserNotification* toast in
211 [notification_center_ deliveredNotifications]) { 212 [notification_center_ deliveredNotifications]) {
212 NSString* toast_profile_id = 213 NSString* toast_profile_id =
213 [toast.userInfo objectForKey:kNotificationProfilePersistentIdKey]; 214 [toast.userInfo objectForKey:kNotificationProfilePersistentIdKey];
214 if (toast_profile_id == current_profile_id) { 215 if (toast_profile_id == current_profile_id) {
215 notifications->insert(base::SysNSStringToUTF8( 216 notifications->insert(base::SysNSStringToUTF8(
216 [toast.userInfo objectForKey:kNotificationPersistentIdKey])); 217 [toast.userInfo objectForKey:kNotificationPersistentIdKey]));
217 } 218 }
218 } 219 }
219 return true; 220 return true;
220 } 221 }
221 222
222 bool NotificationUIManagerMac::SupportsNotificationCenter() const { 223 bool NotificationPlatformBridgeMac::SupportsNotificationCenter() const {
223 return true; 224 return true;
224 } 225 }
225 226
226 // ///////////////////////////////////////////////////////////////////////////// 227 // /////////////////////////////////////////////////////////////////////////////
227 228
228 @implementation NotificationCenterDelegate 229 @implementation NotificationCenterDelegate
229 - (void)userNotificationCenter:(NSUserNotificationCenter*)center 230 - (void)userNotificationCenter:(NSUserNotificationCenter*)center
230 didActivateNotification:(NSUserNotification*)notification { 231 didActivateNotification:(NSUserNotification*)notification {
231 std::string notificationOrigin = base::SysNSStringToUTF8( 232 std::string notificationOrigin = base::SysNSStringToUTF8(
232 [notification.userInfo objectForKey:kNotificationOriginKey]); 233 [notification.userInfo objectForKey:kNotificationOriginKey]);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 persistentNotificationId.longLongValue, buttonIndex); 287 persistentNotificationId.longLongValue, buttonIndex);
287 } 288 }
288 289
289 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center 290 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center
290 shouldPresentNotification:(NSUserNotification*)nsNotification { 291 shouldPresentNotification:(NSUserNotification*)nsNotification {
291 // Always display notifications, regardless of whether the app is foreground. 292 // Always display notifications, regardless of whether the app is foreground.
292 return YES; 293 return YES;
293 } 294 }
294 295
295 @end 296 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698