diff --git a/widget/cocoa/OSXNotificationCenter.h b/widget/cocoa/OSXNotificationCenter.h index 3ae5df5b4487..f56ddd2762e7 100644 --- a/widget/cocoa/OSXNotificationCenter.h +++ b/widget/cocoa/OSXNotificationCenter.h @@ -25,13 +25,15 @@ 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(); diff --git a/widget/cocoa/OSXNotificationCenter.mm b/widget/cocoa/OSXNotificationCenter.mm index 54e51886f626..2fee40b40d63 100644 --- a/widget/cocoa/OSXNotificationCenter.mm +++ b/widget/cocoa/OSXNotificationCenter.mm @@ -218,7 +218,8 @@ OSXNotificationCenter::~OSXNotificationCenter() NS_OBJC_END_TRY_ABORT_BLOCK; } -NS_IMPL_ISUPPORTS(OSXNotificationCenter, nsIAlertsService, imgINotificationObserver, nsITimerCallback) +NS_IMPL_ISUPPORTS(OSXNotificationCenter, nsIAlertsService, nsITimerCallback, + imgINotificationObserver, nsIAlertsIconData) nsresult OSXNotificationCenter::Init() { @@ -255,6 +256,15 @@ OSXNotificationCenter::ShowAlertNotification(const nsAString & aImageUrl, const 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; @@ -348,6 +358,18 @@ OSXNotificationCenter::ShowAlert(nsIAlertNotification* aAlert, 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);