Skip to content

Commit 5d850e8

Browse files
Transfer the notification icon through XPC as NSData for OSX 10.09
This is because NSImage only started conforming to NSecureCoding in 10.10 BUG=696759 Review-Url: https://codereview.chromium.org/2728173003 Cr-Commit-Position: refs/heads/master@{#454916} (cherry picked from commit 52f904d) Review-Url: https://codereview.chromium.org/2736223002 . Cr-Commit-Position: refs/branch-heads/3029@{#62} Cr-Branched-From: 939b32e-refs/heads/master@{#454471}
1 parent 689d469 commit 5d850e8

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

chrome/browser/ui/cocoa/notifications/notification_builder_mac.mm

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
#import <AppKit/AppKit.h>
88

9+
#include "base/mac/mac_util.h"
910
#include "base/mac/scoped_nsobject.h"
11+
1012
#include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h"
1113

1214
namespace {
@@ -68,8 +70,14 @@ - (void)setContextMessage:(NSString*)contextMessage {
6870
}
6971

7072
- (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+
}
7381
}
7482

7583
- (void)setButtons:(NSString*)primaryButton
@@ -125,8 +133,14 @@ - (NSUserNotification*)buildUserNotification {
125133
// Icon
126134
if ([notificationData_ objectForKey:kNotificationImage]) {
127135
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+
}
130144
[toast setValue:@NO forKey:@"_identityImageHasBorder"];
131145
}
132146
}

chrome/browser/ui/cocoa/notifications/notification_service_delegate.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ - (BOOL)listener:(NSXPCListener*)listener
3838
newConnection.exportedInterface =
3939
[NSXPCInterface interfaceWithProtocol:@protocol(NotificationDelivery)];
4040
[newConnection.exportedInterface
41-
setClasses:[NSSet setWithObjects:[NSDictionary class], [NSImage class],
42-
[NSNumber class], [NSString class],
43-
nil]
41+
setClasses:[NSSet setWithObjects:[NSData class], [NSDictionary class],
42+
[NSImage class], [NSNumber class],
43+
[NSString class], nil]
4444
forSelector:@selector(deliverNotification:)
4545
argumentIndex:0
4646
ofReply:NO];

0 commit comments

Comments
 (0)