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

Unified Diff: chrome/browser/ui/cocoa/notifications/notification_builder_mac.mm

Issue 2799343003: Add support for native extension notifications (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/notifications/notification_builder_mac.mm
diff --git a/chrome/browser/ui/cocoa/notifications/notification_builder_mac.mm b/chrome/browser/ui/cocoa/notifications/notification_builder_mac.mm
index e1c8a25813189eae6bc54a6fdd7f4aa34b0e3569..89d2738a55704acf3266dd496f28af1b1652d939 100644
--- a/chrome/browser/ui/cocoa/notifications/notification_builder_mac.mm
+++ b/chrome/browser/ui/cocoa/notifications/notification_builder_mac.mm
@@ -26,6 +26,10 @@ NSString* const kNotificationTag = @"tag";
NSString* const kNotificationCloseButtonTag = @"closeButton";
NSString* const kNotificationOptionsButtonTag = @"optionsButton";
NSString* const kNotificationSettingsButtonTag = @"settingsButton";
+
+// From NotificationCommon#Type hard coded in order to not
+// pull in the enum into the XPC library.
+const int kExtensionType = 2;
} // namespace
@implementation NotificationBuilder {
@@ -142,6 +146,10 @@ NSString* const kNotificationSettingsButtonTag = @"settingsButton";
}
}
+ // Type (needed to define the buttons)
+ NSNumber* type = [notificationData_
+ objectForKey:notification_constants::kNotificationType];
+
// Buttons
if ([toast respondsToSelector:@selector(_showsButtons)]) {
DCHECK([notificationData_ objectForKey:kNotificationCloseButtonTag]);
@@ -155,18 +163,25 @@ NSString* const kNotificationSettingsButtonTag = @"settingsButton";
[toast setOtherButtonTitle:[notificationData_
objectForKey:kNotificationCloseButtonTag]];
+ // Extensions don't have a settings button.
+ BOOL showSettingsButton = (type.unsignedIntegerValue != kExtensionType);
Peter Beverloo 2017/04/07 02:26:53 Could we just give the notificationData_ dictionar
Miguel Garcia 2017/04/07 13:32:07 Yes, in fact we need to store the fact so the resp
+
// Display the Settings button as the action button if there are either no
// developer-provided action buttons, or the alternate action menu is not
// available on this Mac version. This avoids needlessly showing the menu.
- // TODO(miguelg): Extensions should not have a settings button.
if (![notificationData_ objectForKey:kNotificationButtonOne] ||
![toast respondsToSelector:@selector(_alwaysShowAlternateActionMenu)]) {
- [toast
- setActionButtonTitle:
- [notificationData_ objectForKey:kNotificationSettingsButtonTag]];
+ if (showSettingsButton) {
+ [toast setActionButtonTitle:
+ [notificationData_
+ objectForKey:kNotificationSettingsButtonTag]];
+ } else {
+ [toast setHasActionButton:NO];
+ }
+
} else {
// Otherwise show the alternate menu, then show the developer actions and
- // finally the settings one.
+ // finally the settings one if needed.
DCHECK(
[toast respondsToSelector:@selector(_alwaysShowAlternateActionMenu)]);
DCHECK(
@@ -183,8 +198,11 @@ NSString* const kNotificationSettingsButtonTag = @"settingsButton";
[buttons
addObject:[notificationData_ objectForKey:kNotificationButtonTwo]];
}
- [buttons addObject:[notificationData_
- objectForKey:kNotificationSettingsButtonTag]];
+ if (showSettingsButton) {
+ [buttons addObject:[notificationData_
+ objectForKey:kNotificationSettingsButtonTag]];
+ }
+
[toast setValue:buttons forKey:@"_alternateActionButtonTitles"];
}
}
@@ -216,8 +234,6 @@ NSString* const kNotificationSettingsButtonTag = @"settingsButton";
objectForKey:notification_constants::kNotificationIncognito]);
NSNumber* incognito = [notificationData_
objectForKey:notification_constants::kNotificationIncognito];
- NSNumber* type = [notificationData_
- objectForKey:notification_constants::kNotificationType];
toast.get().userInfo = @{
notification_constants::kNotificationOrigin : origin,

Powered by Google App Engine
This is Rietveld 408576698