| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #import "base/mac/launch_services_util.h" | 5 #import "base/mac/launch_services_util.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| 11 namespace mac { | 11 namespace mac { |
| 12 | 12 |
| 13 Process OpenApplicationWithPath(const base::FilePath& bundle_path, | 13 Process OpenApplicationWithPath(const base::FilePath& bundle_path, |
| 14 const CommandLine& command_line, | 14 const CommandLine& command_line, |
| 15 NSWorkspaceLaunchOptions launch_options) { | 15 NSWorkspaceLaunchOptions launch_options, |
| 16 NSAppleEventDescriptor* descriptor) { |
| 16 NSString* bundle_url_spec = base::SysUTF8ToNSString(bundle_path.value()); | 17 NSString* bundle_url_spec = base::SysUTF8ToNSString(bundle_path.value()); |
| 17 NSURL* bundle_url = [NSURL fileURLWithPath:bundle_url_spec isDirectory:YES]; | 18 NSURL* bundle_url = [NSURL fileURLWithPath:bundle_url_spec isDirectory:YES]; |
| 18 DCHECK(bundle_url); | 19 DCHECK(bundle_url); |
| 19 if (!bundle_url) { | 20 if (!bundle_url) { |
| 20 return Process(); | 21 return Process(); |
| 21 } | 22 } |
| 22 | 23 |
| 23 // NSWorkspace automatically adds the binary path as the first argument and | 24 // NSWorkspace automatically adds the binary path as the first argument and |
| 24 // it should not be included into the list. | 25 // it should not be included into the list. |
| 25 std::vector<std::string> argv = command_line.argv(); | 26 std::vector<std::string> argv = command_line.argv(); |
| 26 int argc = argv.size(); | 27 int argc = argv.size(); |
| 27 NSMutableArray* launch_args = [NSMutableArray arrayWithCapacity:argc - 1]; | 28 NSMutableArray* launch_args = [NSMutableArray arrayWithCapacity:argc - 1]; |
| 28 for (int i = 1; i < argc; ++i) { | 29 for (int i = 1; i < argc; ++i) { |
| 29 [launch_args addObject:base::SysUTF8ToNSString(argv[i])]; | 30 [launch_args addObject:base::SysUTF8ToNSString(argv[i])]; |
| 30 } | 31 } |
| 31 | 32 |
| 32 NSDictionary* configuration = @{ | 33 NSMutableDictionary* configuration = [NSMutableDictionary dictionary]; |
| 33 NSWorkspaceLaunchConfigurationArguments : launch_args, | 34 configuration[NSWorkspaceLaunchConfigurationArguments] = launch_args; |
| 34 }; | 35 [configuration setObject:launch_args |
| 36 forKey:NSWorkspaceLaunchConfigurationArguments]; |
| 37 |
| 38 if (descriptor) |
| 39 configuration[NSWorkspaceLaunchConfigurationAppleEvent] = descriptor; |
| 40 |
| 35 NSError* launch_error = nil; | 41 NSError* launch_error = nil; |
| 36 // TODO(jeremya): this opens a new browser window if Chrome is already | 42 // TODO(jeremya): this opens a new browser window if Chrome is already |
| 37 // running without any windows open. | 43 // running without any windows open. |
| 38 NSRunningApplication* app = | 44 NSRunningApplication* app = |
| 39 [[NSWorkspace sharedWorkspace] launchApplicationAtURL:bundle_url | 45 [[NSWorkspace sharedWorkspace] launchApplicationAtURL:bundle_url |
| 40 options:launch_options | 46 options:launch_options |
| 41 configuration:configuration | 47 configuration:configuration |
| 42 error:&launch_error]; | 48 error:&launch_error]; |
| 43 if (launch_error) { | 49 if (launch_error) { |
| 44 LOG(ERROR) << base::SysNSStringToUTF8([launch_error localizedDescription]); | 50 LOG(ERROR) << base::SysNSStringToUTF8([launch_error localizedDescription]); |
| 45 return Process(); | 51 return Process(); |
| 46 } | 52 } |
| 47 DCHECK(app); | 53 DCHECK(app); |
| 48 return Process([app processIdentifier]); | 54 return Process([app processIdentifier]); |
| 49 } | 55 } |
| 50 | 56 |
| 51 } // namespace mac | 57 } // namespace mac |
| 52 } // namespace base | 58 } // namespace base |
| OLD | NEW |