| 
									
										
										
										
											2013-03-28 18:03:58 -04:00
										 |  |  | #import "browser/notification_presenter_mac.h" | 
					
						
							| 
									
										
										
										
											2013-03-28 17:17:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | #import "base/strings/sys_string_conversions.h" | 
					
						
							| 
									
										
										
										
											2013-03-28 17:20:06 -04:00
										 |  |  | #import "content/public/browser/render_view_host.h" | 
					
						
							| 
									
										
										
										
											2013-03-28 17:17:46 -04:00
										 |  |  | #import "content/public/common/show_desktop_notification_params.h" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #import <Foundation/Foundation.h> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-28 18:08:34 -04:00
										 |  |  | @interface BRYUserNotificationCenterDelegate : NSObject <NSUserNotificationCenterDelegate> | 
					
						
							|  |  |  | @end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-28 17:17:46 -04:00
										 |  |  | namespace brightray { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-28 18:03:58 -04:00
										 |  |  | NotificationPresenter* NotificationPresenter::Create() { | 
					
						
							|  |  |  |   return new NotificationPresenterMac; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-28 18:08:34 -04:00
										 |  |  | NotificationPresenterMac::NotificationPresenterMac() | 
					
						
							|  |  |  |     : delegate_([[BRYUserNotificationCenterDelegate alloc] init]) { | 
					
						
							|  |  |  |   NSUserNotificationCenter.defaultUserNotificationCenter.delegate = delegate_; | 
					
						
							| 
									
										
										
										
											2013-03-28 18:03:58 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NotificationPresenterMac::~NotificationPresenterMac() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NotificationPresenterMac::ShowNotification( | 
					
						
							| 
									
										
										
										
											2013-03-28 17:17:46 -04:00
										 |  |  |     const content::ShowDesktopNotificationHostMsgParams& params, | 
					
						
							|  |  |  |     int render_process_id, | 
					
						
							| 
									
										
										
										
											2013-03-28 17:49:29 -04:00
										 |  |  |     int render_view_id) { | 
					
						
							| 
									
										
										
										
											2013-03-28 17:17:46 -04:00
										 |  |  |   auto notification = [[NSUserNotification alloc] init]; | 
					
						
							|  |  |  |   notification.title = base::SysUTF16ToNSString(params.title); | 
					
						
							|  |  |  |   notification.informativeText = base::SysUTF16ToNSString(params.body); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; | 
					
						
							|  |  |  |   [notification release]; | 
					
						
							| 
									
										
										
										
											2013-03-28 17:20:06 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); | 
					
						
							|  |  |  |   if (!host) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   host->DesktopNotificationPostDisplay(params.notification_id); | 
					
						
							| 
									
										
										
										
											2013-03-28 17:17:46 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-03-28 18:08:34 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | @implementation BRYUserNotificationCenterDelegate | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification { | 
					
						
							|  |  |  |   // Display notifications even if the app is active. | 
					
						
							|  |  |  |   return YES; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @end |