OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <AppKit/AppKit.h> |
| 6 #import <Foundation/Foundation.h> |
| 7 |
| 8 #import "chrome/browser/ui/cocoa/notifications/notification_service_delegate.h" |
| 9 |
| 10 #include "base/mac/scoped_nsobject.h" |
| 11 #import "chrome/browser/ui/cocoa/notifications/alert_notification_service.h" |
| 12 #import "chrome/browser/ui/cocoa/notifications/notification_delivery.h" |
| 13 #import "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac
.h" |
| 14 |
| 15 @class NSUserNotification; |
| 16 @class NSUserNotificationCenter; |
| 17 |
| 18 @implementation ServiceDelegate |
| 19 |
| 20 @synthesize connection = _connection; |
| 21 |
| 22 - (instancetype)init { |
| 23 if (self = [super init]) { |
| 24 [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self]; |
| 25 } |
| 26 return self; |
| 27 } |
| 28 |
| 29 - (BOOL)listener:(NSXPCListener*)listener |
| 30 shouldAcceptNewConnection:(NSXPCConnection*)newConnection { |
| 31 newConnection.exportedInterface = |
| 32 [NSXPCInterface interfaceWithProtocol:@protocol(NotificationDelivery)]; |
| 33 [newConnection.exportedInterface |
| 34 setClasses:[NSSet setWithObjects:[NSDictionary class], [NSImage class], |
| 35 [NSNumber class], [NSString class], |
| 36 nil] |
| 37 forSelector:@selector(deliverNotification:) |
| 38 argumentIndex:0 |
| 39 ofReply:NO]; |
| 40 |
| 41 base::scoped_nsobject<AlertNotificationService> object( |
| 42 [[AlertNotificationService alloc] init]); |
| 43 newConnection.exportedObject = object.get(); |
| 44 newConnection.remoteObjectInterface = |
| 45 [NSXPCInterface interfaceWithProtocol:@protocol(NotificationReply)]; |
| 46 _connection = newConnection; |
| 47 [newConnection resume]; |
| 48 |
| 49 return YES; |
| 50 } |
| 51 |
| 52 // NSUserNotification center delegate |
| 53 - (void)userNotificationCenter:(NSUserNotificationCenter*)center |
| 54 didActivateNotification:(NSUserNotification*)notification { |
| 55 NSDictionary* response = |
| 56 [NotificationResponseBuilder buildDictionary:notification]; |
| 57 [[_connection remoteObjectProxy] notificationClick:response]; |
| 58 } |
| 59 |
| 60 @end |
OLD | NEW |