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/files/file_util.h" | |
11 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
13 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
14 | 15 |
15 namespace app_mode { | 16 namespace app_mode { |
16 | 17 |
17 bool FindBundleById(NSString* bundle_id, base::FilePath* out_bundle) { | 18 bool FindBundleById(NSString* bundle_id, base::FilePath* out_bundle) { |
18 NSWorkspace* ws = [NSWorkspace sharedWorkspace]; | 19 NSWorkspace* ws = [NSWorkspace sharedWorkspace]; |
19 NSString *bundlePath = [ws absolutePathForAppBundleWithIdentifier:bundle_id]; | 20 NSString *bundlePath = [ws absolutePathForAppBundleWithIdentifier:bundle_id]; |
20 if (!bundlePath) | 21 if (!bundlePath) |
21 return false; | 22 return false; |
22 | 23 |
23 *out_bundle = base::mac::NSStringToFilePath(bundlePath); | 24 *out_bundle = base::mac::NSStringToFilePath(bundlePath); |
24 return true; | 25 return true; |
25 } | 26 } |
26 | 27 |
28 NSString* GetVersionedPath(NSString* bundle_path, NSString* version) { | |
29 NSArray* versioned_path_components = [NSArray | |
30 arrayWithObjects:bundle_path, @"Contents", @"Versions", version, nil]; | |
Robert Sesek
2014/08/26 16:41:08
You can use @[ ] syntax instead.
jackhou1
2014/08/27 03:04:52
Done.
| |
31 return [NSString pathWithComponents:versioned_path_components]; | |
32 } | |
33 | |
27 bool GetChromeBundleInfo(const base::FilePath& chrome_bundle, | 34 bool GetChromeBundleInfo(const base::FilePath& chrome_bundle, |
35 const std::string& version_str, | |
28 base::FilePath* executable_path, | 36 base::FilePath* executable_path, |
29 base::string16* raw_version_str, | |
30 base::FilePath* version_path, | 37 base::FilePath* version_path, |
31 base::FilePath* framework_shlib_path) { | 38 base::FilePath* framework_shlib_path) { |
32 using base::mac::ObjCCast; | 39 using base::mac::ObjCCast; |
33 | 40 |
34 NSString* cr_bundle_path = base::mac::FilePathToNSString(chrome_bundle); | 41 NSString* cr_bundle_path = base::mac::FilePathToNSString(chrome_bundle); |
35 NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path]; | 42 NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path]; |
36 | 43 |
37 if (!cr_bundle) | 44 if (!cr_bundle) |
38 return false; | 45 return false; |
39 | 46 |
40 // Read raw version string. | 47 // Get versioned directory. |
41 NSString* cr_version = | 48 NSString* cr_versioned_path; |
42 ObjCCast<NSString>( | 49 if (!version_str.empty()) { |
43 [cr_bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]); | 50 cr_versioned_path = |
44 if (!cr_version) | 51 GetVersionedPath(cr_bundle_path, base::SysUTF8ToNSString(version_str)); |
45 return false; | 52 } |
46 | 53 |
47 // Get versioned directory. | 54 if (version_str.empty() || |
48 NSArray* cr_versioned_path_components = | 55 !base::PathExists(base::mac::NSStringToFilePath(cr_versioned_path))) { |
49 [NSArray arrayWithObjects:cr_bundle_path, | 56 // Read version string. |
50 @"Contents", | 57 NSString* cr_version = ObjCCast<NSString>( |
51 @"Versions", | 58 [cr_bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]); |
52 cr_version, | 59 if (!cr_version) |
53 nil]; | 60 return false; |
54 NSString* cr_versioned_path = | 61 |
55 [NSString pathWithComponents:cr_versioned_path_components]; | 62 cr_versioned_path = GetVersionedPath(cr_bundle_path, cr_version); |
63 } | |
56 | 64 |
57 // Get the framework path. | 65 // Get the framework path. |
58 NSString* cr_bundle_exe = | 66 NSString* cr_bundle_exe = |
59 ObjCCast<NSString>( | 67 ObjCCast<NSString>( |
60 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]); | 68 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]); |
61 // Essentially we want chrome::kFrameworkName which looks like | 69 // Essentially we want chrome::kFrameworkName which looks like |
62 // "$PRODUCT_STRING Framework.framework". The library itself is at | 70 // "$PRODUCT_STRING Framework.framework". The library itself is at |
63 // "$PRODUCT_STRING Framework.framework/$PRODUCT_STRING Framework". Note that | 71 // "$PRODUCT_STRING Framework.framework/$PRODUCT_STRING Framework". Note that |
64 // $PRODUCT_STRING is not |cr_bundle_exe| because in Canary the framework is | 72 // $PRODUCT_STRING is not |cr_bundle_exe| because in Canary the framework is |
65 // still called "Google Chrome Framework". | 73 // still called "Google Chrome Framework". |
(...skipping 17 matching lines...) Expand all Loading... | |
83 // A few more sanity checks. | 91 // A few more sanity checks. |
84 BOOL is_directory; | 92 BOOL is_directory; |
85 BOOL exists = [[NSFileManager defaultManager] | 93 BOOL exists = [[NSFileManager defaultManager] |
86 fileExistsAtPath:cr_framework_shlib_path | 94 fileExistsAtPath:cr_framework_shlib_path |
87 isDirectory:&is_directory]; | 95 isDirectory:&is_directory]; |
88 if (!exists || is_directory) | 96 if (!exists || is_directory) |
89 return false; | 97 return false; |
90 | 98 |
91 // Everything OK, copy output parameters. | 99 // Everything OK, copy output parameters. |
92 *executable_path = base::mac::NSStringToFilePath([cr_bundle executablePath]); | 100 *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); | 101 *version_path = base::mac::NSStringToFilePath(cr_versioned_path); |
95 *framework_shlib_path = | 102 *framework_shlib_path = |
96 base::mac::NSStringToFilePath(cr_framework_shlib_path); | 103 base::mac::NSStringToFilePath(cr_framework_shlib_path); |
97 return true; | 104 return true; |
98 } | 105 } |
99 | 106 |
100 } // namespace app_mode | 107 } // namespace app_mode |
OLD | NEW |