Bug 1224785, Part 2 - Show the site favicon in OS X notifications. r=mstange
authorKit Cambridge <kcambridge@mozilla.com>
Thu, 07 Jan 2016 13:16:54 -0700
changeset 284520 0457ade4bd4bd6e13594c9f89c5c4f1a83d85795
parent 284519 d5b329a9cd6bf24394d62a489991362d16973276
child 284521 4357fe5a9d22822ffbc5d15246c7df34a484816f
push id71993
push usercbook@mozilla.com
push dateWed, 17 Feb 2016 11:16:29 +0000
treeherdermozilla-inbound@60f020c84b23 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1224785
milestone47.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 1224785, Part 2 - Show the site favicon in OS X notifications. r=mstange MozReview-Commit-ID: L7d00xEY6Ka
widget/cocoa/OSXNotificationCenter.h
widget/cocoa/OSXNotificationCenter.mm
--- a/widget/cocoa/OSXNotificationCenter.h
+++ b/widget/cocoa/OSXNotificationCenter.h
@@ -20,23 +20,25 @@ typedef NSInteger NSUserNotificationActi
 #endif
 
 namespace mozilla {
 
 class OSXNotificationInfo;
 
 class OSXNotificationCenter : public nsIAlertsService,
                               public imgINotificationObserver,
-                              public nsITimerCallback
+                              public nsITimerCallback,
+                              public nsIAlertsIconData
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIALERTSSERVICE
   NS_DECL_IMGINOTIFICATIONOBSERVER
   NS_DECL_NSITIMERCALLBACK
+  NS_DECL_NSIALERTSICONDATA
 
   OSXNotificationCenter();
 
   nsresult Init();
   void CloseAlertCocoaString(NSString *aAlertName);
   void OnActivate(NSString *aAlertName, NSUserNotificationActivationType aActivationType,
                   unsigned long long aAdditionalActionIndex);
   void ShowPendingNotification(OSXNotificationInfo *osxni);
--- a/widget/cocoa/OSXNotificationCenter.mm
+++ b/widget/cocoa/OSXNotificationCenter.mm
@@ -213,17 +213,18 @@ OSXNotificationCenter::~OSXNotificationC
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   [GetNotificationCenter() removeAllDeliveredNotifications];
   [mDelegate release];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
-NS_IMPL_ISUPPORTS(OSXNotificationCenter, nsIAlertsService, imgINotificationObserver, nsITimerCallback)
+NS_IMPL_ISUPPORTS(OSXNotificationCenter, nsIAlertsService, nsITimerCallback,
+                  imgINotificationObserver, nsIAlertsIconData)
 
 nsresult OSXNotificationCenter::Init()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   return (!!NSClassFromString(@"NSUserNotification")) ? NS_OK : NS_ERROR_FAILURE;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
@@ -251,16 +252,25 @@ OSXNotificationCenter::ShowAlertNotifica
   NS_ENSURE_SUCCESS(rv, rv);
   return ShowAlert(alert, aAlertListener);
 }
 
 NS_IMETHODIMP
 OSXNotificationCenter::ShowAlert(nsIAlertNotification* aAlert,
                                  nsIObserver* aAlertListener)
 {
+  return ShowAlertWithIconData(aAlert, aAlertListener, 0, nullptr);
+}
+
+NS_IMETHODIMP
+OSXNotificationCenter::ShowAlertWithIconData(nsIAlertNotification* aAlert,
+                                             nsIObserver* aAlertListener,
+                                             uint32_t aIconSize,
+                                             const uint8_t* aIconData)
+{
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   NS_ENSURE_ARG(aAlert);
 
   Class unClass = NSClassFromString(@"NSUserNotification");
   id<FakeNSUserNotification> notification = [[unClass alloc] init];
 
   nsAutoString title;
@@ -343,16 +353,28 @@ OSXNotificationCenter::ShowAlert(nsIAler
                                                       forKeys:[NSArray arrayWithObjects:@"name", nil]];
 
   nsAutoString cookie;
   rv = aAlert->GetCookie(cookie);
   NS_ENSURE_SUCCESS(rv, rv);
 
   OSXNotificationInfo *osxni = new OSXNotificationInfo(alertName, aAlertListener, cookie);
 
+  // Show the favicon if supported on this version of OS X.
+  if (aIconSize > 0 &&
+      [notification respondsToSelector:@selector(set_identityImage:)] &&
+      [notification respondsToSelector:@selector(set_identityImageHasBorder:)]) {
+
+    NSData *iconData = [NSData dataWithBytes:aIconData length:aIconSize];
+    NSImage *icon = [[[NSImage alloc] initWithData:iconData] autorelease];
+
+    [(NSObject*)notification setValue:icon forKey:@"_identityImage"];
+    [(NSObject*)notification setValue:@(NO) forKey:@"_identityImageHasBorder"];
+  }
+
   nsAutoString imageUrl;
   rv = aAlert->GetImageURL(imageUrl);
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool inPrivateBrowsing;
   rv = aAlert->GetInPrivateBrowsing(&inPrivateBrowsing);
   NS_ENSURE_SUCCESS(rv, rv);