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