| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/mac/launch_services_util.h" |
| 6 |
| 7 #import <AppKit/AppKit.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/mac/mac_logging.h" |
| 11 #include "base/mac/mac_util.h" |
| 12 #include "base/mac/scoped_cftyperef.h" |
| 13 #include "base/mac/scoped_nsobject.h" |
| 14 #include "base/strings/sys_string_conversions.h" |
| 15 |
| 16 namespace base { |
| 17 namespace mac { |
| 18 |
| 19 bool OpenApplicationWithPath(const base::FilePath& bundle_path, |
| 20 const CommandLine& command_line, |
| 21 NSWorkspaceLaunchOptions launch_flags, |
| 22 NSAppleEventDescriptor* descriptor, |
| 23 pid_t* pid) { |
| 24 const std::vector<std::string>& argv = command_line.argv(); |
| 25 int argc = argv.size(); |
| 26 base::scoped_nsobject<NSMutableArray> launch_args( |
| 27 [[NSMutableArray alloc] initWithCapacity:argc - 1]); |
| 28 |
| 29 for (int i = 1; i < argc; ++i) { |
| 30 const std::string& arg(argv[i]); |
| 31 [launch_args addObject:base::SysUTF8ToNSString(arg)]; |
| 32 } |
| 33 |
| 34 NSURL* url = |
| 35 [NSURL fileURLWithPath:base::SysUTF8ToNSString(bundle_path.value())]; |
| 36 base::scoped_nsobject<NSMutableDictionary> configuration( |
| 37 [[NSMutableDictionary alloc] init]); |
| 38 [configuration setObject:launch_args |
| 39 forKey:NSWorkspaceLaunchConfigurationArguments]; |
| 40 if (descriptor) |
| 41 [configuration setObject:descriptor |
| 42 forKey:NSWorkspaceLaunchConfigurationAppleEvent]; |
| 43 |
| 44 NSError* error = nil; |
| 45 NSRunningApplication* application = |
| 46 [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url |
| 47 options:launch_flags |
| 48 configuration:configuration |
| 49 error:&error]; |
| 50 |
| 51 if (error) { |
| 52 const char* error_description = [[error description] UTF8String]; |
| 53 LOG(ERROR) << "Failed to launch application: " |
| 54 << (error_description ? error_description : ""); |
| 55 return false; |
| 56 } |
| 57 if (pid) |
| 58 *pid = [application processIdentifier]; |
| 59 return true; |
| 60 } |
| 61 |
| 62 } // namespace mac |
| 63 } // namespace base |
| OLD | NEW |