Bug 1202933, Part 2 - Show the origin for OS X notifications. r=MattN,wchen
☠☠ backed out by a1736287f404 ☠ ☠
authorKit Cambridge <kcambridge@mozilla.com>
Mon, 05 Oct 2015 11:49:38 -0700
changeset 266195 fbcc1bb170e9b8d108ee02b30643b48e76f49db1
parent 266194 1763e148406574a02a516e199a820f7a33297e3d
child 266196 c87ce743e34eb2bcd586b30d2cdc935882186ed2
push id15532
push usercbook@mozilla.com
push dateTue, 06 Oct 2015 10:23:06 +0000
treeherderfx-team@7603d2860165 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, wchen
bugs1202933
milestone44.0a1
Bug 1202933, Part 2 - Show the origin for OS X notifications. r=MattN,wchen
widget/cocoa/OSXNotificationCenter.mm
--- a/widget/cocoa/OSXNotificationCenter.mm
+++ b/widget/cocoa/OSXNotificationCenter.mm
@@ -12,16 +12,17 @@
 #include "imgLoader.h"
 #import "nsCocoaUtils.h"
 #include "nsContentUtils.h"
 #include "nsObjCExceptions.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsIObserver.h"
 #include "nsIContentPolicy.h"
+#include "nsAlertsUtils.h"
 #include "imgRequestProxy.h"
 
 using namespace mozilla;
 
 #if !defined(MAC_OS_X_VERSION_10_8) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8)
 @protocol NSUserNotificationCenterDelegate
 @end
 static NSString * const NSUserNotificationDefaultSoundName = @"DefaultSoundName";
@@ -234,26 +235,31 @@ OSXNotificationCenter::ShowAlertNotifica
                                              const nsAString & aData,
                                              nsIPrincipal * aPrincipal,
                                              bool aInPrivateBrowsing)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   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));
     if (NS_SUCCEEDED(rv)) {
       nsXPIDLString closeButtonTitle, actionButtonTitle, disableButtonTitle;
       bundle->GetStringFromName(NS_LITERAL_STRING("closeButton.title").get(),
                                 getter_Copies(closeButtonTitle));
       bundle->GetStringFromName(NS_LITERAL_STRING("actionButton.label").get(),
@@ -267,17 +273,17 @@ OSXNotificationCenter::ShowAlertNotifica
       [(NSObject*)notification setValue:@(YES) forKey:@"_showsButtons"];
       [(NSObject*)notification setValue:@(YES) forKey:@"_alwaysShowAlternateActionMenu"];
       [(NSObject*)notification setValue:@[
                                           nsCocoaUtils::ToNSString(disableButtonTitle)
                                           ]
                                forKey:@"_alternateActionButtonTitles"];
     }
   }
-  NSString *alertName = [NSString stringWithCharacters:(const unichar *)aAlertName.BeginReading() length:aAlertName.Length()];
+  NSString *alertName = nsCocoaUtils::ToNSString(aAlertName);
   if (!alertName) {
     return NS_ERROR_FAILURE;
   }
   notification.userInfo = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:alertName, nil]
                                                       forKeys:[NSArray arrayWithObjects:@"name", nil]];
 
   OSXNotificationInfo *osxni = new OSXNotificationInfo(alertName, aAlertListener, aAlertCookie);
 
@@ -327,17 +333,17 @@ OSXNotificationCenter::ShowAlertNotifica
 }
 
 NS_IMETHODIMP
 OSXNotificationCenter::CloseAlert(const nsAString& aAlertName,
                                   nsIPrincipal* aPrincipal)
 {
   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;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 void
 OSXNotificationCenter::CloseAlertCocoaString(NSString *aAlertName)