OLD | NEW |
| (Empty) |
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 "webkit/glue/user_agent.h" | |
6 | |
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
8 #include <sys/utsname.h> | |
9 #endif | |
10 | |
11 #include "base/lazy_instance.h" | |
12 #include "base/string_util.h" | |
13 #include "base/stringprintf.h" | |
14 #include "base/sys_info.h" | |
15 | |
16 #if defined(OS_WIN) | |
17 #include "base/win/windows_version.h" | |
18 #endif | |
19 | |
20 // Generated | |
21 #include "webkit_version.h" // NOLINT | |
22 | |
23 namespace webkit_glue { | |
24 | |
25 std::string GetWebKitVersion() { | |
26 return base::StringPrintf("%d.%d (%s)", | |
27 WEBKIT_VERSION_MAJOR, | |
28 WEBKIT_VERSION_MINOR, | |
29 WEBKIT_SVN_REVISION); | |
30 } | |
31 | |
32 std::string GetWebKitRevision() { | |
33 return WEBKIT_SVN_REVISION; | |
34 } | |
35 | |
36 std::string BuildOSCpuInfo() { | |
37 std::string os_cpu; | |
38 | |
39 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) ||\ | |
40 defined(OS_ANDROID) | |
41 int32 os_major_version = 0; | |
42 int32 os_minor_version = 0; | |
43 int32 os_bugfix_version = 0; | |
44 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | |
45 &os_minor_version, | |
46 &os_bugfix_version); | |
47 #endif | |
48 | |
49 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | |
50 // Should work on any Posix system. | |
51 struct utsname unixinfo; | |
52 uname(&unixinfo); | |
53 | |
54 std::string cputype; | |
55 // special case for biarch systems | |
56 if (strcmp(unixinfo.machine, "x86_64") == 0 && | |
57 sizeof(void*) == sizeof(int32)) { // NOLINT | |
58 cputype.assign("i686 (x86_64)"); | |
59 } else { | |
60 cputype.assign(unixinfo.machine); | |
61 } | |
62 #endif | |
63 | |
64 #if defined(OS_WIN) | |
65 std::string architecture_token; | |
66 base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); | |
67 if (os_info->wow64_status() == base::win::OSInfo::WOW64_ENABLED) { | |
68 architecture_token = "; WOW64"; | |
69 } else { | |
70 base::win::OSInfo::WindowsArchitecture windows_architecture = | |
71 os_info->architecture(); | |
72 if (windows_architecture == base::win::OSInfo::X64_ARCHITECTURE) | |
73 architecture_token = "; Win64; x64"; | |
74 else if (windows_architecture == base::win::OSInfo::IA64_ARCHITECTURE) | |
75 architecture_token = "; Win64; IA64"; | |
76 } | |
77 #endif | |
78 | |
79 #if defined(OS_ANDROID) | |
80 std::string android_info_str; | |
81 | |
82 // Send information about the device. | |
83 bool semicolon_inserted = false; | |
84 std::string android_build_codename = base::SysInfo::GetAndroidBuildCodename(); | |
85 std::string android_device_name = base::SysInfo::GetDeviceName(); | |
86 if ("REL" == android_build_codename && android_device_name.size() > 0) { | |
87 android_info_str += "; " + android_device_name; | |
88 semicolon_inserted = true; | |
89 } | |
90 | |
91 // Append the build ID. | |
92 std::string android_build_id = base::SysInfo::GetAndroidBuildID(); | |
93 if (android_build_id.size() > 0) { | |
94 if (!semicolon_inserted) { | |
95 android_info_str += ";"; | |
96 } | |
97 android_info_str += " Build/" + android_build_id; | |
98 } | |
99 #endif | |
100 | |
101 base::StringAppendF( | |
102 &os_cpu, | |
103 #if defined(OS_WIN) | |
104 "Windows NT %d.%d%s", | |
105 os_major_version, | |
106 os_minor_version, | |
107 architecture_token.c_str() | |
108 #elif defined(OS_MACOSX) | |
109 "Intel Mac OS X %d_%d_%d", | |
110 os_major_version, | |
111 os_minor_version, | |
112 os_bugfix_version | |
113 #elif defined(OS_CHROMEOS) | |
114 "CrOS " | |
115 "%s %d.%d.%d", | |
116 cputype.c_str(), // e.g. i686 | |
117 os_major_version, | |
118 os_minor_version, | |
119 os_bugfix_version | |
120 #elif defined(OS_ANDROID) | |
121 "Android %d.%d.%d%s", | |
122 os_major_version, | |
123 os_minor_version, | |
124 os_bugfix_version, | |
125 android_info_str.c_str() | |
126 #else | |
127 "%s %s", | |
128 unixinfo.sysname, // e.g. Linux | |
129 cputype.c_str() // e.g. i686 | |
130 #endif | |
131 ); // NOLINT | |
132 | |
133 return os_cpu; | |
134 } | |
135 | |
136 int GetWebKitMajorVersion() { | |
137 return WEBKIT_VERSION_MAJOR; | |
138 } | |
139 | |
140 int GetWebKitMinorVersion() { | |
141 return WEBKIT_VERSION_MINOR; | |
142 } | |
143 | |
144 std::string BuildUserAgentFromProduct(const std::string& product) { | |
145 const char kUserAgentPlatform[] = | |
146 #if defined(OS_WIN) | |
147 ""; | |
148 #elif defined(OS_MACOSX) | |
149 "Macintosh; "; | |
150 #elif defined(USE_X11) | |
151 "X11; "; // strange, but that's what Firefox uses | |
152 #elif defined(OS_ANDROID) | |
153 "Linux; "; | |
154 #else | |
155 "Unknown; "; | |
156 #endif | |
157 | |
158 std::string os_info; | |
159 base::StringAppendF(&os_info, "%s%s", kUserAgentPlatform, | |
160 webkit_glue::BuildOSCpuInfo().c_str()); | |
161 return BuildUserAgentFromOSAndProduct(os_info, product); | |
162 } | |
163 | |
164 std::string BuildUserAgentFromOSAndProduct(const std::string& os_info, | |
165 const std::string& product) { | |
166 // Derived from Safari's UA string. | |
167 // This is done to expose our product name in a manner that is maximally | |
168 // compatible with Safari, we hope!! | |
169 std::string user_agent; | |
170 base::StringAppendF( | |
171 &user_agent, | |
172 "Mozilla/5.0 (%s) AppleWebKit/%d.%d (KHTML, like Gecko) %s Safari/%d.%d", | |
173 os_info.c_str(), | |
174 WEBKIT_VERSION_MAJOR, | |
175 WEBKIT_VERSION_MINOR, | |
176 product.c_str(), | |
177 WEBKIT_VERSION_MAJOR, | |
178 WEBKIT_VERSION_MINOR); | |
179 return user_agent; | |
180 } | |
181 | |
182 } // namespace webkit_glue | |
OLD | NEW |