blob: ef5a2994552ec735f52958f5fb9eded5bab1bc04 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2012 The Chromium Authors
[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
Avi Drissman412e7b72023-08-15 00:33:445#include "base/file_version_info_apple.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
Avi Drissman6fdbaf082023-06-07 19:35:099#include "base/apple/bridging.h"
Avi Drissmand4f07082023-05-12 18:05:4410#include "base/apple/bundle_locations.h"
Avi Drissmaneac566b02023-08-18 02:56:2111#include "base/apple/foundation_util.h"
[email protected]57999812013-02-24 05:40:5212#include "base/files/file_path.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
Avi Drissman412e7b72023-08-15 00:33:4416FileVersionInfoApple::FileVersionInfoApple(NSBundle* bundle)
17 : bundle_(bundle) {}
Avi Drissman6fdbaf082023-06-07 19:35:0918
Avi Drissman412e7b72023-08-15 00:33:4419FileVersionInfoApple::~FileVersionInfoApple() = default;
[email protected]64b29caf2011-02-24 20:23:0320
[email protected]6723f832008-08-11 15:38:2721// static
David Benjamin04cc2b42019-01-29 05:30:3322std::unique_ptr<FileVersionInfo>
23FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
Avi Drissmand4f07082023-05-12 18:05:4424 return CreateFileVersionInfo(base::apple::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];
Avi Drissman412e7b72023-08-15 00:33:4432 return std::make_unique<FileVersionInfoApple>(bundle);
[email protected]6723f832008-08-11 15:38:2733}
34
Avi Drissman412e7b72023-08-15 00:33:4435std::u16string FileVersionInfoApple::company_name() {
Jan Wilken Dörrie85285b02021-03-11 23:38:4736 return std::u16string();
[email protected]6723f832008-08-11 15:38:2737}
38
Avi Drissman412e7b72023-08-15 00:33:4439std::u16string FileVersionInfoApple::company_short_name() {
Jan Wilken Dörrie85285b02021-03-11 23:38:4740 return std::u16string();
[email protected]6723f832008-08-11 15:38:2741}
42
Avi Drissman412e7b72023-08-15 00:33:4443std::u16string FileVersionInfoApple::internal_name() {
Jan Wilken Dörrie85285b02021-03-11 23:38:4744 return std::u16string();
[email protected]6723f832008-08-11 15:38:2745}
46
Avi Drissman412e7b72023-08-15 00:33:4447std::u16string FileVersionInfoApple::product_name() {
[email protected]4f260d02010-12-23 18:35:4248 return GetString16Value(kCFBundleNameKey);
[email protected]6723f832008-08-11 15:38:2749}
50
Avi Drissman412e7b72023-08-15 00:33:4451std::u16string FileVersionInfoApple::product_short_name() {
[email protected]4f260d02010-12-23 18:35:4252 return GetString16Value(kCFBundleNameKey);
[email protected]6723f832008-08-11 15:38:2753}
54
Avi Drissman412e7b72023-08-15 00:33:4455std::u16string FileVersionInfoApple::product_version() {
Avi Drissman6fdbaf082023-06-07 19:35:0956 // On macOS, CFBundleVersion is used by LaunchServices, and must follow
[email protected]77816eaa2012-07-24 11:19:0857 // specific formatting rules, so the four-part Chrome version is in
Avi Drissman6fdbaf082023-06-07 19:35:0958 // CFBundleShortVersionString. On iOS, both have a policy-enforced limit
stuartmorgan5e617ac2014-09-08 22:51:2459 // 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")));
Avi Drissman412e7b72023-08-15 00:33:4463 if (version.length() > 0) {
stuartmorgan5e617ac2014-09-08 22:51:2464 return version;
Avi Drissman412e7b72023-08-15 00:33:4465 }
[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"));
Xiaohan Wang38e4ebb2022-01-19 06:57:4369#endif // BUILDFLAG(IS_IOS)
[email protected]6723f832008-08-11 15:38:2770}
71
Avi Drissman412e7b72023-08-15 00:33:4472std::u16string FileVersionInfoApple::file_description() {
Jan Wilken Dörrie85285b02021-03-11 23:38:4773 return std::u16string();
[email protected]6723f832008-08-11 15:38:2774}
75
Avi Drissman412e7b72023-08-15 00:33:4476std::u16string FileVersionInfoApple::file_version() {
[email protected]41cd00a42009-10-14 15:51:5777 return product_version();
[email protected]6723f832008-08-11 15:38:2778}
79
Avi Drissman412e7b72023-08-15 00:33:4480std::u16string FileVersionInfoApple::original_filename() {
[email protected]4f260d02010-12-23 18:35:4281 return GetString16Value(kCFBundleNameKey);
[email protected]6723f832008-08-11 15:38:2782}
83
Avi Drissman412e7b72023-08-15 00:33:4484std::u16string FileVersionInfoApple::special_build() {
Jan Wilken Dörrie85285b02021-03-11 23:38:4785 return std::u16string();
[email protected]6723f832008-08-11 15:38:2786}
87
Avi Drissman412e7b72023-08-15 00:33:4488std::u16string FileVersionInfoApple::GetString16Value(CFStringRef name) {
[email protected]6723f832008-08-11 15:38:2789 if (bundle_) {
Avi Drissman6fdbaf082023-06-07 19:35:0990 NSString* ns_name = base::apple::CFToNSPtrCast(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 }
Jan Wilken Dörrie85285b02021-03-11 23:38:4796 return std::u16string();
[email protected]6723f832008-08-11 15:38:2797}