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