Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: chrome/browser/mac/install_from_dmg.mm

Issue 7215040: Fix relaunches on the Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/mac/install_from_dmg.h" 5 #include "chrome/browser/mac/install_from_dmg.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 #import <AppKit/AppKit.h> 8 #import <AppKit/AppKit.h>
9 #include <CoreFoundation/CoreFoundation.h> 9 #include <CoreFoundation/CoreFoundation.h>
10 #include <CoreServices/CoreServices.h> 10 #include <CoreServices/CoreServices.h>
11 #include <IOKit/IOKitLib.h> 11 #include <IOKit/IOKitLib.h>
12 #include <string.h> 12 #include <string.h>
13 #include <sys/param.h> 13 #include <sys/param.h>
14 #include <sys/mount.h> 14 #include <sys/mount.h>
15 15
16 #include "base/basictypes.h" 16 #include "base/basictypes.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/file_path.h"
18 #include "base/logging.h" 19 #include "base/logging.h"
19 #import "base/mac/mac_util.h" 20 #import "base/mac/mac_util.h"
20 #include "base/mac/scoped_nsautorelease_pool.h" 21 #include "base/mac/scoped_nsautorelease_pool.h"
21 #include "chrome/browser/mac/authorization_util.h" 22 #include "chrome/browser/mac/authorization_util.h"
22 #include "chrome/browser/mac/scoped_authorizationref.h" 23 #include "chrome/browser/mac/scoped_authorizationref.h"
23 #import "chrome/browser/mac/keystone_glue.h" 24 #import "chrome/browser/mac/keystone_glue.h"
25 #include "chrome/browser/mac/relauncher.h"
26 #include "chrome/common/chrome_constants.h"
24 #include "grit/chromium_strings.h" 27 #include "grit/chromium_strings.h"
25 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/l10n/l10n_util_mac.h" 30 #include "ui/base/l10n/l10n_util_mac.h"
28 31
29 // When C++ exceptions are disabled, the C++ library defines |try| and 32 // When C++ exceptions are disabled, the C++ library defines |try| and
30 // |catch| so as to allow exception-expecting C++ code to build properly when 33 // |catch| so as to allow exception-expecting C++ code to build properly when
31 // language support for exceptions is not present. These macros interfere 34 // language support for exceptions is not present. These macros interfere
32 // with the use of |@try| and |@catch| in Objective-C files such as this one. 35 // with the use of |@try| and |@catch| in Objective-C files such as this one.
33 // Undefine these macros here, after everything has been #included, since 36 // Undefine these macros here, after everything has been #included, since
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 // ticket. Inform KeystoneGlue of the new path to use. 303 // ticket. Inform KeystoneGlue of the new path to use.
301 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue]; 304 KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue];
302 [keystone_glue setAppPath:target_path]; 305 [keystone_glue setAppPath:target_path];
303 [keystone_glue promoteTicketWithAuthorization:authorization.release() 306 [keystone_glue promoteTicketWithAuthorization:authorization.release()
304 synchronous:YES]; 307 synchronous:YES];
305 } 308 }
306 309
307 return true; 310 return true;
308 } 311 }
309 312
310 // Launches the application at app_path. The arguments passed to app_path 313 // Launches the application at installed_path. The helper application
311 // will be the same as the arguments used to invoke this process, except any 314 // contained within install_path will be used for the relauncher process. This
312 // arguments beginning with -psn_ will be stripped. 315 // keeps Launch Services from ever having to see or think about the helper
313 bool LaunchInstalledApp(NSString* app_path) { 316 // application on the disk image.
314 const UInt8* app_path_c = 317 bool LaunchInstalledApp(NSString* installed_path) {
315 reinterpret_cast<const UInt8*>([app_path fileSystemRepresentation]); 318 FilePath browser_path([installed_path fileSystemRepresentation]);
316 FSRef app_fsref;
317 OSStatus err = FSPathMakeRef(app_path_c, &app_fsref, NULL);
318 if (err != noErr) {
319 LOG(ERROR) << "FSPathMakeRef: " << err;
320 return false;
321 }
322 319
323 const std::vector<std::string>& argv = 320 FilePath helper_path = browser_path.Append("Contents/Versions");
Robert Sesek 2011/06/23 19:30:16 Is there any way to get this without hard-coding?
Mark Mentovai 2011/06/23 20:23:03 rsesek wrote:
321 helper_path = helper_path.Append(chrome::kChromeVersion);
322 helper_path = helper_path.Append(chrome::kHelperProcessExecutablePath);
323
324 std::vector<std::string> args =
324 CommandLine::ForCurrentProcess()->argv(); 325 CommandLine::ForCurrentProcess()->argv();
325 NSMutableArray* arguments = 326 args[0] = browser_path.value();
326 [NSMutableArray arrayWithCapacity:argv.size() - 1];
327 // Start at argv[1]. LSOpenApplication adds its own argv[0] as the path of
328 // the launched executable.
329 for (size_t index = 1; index < argv.size(); ++index) {
330 std::string argument = argv[index];
331 const char psn_flag[] = "-psn_";
332 const int psn_flag_length = arraysize(psn_flag) - 1;
333 if (argument.compare(0, psn_flag_length, psn_flag) != 0) {
334 // Strip any -psn_ arguments, as they apply to a specific process.
335 [arguments addObject:[NSString stringWithUTF8String:argument.c_str()]];
336 }
337 }
338 327
339 struct LSApplicationParameters parameters = {0}; 328 return mac_relauncher::RelaunchAppWithHelper(helper_path.value(), args);
340 parameters.flags = kLSLaunchDefaults;
341 parameters.application = &app_fsref;
342 parameters.argv = base::mac::NSToCFCast(arguments);
343
344 err = LSOpenApplication(&parameters, NULL);
345 if (err != noErr) {
346 LOG(ERROR) << "LSOpenApplication: " << err;
347 return false;
348 }
349
350 return true;
351 } 329 }
352 330
353 void ShowErrorDialog() { 331 void ShowErrorDialog() {
354 NSString* title = l10n_util::GetNSStringWithFixup( 332 NSString* title = l10n_util::GetNSStringWithFixup(
355 IDS_INSTALL_FROM_DMG_ERROR_TITLE); 333 IDS_INSTALL_FROM_DMG_ERROR_TITLE);
356 NSString* error = l10n_util::GetNSStringFWithFixup( 334 NSString* error = l10n_util::GetNSStringFWithFixup(
357 IDS_INSTALL_FROM_DMG_ERROR, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 335 IDS_INSTALL_FROM_DMG_ERROR, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
358 NSString* ok = l10n_util::GetNSStringWithFixup(IDS_OK); 336 NSString* ok = l10n_util::GetNSStringWithFixup(IDS_OK);
359 337
360 NSAlert* alert = [[[NSAlert alloc] init] autorelease]; 338 NSAlert* alert = [[[NSAlert alloc] init] autorelease];
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 installer_path, 407 installer_path,
430 source_path, 408 source_path,
431 target_path) || 409 target_path) ||
432 !LaunchInstalledApp(target_path)) { 410 !LaunchInstalledApp(target_path)) {
433 ShowErrorDialog(); 411 ShowErrorDialog();
434 return false; 412 return false;
435 } 413 }
436 414
437 return true; 415 return true;
438 } 416 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698