Chromium Code Reviews| Index: base/mac/launch_services_util.mm |
| diff --git a/base/mac/launch_services_util.mm b/base/mac/launch_services_util.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f5b9dae7679eb95331924b97c1a3601d65a6e447 |
| --- /dev/null |
| +++ b/base/mac/launch_services_util.mm |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "base/mac/launch_services_util.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/strings/sys_string_conversions.h" |
| + |
| +namespace base { |
| +namespace mac { |
| + |
| +bool OpenApplicationWithPath(const base::FilePath& bundle_path, |
| + const CommandLine& command_line, |
| + NSWorkspaceLaunchOptions launch_options, |
| + pid_t* out_pid) { |
| + NSString* bundle_url_spec = base::SysUTF8ToNSString(bundle_path.value()); |
| + NSURL* bundle_url = [NSURL fileURLWithPath:bundle_url_spec isDirectory:YES]; |
| + if (!bundle_url) { |
|
tapted
2016/10/04 05:54:08
apart from OOM, can this fail? Perhaps just DCHECK
Eugene But (OOO till 7-30)
2016/10/04 07:02:49
It can if bundle_path.value() is an empty string.
|
| + LOG(ERROR) << "Cannot create NSURL for " << bundle_path.value(); |
| + } |
| + |
| + std::vector<std::string> argv = command_line.argv(); |
| + int argc = argv.size(); |
| + NSMutableArray* launch_args = [NSMutableArray arrayWithCapacity:argc - 1]; |
|
tapted
2016/10/04 05:54:08
NSWorkspaceLaunchConfigurationArguments says it's
Eugene But (OOO till 7-30)
2016/10/04 07:02:49
argv[0] is a binary path, which automatically adde
|
| + for (int i = 1; i < argc; ++i) { |
| + const std::string& arg(argv[i]); |
| + [launch_args addObject:base::SysUTF8ToNSString(arg)]; |
| + } |
| + |
| + NSDictionary* configuration = @{ |
| + NSWorkspaceLaunchConfigurationArguments : launch_args, |
| + }; |
|
tapted
2016/10/04 05:54:08
That // TODO(jeremya): this opens a new browser wi
Eugene But (OOO till 7-30)
2016/10/04 07:02:49
Added back TODO.
|
| + NSError* launch_error = nil; |
| + NSRunningApplication* app = |
| + [[NSWorkspace sharedWorkspace] launchApplicationAtURL:bundle_url |
| + options:launch_options |
| + configuration:configuration |
| + error:&launch_error]; |
| + |
| + if (out_pid) { |
| + *out_pid = app.processIdentifier; |
|
tapted
2016/10/04 05:54:08
[app processIdentifier]
But also launchApplicatio
Eugene But (OOO till 7-30)
2016/10/04 07:02:49
Done. New code now correctly handles nil case.
|
| + } |
| + |
| + if (launch_error) { |
| + NSString* error_description = |
| + [[launch_error userInfo] objectForKey:NSLocalizedDescriptionKey]; |
| + DLOG(ERROR) << base::SysNSStringToUTF8(error_description); |
|
tapted
2016/10/04 05:54:08
There's probably a good argument for making this a
Eugene But (OOO till 7-30)
2016/10/04 07:02:49
Localized description prints this:
The applicati
tapted
2016/10/05 01:40:47
The localized description should be OK - I agree i
|
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +} // namespace mac |
| +} // namespace base |