Bug 1208295 - Show an additional action on OS X notifications to open notification settings. r=mstange
☠☠ backed out by e34f9feccd3f ☠ ☠
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 25 Sep 2015 13:18:29 -0700
changeset 264696 3242ff9a86bbc2f01836a02fbf6ddd5bd846ab65
parent 264695 04f2a2c320a39859720caf16a7f5b5de836ab997
child 264697 1c16e9f4aa2ff3bae05243941adab5620365e4de
push id65707
push usercbook@mozilla.com
push dateMon, 28 Sep 2015 12:18:34 +0000
treeherdermozilla-inbound@2c0e60a8f736 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1208295
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1208295 - Show an additional action on OS X notifications to open notification settings. r=mstange
toolkit/locales/en-US/chrome/alerts/alert.properties
widget/cocoa/OSXNotificationCenter.mm
--- a/toolkit/locales/en-US/chrome/alerts/alert.properties
+++ b/toolkit/locales/en-US/chrome/alerts/alert.properties
@@ -4,8 +4,9 @@
 
 # LOCALIZATION NOTE(closeButton.title): Used as the close button text for web notifications on OS X.
 # This should ideally match the string that OS X uses for the close button on alert-type
 # notifications. OS X will truncate the value if it's too long.
 closeButton.title = Close
 # LOCALIZATION NOTE(actionButton.label): Used as the button label to provide more actions on OS X notifications. OS X will truncate this if it's too long.
 actionButton.label = …
 webActions.disable.label = Disable notifications from this site
+webActions.settings.label = Notification settings
--- a/widget/cocoa/OSXNotificationCenter.mm
+++ b/widget/cocoa/OSXNotificationCenter.mm
@@ -134,17 +134,18 @@ enum {
   mOSXNC->CloseAlertCocoaString(name);
 }
 
 @end
 
 namespace mozilla {
 
 enum {
-  OSXNotificationActionDisable = 0
+  OSXNotificationActionDisable = 0,
+  OSXNotificationActionSettings = 1,
 };
 
 class OSXNotificationInfo {
 private:
   ~OSXNotificationInfo();
 
 public:
   NS_INLINE_DECL_REFCOUNTING(OSXNotificationInfo)
@@ -248,31 +249,34 @@ OSXNotificationCenter::ShowAlertNotifica
 
   // If this is not an application/extension alert, show additional actions dealing with permissions.
   if (!nsContentUtils::IsSystemOrExpandedPrincipal(aPrincipal)
       && !aPrincipal->GetIsNullPrincipal()) {
     nsCOMPtr<nsIStringBundleService> sbs = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
     nsCOMPtr<nsIStringBundle> bundle;
     nsresult rv = sbs->CreateBundle("chrome://alerts/locale/alert.properties", getter_AddRefs(bundle));
     if (NS_SUCCEEDED(rv)) {
-      nsXPIDLString closeButtonTitle, actionButtonTitle, disableButtonTitle;
+      nsXPIDLString closeButtonTitle, actionButtonTitle, disableButtonTitle, settingsButtonTitle;
       bundle->GetStringFromName(NS_LITERAL_STRING("closeButton.title").get(),
                                 getter_Copies(closeButtonTitle));
       bundle->GetStringFromName(NS_LITERAL_STRING("actionButton.label").get(),
                                 getter_Copies(actionButtonTitle));
       bundle->GetStringFromName(NS_LITERAL_STRING("webActions.disable.label").get(),
                                 getter_Copies(disableButtonTitle));
+      bundle->GetStringFromName(NS_LITERAL_STRING("webActions.settings.label").get(),
+                                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(disableButtonTitle),
+                                          nsCocoaUtils::ToNSString(settingsButtonTitle)
                                           ]
                                forKey:@"_alternateActionButtonTitles"];
     }
   }
   NSString *alertName = [NSString stringWithCharacters:(const unichar *)aAlertName.BeginReading() length:aAlertName.Length()];
   if (!alertName) {
     return NS_ERROR_FAILURE;
   }
@@ -389,16 +393,19 @@ OSXNotificationCenter::OnActivate(NSStri
       if (osxni->mObserver) {
         switch (aActivationType) {
           case NSUserNotificationActivationTypeAdditionalActionClicked:
           case NSUserNotificationActivationTypeActionButtonClicked:
             switch (aAdditionalActionIndex) {
               case OSXNotificationActionDisable:
                 osxni->mObserver->Observe(nullptr, "alertdisablecallback", osxni->mCookie.get());
                 break;
+              case OSXNotificationActionSettings:
+                osxni->mObserver->Observe(nullptr, "alertsettingscallback", osxni->mCookie.get());
+                break;
               default:
                 NS_WARNING("Unknown NSUserNotification additional action clicked");
                 break;
             }
             break;
           default:
             osxni->mObserver->Observe(nullptr, "alertclickcallback", osxni->mCookie.get());
             break;