[M85 Dev][EFL] Fix crashes at webview launch
[platform/framework/web/chromium-efl.git] / base / file_version_info_mac.mm
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/file_version_info_mac.h"
6
7 #import <Foundation/Foundation.h>
8
9 #include "base/files/file_path.h"
10 #include "base/mac/bundle_locations.h"
11 #include "base/mac/foundation_util.h"
12 #include "base/strings/sys_string_conversions.h"
13 #include "build/build_config.h"
14
15 FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle)
16     : bundle_([bundle retain]) {
17 }
18
19 FileVersionInfoMac::~FileVersionInfoMac() {}
20
21 // static
22 std::unique_ptr<FileVersionInfo>
23 FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
24   return CreateFileVersionInfo(base::mac::FrameworkBundlePath());
25 }
26
27 // static
28 std::unique_ptr<FileVersionInfo> FileVersionInfo::CreateFileVersionInfo(
29     const base::FilePath& file_path) {
30   NSString* path = base::SysUTF8ToNSString(file_path.value());
31   NSBundle* bundle = [NSBundle bundleWithPath:path];
32   return std::make_unique<FileVersionInfoMac>(bundle);
33 }
34
35 base::string16 FileVersionInfoMac::company_name() {
36   return base::string16();
37 }
38
39 base::string16 FileVersionInfoMac::company_short_name() {
40   return base::string16();
41 }
42
43 base::string16 FileVersionInfoMac::internal_name() {
44   return base::string16();
45 }
46
47 base::string16 FileVersionInfoMac::product_name() {
48   return GetString16Value(kCFBundleNameKey);
49 }
50
51 base::string16 FileVersionInfoMac::product_short_name() {
52   return GetString16Value(kCFBundleNameKey);
53 }
54
55 base::string16 FileVersionInfoMac::product_version() {
56   // On OS X, CFBundleVersion is used by LaunchServices, and must follow
57   // specific formatting rules, so the four-part Chrome version is in
58   // 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.
61 #if defined(OS_IOS)
62   base::string16 version(GetString16Value(CFSTR("CrBundleVersion")));
63   if (version.length() > 0)
64     return version;
65   return GetString16Value(CFSTR("CFBundleVersion"));
66 #else
67   return GetString16Value(CFSTR("CFBundleShortVersionString"));
68 #endif  // defined(OS_IOS)
69 }
70
71 base::string16 FileVersionInfoMac::file_description() {
72   return base::string16();
73 }
74
75 base::string16 FileVersionInfoMac::file_version() {
76   return product_version();
77 }
78
79 base::string16 FileVersionInfoMac::original_filename() {
80   return GetString16Value(kCFBundleNameKey);
81 }
82
83 base::string16 FileVersionInfoMac::special_build() {
84   return base::string16();
85 }
86
87 base::string16 FileVersionInfoMac::GetString16Value(CFStringRef name) {
88   if (bundle_) {
89     NSString *ns_name = base::mac::CFToNSCast(name);
90     NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name];
91     if (value) {
92       return base::SysNSStringToUTF16(value);
93     }
94   }
95   return base::string16();
96 }