[email protected] | 77816eaa | 2012-07-24 11:19:08 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 49df602 | 2008-08-27 19:03:43 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 4 | |
[email protected] | bcff05a | 2010-04-14 01:46:43 | [diff] [blame] | 5 | #include "base/file_version_info_mac.h" |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 6 | |
[email protected] | 7c1e303 | 2010-12-20 18:40:42 | [diff] [blame] | 7 | #import <Foundation/Foundation.h> |
[email protected] | 1265917f | 2008-08-12 17:33:52 | [diff] [blame] | 8 | |
[email protected] | f539333 | 2009-06-03 15:01:29 | [diff] [blame] | 9 | #include "base/file_path.h" |
[email protected] | 7c1e303 | 2010-12-20 18:40:42 | [diff] [blame] | 10 | #include "base/logging.h" |
[email protected] | 2f1804c | 2012-01-19 14:59:07 | [diff] [blame] | 11 | #include "base/mac/bundle_locations.h" |
[email protected] | 27d02e0 | 2011-05-05 21:27:07 | [diff] [blame] | 12 | #include "base/mac/foundation_util.h" |
[email protected] | 7c1e303 | 2010-12-20 18:40:42 | [diff] [blame] | 13 | #include "base/sys_string_conversions.h" |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 14 | |
[email protected] | ea053a98 | 2011-04-11 19:17:13 | [diff] [blame] | 15 | FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) |
16 | : bundle_([bundle retain]) { | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 17 | } |
18 | |||||
[email protected] | 64b29caf | 2011-02-24 20:23:03 | [diff] [blame] | 19 | FileVersionInfoMac::~FileVersionInfoMac() {} |
20 | |||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 21 | // static |
22 | FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { | ||||
[email protected] | 2f1804c | 2012-01-19 14:59:07 | [diff] [blame] | 23 | return CreateFileVersionInfo(base::mac::FrameworkBundlePath()); |
[email protected] | 0956223 | 2008-12-23 16:57:36 | [diff] [blame] | 24 | } |
25 | |||||
26 | // static | ||||
27 | FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( | ||||
28 | const FilePath& file_path) { | ||||
[email protected] | 7c1e303 | 2010-12-20 18:40:42 | [diff] [blame] | 29 | NSString* path = base::SysUTF8ToNSString(file_path.value()); |
30 | NSBundle* bundle = [NSBundle bundleWithPath:path]; | ||||
31 | return new FileVersionInfoMac(bundle); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 32 | } |
33 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 34 | string16 FileVersionInfoMac::company_name() { |
35 | return string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 36 | } |
37 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 38 | string16 FileVersionInfoMac::company_short_name() { |
39 | return string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 40 | } |
41 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 42 | string16 FileVersionInfoMac::internal_name() { |
43 | return string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 44 | } |
45 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 46 | string16 FileVersionInfoMac::product_name() { |
47 | return GetString16Value(kCFBundleNameKey); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 48 | } |
49 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 50 | string16 FileVersionInfoMac::product_short_name() { |
51 | return GetString16Value(kCFBundleNameKey); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 52 | } |
53 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 54 | string16 FileVersionInfoMac::comments() { |
55 | return string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 56 | } |
57 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 58 | string16 FileVersionInfoMac::legal_copyright() { |
59 | return GetString16Value(CFSTR("CFBundleGetInfoString")); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 60 | } |
61 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 62 | string16 FileVersionInfoMac::product_version() { |
[email protected] | 77816eaa | 2012-07-24 11:19:08 | [diff] [blame^] | 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. | ||||
68 | #if defined(OS_IOS) | ||||
69 | return GetString16Value(CFSTR("CFBundleVersion")); | ||||
70 | #else | ||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 71 | return GetString16Value(CFSTR("CFBundleShortVersionString")); |
[email protected] | 77816eaa | 2012-07-24 11:19:08 | [diff] [blame^] | 72 | #endif // defined(OS_IOS) |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 73 | } |
74 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 75 | string16 FileVersionInfoMac::file_description() { |
76 | return string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 77 | } |
78 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 79 | string16 FileVersionInfoMac::legal_trademarks() { |
80 | return string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 81 | } |
82 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 83 | string16 FileVersionInfoMac::private_build() { |
84 | return string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 85 | } |
86 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 87 | string16 FileVersionInfoMac::file_version() { |
[email protected] | 41cd00a4 | 2009-10-14 15:51:57 | [diff] [blame] | 88 | return product_version(); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 89 | } |
90 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 91 | string16 FileVersionInfoMac::original_filename() { |
92 | return GetString16Value(kCFBundleNameKey); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 93 | } |
94 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 95 | string16 FileVersionInfoMac::special_build() { |
96 | return string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 97 | } |
98 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 99 | string16 FileVersionInfoMac::last_change() { |
100 | return GetString16Value(CFSTR("SVNRevision")); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 101 | } |
102 | |||||
[email protected] | bcff05a | 2010-04-14 01:46:43 | [diff] [blame] | 103 | bool FileVersionInfoMac::is_official_build() { |
[email protected] | 1f2fe99 | 2009-06-01 18:27:27 | [diff] [blame] | 104 | #if defined (GOOGLE_CHROME_BUILD) |
105 | return true; | ||||
106 | #else | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 107 | return false; |
[email protected] | 1f2fe99 | 2009-06-01 18:27:27 | [diff] [blame] | 108 | #endif |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 109 | } |
110 | |||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 111 | string16 FileVersionInfoMac::GetString16Value(CFStringRef name) { |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 112 | if (bundle_) { |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 113 | NSString *ns_name = base::mac::CFToNSCast(name); |
[email protected] | 7c1e303 | 2010-12-20 18:40:42 | [diff] [blame] | 114 | NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name]; |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 115 | if (value) { |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 116 | return base::SysNSStringToUTF16(value); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 117 | } |
118 | } | ||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 119 | return string16(); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 120 | } |