OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/common/user_agent/user_agent_util.h" | 5 #include "content/public/common/user_agent.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/sys_info.h" |
| 11 #include "build/build_config.h" |
6 | 12 |
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 13 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
8 #include <sys/utsname.h> | 14 #include <sys/utsname.h> |
9 #endif | 15 #endif |
10 | 16 |
11 #include "base/lazy_instance.h" | |
12 #include "base/strings/string_util.h" | |
13 #include "base/strings/stringprintf.h" | |
14 #include "base/sys_info.h" | |
15 | |
16 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
17 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
18 #endif | 19 #endif |
19 | 20 |
20 // Generated | 21 // Generated |
21 #include "webkit_version.h" // NOLINT | 22 #include "webkit_version.h" // NOLINT |
22 | 23 |
23 namespace webkit_glue { | 24 namespace content { |
| 25 |
| 26 namespace { |
| 27 |
| 28 #if defined(OS_ANDROID) |
| 29 std::string GetAndroidDeviceName() { |
| 30 return base::SysInfo::GetDeviceName(); |
| 31 } |
| 32 #endif |
| 33 |
| 34 } // namespace |
24 | 35 |
25 std::string GetWebKitVersion() { | 36 std::string GetWebKitVersion() { |
26 return base::StringPrintf("%d.%d (%s)", | 37 return base::StringPrintf("%d.%d (%s)", |
27 WEBKIT_VERSION_MAJOR, | 38 WEBKIT_VERSION_MAJOR, |
28 WEBKIT_VERSION_MINOR, | 39 WEBKIT_VERSION_MINOR, |
29 WEBKIT_SVN_REVISION); | 40 WEBKIT_SVN_REVISION); |
30 } | 41 } |
31 | 42 |
| 43 int GetWebKitMajorVersion() { |
| 44 return WEBKIT_VERSION_MAJOR; |
| 45 } |
| 46 |
| 47 int GetWebKitMinorVersion() { |
| 48 return WEBKIT_VERSION_MINOR; |
| 49 } |
| 50 |
32 std::string GetWebKitRevision() { | 51 std::string GetWebKitRevision() { |
33 return WEBKIT_SVN_REVISION; | 52 return WEBKIT_SVN_REVISION; |
34 } | 53 } |
35 | 54 |
36 #if defined(OS_ANDROID) | |
37 std::string GetAndroidDeviceName() { | |
38 return base::SysInfo::GetDeviceName(); | |
39 } | |
40 #endif | |
41 | |
42 std::string BuildOSCpuInfo() { | 55 std::string BuildOSCpuInfo() { |
43 std::string os_cpu; | 56 std::string os_cpu; |
44 | 57 |
45 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) ||\ | 58 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) ||\ |
46 defined(OS_ANDROID) | 59 defined(OS_ANDROID) |
47 int32 os_major_version = 0; | 60 int32 os_major_version = 0; |
48 int32 os_minor_version = 0; | 61 int32 os_minor_version = 0; |
49 int32 os_bugfix_version = 0; | 62 int32 os_bugfix_version = 0; |
50 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 63 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
51 &os_minor_version, | 64 &os_minor_version, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 #else | 149 #else |
137 "%s %s", | 150 "%s %s", |
138 unixinfo.sysname, // e.g. Linux | 151 unixinfo.sysname, // e.g. Linux |
139 cputype.c_str() // e.g. i686 | 152 cputype.c_str() // e.g. i686 |
140 #endif | 153 #endif |
141 ); // NOLINT | 154 ); // NOLINT |
142 | 155 |
143 return os_cpu; | 156 return os_cpu; |
144 } | 157 } |
145 | 158 |
146 int GetWebKitMajorVersion() { | |
147 return WEBKIT_VERSION_MAJOR; | |
148 } | |
149 | |
150 int GetWebKitMinorVersion() { | |
151 return WEBKIT_VERSION_MINOR; | |
152 } | |
153 | |
154 std::string BuildUserAgentFromProduct(const std::string& product) { | 159 std::string BuildUserAgentFromProduct(const std::string& product) { |
155 const char kUserAgentPlatform[] = | 160 const char kUserAgentPlatform[] = |
156 #if defined(OS_WIN) | 161 #if defined(OS_WIN) |
157 ""; | 162 ""; |
158 #elif defined(OS_MACOSX) | 163 #elif defined(OS_MACOSX) |
159 "Macintosh; "; | 164 "Macintosh; "; |
160 #elif defined(USE_X11) | 165 #elif defined(USE_X11) |
161 "X11; "; // strange, but that's what Firefox uses | 166 "X11; "; // strange, but that's what Firefox uses |
162 #elif defined(OS_ANDROID) | 167 #elif defined(OS_ANDROID) |
163 "Linux; "; | 168 "Linux; "; |
164 #else | 169 #else |
165 "Unknown; "; | 170 "Unknown; "; |
166 #endif | 171 #endif |
167 | 172 |
168 std::string os_info; | 173 std::string os_info; |
169 base::StringAppendF(&os_info, "%s%s", kUserAgentPlatform, | 174 base::StringAppendF( |
170 webkit_glue::BuildOSCpuInfo().c_str()); | 175 &os_info, "%s%s", kUserAgentPlatform, BuildOSCpuInfo().c_str()); |
171 return BuildUserAgentFromOSAndProduct(os_info, product); | 176 return BuildUserAgentFromOSAndProduct(os_info, product); |
172 } | 177 } |
173 | 178 |
174 std::string BuildUserAgentFromOSAndProduct(const std::string& os_info, | 179 std::string BuildUserAgentFromOSAndProduct(const std::string& os_info, |
175 const std::string& product) { | 180 const std::string& product) { |
176 // Derived from Safari's UA string. | 181 // Derived from Safari's UA string. |
177 // This is done to expose our product name in a manner that is maximally | 182 // This is done to expose our product name in a manner that is maximally |
178 // compatible with Safari, we hope!! | 183 // compatible with Safari, we hope!! |
179 std::string user_agent; | 184 std::string user_agent; |
180 base::StringAppendF( | 185 base::StringAppendF( |
181 &user_agent, | 186 &user_agent, |
182 "Mozilla/5.0 (%s) AppleWebKit/%d.%d (KHTML, like Gecko) %s Safari/%d.%d", | 187 "Mozilla/5.0 (%s) AppleWebKit/%d.%d (KHTML, like Gecko) %s Safari/%d.%d", |
183 os_info.c_str(), | 188 os_info.c_str(), |
184 WEBKIT_VERSION_MAJOR, | 189 WEBKIT_VERSION_MAJOR, |
185 WEBKIT_VERSION_MINOR, | 190 WEBKIT_VERSION_MINOR, |
186 product.c_str(), | 191 product.c_str(), |
187 WEBKIT_VERSION_MAJOR, | 192 WEBKIT_VERSION_MAJOR, |
188 WEBKIT_VERSION_MINOR); | 193 WEBKIT_VERSION_MINOR); |
189 return user_agent; | 194 return user_agent; |
190 } | 195 } |
191 | 196 |
192 } // namespace webkit_glue | 197 } // namespace content |
OLD | NEW |