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

Side by Side Diff: chrome/browser/ui/cocoa/notifications/notification_builder_mac.mm

Issue 2736223002: Transfer the notification icon through XPC as NSData for OSX 10.09 (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/notifications/notification_service_delegate.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 ([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 - (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
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 ([[NSImage class] conformsToProtocol:@protocol(NSSecureCoding)]) {
129 [toast setValue:image forKey:@"_identityImage"]; 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 [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
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
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/notifications/notification_service_delegate.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698