Chromium Code Reviews| 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/sys_string_conversions.h" | |
| 12 | |
| 13 namespace app_mode { | |
| 14 | |
| 15 bool FindBundleById(NSString* bundle_id, FilePath* out_bundle) { | |
| 16 NSWorkspace* ws = [NSWorkspace sharedWorkspace]; | |
| 17 NSString *bundlePath = [ws absolutePathForAppBundleWithIdentifier:bundle_id]; | |
| 18 if (!bundlePath) | |
| 19 return false; | |
| 20 | |
| 21 *out_bundle = FilePath([bundlePath fileSystemRepresentation]); | |
| 22 return true; | |
| 23 } | |
| 24 | |
| 25 bool GetChromeBundleInfo(const FilePath& chrome_bundle, | |
| 26 string16* raw_version_str, | |
| 27 FilePath* version_path, | |
| 28 FilePath* framework_shlib_path) { | |
| 29 NSString* cr_bundle_path = | |
| 30 [[NSFileManager defaultManager] | |
| 31 stringWithFileSystemRepresentation:chrome_bundle.value().c_str() | |
| 32 length:chrome_bundle.value().size()]; | |
| 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 [cr_bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; | |
|
sail
2012/02/09 23:31:37
use base::mac::ObjCCast?
| |
| 41 if (!cr_version) | |
| 42 return false; | |
| 43 | |
| 44 // Get versioned directory. | |
| 45 NSArray* cr_versioned_path_components = | |
| 46 [NSArray arrayWithObjects:cr_bundle_path, | |
| 47 @"Contents", | |
| 48 @"Versions", | |
| 49 cr_version, | |
| 50 nil]; | |
| 51 NSString* cr_versioned_path = | |
| 52 [NSString pathWithComponents:cr_versioned_path_components]; | |
| 53 | |
| 54 // Get the framework path. | |
| 55 NSString* cr_bundle_exe = | |
| 56 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]; | |
|
sail
2012/02/09 23:31:37
same (base::mac::ObjCCast)
| |
| 57 NSString* cr_framework_shlib_path = | |
| 58 [cr_versioned_path stringByAppendingPathComponent: | |
| 59 [cr_bundle_exe stringByAppendingString:@" Framework.framework"]]; | |
| 60 cr_framework_shlib_path = | |
| 61 [cr_framework_shlib_path stringByAppendingPathComponent: | |
| 62 [cr_bundle_exe stringByAppendingString:@" Framework"]]; | |
| 63 if (!cr_bundle_exe || !cr_framework_shlib_path) | |
| 64 return false; | |
| 65 | |
| 66 // A few more sanity checks. | |
| 67 BOOL is_directory; | |
| 68 BOOL exists = [[NSFileManager defaultManager] | |
| 69 fileExistsAtPath:cr_framework_shlib_path | |
| 70 isDirectory:&is_directory]; | |
| 71 if (!exists || is_directory) | |
| 72 return false; | |
| 73 | |
| 74 // Everything OK, copy output parameters. | |
| 75 *raw_version_str = base::SysNSStringToUTF16(cr_version); | |
| 76 *version_path = FilePath([cr_versioned_path fileSystemRepresentation]); | |
| 77 *framework_shlib_path = FilePath( | |
| 78 [cr_framework_shlib_path fileSystemRepresentation]); | |
| 79 return true; | |
| 80 } | |
| 81 | |
| 82 } // namespace app_mode | |
| OLD | NEW |