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