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