Chromium Code Reviews| 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> | |
|
Robert Sesek
2016/09/29 14:23:05
Do you need AppKit?
Miguel Garcia
2016/10/03 16:07:51
For NSImage
| |
| 6 #import <Foundation/Foundation.h> | |
|
Robert Sesek
2016/09/29 14:23:05
Foundation is already included in the .h.
Miguel Garcia
2016/10/03 16:07:51
Done.
| |
| 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; | |
|
Robert Sesek
2016/09/29 14:23:05
Remove forward decls.
Miguel Garcia
2016/10/03 16:07:51
Same as before, need to keep NSUserNotificationCen
| |
| 16 @class NSUserNotificationCenter; | |
| 17 | |
| 18 @implementation ServiceDelegate | |
| 19 | |
| 20 @synthesize connection = _connection; | |
|
Robert Sesek
2016/09/29 14:23:05
Use trailing underscores for ivar names.
Miguel Garcia
2016/10/03 16:07:51
Done.
| |
| 21 | |
| 22 - (instancetype)init { | |
| 23 if (self = [super init]) { | |
| 24 [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self]; | |
| 25 } | |
| 26 return self; | |
| 27 } | |
| 28 | |
|
Robert Sesek
2016/09/29 14:23:05
Should set the NSUserNotificationCenter to nil in
Miguel Garcia
2016/10/03 16:07:51
I assume you mean the delegate? If so done.
| |
| 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 |