blob: 0b50a756c9857b2241291a92095355ec9175c108 [file] [log] [blame]
[email protected]77816eaa2012-07-24 11:19:081// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]49df6022008-08-27 19:03:432// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]6723f832008-08-11 15:38:274
[email protected]bcff05a2010-04-14 01:46:435#include "base/file_version_info_mac.h"
[email protected]6723f832008-08-11 15:38:276
[email protected]7c1e3032010-12-20 18:40:427#import <Foundation/Foundation.h>
[email protected]1265917f2008-08-12 17:33:528
[email protected]57999812013-02-24 05:40:529#include "base/files/file_path.h"
[email protected]7c1e3032010-12-20 18:40:4210#include "base/logging.h"
[email protected]2f1804c2012-01-19 14:59:0711#include "base/mac/bundle_locations.h"
[email protected]27d02e02011-05-05 21:27:0712#include "base/mac/foundation_util.h"
[email protected]9fe1a5b2013-02-07 19:18:0313#include "base/strings/sys_string_conversions.h"
avi9b6f42932015-12-26 22:15:1414#include "build/build_config.h"
[email protected]6723f832008-08-11 15:38:2715
[email protected]ea053a982011-04-11 19:17:1316FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle)
17 : bundle_([bundle retain]) {
[email protected]6723f832008-08-11 15:38:2718}
19
[email protected]64b29caf2011-02-24 20:23:0320FileVersionInfoMac::~FileVersionInfoMac() {}
21
[email protected]6723f832008-08-11 15:38:2722// static
David Benjamin04cc2b42019-01-29 05:30:3323std::unique_ptr<FileVersionInfo>
24FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
[email protected]2f1804c2012-01-19 14:59:0725 return CreateFileVersionInfo(base::mac::FrameworkBundlePath());
[email protected]09562232008-12-23 16:57:3626}
27
28// static
David Benjamin04cc2b42019-01-29 05:30:3329std::unique_ptr<FileVersionInfo> FileVersionInfo::CreateFileVersionInfo(
[email protected]aaa6df42013-02-17 19:36:0330 const base::FilePath& file_path) {
[email protected]7c1e3032010-12-20 18:40:4231 NSString* path = base::SysUTF8ToNSString(file_path.value());
32 NSBundle* bundle = [NSBundle bundleWithPath:path];
David Benjamin04cc2b42019-01-29 05:30:3333 return std::make_unique<FileVersionInfoMac>(bundle);
[email protected]6723f832008-08-11 15:38:2734}
35
[email protected]f527d9c2013-12-30 21:43:0036base::string16 FileVersionInfoMac::company_name() {
37 return base::string16();
[email protected]6723f832008-08-11 15:38:2738}
39
[email protected]f527d9c2013-12-30 21:43:0040base::string16 FileVersionInfoMac::company_short_name() {
41 return base::string16();
[email protected]6723f832008-08-11 15:38:2742}
43
[email protected]f527d9c2013-12-30 21:43:0044base::string16 FileVersionInfoMac::internal_name() {
45 return base::string16();
[email protected]6723f832008-08-11 15:38:2746}
47
[email protected]f527d9c2013-12-30 21:43:0048base::string16 FileVersionInfoMac::product_name() {
[email protected]4f260d02010-12-23 18:35:4249 return GetString16Value(kCFBundleNameKey);
[email protected]6723f832008-08-11 15:38:2750}
51
[email protected]f527d9c2013-12-30 21:43:0052base::string16 FileVersionInfoMac::product_short_name() {
[email protected]4f260d02010-12-23 18:35:4253 return GetString16Value(kCFBundleNameKey);
[email protected]6723f832008-08-11 15:38:2754}
55
[email protected]f527d9c2013-12-30 21:43:0056base::string16 FileVersionInfoMac::product_version() {
[email protected]77816eaa2012-07-24 11:19:0857 // On OS X, CFBundleVersion is used by LaunchServices, and must follow
58 // specific formatting rules, so the four-part Chrome version is in
stuartmorgan5e617ac2014-09-08 22:51:2459 // 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]77816eaa2012-07-24 11:19:0862#if defined(OS_IOS)
stuartmorgan5e617ac2014-09-08 22:51:2463 base::string16 version(GetString16Value(CFSTR("CrBundleVersion")));
64 if (version.length() > 0)
65 return version;
[email protected]77816eaa2012-07-24 11:19:0866 return GetString16Value(CFSTR("CFBundleVersion"));
67#else
[email protected]4f260d02010-12-23 18:35:4268 return GetString16Value(CFSTR("CFBundleShortVersionString"));
[email protected]77816eaa2012-07-24 11:19:0869#endif // defined(OS_IOS)
[email protected]6723f832008-08-11 15:38:2770}
71
[email protected]f527d9c2013-12-30 21:43:0072base::string16 FileVersionInfoMac::file_description() {
73 return base::string16();
[email protected]6723f832008-08-11 15:38:2774}
75
[email protected]f527d9c2013-12-30 21:43:0076base::string16 FileVersionInfoMac::file_version() {
[email protected]41cd00a42009-10-14 15:51:5777 return product_version();
[email protected]6723f832008-08-11 15:38:2778}
79
[email protected]f527d9c2013-12-30 21:43:0080base::string16 FileVersionInfoMac::original_filename() {
[email protected]4f260d02010-12-23 18:35:4281 return GetString16Value(kCFBundleNameKey);
[email protected]6723f832008-08-11 15:38:2782}
83
[email protected]f527d9c2013-12-30 21:43:0084base::string16 FileVersionInfoMac::special_build() {
85 return base::string16();
[email protected]6723f832008-08-11 15:38:2786}
87
[email protected]f527d9c2013-12-30 21:43:0088base::string16 FileVersionInfoMac::GetString16Value(CFStringRef name) {
[email protected]6723f832008-08-11 15:38:2789 if (bundle_) {
[email protected]0378bf42011-01-01 18:20:1490 NSString *ns_name = base::mac::CFToNSCast(name);
[email protected]7c1e3032010-12-20 18:40:4291 NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name];
[email protected]6723f832008-08-11 15:38:2792 if (value) {
[email protected]4f260d02010-12-23 18:35:4293 return base::SysNSStringToUTF16(value);
[email protected]6723f832008-08-11 15:38:2794 }
95 }
[email protected]f527d9c2013-12-30 21:43:0096 return base::string16();
[email protected]6723f832008-08-11 15:38:2797}