Bug 1202933, Part 2 - Show the origin for OS X notifications. r=MattN,wchen

--HG--
extra : commitid : 6sBIPzwwtYv
extra : rebase_source : 0eeda028206841fe096c765832163f5f783aa5e7
This commit is contained in:
Kit Cambridge 2015-10-05 11:49:38 -07:00
parent e088390533
commit 3c04c0a85d

View File

@ -17,6 +17,7 @@
#include "nsCOMPtr.h"
#include "nsIObserver.h"
#include "nsIContentPolicy.h"
#include "nsAlertsUtils.h"
#include "imgRequestProxy.h"
using namespace mozilla;
@ -239,16 +240,21 @@ OSXNotificationCenter::ShowAlertNotification(const nsAString & aImageUrl, const
Class unClass = NSClassFromString(@"NSUserNotification");
id<FakeNSUserNotification> notification = [[unClass alloc] init];
notification.title = [NSString stringWithCharacters:(const unichar *)aAlertTitle.BeginReading()
length:aAlertTitle.Length()];
notification.informativeText = [NSString stringWithCharacters:(const unichar *)aAlertText.BeginReading()
length:aAlertText.Length()];
notification.title = nsCocoaUtils::ToNSString(aAlertTitle);
nsAutoString hostPort;
nsAlertsUtils::GetSourceHostPort(aPrincipal, hostPort);
if (!hostPort.IsEmpty()) {
notification.subtitle = nsCocoaUtils::ToNSString(hostPort);
}
notification.informativeText = nsCocoaUtils::ToNSString(aAlertText);
notification.soundName = NSUserNotificationDefaultSoundName;
notification.hasActionButton = NO;
// If this is not an application/extension alert, show additional actions dealing with permissions.
if (aPrincipal && !nsContentUtils::IsSystemOrExpandedPrincipal(aPrincipal)
&& !aPrincipal->GetIsNullPrincipal()) {
if (nsAlertsUtils::IsActionablePrincipal(aPrincipal)) {
nsCOMPtr<nsIStringBundleService> sbs = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
nsCOMPtr<nsIStringBundle> bundle;
nsresult rv = sbs->CreateBundle("chrome://alerts/locale/alert.properties", getter_AddRefs(bundle));
@ -272,7 +278,7 @@ OSXNotificationCenter::ShowAlertNotification(const nsAString & aImageUrl, const
forKey:@"_alternateActionButtonTitles"];
}
}
NSString *alertName = [NSString stringWithCharacters:(const unichar *)aAlertName.BeginReading() length:aAlertName.Length()];
NSString *alertName = nsCocoaUtils::ToNSString(aAlertName);
if (!alertName) {
return NS_ERROR_FAILURE;
}
@ -332,7 +338,7 @@ OSXNotificationCenter::CloseAlert(const nsAString& aAlertName,
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
NSString *alertName = [NSString stringWithCharacters:(const unichar *)aAlertName.BeginReading() length:aAlertName.Length()];
NSString *alertName = nsCocoaUtils::ToNSString(aAlertName);
CloseAlertCocoaString(alertName);
return NS_OK;