| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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 "chrome/common/mac/app_mode_chrome_locator.h" |
| 6 |
| 7 #import <AppKit/AppKit.h> |
| 8 #include <CoreFoundation/CoreFoundation.h> |
| 9 |
| 10 #include "base/file_path.h" |
| 11 #include "base/mac/foundation_util.h" |
| 12 #include "base/sys_string_conversions.h" |
| 13 |
| 14 namespace app_mode { |
| 15 |
| 16 bool FindBundleById(NSString* bundle_id, FilePath* out_bundle) { |
| 17 NSWorkspace* ws = [NSWorkspace sharedWorkspace]; |
| 18 NSString *bundlePath = [ws absolutePathForAppBundleWithIdentifier:bundle_id]; |
| 19 if (!bundlePath) |
| 20 return false; |
| 21 |
| 22 *out_bundle = base::mac::NSStringToFilePath(bundlePath); |
| 23 return true; |
| 24 } |
| 25 |
| 26 bool GetChromeBundleInfo(const FilePath& chrome_bundle, |
| 27 string16* raw_version_str, |
| 28 FilePath* version_path, |
| 29 FilePath* framework_shlib_path) { |
| 30 using base::mac::ObjCCast; |
| 31 |
| 32 NSString* cr_bundle_path = base::mac::FilePathToNSString(chrome_bundle); |
| 33 NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path]; |
| 34 |
| 35 if (!cr_bundle) |
| 36 return false; |
| 37 |
| 38 // Read raw version string. |
| 39 NSString* cr_version = |
| 40 ObjCCast<NSString>( |
| 41 [cr_bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]); |
| 42 if (!cr_version) |
| 43 return false; |
| 44 |
| 45 // Get versioned directory. |
| 46 NSArray* cr_versioned_path_components = |
| 47 [NSArray arrayWithObjects:cr_bundle_path, |
| 48 @"Contents", |
| 49 @"Versions", |
| 50 cr_version, |
| 51 nil]; |
| 52 NSString* cr_versioned_path = |
| 53 [NSString pathWithComponents:cr_versioned_path_components]; |
| 54 |
| 55 // Get the framework path. |
| 56 NSString* cr_bundle_exe = |
| 57 ObjCCast<NSString>( |
| 58 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]); |
| 59 NSString* cr_framework_shlib_path = |
| 60 [cr_versioned_path stringByAppendingPathComponent: |
| 61 [cr_bundle_exe stringByAppendingString:@" Framework.framework"]]; |
| 62 cr_framework_shlib_path = |
| 63 [cr_framework_shlib_path stringByAppendingPathComponent: |
| 64 [cr_bundle_exe stringByAppendingString:@" Framework"]]; |
| 65 if (!cr_bundle_exe || !cr_framework_shlib_path) |
| 66 return false; |
| 67 |
| 68 // A few more sanity checks. |
| 69 BOOL is_directory; |
| 70 BOOL exists = [[NSFileManager defaultManager] |
| 71 fileExistsAtPath:cr_framework_shlib_path |
| 72 isDirectory:&is_directory]; |
| 73 if (!exists || is_directory) |
| 74 return false; |
| 75 |
| 76 // Everything OK, copy output parameters. |
| 77 *raw_version_str = base::SysNSStringToUTF16(cr_version); |
| 78 *version_path = base::mac::NSStringToFilePath(cr_versioned_path); |
| 79 *framework_shlib_path = |
| 80 base::mac::NSStringToFilePath(cr_framework_shlib_path); |
| 81 return true; |
| 82 } |
| 83 |
| 84 } // namespace app_mode |
| OLD | NEW |