1 // Copyright (c) 2011 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. 4 5 #include "base/file_version_info_mac.h" 6 7 #import <Foundation/Foundation.h> 8 9 #include "base/file_path.h" 10 #include "base/logging.h" 11 #include "base/mac/mac_util.h" 12 #include "base/sys_string_conversions.h" 13 14 FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) 15 : bundle_([bundle retain]) { 16 } 17 18 FileVersionInfoMac::~FileVersionInfoMac() {} 19 20 // static 21 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { 22 return CreateFileVersionInfo(base::mac::MainAppBundlePath()); 23 } 24 25 // static 26 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( 27 const FilePath& file_path) { 28 NSString* path = base::SysUTF8ToNSString(file_path.value()); 29 NSBundle* bundle = [NSBundle bundleWithPath:path]; 30 return new FileVersionInfoMac(bundle); 31 } 32 33 string16 FileVersionInfoMac::company_name() { 34 return string16(); 35 } 36 37 string16 FileVersionInfoMac::company_short_name() { 38 return string16(); 39 } 40 41 string16 FileVersionInfoMac::internal_name() { 42 return string16(); 43 } 44 45 string16 FileVersionInfoMac::product_name() { 46 return GetString16Value(kCFBundleNameKey); 47 } 48 49 string16 FileVersionInfoMac::product_short_name() { 50 return GetString16Value(kCFBundleNameKey); 51 } 52 53 string16 FileVersionInfoMac::comments() { 54 return string16(); 55 } 56 57 string16 FileVersionInfoMac::legal_copyright() { 58 return GetString16Value(CFSTR("CFBundleGetInfoString")); 59 } 60 61 string16 FileVersionInfoMac::product_version() { 62 return GetString16Value(CFSTR("CFBundleShortVersionString")); 63 } 64 65 string16 FileVersionInfoMac::file_description() { 66 return string16(); 67 } 68 69 string16 FileVersionInfoMac::legal_trademarks() { 70 return string16(); 71 } 72 73 string16 FileVersionInfoMac::private_build() { 74 return string16(); 75 } 76 77 string16 FileVersionInfoMac::file_version() { 78 return product_version(); 79 } 80 81 string16 FileVersionInfoMac::original_filename() { 82 return GetString16Value(kCFBundleNameKey); 83 } 84 85 string16 FileVersionInfoMac::special_build() { 86 return string16(); 87 } 88 89 string16 FileVersionInfoMac::last_change() { 90 return GetString16Value(CFSTR("SVNRevision")); 91 } 92 93 bool FileVersionInfoMac::is_official_build() { 94 #if defined (GOOGLE_CHROME_BUILD) 95 return true; 96 #else 97 return false; 98 #endif 99 } 100 101 string16 FileVersionInfoMac::GetString16Value(CFStringRef name) { 102 if (bundle_) { 103 NSString *ns_name = base::mac::CFToNSCast(name); 104 NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name]; 105 if (value) { 106 return base::SysNSStringToUTF16(value); 107 } 108 } 109 return string16(); 110 } 111