Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: webkit/common/user_agent/user_agent_util.cc

Issue 186883002: Move user_agent code from webkit/ to content/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm build directory Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/common/user_agent/user_agent_util.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/strings/string_util.h"
13 #include "base/strings/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 #if defined(OS_ANDROID)
37 std::string GetAndroidDeviceName() {
38 return base::SysInfo::GetDeviceName();
39 }
40 #endif
41
42 std::string BuildOSCpuInfo() {
43 std::string os_cpu;
44
45 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) ||\
46 defined(OS_ANDROID)
47 int32 os_major_version = 0;
48 int32 os_minor_version = 0;
49 int32 os_bugfix_version = 0;
50 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
51 &os_minor_version,
52 &os_bugfix_version);
53 #endif
54
55 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
56 // Should work on any Posix system.
57 struct utsname unixinfo;
58 uname(&unixinfo);
59
60 std::string cputype;
61 // special case for biarch systems
62 if (strcmp(unixinfo.machine, "x86_64") == 0 &&
63 sizeof(void*) == sizeof(int32)) { // NOLINT
64 cputype.assign("i686 (x86_64)");
65 } else {
66 cputype.assign(unixinfo.machine);
67 }
68 #endif
69
70 #if defined(OS_WIN)
71 std::string architecture_token;
72 base::win::OSInfo* os_info = base::win::OSInfo::GetInstance();
73 if (os_info->wow64_status() == base::win::OSInfo::WOW64_ENABLED) {
74 architecture_token = "; WOW64";
75 } else {
76 base::win::OSInfo::WindowsArchitecture windows_architecture =
77 os_info->architecture();
78 if (windows_architecture == base::win::OSInfo::X64_ARCHITECTURE)
79 architecture_token = "; Win64; x64";
80 else if (windows_architecture == base::win::OSInfo::IA64_ARCHITECTURE)
81 architecture_token = "; Win64; IA64";
82 }
83 #endif
84
85 #if defined(OS_ANDROID)
86 std::string android_version_str;
87 base::StringAppendF(
88 &android_version_str, "%d.%d", os_major_version, os_minor_version);
89 if (os_bugfix_version != 0)
90 base::StringAppendF(&android_version_str, ".%d", os_bugfix_version);
91
92 std::string android_info_str;
93
94 // Send information about the device.
95 bool semicolon_inserted = false;
96 std::string android_build_codename = base::SysInfo::GetAndroidBuildCodename();
97 std::string android_device_name = GetAndroidDeviceName();
98 if ("REL" == android_build_codename && android_device_name.size() > 0) {
99 android_info_str += "; " + android_device_name;
100 semicolon_inserted = true;
101 }
102
103 // Append the build ID.
104 std::string android_build_id = base::SysInfo::GetAndroidBuildID();
105 if (android_build_id.size() > 0) {
106 if (!semicolon_inserted) {
107 android_info_str += ";";
108 }
109 android_info_str += " Build/" + android_build_id;
110 }
111 #endif
112
113 base::StringAppendF(
114 &os_cpu,
115 #if defined(OS_WIN)
116 "Windows NT %d.%d%s",
117 os_major_version,
118 os_minor_version,
119 architecture_token.c_str()
120 #elif defined(OS_MACOSX)
121 "Intel Mac OS X %d_%d_%d",
122 os_major_version,
123 os_minor_version,
124 os_bugfix_version
125 #elif defined(OS_CHROMEOS)
126 "CrOS "
127 "%s %d.%d.%d",
128 cputype.c_str(), // e.g. i686
129 os_major_version,
130 os_minor_version,
131 os_bugfix_version
132 #elif defined(OS_ANDROID)
133 "Android %s%s",
134 android_version_str.c_str(),
135 android_info_str.c_str()
136 #else
137 "%s %s",
138 unixinfo.sysname, // e.g. Linux
139 cputype.c_str() // e.g. i686
140 #endif
141 ); // NOLINT
142
143 return os_cpu;
144 }
145
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) {
155 const char kUserAgentPlatform[] =
156 #if defined(OS_WIN)
157 "";
158 #elif defined(OS_MACOSX)
159 "Macintosh; ";
160 #elif defined(USE_X11)
161 "X11; "; // strange, but that's what Firefox uses
162 #elif defined(OS_ANDROID)
163 "Linux; ";
164 #else
165 "Unknown; ";
166 #endif
167
168 std::string os_info;
169 base::StringAppendF(&os_info, "%s%s", kUserAgentPlatform,
170 webkit_glue::BuildOSCpuInfo().c_str());
171 return BuildUserAgentFromOSAndProduct(os_info, product);
172 }
173
174 std::string BuildUserAgentFromOSAndProduct(const std::string& os_info,
175 const std::string& product) {
176 // Derived from Safari's UA string.
177 // This is done to expose our product name in a manner that is maximally
178 // compatible with Safari, we hope!!
179 std::string user_agent;
180 base::StringAppendF(
181 &user_agent,
182 "Mozilla/5.0 (%s) AppleWebKit/%d.%d (KHTML, like Gecko) %s Safari/%d.%d",
183 os_info.c_str(),
184 WEBKIT_VERSION_MAJOR,
185 WEBKIT_VERSION_MINOR,
186 product.c_str(),
187 WEBKIT_VERSION_MAJOR,
188 WEBKIT_VERSION_MINOR);
189 return user_agent;
190 }
191
192 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/common/user_agent/user_agent_util.h ('k') | webkit/common/user_agent/user_agent_util_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698