blob: 600a0faed9d855554556995de8afa20a3dd1cf4c [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]2f1804c2012-01-19 14:59:0710#include "base/mac/bundle_locations.h"
[email protected]27d02e02011-05-05 21:27:0711#include "base/mac/foundation_util.h"
[email protected]9fe1a5b2013-02-07 19:18:0312#include "base/strings/sys_string_conversions.h"
avi9b6f42932015-12-26 22:15:1413#include "build/build_config.h"
[email protected]6723f832008-08-11 15:38:2714
[email protected]ea053a982011-04-11 19:17:1315FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle)
16 : bundle_([bundle retain]) {
[email protected]6723f832008-08-11 15:38:2717}
18
[email protected]64b29caf2011-02-24 20:23:0319FileVersionInfoMac::~FileVersionInfoMac() {}
20
[email protected]6723f832008-08-11 15:38:2721// static
David Benjamin04cc2b42019-01-29 05:30:3322std::unique_ptr<FileVersionInfo>
23FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
[email protected]2f1804c2012-01-19 14:59:0724 return CreateFileVersionInfo(base::mac::FrameworkBundlePath());
[email protected]09562232008-12-23 16:57:3625}
26
27// static
David Benjamin04cc2b42019-01-29 05:30:3328std::unique_ptr<FileVersionInfo> FileVersionInfo::CreateFileVersionInfo(
[email protected]aaa6df42013-02-17 19:36:0329 const base::FilePath& file_path) {
[email protected]7c1e3032010-12-20 18:40:4230 NSString* path = base::SysUTF8ToNSString(file_path.value());
31 NSBundle* bundle = [NSBundle bundleWithPath:path];
David Benjamin04cc2b42019-01-29 05:30:3332 return std::make_unique<FileVersionInfoMac>(bundle);
[email protected]6723f832008-08-11 15:38:2733}
34
Jan Wilken Dörrie85285b02021-03-11 23:38:4735std::u16string FileVersionInfoMac::company_name() {
36 return std::u16string();
[email protected]6723f832008-08-11 15:38:2737}
38
Jan Wilken Dörrie85285b02021-03-11 23:38:4739std::u16string FileVersionInfoMac::company_short_name() {
40 return std::u16string();
[email protected]6723f832008-08-11 15:38:2741}
42
Jan Wilken Dörrie85285b02021-03-11 23:38:4743std::u16string FileVersionInfoMac::internal_name() {
44 return std::u16string();
[email protected]6723f832008-08-11 15:38:2745}
46
Jan Wilken Dörrie85285b02021-03-11 23:38:4747std::u16string FileVersionInfoMac::product_name() {
[email protected]4f260d02010-12-23 18:35:4248 return GetString16Value(kCFBundleNameKey);
[email protected]6723f832008-08-11 15:38:2749}
50
Jan Wilken Dörrie85285b02021-03-11 23:38:4751std::u16string FileVersionInfoMac::product_short_name() {
[email protected]4f260d02010-12-23 18:35:4252 return GetString16Value(kCFBundleNameKey);
[email protected]6723f832008-08-11 15:38:2753}
54
Jan Wilken Dörrie85285b02021-03-11 23:38:4755std::u16string FileVersionInfoMac::product_version() {
[email protected]77816eaa2012-07-24 11:19:0856 // On OS X, CFBundleVersion is used by LaunchServices, and must follow
57 // specific formatting rules, so the four-part Chrome version is in
stuartmorgan5e617ac2014-09-08 22:51:2458 // CFBundleShortVersionString. On iOS, both have a policy-enfoced limit
59 // of three version components, so the full version is stored in a custom
60 // key (CrBundleVersion) falling back to CFBundleVersion if not present.
Xiaohan Wang38e4ebb2022-01-19 06:57:4361#if BUILDFLAG(IS_IOS)
Jan Wilken Dörrie85285b02021-03-11 23:38:4762 std::u16string version(GetString16Value(CFSTR("CrBundleVersion")));
stuartmorgan5e617ac2014-09-08 22:51:2463 if (version.length() > 0)
64 return version;
[email protected]77816eaa2012-07-24 11:19:0865 return GetString16Value(CFSTR("CFBundleVersion"));
66#else
[email protected]4f260d02010-12-23 18:35:4267 return GetString16Value(CFSTR("CFBundleShortVersionString"));
Xiaohan Wang38e4ebb2022-01-19 06:57:4368#endif // BUILDFLAG(IS_IOS)
[email protected]6723f832008-08-11 15:38:2769}
70
Jan Wilken Dörrie85285b02021-03-11 23:38:4771std::u16string FileVersionInfoMac::file_description() {
72 return std::u16string();
[email protected]6723f832008-08-11 15:38:2773}
74
Jan Wilken Dörrie85285b02021-03-11 23:38:4775std::u16string FileVersionInfoMac::file_version() {
[email protected]41cd00a42009-10-14 15:51:5776 return product_version();
[email protected]6723f832008-08-11 15:38:2777}
78
Jan Wilken Dörrie85285b02021-03-11 23:38:4779std::u16string FileVersionInfoMac::original_filename() {
[email protected]4f260d02010-12-23 18:35:4280 return GetString16Value(kCFBundleNameKey);
[email protected]6723f832008-08-11 15:38:2781}
82
Jan Wilken Dörrie85285b02021-03-11 23:38:4783std::u16string FileVersionInfoMac::special_build() {
84 return std::u16string();
[email protected]6723f832008-08-11 15:38:2785}
86
Jan Wilken Dörrie85285b02021-03-11 23:38:4787std::u16string FileVersionInfoMac::GetString16Value(CFStringRef name) {
[email protected]6723f832008-08-11 15:38:2788 if (bundle_) {
[email protected]0378bf42011-01-01 18:20:1489 NSString *ns_name = base::mac::CFToNSCast(name);
[email protected]7c1e3032010-12-20 18:40:4290 NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name];
[email protected]6723f832008-08-11 15:38:2791 if (value) {
[email protected]4f260d02010-12-23 18:35:4292 return base::SysNSStringToUTF16(value);
[email protected]6723f832008-08-11 15:38:2793 }
94 }
Jan Wilken Dörrie85285b02021-03-11 23:38:4795 return std::u16string();
[email protected]6723f832008-08-11 15:38:2796}