Chromium Code Reviews| Index: chrome/browser/mac/relauncher.mm |
| diff --git a/chrome/browser/mac/relauncher.cc b/chrome/browser/mac/relauncher.mm |
| similarity index 90% |
| rename from chrome/browser/mac/relauncher.cc |
| rename to chrome/browser/mac/relauncher.mm |
| index 40ea5371bf90732f5c8ea768b4d9bb80bb158eee..abc309410658dde15beb466fa95a72c41f87ab10 100644 |
| --- a/chrome/browser/mac/relauncher.cc |
| +++ b/chrome/browser/mac/relauncher.mm |
| @@ -4,7 +4,8 @@ |
| #include "chrome/browser/mac/relauncher.h" |
| -#include <ApplicationServices/ApplicationServices.h> |
| +#import <AppKit/AppKit.h> |
| + |
| #include <AvailabilityMacros.h> |
| #include <crt_externs.h> |
| #include <dlfcn.h> |
| @@ -23,7 +24,7 @@ |
| #include "base/logging.h" |
| #include "base/mac/mac_logging.h" |
| #include "base/mac/mac_util.h" |
| -#include "base/mac/scoped_cftyperef.h" |
| +#include "base/mac/scoped_nsobject.h" |
| #include "base/path_service.h" |
| #include "base/posix/eintr_wrapper.h" |
| #include "base/process/launch.h" |
| @@ -281,12 +282,8 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) { |
| // won't contain the argv[0] of the relauncher process, the |
| // RelauncherTypeArg() at argv[1], kRelauncherArgSeparator, or the |
| // executable path of the process to be launched. |
| - base::ScopedCFTypeRef<CFMutableArrayRef> relaunch_args( |
| - CFArrayCreateMutable(NULL, argc - 4, &kCFTypeArrayCallBacks)); |
| - if (!relaunch_args) { |
| - LOG(ERROR) << "CFArrayCreateMutable"; |
| - return 1; |
| - } |
| + base::scoped_nsobject<NSMutableArray> relaunch_args( |
| + [[NSMutableArray alloc] init]); |
| // Figure out what to execute, what arguments to pass it, and whether to |
| // start it in the background. |
| @@ -326,13 +323,13 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) { |
| relaunch_executable.assign(arg); |
| seen_relaunch_executable = true; |
| } else { |
| - base::ScopedCFTypeRef<CFStringRef> arg_cf( |
| - base::SysUTF8ToCFStringRef(arg)); |
| - if (!arg_cf) { |
| - LOG(ERROR) << "base::SysUTF8ToCFStringRef failed for " << arg; |
| + |
| + NSString* arg_string = base::SysUTF8ToNSString(arg); |
| + if (!arg_string) { |
| + LOG(ERROR) << "base::SysUTF8ToNSString failed for " << arg; |
| return 1; |
| } |
| - CFArrayAppendValue(relaunch_args, arg_cf); |
| + [relaunch_args addObject:arg_string]; |
| } |
| } |
| } |
| @@ -342,26 +339,24 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) { |
| return 1; |
| } |
| - FSRef app_fsref; |
| - if (!base::mac::FSRefFromPath(relaunch_executable, &app_fsref)) { |
| - LOG(ERROR) << "base::mac::FSRefFromPath failed for " << relaunch_executable; |
| - return 1; |
| - } |
| - |
| - LSApplicationParameters ls_parameters = { |
| - 0, // version |
| - kLSLaunchDefaults | kLSLaunchAndDisplayErrors | kLSLaunchNewInstance | |
| - (background ? kLSLaunchDontSwitch : 0), |
| - &app_fsref, |
| - NULL, // asyncLaunchRefCon |
| - NULL, // environment |
| - relaunch_args, |
| - NULL // initialEvent |
| - }; |
| - |
| - OSStatus status = LSOpenApplication(&ls_parameters, NULL); |
| - if (status != noErr) { |
| - OSSTATUS_LOG(ERROR, status) << "LSOpenApplication"; |
| + base::scoped_nsobject<NSString> path([[NSString alloc] |
| + initWithCString:relaunch_executable.c_str() |
|
Mark Mentovai
2016/08/22 17:43:31
Wouldn’t we usually -initWithUTF8String?
Technica
erikchen
2016/08/22 17:54:12
Switched to base::SysUTF8ToNSString
|
| + encoding:NSUTF8StringEncoding]); |
| + base::scoped_nsobject<NSURL> url([[NSURL alloc] initFileURLWithPath:path]); |
| + NSDictionary* configuration = |
| + @{NSWorkspaceLaunchConfigurationArguments : (relaunch_args.get())}; |
| + |
| + NSRunningApplication *application = [[NSWorkspace sharedWorkspace] |
| + launchApplicationAtURL:url |
| + options:NSWorkspaceLaunchDefault | |
| + NSWorkspaceLaunchWithErrorPresentation | |
| + (background ? NSWorkspaceLaunchWithoutActivation |
| + : 0) | |
| + NSWorkspaceLaunchNewInstance |
| + configuration:configuration |
| + error:nil]; |
| + if (!application) { |
| + LOG(ERROR) << "Failed to relaunch " << relaunch_executable; |
| return 1; |
| } |