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.
5 #include "base/mac/launch_services_util.h"
7 #include <ApplicationServices/ApplicationServices.h>
9 #include "base/logging.h"
10 #include "base/mac/mac_logging.h"
11 #include "base/mac/mac_util.h"
12 #include "base/strings/sys_string_conversions.h"
17 bool OpenApplicationWithPath(const base::FilePath
& bundle_path
,
18 const CommandLine
& command_line
,
19 ProcessSerialNumber
* out_psn
) {
21 if (!base::mac::FSRefFromPath(bundle_path
.value(), &app_fsref
)) {
22 LOG(ERROR
) << "base::mac::FSRefFromPath failed for " << bundle_path
.value();
26 std::vector
<std::string
> argv
= command_line
.argv();
27 int argc
= argv
.size();
28 base::mac::ScopedCFTypeRef
<CFMutableArrayRef
> launch_args(
29 CFArrayCreateMutable(NULL
, argc
- 1, &kCFTypeArrayCallBacks
));
31 LOG(ERROR
) << "CFArrayCreateMutable failed, size was " << argc
;
35 for (int i
= 1; i
< argc
; ++i
) {
36 const std::string
& arg(argv
[i
]);
38 base::mac::ScopedCFTypeRef
<CFStringRef
> arg_cf(
39 base::SysUTF8ToCFStringRef(arg
));
41 LOG(ERROR
) << "base::SysUTF8ToCFStringRef failed for " << arg
;
44 CFArrayAppendValue(launch_args
, arg_cf
);
47 LSApplicationParameters ls_parameters
= {
51 NULL
, // asyncLaunchRefCon
56 // TODO(jeremya): this opens a new browser window if Chrome is already
57 // running without any windows open.
58 OSStatus status
= LSOpenApplication(&ls_parameters
, out_psn
);
59 if (status
!= noErr
) {
60 OSSTATUS_LOG(ERROR
, status
) << "LSOpenApplication";