- add sources.
[platform/framework/web/crosswalk.git] / src / remoting / host / installer / mac / uninstaller / remoting_uninstaller_app.mm
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.
4
5 #include "remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "base/mac/scoped_cftyperef.h"
10 #include "remoting/host/installer/mac/uninstaller/remoting_uninstaller.h"
11
12 @implementation RemotingUninstallerAppDelegate
13
14 - (void)dealloc {
15   [super dealloc];
16 }
17
18 - (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
19 }
20
21 - (void)showSuccess:(bool)success withMessage:(NSString*) message {
22   NSString* summary = success ? @"Uninstall succeeded" : @"Uninstall failed";
23   NSAlert* alert = [NSAlert alertWithMessageText:summary
24                                    defaultButton:@"OK"
25                                  alternateButton:nil
26                                      otherButton:nil
27                        informativeTextWithFormat:@"%@", message];
28   [alert setAlertStyle:
29        (success ? NSInformationalAlertStyle : NSCriticalAlertStyle)];
30   [alert runModal];
31 }
32
33 - (IBAction)uninstall:(NSButton*)sender {
34   @try {
35     NSLog(@"Chrome Remote Desktop uninstall starting.");
36
37     RemotingUninstaller* uninstaller =
38         [[[RemotingUninstaller alloc] init] autorelease];
39     OSStatus status = [uninstaller remotingUninstall];
40
41     NSLog(@"Chrome Remote Desktop Host uninstall complete.");
42
43     bool success = false;
44     NSString* message = NULL;
45     if (status == errAuthorizationSuccess) {
46       success = true;
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.";
52     } else {
53       [NSException raise:@"AuthorizationCopyRights Failure"
54                   format:@"Error during AuthorizationCopyRights status=%d",
55                              static_cast<int>(status)];
56     }
57     if (message != NULL) {
58       NSLog(@"Uninstall %s: %@", success ? "succeeded" : "failed", message);
59       [self showSuccess:success withMessage:message];
60     }
61   }
62   @catch (NSException* exception) {
63     NSLog(@"Exception %@ %@", [exception name], [exception reason]);
64     NSString* message =
65         @"Error! Unable to uninstall Chrome Remote Desktop Host.";
66     [self showSuccess:false withMessage:message];
67   }
68
69   [NSApp terminate:self];
70 }
71
72 - (IBAction)cancel:(id)sender {
73   [NSApp terminate:self];
74 }
75
76 - (IBAction)handleMenuClose:(NSMenuItem*)sender {
77   [NSApp terminate:self];
78 }
79
80 @end
81
82 int main(int argc, char* argv[])
83 {
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")) {
88     @autoreleasepool {
89       NSLog(@"Chrome Remote Desktop uninstall starting.");
90       NSLog(@"--no-ui : Suppressing UI");
91
92       RemotingUninstaller* uninstaller =
93           [[[RemotingUninstaller alloc] init] autorelease];
94       OSStatus status = [uninstaller remotingUninstall];
95
96       NSLog(@"Chrome Remote Desktop Host uninstall complete.");
97       NSLog(@"Status = %d", static_cast<int>(status));
98       return status != errAuthorizationSuccess;
99     }
100   } else {
101     return NSApplicationMain(argc, (const char**)argv);
102   }
103 }
104