1 // Copyright (c) 2012 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.
5 #include "remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.h"
7 #import <Cocoa/Cocoa.h>
9 #include "base/mac/scoped_cftyperef.h"
10 #include "remoting/host/installer/mac/uninstaller/remoting_uninstaller.h"
12 @implementation RemotingUninstallerAppDelegate
18 - (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
21 - (void)showSuccess:(bool)success withMessage:(NSString*) message {
22 NSString* summary = success ? @"Uninstall succeeded" : @"Uninstall failed";
23 NSAlert* alert = [NSAlert alertWithMessageText:summary
27 informativeTextWithFormat:@"%@", message];
29 (success ? NSInformationalAlertStyle : NSCriticalAlertStyle)];
33 - (IBAction)uninstall:(NSButton*)sender {
35 NSLog(@"Chrome Remote Desktop uninstall starting.");
37 RemotingUninstaller* uninstaller =
38 [[[RemotingUninstaller alloc] init] autorelease];
39 OSStatus status = [uninstaller remotingUninstall];
41 NSLog(@"Chrome Remote Desktop Host uninstall complete.");
44 NSString* message = NULL;
45 if (status == errAuthorizationSuccess) {
47 message = @"Chrome Remote Desktop Host successfully uninstalled.";
48 } else if (status == errAuthorizationCanceled) {
49 message = @"Chrome Remote Desktop Host uninstall canceled.";
50 } else if (status == errAuthorizationDenied) {
51 message = @"Chrome Remote Desktop Host uninstall authorization denied.";
53 [NSException raise:@"AuthorizationCopyRights Failure"
54 format:@"Error during AuthorizationCopyRights status=%d",
55 static_cast<int>(status)];
57 if (message != NULL) {
58 NSLog(@"Uninstall %s: %@", success ? "succeeded" : "failed", message);
59 [self showSuccess:success withMessage:message];
62 @catch (NSException* exception) {
63 NSLog(@"Exception %@ %@", [exception name], [exception reason]);
65 @"Error! Unable to uninstall Chrome Remote Desktop Host.";
66 [self showSuccess:false withMessage:message];
69 [NSApp terminate:self];
72 - (IBAction)cancel:(id)sender {
73 [NSApp terminate:self];
76 - (IBAction)handleMenuClose:(NSMenuItem*)sender {
77 [NSApp terminate:self];
82 int main(int argc, char* argv[])
84 // The no-ui option skips the UI confirmation dialogs. This is provided as
85 // a convenience for our automated testing.
86 // There will still be an elevation prompt unless the command is run as root.
87 if (argc == 2 && !strcmp(argv[1], "--no-ui")) {
89 NSLog(@"Chrome Remote Desktop uninstall starting.");
90 NSLog(@"--no-ui : Suppressing UI");
92 RemotingUninstaller* uninstaller =
93 [[[RemotingUninstaller alloc] init] autorelease];
94 OSStatus status = [uninstaller remotingUninstall];
96 NSLog(@"Chrome Remote Desktop Host uninstall complete.");
97 NSLog(@"Status = %d", static_cast<int>(status));
98 return status != errAuthorizationSuccess;
101 return NSApplicationMain(argc, (const char**)argv);