Bug 1220337 - Don't show alternate notification actions on OS X 10.8. r=MattN a=ritu
authorKit Cambridge <kcambridge@mozilla.com>
Tue, 10 Nov 2015 11:23:13 -0800
changeset 305508 ef1e3a6411d78479e399c5b449c3df9822120594
parent 305507 b50c13a2d7bb3347656485d2f67fa05f789a4c42
child 305509 6f3bd4c434bd4bb23176e1a4717d18b79da06920
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, ritu
bugs1220337
milestone44.0a2
Bug 1220337 - Don't show alternate notification actions on OS X 10.8. r=MattN a=ritu
widget/cocoa/OSXNotificationCenter.mm
--- a/widget/cocoa/OSXNotificationCenter.mm
+++ b/widget/cocoa/OSXNotificationCenter.mm
@@ -99,20 +99,24 @@ enum {
         didDeliverNotification:(id<FakeNSUserNotification>)notification
 {
 
 }
 
 - (void)userNotificationCenter:(id<FakeNSUserNotificationCenter>)center
        didActivateNotification:(id<FakeNSUserNotification>)notification
 {
-  NSNumber *alternateActionIndex = [(NSObject*)notification valueForKey:@"_alternateActionIndex"];
+  unsigned long long additionalActionIndex = ULLONG_MAX;
+  if ([notification respondsToSelector:@selector(get_alternateActionIndex:)]) {
+    NSNumber *alternateActionIndex = [(NSObject*)notification valueForKey:@"_alternateActionIndex"];
+    additionalActionIndex = [alternateActionIndex unsignedLongLongValue];
+  }
   mOSXNC->OnActivate([[notification userInfo] valueForKey:@"name"],
                      notification.activationType,
-                     [alternateActionIndex unsignedLongLongValue]);
+                     additionalActionIndex);
 }
 
 - (BOOL)userNotificationCenter:(id<FakeNSUserNotificationCenter>)center
      shouldPresentNotification:(id<FakeNSUserNotification>)notification
 {
   return YES;
 }
 
@@ -276,26 +280,36 @@ OSXNotificationCenter::ShowAlertNotifica
         bundle->FormatStringFromName(MOZ_UTF16("webActions.disableForOrigin.label"),
                                      formatStrings,
                                      ArrayLength(formatStrings),
                                      getter_Copies(disableButtonTitle));
       }
       bundle->GetStringFromName(MOZ_UTF16("webActions.settings.label"),
                                 getter_Copies(settingsButtonTitle));
 
-      notification.hasActionButton = YES;
       notification.otherButtonTitle = nsCocoaUtils::ToNSString(closeButtonTitle);
-      notification.actionButtonTitle = nsCocoaUtils::ToNSString(actionButtonTitle);
-      [(NSObject*)notification setValue:@(YES) forKey:@"_showsButtons"];
-      [(NSObject*)notification setValue:@(YES) forKey:@"_alwaysShowAlternateActionMenu"];
-      [(NSObject*)notification setValue:@[
-                                          nsCocoaUtils::ToNSString(disableButtonTitle),
-                                          nsCocoaUtils::ToNSString(settingsButtonTitle)
-                                          ]
-                               forKey:@"_alternateActionButtonTitles"];
+
+      // OS X 10.8 only shows action buttons if the "Alerts" style is set in
+      // Notification Center preferences, and doesn't support the alternate
+      // action menu.
+      if ([notification respondsToSelector:@selector(set_showsButtons:)] &&
+          [notification respondsToSelector:@selector(set_alwaysShowAlternateActionMenu:)] &&
+          [notification respondsToSelector:@selector(set_alternateActionButtonTitles:)]) {
+
+        notification.hasActionButton = YES;
+        notification.actionButtonTitle = nsCocoaUtils::ToNSString(actionButtonTitle);
+
+        [(NSObject*)notification setValue:@(YES) forKey:@"_showsButtons"];
+        [(NSObject*)notification setValue:@(YES) forKey:@"_alwaysShowAlternateActionMenu"];
+        [(NSObject*)notification setValue:@[
+                                            nsCocoaUtils::ToNSString(disableButtonTitle),
+                                            nsCocoaUtils::ToNSString(settingsButtonTitle)
+                                            ]
+                                 forKey:@"_alternateActionButtonTitles"];
+      }
     }
   }
   NSString *alertName = nsCocoaUtils::ToNSString(aAlertName);
   if (!alertName) {
     return NS_ERROR_FAILURE;
   }
   notification.userInfo = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:alertName, nil]
                                                       forKeys:[NSArray arrayWithObjects:@"name", nil]];