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 base::FilePath* executable_path, | |
28 base::string16* raw_version_str, | 29 base::string16* raw_version_str, |
29 base::FilePath* version_path, | 30 base::FilePath* version_path, |
30 base::FilePath* framework_shlib_path) { | 31 base::FilePath* framework_shlib_path) { |
31 using base::mac::ObjCCast; | 32 using base::mac::ObjCCast; |
32 | 33 |
33 NSString* cr_bundle_path = base::mac::FilePathToNSString(chrome_bundle); | 34 NSString* cr_bundle_path = base::mac::FilePathToNSString(chrome_bundle); |
34 NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path]; | 35 NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path]; |
35 | 36 |
36 if (!cr_bundle) | 37 if (!cr_bundle) |
37 return false; | 38 return false; |
(...skipping 14 matching lines...) Expand all Loading... | |
52 nil]; | 53 nil]; |
53 NSString* cr_versioned_path = | 54 NSString* cr_versioned_path = |
54 [NSString pathWithComponents:cr_versioned_path_components]; | 55 [NSString pathWithComponents:cr_versioned_path_components]; |
55 | 56 |
56 // Get the framework path. | 57 // Get the framework path. |
57 NSString* cr_bundle_exe = | 58 NSString* cr_bundle_exe = |
58 ObjCCast<NSString>( | 59 ObjCCast<NSString>( |
59 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]); | 60 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]); |
60 NSString* cr_framework_shlib_path = | 61 NSString* cr_framework_shlib_path = |
61 [cr_versioned_path stringByAppendingPathComponent: | 62 [cr_versioned_path stringByAppendingPathComponent: |
62 base::SysUTF8ToNSString(chrome::kFrameworkName)]; | 63 [cr_bundle_exe stringByAppendingString:@" Framework.framework"]]; |
63 // chrome::kFrameworkName looks like "$PRODUCT_STRING Framework.framework". | 64 // chrome::kFrameworkName looks like "$PRODUCT_STRING Framework.framework". |
tapted
2014/06/13 11:15:58
nit: update this comment. Probably still worth men
jackhou1
2014/06/14 10:09:33
Done.
| |
64 // The library itself is at | 65 // The library itself is at |
65 // "$PRODUCT_STRING Framework.framework/$PRODUCT_STRING Framework", so we cut | 66 // "$PRODUCT_STRING Framework.framework/$PRODUCT_STRING Framework", so we cut |
66 // off the .framework extension here and append it to the path. | 67 // off the .framework extension here and append it to the path. |
67 // It's important to build the path to the framework this way because | 68 // It's important to build the path to the framework this way because |
68 // in Canary the framework is still called "Google Chrome Framework". | 69 // in Canary the framework is still called "Google Chrome Framework". |
69 cr_framework_shlib_path = | 70 cr_framework_shlib_path = |
70 [cr_framework_shlib_path stringByAppendingPathComponent: | 71 [cr_framework_shlib_path stringByAppendingPathComponent: |
71 [base::SysUTF8ToNSString(chrome::kFrameworkName) | 72 [cr_bundle_exe stringByAppendingString:@" Framework"]]; |
72 stringByDeletingPathExtension]]; | |
73 if (!cr_bundle_exe || !cr_framework_shlib_path) | 73 if (!cr_bundle_exe || !cr_framework_shlib_path) |
74 return false; | 74 return false; |
75 | 75 |
76 // A few more sanity checks. | 76 // A few more sanity checks. |
77 BOOL is_directory; | 77 BOOL is_directory; |
78 BOOL exists = [[NSFileManager defaultManager] | 78 BOOL exists = [[NSFileManager defaultManager] |
79 fileExistsAtPath:cr_framework_shlib_path | 79 fileExistsAtPath:cr_framework_shlib_path |
80 isDirectory:&is_directory]; | 80 isDirectory:&is_directory]; |
81 if (!exists || is_directory) | 81 if (!exists || is_directory) |
82 return false; | 82 return false; |
83 | 83 |
84 // Everything OK, copy output parameters. | 84 // Everything OK, copy output parameters. |
85 *executable_path = base::mac::NSStringToFilePath([cr_bundle executablePath]); | |
85 *raw_version_str = base::SysNSStringToUTF16(cr_version); | 86 *raw_version_str = base::SysNSStringToUTF16(cr_version); |
86 *version_path = base::mac::NSStringToFilePath(cr_versioned_path); | 87 *version_path = base::mac::NSStringToFilePath(cr_versioned_path); |
87 *framework_shlib_path = | 88 *framework_shlib_path = |
88 base::mac::NSStringToFilePath(cr_framework_shlib_path); | 89 base::mac::NSStringToFilePath(cr_framework_shlib_path); |
89 return true; | 90 return true; |
90 } | 91 } |
91 | 92 |
92 } // namespace app_mode | 93 } // namespace app_mode |
OLD | NEW |