Bug 1208295 - Show an additional action on OS X notifications to open notification settings. r=mstange

--HG--
extra : commitid : 1LMiMvjWhST
extra : rebase_source : ae556b8e132e43b52eae947455eda288e53660a1
This commit is contained in:
Matthew Noorenberghe 2015-09-25 13:18:29 -07:00
parent 9736cd824c
commit d3537d6383
2 changed files with 11 additions and 3 deletions

View File

@ -9,3 +9,4 @@ 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. # 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 = actionButton.label =
webActions.disable.label = Disable notifications from this site webActions.disable.label = Disable notifications from this site
webActions.settings.label = Notification settings

View File

@ -139,7 +139,8 @@ enum {
namespace mozilla { namespace mozilla {
enum { enum {
OSXNotificationActionDisable = 0 OSXNotificationActionDisable = 0,
OSXNotificationActionSettings = 1,
}; };
class OSXNotificationInfo { class OSXNotificationInfo {
@ -253,13 +254,15 @@ OSXNotificationCenter::ShowAlertNotification(const nsAString & aImageUrl, const
nsCOMPtr<nsIStringBundle> bundle; nsCOMPtr<nsIStringBundle> bundle;
nsresult rv = sbs->CreateBundle("chrome://alerts/locale/alert.properties", getter_AddRefs(bundle)); nsresult rv = sbs->CreateBundle("chrome://alerts/locale/alert.properties", getter_AddRefs(bundle));
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
nsXPIDLString closeButtonTitle, actionButtonTitle, disableButtonTitle; nsXPIDLString closeButtonTitle, actionButtonTitle, disableButtonTitle, settingsButtonTitle;
bundle->GetStringFromName(NS_LITERAL_STRING("closeButton.title").get(), bundle->GetStringFromName(NS_LITERAL_STRING("closeButton.title").get(),
getter_Copies(closeButtonTitle)); getter_Copies(closeButtonTitle));
bundle->GetStringFromName(NS_LITERAL_STRING("actionButton.label").get(), bundle->GetStringFromName(NS_LITERAL_STRING("actionButton.label").get(),
getter_Copies(actionButtonTitle)); getter_Copies(actionButtonTitle));
bundle->GetStringFromName(NS_LITERAL_STRING("webActions.disable.label").get(), bundle->GetStringFromName(NS_LITERAL_STRING("webActions.disable.label").get(),
getter_Copies(disableButtonTitle)); getter_Copies(disableButtonTitle));
bundle->GetStringFromName(NS_LITERAL_STRING("webActions.settings.label").get(),
getter_Copies(settingsButtonTitle));
notification.hasActionButton = YES; notification.hasActionButton = YES;
notification.otherButtonTitle = nsCocoaUtils::ToNSString(closeButtonTitle); notification.otherButtonTitle = nsCocoaUtils::ToNSString(closeButtonTitle);
@ -267,7 +270,8 @@ OSXNotificationCenter::ShowAlertNotification(const nsAString & aImageUrl, const
[(NSObject*)notification setValue:@(YES) forKey:@"_showsButtons"]; [(NSObject*)notification setValue:@(YES) forKey:@"_showsButtons"];
[(NSObject*)notification setValue:@(YES) forKey:@"_alwaysShowAlternateActionMenu"]; [(NSObject*)notification setValue:@(YES) forKey:@"_alwaysShowAlternateActionMenu"];
[(NSObject*)notification setValue:@[ [(NSObject*)notification setValue:@[
nsCocoaUtils::ToNSString(disableButtonTitle) nsCocoaUtils::ToNSString(disableButtonTitle),
nsCocoaUtils::ToNSString(settingsButtonTitle)
] ]
forKey:@"_alternateActionButtonTitles"]; forKey:@"_alternateActionButtonTitles"];
} }
@ -394,6 +398,9 @@ OSXNotificationCenter::OnActivate(NSString *aAlertName,
case OSXNotificationActionDisable: case OSXNotificationActionDisable:
osxni->mObserver->Observe(nullptr, "alertdisablecallback", osxni->mCookie.get()); osxni->mObserver->Observe(nullptr, "alertdisablecallback", osxni->mCookie.get());
break; break;
case OSXNotificationActionSettings:
osxni->mObserver->Observe(nullptr, "alertsettingscallback", osxni->mCookie.get());
break;
default: default:
NS_WARNING("Unknown NSUserNotification additional action clicked"); NS_WARNING("Unknown NSUserNotification additional action clicked");
break; break;