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 #import "Downloader.h" | 7 #import "Downloader.h" |
8 #import "InstallerWindowController.h" | 8 #import "InstallerWindowController.h" |
9 #import "NSError+ChromeInstallerAdditions.h" | 9 #import "NSError+ChromeInstallerAdditions.h" |
10 #import "NSAlert+ChromeInstallerAdditions.h" | 10 #import "NSAlert+ChromeInstallerAdditions.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 // Bridge method from Downloader to InstallerWindowController. Allows Downloader | 108 // Bridge method from Downloader to InstallerWindowController. Allows Downloader |
109 // to update the progressbar without having direct access to any UI obejcts. | 109 // to update the progressbar without having direct access to any UI obejcts. |
110 - (void)downloader:(Downloader*)download percentProgress:(double)percentage { | 110 - (void)downloader:(Downloader*)download percentProgress:(double)percentage { |
111 [installerWindowController_ updateDownloadProgress:(double)percentage]; | 111 [installerWindowController_ updateDownloadProgress:(double)percentage]; |
112 } | 112 } |
113 | 113 |
114 - (void)downloader:(Downloader*)download onSuccess:(NSURL*)diskImageURL { | 114 - (void)downloader:(Downloader*)download onSuccess:(NSURL*)diskImageURL { |
115 [installerWindowController_ updateStatusDescription:@"Installing..."]; | 115 [installerWindowController_ updateStatusDescription:@"Installing..."]; |
116 [installerWindowController_ enableLaunchButton]; | 116 [installerWindowController_ enableLaunchButton]; |
117 // TODO: Add unpacking step here and pass the path to the app bundle inside | |
118 // the mounted disk image path to startInstall. Currently passing hardcoded | |
119 // path to preunpacked app bundle. | |
120 //[authorizedInstall_ | |
121 // startInstall:@"$HOME/Downloads/Google Chrome.app"]; | |
122 | 117 |
123 Unpacker* unpacker = [[Unpacker alloc] init]; | 118 Unpacker* unpacker = [[Unpacker alloc] init]; |
124 unpacker.delegate = self; | 119 unpacker.delegate = self; |
125 [unpacker mountDMGFromURL:diskImageURL]; | 120 [unpacker mountDMGFromURL:diskImageURL]; |
126 } | 121 } |
127 | 122 |
128 - (void)downloader:(Downloader*)download onFailure:(NSError*)error { | 123 - (void)downloader:(Downloader*)download onFailure:(NSError*)error { |
129 NSError* downloadError = | 124 NSError* downloadError = |
130 [NSError errorForAlerts:@"Download Failure" | 125 [NSError errorForAlerts:@"Download Failure" |
131 withDescription:@"Unable to download Google Chrome." | 126 withDescription:@"Unable to download Google Chrome." |
132 isRecoverable:NO]; | 127 isRecoverable:NO]; |
133 [self displayError:downloadError]; | 128 [self displayError:downloadError]; |
134 } | 129 } |
135 | 130 |
136 - (void)unpacker:(Unpacker*)unpacker onMountSuccess:(NSString*)tempAppPath { | 131 - (void)unpacker:(Unpacker*)unpacker onMountSuccess:(NSString*)tempAppPath { |
| 132 SecStaticCodeRef diskStaticCode; |
| 133 SecRequirementRef diskRequirement; |
| 134 SecStaticCodeCreateWithPath( |
| 135 (CFURLRef)CFBridgingRetain( |
| 136 [NSURL fileURLWithPath:tempAppPath isDirectory:NO]), |
| 137 kSecCSDefaultFlags, &diskStaticCode); |
| 138 // TODO: update the requirement in here |
| 139 SecRequirementCreateWithString((CFStringRef) @"anchor apple generic", |
| 140 kSecCSDefaultFlags, &diskRequirement); |
| 141 OSStatus oserror = 0; |
| 142 if ((oserror = SecStaticCodeCheckValidity(diskStaticCode, kSecCSDefaultFlags, |
| 143 diskRequirement)) != |
| 144 errSecSuccess) { |
| 145 // TODO: add in more reasonable error handling |
| 146 NSLog(@"verification failed: %d", oserror); |
| 147 } |
| 148 |
137 // Calling this function will change the progress bar into an indeterminate | 149 // Calling this function will change the progress bar into an indeterminate |
138 // one. We won't need to update the progress bar any more after this point. | 150 // one. We won't need to update the progress bar any more after this point. |
139 [installerWindowController_ updateDownloadProgress:-1.0]; | 151 [installerWindowController_ updateDownloadProgress:-1.0]; |
140 // By disabling closing the window or quitting, we can tell the user that | 152 // By disabling closing the window or quitting, we can tell the user that |
141 // closing the application at this point is not a good idea. | 153 // closing the application at this point is not a good idea. |
142 window_.styleMask &= ~NSClosableWindowMask; | 154 window_.styleMask &= ~NSClosableWindowMask; |
143 preventTermination_ = YES; | 155 preventTermination_ = YES; |
144 | 156 |
145 // TODO: move the below code into AuthorizedInstall | 157 NSString* chromeInApplicationsFolder = |
146 NSString* chromeInApplicationsFolder = @"/Applications/Google Chromo.app"; | 158 [authorizedInstall_ startInstall:tempAppPath]; |
147 | 159 |
148 NSError* error = nil; | 160 NSError* error = nil; |
149 if ([[NSFileManager defaultManager] | |
150 fileExistsAtPath:chromeInApplicationsFolder]) { | |
151 [[NSFileManager defaultManager] moveItemAtPath:chromeInApplicationsFolder | |
152 toPath:tempAppPath | |
153 error:nil]; | |
154 } | |
155 if (![[NSFileManager defaultManager] moveItemAtPath:tempAppPath | |
156 toPath:chromeInApplicationsFolder | |
157 error:&error]) { | |
158 NSLog(@"%@", error); | |
159 } | |
160 // TODO: move the above code into AuthorizedInstall | |
161 | |
162 [[NSWorkspace sharedWorkspace] | 161 [[NSWorkspace sharedWorkspace] |
163 launchApplicationAtURL:[NSURL fileURLWithPath:chromeInApplicationsFolder | 162 launchApplicationAtURL:[NSURL fileURLWithPath:chromeInApplicationsFolder |
164 isDirectory:NO] | 163 isDirectory:NO] |
165 options:NSWorkspaceLaunchDefault | 164 options:NSWorkspaceLaunchDefault |
166 configuration:@{} | 165 configuration:@{} |
167 error:&error]; | 166 error:&error]; |
168 if (error) { | 167 if (error) { |
169 NSLog(@"Chrome failed to launch: %@", error); | 168 NSLog(@"Chrome failed to launch: %@", error); |
170 } | 169 } |
171 | 170 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 if (returnCode != [alertForUser quitResponse]) { | 208 if (returnCode != [alertForUser quitResponse]) { |
210 [self startDownload]; | 209 [self startDownload]; |
211 } else { | 210 } else { |
212 [NSApp terminate:nil]; | 211 [NSApp terminate:nil]; |
213 } | 212 } |
214 }]; | 213 }]; |
215 }); | 214 }); |
216 } | 215 } |
217 | 216 |
218 @end | 217 @end |
OLD | NEW |