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
3 // found in the LICENSE file.
5 #include "base/file_version_info_mac.h"
7 #import <Foundation/Foundation.h>
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "base/mac/bundle_locations.h"
12 #include "base/mac/foundation_util.h"
13 #include "base/strings/sys_string_conversions.h"
15 FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle)
16 : bundle_([bundle retain]) {
19 FileVersionInfoMac::~FileVersionInfoMac() {}
22 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
23 return CreateFileVersionInfo(base::mac::FrameworkBundlePath());
27 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo(
28 const base::FilePath& file_path) {
29 NSString* path = base::SysUTF8ToNSString(file_path.value());
30 NSBundle* bundle = [NSBundle bundleWithPath:path];
31 return new FileVersionInfoMac(bundle);
34 base::string16 FileVersionInfoMac::company_name() {
35 return base::string16();
38 base::string16 FileVersionInfoMac::company_short_name() {
39 return base::string16();
42 base::string16 FileVersionInfoMac::internal_name() {
43 return base::string16();
46 base::string16 FileVersionInfoMac::product_name() {
47 return GetString16Value(kCFBundleNameKey);
50 base::string16 FileVersionInfoMac::product_short_name() {
51 return GetString16Value(kCFBundleNameKey);
54 base::string16 FileVersionInfoMac::comments() {
55 return base::string16();
58 base::string16 FileVersionInfoMac::legal_copyright() {
59 return GetString16Value(CFSTR("CFBundleGetInfoString"));
62 base::string16 FileVersionInfoMac::product_version() {
63 // On OS X, CFBundleVersion is used by LaunchServices, and must follow
64 // specific formatting rules, so the four-part Chrome version is in
65 // CFBundleShortVersionString. On iOS, however, CFBundleVersion can be the
66 // full version, but CFBundleShortVersionString has a policy-enfoced limit
67 // of three version components.
69 return GetString16Value(CFSTR("CFBundleVersion"));
71 return GetString16Value(CFSTR("CFBundleShortVersionString"));
72 #endif // defined(OS_IOS)
75 base::string16 FileVersionInfoMac::file_description() {
76 return base::string16();
79 base::string16 FileVersionInfoMac::legal_trademarks() {
80 return base::string16();
83 base::string16 FileVersionInfoMac::private_build() {
84 return base::string16();
87 base::string16 FileVersionInfoMac::file_version() {
88 return product_version();
91 base::string16 FileVersionInfoMac::original_filename() {
92 return GetString16Value(kCFBundleNameKey);
95 base::string16 FileVersionInfoMac::special_build() {
96 return base::string16();
99 base::string16 FileVersionInfoMac::last_change() {
100 return GetString16Value(CFSTR("SCMRevision"));
103 bool FileVersionInfoMac::is_official_build() {
104 #if defined (GOOGLE_CHROME_BUILD)
111 base::string16 FileVersionInfoMac::GetString16Value(CFStringRef name) {
113 NSString *ns_name = base::mac::CFToNSCast(name);
114 NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name];
116 return base::SysNSStringToUTF16(value);
119 return base::string16();