OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #import "chrome/common/mac/app_mode_chrome_locator.h" | 5 #import "chrome/common/mac/app_mode_chrome_locator.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 #include <CoreFoundation/CoreFoundation.h> | 8 #include <CoreFoundation/CoreFoundation.h> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/mac/foundation_util.h" | 11 #include "base/mac/foundation_util.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
14 | 14 |
15 namespace app_mode { | 15 namespace app_mode { |
16 | 16 |
17 bool FindBundleById(NSString* bundle_id, base::FilePath* out_bundle) { | 17 bool FindBundleById(NSString* bundle_id, base::FilePath* out_bundle) { |
18 NSWorkspace* ws = [NSWorkspace sharedWorkspace]; | 18 NSWorkspace* ws = [NSWorkspace sharedWorkspace]; |
19 NSString *bundlePath = [ws absolutePathForAppBundleWithIdentifier:bundle_id]; | 19 NSString *bundlePath = [ws absolutePathForAppBundleWithIdentifier:bundle_id]; |
20 if (!bundlePath) | 20 if (!bundlePath) |
21 return false; | 21 return false; |
22 | 22 |
23 *out_bundle = base::mac::NSStringToFilePath(bundlePath); | 23 *out_bundle = base::mac::NSStringToFilePath(bundlePath); |
24 return true; | 24 return true; |
25 } | 25 } |
26 | 26 |
27 bool GetChromeBundleInfo(const base::FilePath& chrome_bundle, | 27 bool GetChromeBundleInfo(const base::FilePath& chrome_bundle, |
28 const std::string& version_str, | |
28 base::FilePath* executable_path, | 29 base::FilePath* executable_path, |
29 base::string16* raw_version_str, | |
30 base::FilePath* version_path, | 30 base::FilePath* version_path, |
31 base::FilePath* framework_shlib_path) { | 31 base::FilePath* framework_shlib_path) { |
32 using base::mac::ObjCCast; | 32 using base::mac::ObjCCast; |
33 | 33 |
34 NSString* cr_bundle_path = base::mac::FilePathToNSString(chrome_bundle); | 34 NSString* cr_bundle_path = base::mac::FilePathToNSString(chrome_bundle); |
35 NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path]; | 35 NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path]; |
36 | 36 |
37 if (!cr_bundle) | 37 if (!cr_bundle) |
38 return false; | 38 return false; |
39 | 39 |
40 // Read raw version string. | 40 // Read version string. |
41 NSString* cr_version = | 41 NSString* cr_version; |
42 ObjCCast<NSString>( | 42 if (version_str.empty()) { |
43 [cr_bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]); | 43 cr_version = ObjCCast<NSString>( |
44 if (!cr_version) | 44 [cr_bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]); |
45 return false; | 45 if (!cr_version) |
46 return false; | |
47 } else { | |
48 cr_version = base::SysUTF8ToNSString(version_str); | |
49 } | |
46 | 50 |
47 // Get versioned directory. | 51 // Get versioned directory. |
48 NSArray* cr_versioned_path_components = | 52 NSArray* cr_versioned_path_components = |
49 [NSArray arrayWithObjects:cr_bundle_path, | 53 [NSArray arrayWithObjects:cr_bundle_path, |
50 @"Contents", | 54 @"Contents", |
51 @"Versions", | 55 @"Versions", |
52 cr_version, | 56 cr_version, |
tapted
2014/08/26 07:12:48
Do we need to handle the case that this path doesn
jackhou1
2014/08/26 08:15:14
I think it's reasonable to handle it here. If the
tapted
2014/08/26 08:43:47
lg
| |
53 nil]; | 57 nil]; |
54 NSString* cr_versioned_path = | 58 NSString* cr_versioned_path = |
55 [NSString pathWithComponents:cr_versioned_path_components]; | 59 [NSString pathWithComponents:cr_versioned_path_components]; |
56 | 60 |
57 // Get the framework path. | 61 // Get the framework path. |
58 NSString* cr_bundle_exe = | 62 NSString* cr_bundle_exe = |
59 ObjCCast<NSString>( | 63 ObjCCast<NSString>( |
60 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]); | 64 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]); |
61 // Essentially we want chrome::kFrameworkName which looks like | 65 // Essentially we want chrome::kFrameworkName which looks like |
62 // "$PRODUCT_STRING Framework.framework". The library itself is at | 66 // "$PRODUCT_STRING Framework.framework". The library itself is at |
(...skipping 20 matching lines...) Expand all Loading... | |
83 // A few more sanity checks. | 87 // A few more sanity checks. |
84 BOOL is_directory; | 88 BOOL is_directory; |
85 BOOL exists = [[NSFileManager defaultManager] | 89 BOOL exists = [[NSFileManager defaultManager] |
86 fileExistsAtPath:cr_framework_shlib_path | 90 fileExistsAtPath:cr_framework_shlib_path |
87 isDirectory:&is_directory]; | 91 isDirectory:&is_directory]; |
88 if (!exists || is_directory) | 92 if (!exists || is_directory) |
89 return false; | 93 return false; |
90 | 94 |
91 // Everything OK, copy output parameters. | 95 // Everything OK, copy output parameters. |
92 *executable_path = base::mac::NSStringToFilePath([cr_bundle executablePath]); | 96 *executable_path = base::mac::NSStringToFilePath([cr_bundle executablePath]); |
93 *raw_version_str = base::SysNSStringToUTF16(cr_version); | |
94 *version_path = base::mac::NSStringToFilePath(cr_versioned_path); | 97 *version_path = base::mac::NSStringToFilePath(cr_versioned_path); |
95 *framework_shlib_path = | 98 *framework_shlib_path = |
96 base::mac::NSStringToFilePath(cr_framework_shlib_path); | 99 base::mac::NSStringToFilePath(cr_framework_shlib_path); |
97 return true; | 100 return true; |
98 } | 101 } |
99 | 102 |
100 } // namespace app_mode | 103 } // namespace app_mode |
OLD | NEW |