| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "AppDelegate.h" | 5 #import "AppDelegate.h" |
| 6 | 6 |
| 7 #include <Security/Security.h> | 7 #include <Security/Security.h> |
| 8 | 8 |
| 9 #import "Downloader.h" | 9 #import "Downloader.h" |
| 10 #import "InstallerWindowController.h" | 10 #import "InstallerWindowController.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 // Bridge method from Downloader to InstallerWindowController. Allows Downloader | 110 // Bridge method from Downloader to InstallerWindowController. Allows Downloader |
| 111 // to update the progressbar without having direct access to any UI obejcts. | 111 // to update the progressbar without having direct access to any UI obejcts. |
| 112 - (void)downloader:(Downloader*)download percentProgress:(double)percentage { | 112 - (void)downloader:(Downloader*)download percentProgress:(double)percentage { |
| 113 [installerWindowController_ updateDownloadProgress:(double)percentage]; | 113 [installerWindowController_ updateDownloadProgress:(double)percentage]; |
| 114 } | 114 } |
| 115 | 115 |
| 116 - (void)downloader:(Downloader*)download onSuccess:(NSURL*)diskImageURL { | 116 - (void)downloader:(Downloader*)download onSuccess:(NSURL*)diskImageURL { |
| 117 [installerWindowController_ updateStatusDescription:@"Installing..."]; | 117 [installerWindowController_ updateStatusDescription:@"Installing..."]; |
| 118 [installerWindowController_ enableLaunchButton]; | 118 [installerWindowController_ enableLaunchButton]; |
| 119 // TODO: Add unpacking step here and pass the path to the app bundle inside | |
| 120 // the mounted disk image path to startInstall. Currently passing hardcoded | |
| 121 // path to preunpacked app bundle. | |
| 122 //[authorizedInstall_ | |
| 123 // startInstall:@"$HOME/Downloads/Google Chrome.app"]; | |
| 124 | 119 |
| 125 Unpacker* unpacker = [[Unpacker alloc] init]; | 120 Unpacker* unpacker = [[Unpacker alloc] init]; |
| 126 unpacker.delegate = self; | 121 unpacker.delegate = self; |
| 127 [unpacker mountDMGFromURL:diskImageURL]; | 122 [unpacker mountDMGFromURL:diskImageURL]; |
| 128 } | 123 } |
| 129 | 124 |
| 130 - (void)downloader:(Downloader*)download onFailure:(NSError*)error { | 125 - (void)downloader:(Downloader*)download onFailure:(NSError*)error { |
| 131 NSError* downloadError = | 126 NSError* downloadError = |
| 132 [NSError errorForAlerts:@"Download Failure" | 127 [NSError errorForAlerts:@"Download Failure" |
| 133 withDescription:@"Unable to download Google Chrome." | 128 withDescription:@"Unable to download Google Chrome." |
| (...skipping 23 matching lines...) Expand all Loading... |
| 157 NSLog(@"static code %d", oserror); | 152 NSLog(@"static code %d", oserror); |
| 158 | 153 |
| 159 // Calling this function will change the progress bar into an indeterminate | 154 // Calling this function will change the progress bar into an indeterminate |
| 160 // one. We won't need to update the progress bar any more after this point. | 155 // one. We won't need to update the progress bar any more after this point. |
| 161 [installerWindowController_ updateDownloadProgress:-1.0]; | 156 [installerWindowController_ updateDownloadProgress:-1.0]; |
| 162 // By disabling closing the window or quitting, we can tell the user that | 157 // By disabling closing the window or quitting, we can tell the user that |
| 163 // closing the application at this point is not a good idea. | 158 // closing the application at this point is not a good idea. |
| 164 window_.styleMask &= ~NSClosableWindowMask; | 159 window_.styleMask &= ~NSClosableWindowMask; |
| 165 preventTermination_ = YES; | 160 preventTermination_ = YES; |
| 166 | 161 |
| 167 // TODO: move the below code into AuthorizedInstall | 162 NSString* chromeInApplicationsFolder = |
| 168 NSString* chromeInApplicationsFolder = @"/Applications/Google Chromo.app"; | 163 [authorizedInstall_ startInstall:tempAppPath]; |
| 169 | 164 |
| 170 NSError* error = nil; | 165 NSError* error = nil; |
| 171 if ([[NSFileManager defaultManager] | |
| 172 fileExistsAtPath:chromeInApplicationsFolder]) { | |
| 173 [[NSFileManager defaultManager] moveItemAtPath:chromeInApplicationsFolder | |
| 174 toPath:tempAppPath | |
| 175 error:nil]; | |
| 176 } | |
| 177 if (![[NSFileManager defaultManager] moveItemAtPath:tempAppPath | |
| 178 toPath:chromeInApplicationsFolder | |
| 179 error:&error]) { | |
| 180 NSLog(@"%@", error); | |
| 181 } | |
| 182 // TODO: move the above code into AuthorizedInstall | |
| 183 | |
| 184 [[NSWorkspace sharedWorkspace] | 166 [[NSWorkspace sharedWorkspace] |
| 185 launchApplicationAtURL:[NSURL fileURLWithPath:chromeInApplicationsFolder | 167 launchApplicationAtURL:[NSURL fileURLWithPath:chromeInApplicationsFolder |
| 186 isDirectory:NO] | 168 isDirectory:NO] |
| 187 options:NSWorkspaceLaunchDefault | 169 options:NSWorkspaceLaunchDefault |
| 188 configuration:@{} | 170 configuration:@{} |
| 189 error:&error]; | 171 error:&error]; |
| 190 if (error) { | 172 if (error) { |
| 191 NSLog(@"Chrome failed to launch: %@", error); | 173 NSLog(@"Chrome failed to launch: %@", error); |
| 192 } | 174 } |
| 193 | 175 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 if (returnCode != [alertForUser quitResponse]) { | 213 if (returnCode != [alertForUser quitResponse]) { |
| 232 [self startDownload]; | 214 [self startDownload]; |
| 233 } else { | 215 } else { |
| 234 [NSApp terminate:nil]; | 216 [NSApp terminate:nil]; |
| 235 } | 217 } |
| 236 }]; | 218 }]; |
| 237 }); | 219 }); |
| 238 } | 220 } |
| 239 | 221 |
| 240 @end | 222 @end |
| OLD | NEW |