OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" | 5 #import "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/mac/mac_util.h" | |
9 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
11 | |
10 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" | 12 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" |
11 | 13 |
12 namespace { | 14 namespace { |
13 | 15 |
14 // Internal builder constants representing the different notification fields | 16 // Internal builder constants representing the different notification fields |
15 // They don't need to be exposed outside the builder. | 17 // They don't need to be exposed outside the builder. |
16 | 18 |
17 NSString* const kNotificationTitle = @"title"; | 19 NSString* const kNotificationTitle = @"title"; |
18 NSString* const kNotificationSubTitle = @"subtitle"; | 20 NSString* const kNotificationSubTitle = @"subtitle"; |
19 NSString* const kNotificationInformativeText = @"informativeText"; | 21 NSString* const kNotificationInformativeText = @"informativeText"; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 [notificationData_ setObject:subTitle forKey:kNotificationSubTitle]; | 63 [notificationData_ setObject:subTitle forKey:kNotificationSubTitle]; |
62 } | 64 } |
63 | 65 |
64 - (void)setContextMessage:(NSString*)contextMessage { | 66 - (void)setContextMessage:(NSString*)contextMessage { |
65 if (contextMessage.length) | 67 if (contextMessage.length) |
66 [notificationData_ setObject:contextMessage | 68 [notificationData_ setObject:contextMessage |
67 forKey:kNotificationInformativeText]; | 69 forKey:kNotificationInformativeText]; |
68 } | 70 } |
69 | 71 |
70 - (void)setIcon:(NSImage*)icon { | 72 - (void)setIcon:(NSImage*)icon { |
71 if (icon) | 73 if (icon) { |
72 [notificationData_ setObject:icon forKey:kNotificationImage]; | 74 if (base::mac::IsAtLeastOS10_10()) { |
Robert Sesek
2017/03/06 16:12:05
Rather than using base::mac, use [icon conformsToP
Miguel Garcia
2017/03/06 16:30:42
So the problem is that down in line 136 I don't ha
Robert Sesek
2017/03/06 17:34:59
You can check the Class too: https://developer.app
| |
75 [notificationData_ setObject:icon forKey:kNotificationImage]; | |
76 } else { // in 10.09 NSImage does not conform to NSecureCoding | |
Robert Sesek
2017/03/06 16:12:05
It's just "10.9" -- also use proper punctuation an
Miguel Garcia
2017/03/06 16:30:42
Done.
| |
77 [notificationData_ setObject:[icon TIFFRepresentation] | |
78 forKey:kNotificationImage]; | |
79 } | |
80 } | |
73 } | 81 } |
74 | 82 |
75 - (void)setButtons:(NSString*)primaryButton | 83 - (void)setButtons:(NSString*)primaryButton |
76 secondaryButton:(NSString*)secondaryButton { | 84 secondaryButton:(NSString*)secondaryButton { |
77 DCHECK(primaryButton.length); | 85 DCHECK(primaryButton.length); |
78 [notificationData_ setObject:primaryButton forKey:kNotificationButtonOne]; | 86 [notificationData_ setObject:primaryButton forKey:kNotificationButtonOne]; |
79 if (secondaryButton.length) { | 87 if (secondaryButton.length) { |
80 [notificationData_ setObject:secondaryButton forKey:kNotificationButtonTwo]; | 88 [notificationData_ setObject:secondaryButton forKey:kNotificationButtonTwo]; |
81 } | 89 } |
82 } | 90 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 base::scoped_nsobject<NSUserNotification> toast( | 126 base::scoped_nsobject<NSUserNotification> toast( |
119 [[NSUserNotification alloc] init]); | 127 [[NSUserNotification alloc] init]); |
120 [toast setTitle:[notificationData_ objectForKey:kNotificationTitle]]; | 128 [toast setTitle:[notificationData_ objectForKey:kNotificationTitle]]; |
121 [toast setSubtitle:[notificationData_ objectForKey:kNotificationSubTitle]]; | 129 [toast setSubtitle:[notificationData_ objectForKey:kNotificationSubTitle]]; |
122 [toast setInformativeText:[notificationData_ | 130 [toast setInformativeText:[notificationData_ |
123 objectForKey:kNotificationInformativeText]]; | 131 objectForKey:kNotificationInformativeText]]; |
124 | 132 |
125 // Icon | 133 // Icon |
126 if ([notificationData_ objectForKey:kNotificationImage]) { | 134 if ([notificationData_ objectForKey:kNotificationImage]) { |
127 if ([toast respondsToSelector:@selector(_identityImage)]) { | 135 if ([toast respondsToSelector:@selector(_identityImage)]) { |
128 NSImage* image = [notificationData_ objectForKey:kNotificationImage]; | 136 if (base::mac::IsAtLeastOS10_10()) { |
129 [toast setValue:image forKey:@"_identityImage"]; | 137 NSImage* image = [notificationData_ objectForKey:kNotificationImage]; |
138 [toast setValue:image forKey:@"_identityImage"]; | |
139 } else { // in 10.09 NSImage does not confirm to NSSecureCoding | |
Robert Sesek
2017/03/06 16:12:05
Same.
Miguel Garcia
2017/03/06 16:30:42
Done.
| |
140 base::scoped_nsobject<NSImage> image([[NSImage alloc] | |
141 initWithData:[notificationData_ objectForKey:kNotificationImage]]); | |
142 [toast setValue:image forKey:@"_identityImage"]; | |
143 } | |
130 [toast setValue:@NO forKey:@"_identityImageHasBorder"]; | 144 [toast setValue:@NO forKey:@"_identityImageHasBorder"]; |
131 } | 145 } |
132 } | 146 } |
133 | 147 |
134 // Buttons | 148 // Buttons |
135 if ([toast respondsToSelector:@selector(_showsButtons)]) { | 149 if ([toast respondsToSelector:@selector(_showsButtons)]) { |
136 DCHECK([notificationData_ objectForKey:kNotificationCloseButtonTag]); | 150 DCHECK([notificationData_ objectForKey:kNotificationCloseButtonTag]); |
137 DCHECK([notificationData_ objectForKey:kNotificationSettingsButtonTag]); | 151 DCHECK([notificationData_ objectForKey:kNotificationSettingsButtonTag]); |
138 DCHECK([notificationData_ objectForKey:kNotificationOptionsButtonTag]); | 152 DCHECK([notificationData_ objectForKey:kNotificationOptionsButtonTag]); |
139 | 153 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 }; | 231 }; |
218 | 232 |
219 return toast.autorelease(); | 233 return toast.autorelease(); |
220 } | 234 } |
221 | 235 |
222 - (NSDictionary*)buildDictionary { | 236 - (NSDictionary*)buildDictionary { |
223 return [[notificationData_ copy] autorelease]; | 237 return [[notificationData_ copy] autorelease]; |
224 } | 238 } |
225 | 239 |
226 @end | 240 @end |
OLD | NEW |