[M49_2623] Chromium upversion to m49_2623 branch.
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / common / version_info.cc
1 // Copyright 2013 Samsung Electronics. 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 "common/version_info.h"
6
7 #if defined(OS_TIZEN)
8 #if !TIZEN_VERSION_EQ(2,3,0)
9 #include "system_info.h"
10 #else
11 #include "system_info_internal.h"
12 #endif
13 #endif
14
15 #include "base/command_line.h"
16 #include "content/public/common/content_switches.h"
17 #include "content/public/common/user_agent.h"
18
19 #include "common/version_info_efl.h"
20
21 namespace EflWebView {
22
23 const char kOSTypeLinux[] = "Linux";
24
25 VersionInfo* VersionInfo::version_info_ = NULL;
26
27 VersionInfo* VersionInfo::GetInstance() {
28   if(!version_info_)
29     version_info_ = new VersionInfo;
30   return version_info_;
31 }
32
33 void VersionInfo::DeleteInstance() {
34   if(version_info_)
35     delete version_info_;
36   version_info_ = NULL;
37 }
38
39 VersionInfo::VersionInfo()
40   : product_name_(PRODUCT_NAME),
41     product_version_(PRODUCT_VERSION) {
42 }
43
44 void VersionInfo::SetProductName(const std::string& name) {
45   if(name.empty())
46     product_name_ = PRODUCT_NAME;
47   else
48     product_name_ = name;
49 }
50
51 std::string VersionInfo::LastChange() const {
52   return LAST_CHANGE;
53 }
54
55 bool VersionInfo::IsOfficialBuild() const {
56   return IS_OFFICIAL_BUILD;
57 }
58
59 std::string VersionInfo::CreateVersionString() const {
60   std::string current_version;
61   if (is_valid()) {
62     current_version += Version();
63     current_version += " (";
64     current_version += " ";
65     current_version += LastChange();
66     current_version += " ";
67     current_version += OSType();
68     current_version += ")";
69   }
70   return current_version;
71 }
72
73 std::string VersionInfo::OSType() const {
74 #if defined(OS_TIZEN)
75   char *device_model = NULL;
76   char *tizen_version = NULL;
77   char *platform_name = NULL;
78   std::string device_model_str;
79   std::string tizen_version_str;
80   std::string platform_name_str;
81 #if TIZEN_VERSION_AT_LEAST(2,4,0)
82   int result = system_info_get_platform_string("http://tizen.org/feature/platform.version",
83                                                &tizen_version);
84 #else
85   int result = system_info_get_value_string(SYSTEM_INFO_KEY_TIZEN_VERSION, &tizen_version);
86 #endif
87   if (result == SYSTEM_INFO_ERROR_NONE) {
88     tizen_version_str.assign(tizen_version);
89     free(tizen_version);
90   }
91 #if TIZEN_VERSION_AT_LEAST(2,4,0)
92   result = system_info_get_platform_string("http://tizen.org/system/platform.name",
93                                            &platform_name);
94 #else
95   result = system_info_get_value_string(SYSTEM_INFO_KEY_PLATFORM_NAME, &platform_name);
96 #endif
97   if (result == SYSTEM_INFO_ERROR_NONE) {
98     platform_name_str.assign(platform_name);
99     free(platform_name);
100   }
101 #if TIZEN_VERSION_AT_LEAST(2,4,0)
102   result = system_info_get_platform_string("http://tizen.org/system/model_name",
103                                            &device_model);
104 #else
105   result = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &device_model);
106 #endif
107   if (result == SYSTEM_INFO_ERROR_NONE) {
108     device_model_str.assign(device_model);
109     free(device_model);
110   }
111   return std::string(kOSTypeLinux) + ("; ") +
112          platform_name_str + (" ") +
113          tizen_version_str + ("; ") + device_model_str;
114 #else
115   return kOSTypeLinux;
116 #endif
117 }
118
119 std::string VersionInfo::ProductNameAndVersionForUserAgent() const {
120   if (!is_valid())
121     return std::string();
122
123   // Some WebRTC web-sites need the Chrome version number to check
124   // if the browser supports the WebRTC feature.
125   // TODO(max koo): Do we need to open our real version number
126   // or just use Chrome/aa.bb.cc.dd as Chromium/Chrome do?
127   return std::string("Chrome/") + CHROMIUM_VERSION;
128 }
129
130 std::string VersionInfo::DefaultUserAgent() const {
131   char* override_ua = getenv("CHROMIUM_EFL_OVERRIDE_UA_STRING");
132   if (override_ua)
133     return override_ua;
134
135   std::string product = ProductNameAndVersionForUserAgent();
136
137   if (base::CommandLine::ForCurrentProcess()->HasSwitch(
138       switches::kUseMobileUserAgent)) {
139     product += " Mobile";
140   }
141
142 // FIXME : The hard-coded user agent for tizen tv
143 #if defined(OS_TIZEN_TV)
144   return "Mozilla/5.0 (SmartHub; SMART-TV; U; Linux/SmartTV+2013; Maple2012) "
145     "AppleWebKit/535.20+ (KHTML, like Gecko) SmartTV Safari/535.20+";
146 #else
147   return content::BuildUserAgentFromOSAndProduct(EflWebView::VersionInfo::GetInstance()->OSType(),
148                                                      product);
149 #endif
150 }
151
152 } //namespace EflWebView