Chromium Code Reviews| Index: chrome/common/mac/app_mode_chrome_locator.mm |
| diff --git a/chrome/common/mac/app_mode_chrome_locator.mm b/chrome/common/mac/app_mode_chrome_locator.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e6082215a82d2e280c6f27cce73c60f56dc91d95 |
| --- /dev/null |
| +++ b/chrome/common/mac/app_mode_chrome_locator.mm |
| @@ -0,0 +1,84 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "chrome/common/mac/app_mode_chrome_locator.h" |
| + |
| +#import <AppKit/AppKit.h> |
| +#include <CoreFoundation/CoreFoundation.h> |
| + |
| +#include "base/file_path.h" |
| +#include "base/sys_string_conversions.h" |
| + |
| +namespace app_mode { |
| + |
|
Mark Mentovai
2012/02/07 17:28:06
Who calls these functions? They may need their own
jeremy
2012/02/09 10:52:51
They are only called by the app_loader_mac.mm code
|
| +bool FindBundleById(NSString* bundle_id, FilePath* out_bundle) { |
| + NSString *bundlePath = [[NSWorkspace sharedWorkspace] |
| + absolutePathForAppBundleWithIdentifier:bundle_id]; |
|
Mark Mentovai
2012/02/07 17:28:06
Weird indentation.
jeremy
2012/02/09 10:52:51
Done.
|
| + if (!bundlePath) |
| + return false; |
| + |
| + *out_bundle = FilePath([bundlePath fileSystemRepresentation]); |
| + return true; |
| +} |
| + |
| +bool GetChromeBundleInfo(FilePath& chrome_bundle, |
| + string16* raw_version_str, |
| + FilePath* version_path, |
| + FilePath* framework_shlib_path) { |
| + NSString* cr_bundle_path = |
| + [[NSFileManager defaultManager] |
| + stringWithFileSystemRepresentation:chrome_bundle.value().c_str() |
| + length:chrome_bundle.value().size()]; |
| + NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path]; |
| + |
| + if (!cr_bundle) |
| + return false; |
| + |
| + // Read raw version string. |
| + NSString* cr_version = |
| + [cr_bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; |
| + if (!cr_version) |
| + return false; |
| + |
| + // Get versioned directory. |
| + NSArray* cr_versioned_path_components = |
| + [NSArray arrayWithObjects:cr_bundle_path, |
| + @"Contents", |
| + @"Versions", |
| + cr_version, |
| + nil]; |
| + NSString* cr_versioned_path = |
| + [[NSString pathWithComponents:cr_versioned_path_components] |
| + stringByStandardizingPath]; |
|
Mark Mentovai
2012/02/07 17:28:06
Do you need -stringByStandardizingPath? Don’t thin
jeremy
2012/02/09 10:52:51
Done.
|
| + |
| + // Get the framework path. |
| + NSString* cr_bundle_exe = |
| + [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]; |
| + NSString* cr_framework_shlib_path = |
| + [cr_versioned_path stringByAppendingPathComponent: |
| + [cr_bundle_exe stringByAppendingString:@" Framework.framework"]]; |
| + cr_framework_shlib_path = |
| + [cr_framework_shlib_path stringByAppendingPathComponent: |
| + [cr_bundle_exe stringByAppendingString:@" Framework"]]; |
| + if (!cr_bundle_exe || !cr_framework_shlib_path) |
| + return false; |
| + |
| + // A few more sanity checks. |
| + BOOL is_directory; |
| + BOOL exists = [[NSFileManager defaultManager] |
| + fileExistsAtPath:cr_framework_shlib_path |
| + isDirectory:&is_directory]; |
| + if (!exists || is_directory) |
| + return false; |
| + |
| + // Everything OK, copy output parameters. |
| + *raw_version_str = base::SysNSStringToUTF16(cr_version); |
| + *version_path = FilePath([cr_versioned_path fileSystemRepresentation]); |
| + *framework_shlib_path = FilePath( |
| + [cr_framework_shlib_path fileSystemRepresentation]); |
| + return true; |
| +} |
| + |
| +} // namespace app_mode |
| + |
|
Mark Mentovai
2012/02/07 17:28:06
Get rid of the blank line.
jeremy
2012/02/09 10:52:51
Done.
|