[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] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 9 | #include "base/files/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] | 9fe1a5b | 2013-02-07 19:18:03 | [diff] [blame] | 13 | #include "base/strings/sys_string_conversions.h" |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 14 | #include "build/build_config.h" |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 15 | |
[email protected] | ea053a98 | 2011-04-11 19:17:13 | [diff] [blame] | 16 | FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) |
17 | : bundle_([bundle retain]) { | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 18 | } |
19 | |||||
[email protected] | 64b29caf | 2011-02-24 20:23:03 | [diff] [blame] | 20 | FileVersionInfoMac::~FileVersionInfoMac() {} |
21 | |||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 22 | // static |
David Benjamin | 04cc2b4 | 2019-01-29 05:30:33 | [diff] [blame] | 23 | std::unique_ptr<FileVersionInfo> |
24 | FileVersionInfo::CreateFileVersionInfoForCurrentModule() { | ||||
[email protected] | 2f1804c | 2012-01-19 14:59:07 | [diff] [blame] | 25 | return CreateFileVersionInfo(base::mac::FrameworkBundlePath()); |
[email protected] | 0956223 | 2008-12-23 16:57:36 | [diff] [blame] | 26 | } |
27 | |||||
28 | // static | ||||
David Benjamin | 04cc2b4 | 2019-01-29 05:30:33 | [diff] [blame] | 29 | std::unique_ptr<FileVersionInfo> FileVersionInfo::CreateFileVersionInfo( |
[email protected] | aaa6df4 | 2013-02-17 19:36:03 | [diff] [blame] | 30 | const base::FilePath& file_path) { |
[email protected] | 7c1e303 | 2010-12-20 18:40:42 | [diff] [blame] | 31 | NSString* path = base::SysUTF8ToNSString(file_path.value()); |
32 | NSBundle* bundle = [NSBundle bundleWithPath:path]; | ||||
David Benjamin | 04cc2b4 | 2019-01-29 05:30:33 | [diff] [blame] | 33 | return std::make_unique<FileVersionInfoMac>(bundle); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 34 | } |
35 | |||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 36 | base::string16 FileVersionInfoMac::company_name() { |
37 | return base::string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 38 | } |
39 | |||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 40 | base::string16 FileVersionInfoMac::company_short_name() { |
41 | return base::string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 42 | } |
43 | |||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 44 | base::string16 FileVersionInfoMac::internal_name() { |
45 | return base::string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 46 | } |
47 | |||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 48 | base::string16 FileVersionInfoMac::product_name() { |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 49 | return GetString16Value(kCFBundleNameKey); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 50 | } |
51 | |||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 52 | base::string16 FileVersionInfoMac::product_short_name() { |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 53 | return GetString16Value(kCFBundleNameKey); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 54 | } |
55 | |||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 56 | base::string16 FileVersionInfoMac::product_version() { |
[email protected] | 77816eaa | 2012-07-24 11:19:08 | [diff] [blame] | 57 | // On OS X, CFBundleVersion is used by LaunchServices, and must follow |
58 | // specific formatting rules, so the four-part Chrome version is in | ||||
stuartmorgan | 5e617ac | 2014-09-08 22:51:24 | [diff] [blame] | 59 | // CFBundleShortVersionString. On iOS, both have a policy-enfoced limit |
60 | // of three version components, so the full version is stored in a custom | ||||
61 | // key (CrBundleVersion) falling back to CFBundleVersion if not present. | ||||
[email protected] | 77816eaa | 2012-07-24 11:19:08 | [diff] [blame] | 62 | #if defined(OS_IOS) |
stuartmorgan | 5e617ac | 2014-09-08 22:51:24 | [diff] [blame] | 63 | base::string16 version(GetString16Value(CFSTR("CrBundleVersion"))); |
64 | if (version.length() > 0) | ||||
65 | return version; | ||||
[email protected] | 77816eaa | 2012-07-24 11:19:08 | [diff] [blame] | 66 | return GetString16Value(CFSTR("CFBundleVersion")); |
67 | #else | ||||
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 68 | return GetString16Value(CFSTR("CFBundleShortVersionString")); |
[email protected] | 77816eaa | 2012-07-24 11:19:08 | [diff] [blame] | 69 | #endif // defined(OS_IOS) |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 70 | } |
71 | |||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 72 | base::string16 FileVersionInfoMac::file_description() { |
73 | return base::string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 74 | } |
75 | |||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 76 | base::string16 FileVersionInfoMac::file_version() { |
[email protected] | 41cd00a4 | 2009-10-14 15:51:57 | [diff] [blame] | 77 | return product_version(); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 78 | } |
79 | |||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 80 | base::string16 FileVersionInfoMac::original_filename() { |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 81 | return GetString16Value(kCFBundleNameKey); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 82 | } |
83 | |||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 84 | base::string16 FileVersionInfoMac::special_build() { |
85 | return base::string16(); | ||||
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 86 | } |
87 | |||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 88 | base::string16 FileVersionInfoMac::GetString16Value(CFStringRef name) { |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 89 | if (bundle_) { |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 90 | NSString *ns_name = base::mac::CFToNSCast(name); |
[email protected] | 7c1e303 | 2010-12-20 18:40:42 | [diff] [blame] | 91 | NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name]; |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 92 | if (value) { |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 93 | return base::SysNSStringToUTF16(value); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 94 | } |
95 | } | ||||
[email protected] | f527d9c | 2013-12-30 21:43:00 | [diff] [blame] | 96 | return base::string16(); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 97 | } |