| 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..0ae4262cefc6bd3adfd89ab0b15dd196a647f7d6
|
| --- /dev/null
|
| +++ b/base/mac/launch_services_util.mm
|
| @@ -0,0 +1,63 @@
|
| +// 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.
|
| +
|
| +#include "base/mac/launch_services_util.h"
|
| +
|
| +#import <AppKit/AppKit.h>
|
| +
|
| +#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/strings/sys_string_conversions.h"
|
| +
|
| +namespace base {
|
| +namespace mac {
|
| +
|
| +bool OpenApplicationWithPath(const base::FilePath& bundle_path,
|
| + const CommandLine& command_line,
|
| + NSWorkspaceLaunchOptions launch_flags,
|
| + NSAppleEventDescriptor* descriptor,
|
| + pid_t* pid) {
|
| + const std::vector<std::string>& argv = command_line.argv();
|
| + int argc = argv.size();
|
| + base::scoped_nsobject<NSMutableArray> launch_args(
|
| + [[NSMutableArray alloc] initWithCapacity:argc - 1]);
|
| +
|
| + for (int i = 1; i < argc; ++i) {
|
| + const std::string& arg(argv[i]);
|
| + [launch_args addObject:base::SysUTF8ToNSString(arg)];
|
| + }
|
| +
|
| + NSURL* url =
|
| + [NSURL fileURLWithPath:base::SysUTF8ToNSString(bundle_path.value())];
|
| + base::scoped_nsobject<NSMutableDictionary> configuration(
|
| + [[NSMutableDictionary alloc] init]);
|
| + [configuration setObject:launch_args
|
| + forKey:NSWorkspaceLaunchConfigurationArguments];
|
| + if (descriptor)
|
| + [configuration setObject:descriptor
|
| + forKey:NSWorkspaceLaunchConfigurationAppleEvent];
|
| +
|
| + NSError* error = nil;
|
| + NSRunningApplication* application =
|
| + [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url
|
| + options:launch_flags
|
| + configuration:configuration
|
| + error:&error];
|
| +
|
| + if (error) {
|
| + const char* error_description = [[error description] UTF8String];
|
| + LOG(ERROR) << "Failed to launch application: "
|
| + << (error_description ? error_description : "");
|
| + return false;
|
| + }
|
| + if (pid)
|
| + *pid = [application processIdentifier];
|
| + return true;
|
| +}
|
| +
|
| +} // namespace mac
|
| +} // namespace base
|
|
|