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

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

Issue 2053613002: Make the notification builder more XPC friendly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert unintended change Created 4 years, 6 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 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 #include "chrome/browser/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/mac_util.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
11 #include "chrome/grit/generated_resources.h" 11 #include "chrome/grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util_mac.h" 12 #include "ui/base/l10n/l10n_util_mac.h"
13 13
14 namespace { 14 namespace {
15 15
16 // Internal builder constants representing the different notification fields 16 // Internal builder constants representing the different notification fields
17 // They don't need to be exposed outside the builder. 17 // They don't need to be exposed outside the builder.
18 18
19 NSString* const kNotificationTitle = @"title"; 19 NSString* const kNotificationTitle = @"title";
20 NSString* const kNotificationSubTitle = @"subtitle"; 20 NSString* const kNotificationSubTitle = @"subtitle";
21 NSString* const kNotificationInformativeText = @"informativeText"; 21 NSString* const kNotificationInformativeText = @"informativeText";
22 NSString* const kNotificationImage = @"icon"; 22 NSString* const kNotificationImage = @"icon";
23 NSString* const kNotificationButtonOne = @"buttonOne"; 23 NSString* const kNotificationButtonOne = @"buttonOne";
24 NSString* const kNotificationButtonTwo = @"buttonTwo"; 24 NSString* const kNotificationButtonTwo = @"buttonTwo";
25 NSString* const kNotificationTag = @"tag"; 25 NSString* const kNotificationTag = @"tag";
26 26 NSString* const kNotificationCloseButtonTag = @"closeButton";
27 NSString* const kNotificationOptionsButtonTag = @"optionsButton";
28 NSString* const kNotificationSettingsButtonTag = @"settingsButton";
27 } // namespace 29 } // namespace
28 30
29 namespace notification_builder { 31 namespace notification_builder {
30 32
31 // Exposed constants to include user related data in the notification. 33 // Exposed constants to include user related data in the notification.
32 NSString* const kNotificationOrigin = @"notificationOrigin"; 34 NSString* const kNotificationOrigin = @"notificationOrigin";
33 NSString* const kNotificationId = @"notificationId"; 35 NSString* const kNotificationId = @"notificationId";
34 NSString* const kNotificationProfileId = @"notificationProfileId"; 36 NSString* const kNotificationProfileId = @"notificationProfileId";
35 NSString* const kNotificationIncognito = @"notificationIncognito"; 37 NSString* const kNotificationIncognito = @"notificationIncognito";
36 38
37 } // namespace notification_builder 39 } // namespace notification_builder
38 40
39 @implementation NotificationBuilder { 41 @implementation NotificationBuilder {
40 base::scoped_nsobject<NSMutableDictionary> notificationData_; 42 base::scoped_nsobject<NSMutableDictionary> notificationData_;
41 } 43 }
42 44
43 - (instancetype)init { 45 - (instancetype)init {
44 if ((self = [super init])) { 46 if ((self = [super init])) {
45 notificationData_.reset([[NSMutableDictionary alloc] init]); 47 notificationData_.reset([[NSMutableDictionary alloc] init]);
48 [notificationData_
49 setObject:l10n_util::GetNSString(IDS_NOTIFICATION_BUTTON_CLOSE)
50 forKey:kNotificationCloseButtonTag];
51 [notificationData_
52 setObject:l10n_util::GetNSString(IDS_NOTIFICATION_BUTTON_OPTIONS)
53 forKey:kNotificationOptionsButtonTag];
54 [notificationData_
55 setObject:l10n_util::GetNSString(IDS_NOTIFICATION_BUTTON_SETTINGS)
56 forKey:kNotificationSettingsButtonTag];
46 } 57 }
47 return self; 58 return self;
48 } 59 }
49 60
50 - (instancetype)initWithDictionary:(NSDictionary*)data { 61 - (instancetype)initWithDictionary:(NSDictionary*)data {
51 if ((self = [super init])) { 62 if ((self = [super init])) {
52 notificationData_.reset([data copy]); 63 notificationData_.reset([data copy]);
53 } 64 }
54 return self; 65 return self;
55 } 66 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 if ([notificationData_ objectForKey:kNotificationImage]) { 135 if ([notificationData_ objectForKey:kNotificationImage]) {
125 if ([toast respondsToSelector:@selector(_identityImage)]) { 136 if ([toast respondsToSelector:@selector(_identityImage)]) {
126 NSImage* image = [notificationData_ objectForKey:kNotificationImage]; 137 NSImage* image = [notificationData_ objectForKey:kNotificationImage];
127 [toast setValue:image forKey:@"_identityImage"]; 138 [toast setValue:image forKey:@"_identityImage"];
128 [toast setValue:@NO forKey:@"_identityImageHasBorder"]; 139 [toast setValue:@NO forKey:@"_identityImageHasBorder"];
129 } 140 }
130 } 141 }
131 142
132 // Buttons 143 // Buttons
133 if ([toast respondsToSelector:@selector(_showsButtons)]) { 144 if ([toast respondsToSelector:@selector(_showsButtons)]) {
145 DCHECK([notificationData_ objectForKey:kNotificationCloseButtonTag]);
146 DCHECK([notificationData_ objectForKey:kNotificationSettingsButtonTag]);
147 DCHECK([notificationData_ objectForKey:kNotificationOptionsButtonTag]);
148
134 [toast setValue:@YES forKey:@"_showsButtons"]; 149 [toast setValue:@YES forKey:@"_showsButtons"];
135 // A default close button label is provided by the platform but we 150 // A default close button label is provided by the platform but we
136 // explicitly override it in case the user decides to not 151 // explicitly override it in case the user decides to not
137 // use the OS language in Chrome. 152 // use the OS language in Chrome.
138 [toast setOtherButtonTitle:l10n_util::GetNSString( 153 [toast setOtherButtonTitle:[notificationData_
139 IDS_NOTIFICATION_BUTTON_CLOSE)]; 154 objectForKey:kNotificationCloseButtonTag]];
140 155
141 // Display the Settings button as the action button if there are either no 156 // Display the Settings button as the action button if there are either no
142 // developer-provided action buttons, or the alternate action menu is not 157 // developer-provided action buttons, or the alternate action menu is not
143 // available on this Mac version. This avoids needlessly showing the menu. 158 // available on this Mac version. This avoids needlessly showing the menu.
144 // TODO(miguelg): Extensions should not have a settings button. 159 // TODO(miguelg): Extensions should not have a settings button.
145 if (![notificationData_ objectForKey:kNotificationButtonOne] || 160 if (![notificationData_ objectForKey:kNotificationButtonOne] ||
146 ![toast respondsToSelector:@selector(_alwaysShowAlternateActionMenu)]) { 161 ![toast respondsToSelector:@selector(_alwaysShowAlternateActionMenu)]) {
147 [toast setActionButtonTitle:l10n_util::GetNSString( 162 [toast
148 IDS_NOTIFICATION_BUTTON_SETTINGS)]; 163 setActionButtonTitle:
164 [notificationData_ objectForKey:kNotificationSettingsButtonTag]];
149 } else { 165 } else {
150 // Otherwise show the alternate menu, then show the developer actions and 166 // Otherwise show the alternate menu, then show the developer actions and
151 // finally the settings one. 167 // finally the settings one.
152 DCHECK( 168 DCHECK(
153 [toast respondsToSelector:@selector(_alwaysShowAlternateActionMenu)]); 169 [toast respondsToSelector:@selector(_alwaysShowAlternateActionMenu)]);
154 DCHECK( 170 DCHECK(
155 [toast respondsToSelector:@selector(_alternateActionButtonTitles)]); 171 [toast respondsToSelector:@selector(_alternateActionButtonTitles)]);
156 [toast setActionButtonTitle:l10n_util::GetNSString( 172 [toast
157 IDS_NOTIFICATION_BUTTON_OPTIONS)]; 173 setActionButtonTitle:[notificationData_
174 objectForKey:kNotificationOptionsButtonTag]];
158 [toast setValue:@YES forKey:@"_alwaysShowAlternateActionMenu"]; 175 [toast setValue:@YES forKey:@"_alwaysShowAlternateActionMenu"];
159 176
160 NSMutableArray* buttons = [NSMutableArray arrayWithCapacity:3]; 177 NSMutableArray* buttons = [NSMutableArray arrayWithCapacity:3];
161 [buttons 178 [buttons
162 addObject:[notificationData_ objectForKey:kNotificationButtonOne]]; 179 addObject:[notificationData_ objectForKey:kNotificationButtonOne]];
163 if ([notificationData_ objectForKey:kNotificationButtonTwo]) { 180 if ([notificationData_ objectForKey:kNotificationButtonTwo]) {
164 [buttons 181 [buttons
165 addObject:[notificationData_ objectForKey:kNotificationButtonTwo]]; 182 addObject:[notificationData_ objectForKey:kNotificationButtonTwo]];
166 } 183 }
167 [buttons 184 [buttons addObject:[notificationData_
168 addObject:l10n_util::GetNSString(IDS_NOTIFICATION_BUTTON_SETTINGS)]; 185 objectForKey:kNotificationSettingsButtonTag]];
169 [toast setValue:buttons forKey:@"_alternateActionButtonTitles"]; 186 [toast setValue:buttons forKey:@"_alternateActionButtonTitles"];
170 } 187 }
171 } 188 }
172 189
173 // Tag 190 // Tag
174 if ([toast respondsToSelector:@selector(setIdentifier:)] && 191 if ([toast respondsToSelector:@selector(setIdentifier:)] &&
175 [notificationData_ objectForKey:kNotificationTag]) { 192 [notificationData_ objectForKey:kNotificationTag]) {
176 [toast setValue:[notificationData_ objectForKey:kNotificationTag] 193 [toast setValue:[notificationData_ objectForKey:kNotificationTag]
177 forKey:@"identifier"]; 194 forKey:@"identifier"];
178 } 195 }
(...skipping 26 matching lines...) Expand all
205 }; 222 };
206 223
207 return toast.autorelease(); 224 return toast.autorelease();
208 } 225 }
209 226
210 - (NSDictionary*)buildDictionary { 227 - (NSDictionary*)buildDictionary {
211 return [[notificationData_ copy] autorelease]; 228 return [[notificationData_ copy] autorelease];
212 } 229 }
213 230
214 @end 231 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698