|
6 | 6 |
|
7 | 7 | #import <AppKit/AppKit.h>
|
8 | 8 |
|
| 9 | +#include "base/mac/mac_util.h" |
9 | 10 | #include "base/mac/scoped_nsobject.h"
|
| 11 | + |
10 | 12 | #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h"
|
11 | 13 |
|
12 | 14 | namespace {
|
@@ -68,8 +70,14 @@ - (void)setContextMessage:(NSString*)contextMessage {
|
68 | 70 | }
|
69 | 71 |
|
70 | 72 | - (void)setIcon:(NSImage*)icon {
|
71 |
| - if (icon) |
72 |
| - [notificationData_ setObject:icon forKey:kNotificationImage]; |
| 73 | + if (icon) { |
| 74 | + if ([icon conformsToProtocol:@protocol(NSSecureCoding)]) { |
| 75 | + [notificationData_ setObject:icon forKey:kNotificationImage]; |
| 76 | + } else { // NSImage only conforms to NSSecureCoding from 10.10 onwards. |
| 77 | + [notificationData_ setObject:[icon TIFFRepresentation] |
| 78 | + forKey:kNotificationImage]; |
| 79 | + } |
| 80 | + } |
73 | 81 | }
|
74 | 82 |
|
75 | 83 | - (void)setButtons:(NSString*)primaryButton
|
@@ -125,8 +133,14 @@ - (NSUserNotification*)buildUserNotification {
|
125 | 133 | // Icon
|
126 | 134 | if ([notificationData_ objectForKey:kNotificationImage]) {
|
127 | 135 | if ([toast respondsToSelector:@selector(_identityImage)]) {
|
128 |
| - NSImage* image = [notificationData_ objectForKey:kNotificationImage]; |
129 |
| - [toast setValue:image forKey:@"_identityImage"]; |
| 136 | + if ([[NSImage class] conformsToProtocol:@protocol(NSSecureCoding)]) { |
| 137 | + NSImage* image = [notificationData_ objectForKey:kNotificationImage]; |
| 138 | + [toast setValue:image forKey:@"_identityImage"]; |
| 139 | + } else { // NSImage only conforms to NSSecureCoding from 10.10 onwards. |
| 140 | + base::scoped_nsobject<NSImage> image([[NSImage alloc] |
| 141 | + initWithData:[notificationData_ objectForKey:kNotificationImage]]); |
| 142 | + [toast setValue:image forKey:@"_identityImage"]; |
| 143 | + } |
130 | 144 | [toast setValue:@NO forKey:@"_identityImageHasBorder"];
|
131 | 145 | }
|
132 | 146 | }
|
|
0 commit comments