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 #include "base/mac/launch_services_util.h" | 5 #include "base/mac/launch_services_util.h" |
6 | 6 |
7 #include <ApplicationServices/ApplicationServices.h> | |
8 | |
9 #include "base/logging.h" | 7 #include "base/logging.h" |
10 #include "base/mac/mac_logging.h" | 8 #include "base/mac/mac_logging.h" |
11 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
12 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
13 | 11 |
14 namespace base { | 12 namespace base { |
15 namespace mac { | 13 namespace mac { |
16 | 14 |
17 bool OpenApplicationWithPath(const base::FilePath& bundle_path, | 15 bool OpenApplicationWithPath(const base::FilePath& bundle_path, |
18 const CommandLine& command_line, | 16 const CommandLine& command_line, |
| 17 LSLaunchFlags launch_flags, |
19 ProcessSerialNumber* out_psn) { | 18 ProcessSerialNumber* out_psn) { |
20 FSRef app_fsref; | 19 FSRef app_fsref; |
21 if (!base::mac::FSRefFromPath(bundle_path.value(), &app_fsref)) { | 20 if (!base::mac::FSRefFromPath(bundle_path.value(), &app_fsref)) { |
22 LOG(ERROR) << "base::mac::FSRefFromPath failed for " << bundle_path.value(); | 21 LOG(ERROR) << "base::mac::FSRefFromPath failed for " << bundle_path.value(); |
23 return false; | 22 return false; |
24 } | 23 } |
25 | 24 |
26 std::vector<std::string> argv = command_line.argv(); | 25 std::vector<std::string> argv = command_line.argv(); |
27 int argc = argv.size(); | 26 int argc = argv.size(); |
28 base::ScopedCFTypeRef<CFMutableArrayRef> launch_args( | 27 base::ScopedCFTypeRef<CFMutableArrayRef> launch_args( |
29 CFArrayCreateMutable(NULL, argc - 1, &kCFTypeArrayCallBacks)); | 28 CFArrayCreateMutable(NULL, argc - 1, &kCFTypeArrayCallBacks)); |
30 if (!launch_args) { | 29 if (!launch_args) { |
31 LOG(ERROR) << "CFArrayCreateMutable failed, size was " << argc; | 30 LOG(ERROR) << "CFArrayCreateMutable failed, size was " << argc; |
32 return false; | 31 return false; |
33 } | 32 } |
34 | 33 |
35 for (int i = 1; i < argc; ++i) { | 34 for (int i = 1; i < argc; ++i) { |
36 const std::string& arg(argv[i]); | 35 const std::string& arg(argv[i]); |
37 | 36 |
38 base::ScopedCFTypeRef<CFStringRef> arg_cf(base::SysUTF8ToCFStringRef(arg)); | 37 base::ScopedCFTypeRef<CFStringRef> arg_cf(base::SysUTF8ToCFStringRef(arg)); |
39 if (!arg_cf) { | 38 if (!arg_cf) { |
40 LOG(ERROR) << "base::SysUTF8ToCFStringRef failed for " << arg; | 39 LOG(ERROR) << "base::SysUTF8ToCFStringRef failed for " << arg; |
41 return false; | 40 return false; |
42 } | 41 } |
43 CFArrayAppendValue(launch_args, arg_cf); | 42 CFArrayAppendValue(launch_args, arg_cf); |
44 } | 43 } |
45 | 44 |
46 LSApplicationParameters ls_parameters = { | 45 LSApplicationParameters ls_parameters = { |
47 0, // version | 46 0, // version |
48 kLSLaunchDefaults, | 47 launch_flags, |
49 &app_fsref, | 48 &app_fsref, |
50 NULL, // asyncLaunchRefCon | 49 NULL, // asyncLaunchRefCon |
51 NULL, // environment | 50 NULL, // environment |
52 launch_args, | 51 launch_args, |
53 NULL // initialEvent | 52 NULL // initialEvent |
54 }; | 53 }; |
55 // TODO(jeremya): this opens a new browser window if Chrome is already | 54 // TODO(jeremya): this opens a new browser window if Chrome is already |
56 // running without any windows open. | 55 // running without any windows open. |
57 OSStatus status = LSOpenApplication(&ls_parameters, out_psn); | 56 OSStatus status = LSOpenApplication(&ls_parameters, out_psn); |
58 if (status != noErr) { | 57 if (status != noErr) { |
59 OSSTATUS_LOG(ERROR, status) << "LSOpenApplication"; | 58 OSSTATUS_LOG(ERROR, status) << "LSOpenApplication"; |
60 return false; | 59 return false; |
61 } | 60 } |
62 return true; | 61 return true; |
63 } | 62 } |
64 | 63 |
65 } // namespace mac | 64 } // namespace mac |
66 } // namespace base | 65 } // namespace base |
OLD | NEW |