a4ed21a29f78e5678f1b6211eaaeba41dbeebf61
[platform/framework/web/chromium-efl.git] / tizen_src / impl / common / version_info.cc
1 /*
2  * Copyright (C) 2013 Samsung Electronics. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  */
14
15 #include "common/version_info.h"
16
17 #if defined(OS_TIZEN)
18 #include "system_info.h"
19 #include "system_info_internal.h"
20 #endif
21
22 #include "common/version_info_efl.h"
23
24 namespace EflWebView {
25
26 const char kOSTypeLinux[] = "Linux";
27
28 VersionInfo* VersionInfo::version_info_ = NULL;
29
30 VersionInfo* VersionInfo::GetInstance() {
31   if(!version_info_)
32     version_info_ = new VersionInfo;
33   return version_info_;
34 }
35
36 void VersionInfo::DeleteInstance() {
37   if(version_info_)
38     delete version_info_;
39   version_info_ = NULL;
40 }
41
42 VersionInfo::VersionInfo()
43   : product_name_(PRODUCT_NAME),
44     product_version_(PRODUCT_VERSION) {
45 }
46
47 void VersionInfo::SetProductName(const std::string& name) {
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   int result = system_info_get_value_string(SYSTEM_INFO_KEY_TIZEN_VERSION, &tizen_version);
82   if (result == SYSTEM_INFO_ERROR_NONE) {
83     tizen_version_str.assign(tizen_version);
84     free(tizen_version);
85   }
86   result = system_info_get_value_string(SYSTEM_INFO_KEY_PLATFORM_NAME, &platform_name);
87   if (result == SYSTEM_INFO_ERROR_NONE) {
88     platform_name_str.assign(platform_name);
89     free(platform_name);
90   }
91   result = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &device_model);
92   if (result == SYSTEM_INFO_ERROR_NONE) {
93     device_model_str.assign(device_model);
94     free(device_model);
95   }
96   return kOSTypeLinux +
97          std::string("; ") +
98          platform_name_str +
99          std::string(" ") +
100          tizen_version_str +
101          std::string("; ") +
102          device_model_str;
103 #else
104   return kOSTypeLinux;
105 #endif
106 }
107
108 std::string VersionInfo::ProductNameAndVersionForUserAgent() const {
109   if (!is_valid())
110     return std::string();
111
112   // max koo : Some WebRTC web-sites needs the Chrome version number to check
113   // if the browser supports the WebRTC feature.
114   // Currently Chumium also use the hard-code for the Chrome version number.
115   // See http://crbug.com/297522
116   // Does we need to open our real version number?
117   // or just use 33.0.0.0 as Chromium does.
118   return std::string("Chrome/34.0.1847.76 ") +
119          Name() +
120          std::string("/") +
121          Version();
122 }
123
124 } //namespace EflWebView