Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4769)

Unified Diff: chrome/common/mac/app_mode_chrome_locator.mm

Issue 9351014: Mac app mode: locate Chrome + refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Path for landing1 Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/mac/app_mode_chrome_locator.h ('k') | chrome/common/mac/app_mode_chrome_locator_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b64778fa8f29c2876d61f46756fe4fb5da6b94b5
--- /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/mac/foundation_util.h"
+#include "base/sys_string_conversions.h"
+
+namespace app_mode {
+
+bool FindBundleById(NSString* bundle_id, FilePath* out_bundle) {
+ NSWorkspace* ws = [NSWorkspace sharedWorkspace];
+ NSString *bundlePath = [ws absolutePathForAppBundleWithIdentifier:bundle_id];
+ if (!bundlePath)
+ return false;
+
+ *out_bundle = base::mac::NSStringToFilePath(bundlePath);
+ return true;
+}
+
+bool GetChromeBundleInfo(const FilePath& chrome_bundle,
+ string16* raw_version_str,
+ FilePath* version_path,
+ FilePath* framework_shlib_path) {
+ using base::mac::ObjCCast;
+
+ NSString* cr_bundle_path = base::mac::FilePathToNSString(chrome_bundle);
+ NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path];
+
+ if (!cr_bundle)
+ return false;
+
+ // Read raw version string.
+ NSString* cr_version =
+ ObjCCast<NSString>(
+ [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];
+
+ // Get the framework path.
+ NSString* cr_bundle_exe =
+ ObjCCast<NSString>(
+ [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 = base::mac::NSStringToFilePath(cr_versioned_path);
+ *framework_shlib_path =
+ base::mac::NSStringToFilePath(cr_framework_shlib_path);
+ return true;
+}
+
+} // namespace app_mode
« no previous file with comments | « chrome/common/mac/app_mode_chrome_locator.h ('k') | chrome/common/mac/app_mode_chrome_locator_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698