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

--HG--
extra : commitid : BP0mSNiIk4X
extra : rebase_source : 48aeb880868927f3df1310de70645e1e943b3d55
This commit is contained in:
Matthew Noorenberghe 2015-09-25 13:18:29 -07:00
parent 1db1a07bb8
commit 57a6416a3c
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.
actionButton.label =
webActions.disable.label = Disable notifications from this site
webActions.settings.label = Notification settings

View File

@ -139,7 +139,8 @@ enum {
namespace mozilla {
enum {
OSXNotificationActionDisable = 0
OSXNotificationActionDisable = 0,
OSXNotificationActionSettings = 1,
};
class OSXNotificationInfo {
@ -253,13 +254,15 @@ OSXNotificationCenter::ShowAlertNotification(const nsAString & aImageUrl, const
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);
@ -267,7 +270,8 @@ OSXNotificationCenter::ShowAlertNotification(const nsAString & aImageUrl, const
[(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"];
}
@ -394,6 +398,9 @@ OSXNotificationCenter::OnActivate(NSString *aAlertName,
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;