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

Side by Side Diff: webkit/glue/user_agent.cc

Issue 10832235: Move Android user agent generation to native code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moved Android OS info function over to webkit_glue Created 8 years, 4 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
« webkit/glue/user_agent.h ('K') | « webkit/glue/user_agent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/glue/user_agent.h" 5 #include "webkit/glue/user_agent.h"
6 6
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) 7 #if defined(OS_POSIX) && !defined(OS_MACOSX)
8 #include <sys/utsname.h> 8 #include <sys/utsname.h>
9 #endif 9 #endif
10 10
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/sys_info.h" 14 #include "base/sys_info.h"
15 15
16 #if defined(OS_WIN) 16 #if defined(OS_WIN)
17 #include "base/win/windows_version.h" 17 #include "base/win/windows_version.h"
18 #endif 18 #endif
19 19
20 // Generated 20 // Generated
21 #include "webkit_version.h" // NOLINT 21 #include "webkit_version.h" // NOLINT
22 22
23 #if defined(OS_ANDROID)
24 namespace {
25
26 base::LazyInstance<std::string>::Leaky g_os_info = LAZY_INSTANCE_INITIALIZER;
27
28 } // namespace
29 #endif
30
31 namespace webkit_glue { 23 namespace webkit_glue {
32 24
33 std::string GetWebKitVersion() { 25 std::string GetWebKitVersion() {
34 return base::StringPrintf("%d.%d (%s)", 26 return base::StringPrintf("%d.%d (%s)",
35 WEBKIT_VERSION_MAJOR, 27 WEBKIT_VERSION_MAJOR,
36 WEBKIT_VERSION_MINOR, 28 WEBKIT_VERSION_MINOR,
37 WEBKIT_SVN_REVISION); 29 WEBKIT_SVN_REVISION);
38 } 30 }
39 31
40 std::string GetWebKitRevision() { 32 std::string GetWebKitRevision() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 os_bugfix_version 88 os_bugfix_version
97 #elif defined(OS_CHROMEOS) 89 #elif defined(OS_CHROMEOS)
98 "CrOS " 90 "CrOS "
99 "%s %d.%d.%d", 91 "%s %d.%d.%d",
100 cputype.c_str(), // e.g. i686 92 cputype.c_str(), // e.g. i686
101 os_major_version, 93 os_major_version,
102 os_minor_version, 94 os_minor_version,
103 os_bugfix_version 95 os_bugfix_version
104 #elif defined(OS_ANDROID) 96 #elif defined(OS_ANDROID)
105 "Android %s", 97 "Android %s",
106 g_os_info.Get().c_str() 98 BuildOSCpuInfoForAndroid().c_str()
107 #else 99 #else
108 "%s %s", 100 "%s %s",
109 unixinfo.sysname, // e.g. Linux 101 unixinfo.sysname, // e.g. Linux
110 cputype.c_str() // e.g. i686 102 cputype.c_str() // e.g. i686
111 #endif 103 #endif
112 ); // NOLINT 104 ); // NOLINT
113 105
114 return os_cpu; 106 return os_cpu;
115 } 107 }
116 108
109 std::string BuildOSCpuInfoForAndroid() {
jar (doing other things) 2012/08/15 23:35:17 Who would ever call this, if not in android? ...
gone 2012/08/16 00:29:31 It's supposed to be used for spoofing the UA in a
110 int32 version_major = base::SysInfo::kDefaultAndroidMajorVersion;
111 int32 version_minor = base::SysInfo::kDefaultAndroidMinorVersion;
112 int32 version_bugfix = base::SysInfo::kDefaultAndroidBugfixVersion;
113 std::string android_build_codename;
114 std::string android_build_id;
115 std::string android_device_name;
116 #if defined(OS_ANDROID)
117 base::SysInfo::OperatingSystemVersionNumbers(&version_major, &version_minor,
118 &version_bugfix);
119 android_build_codename = base::SysInfo::GetAndroidBuildCodename();
120 android_build_id = base::SysInfo::GetAndroidBuildID();
121 android_device_name = base::SysInfo::GetDeviceName();
122 #endif
123
124 bool semicolon_inserted = false;
125 std::string android_info_str;
126
127 // Append information about the OS version.
128 if (version_bugfix == 0) {
129 base::StringAppendF(&android_info_str, "%d.%d", version_major,
130 version_minor);
131 } else {
132 base::StringAppendF(&android_info_str, "%d.%d.%d", version_major,
133 version_minor, version_bugfix);
134 }
135
136 // Append information about the device.
137 if ("REL" == android_build_codename && android_device_name.size() > 0) {
138 if (!semicolon_inserted) {
jar (doing other things) 2012/08/15 23:35:17 Logic for this seems confused. semicolon_inserted
gone 2012/08/16 00:29:31 Good catch, moved it downward.
139 android_info_str += ";";
140 semicolon_inserted = true;
141 }
142 android_info_str += " " + android_device_name;
143 }
144
145 // Append the build ID.
146 if (android_build_id.size() > 0) {
147 if (!semicolon_inserted) {
148 android_info_str += ";";
149 semicolon_inserted = true;
jar (doing other things) 2012/08/15 23:35:17 Why are you setting this variable, given that you
gone 2012/08/16 00:29:31 Done.
150 }
151 android_info_str += " Build/" + android_build_id;
152 }
153
154 return android_info_str;
155 }
156
117 int GetWebKitMajorVersion() { 157 int GetWebKitMajorVersion() {
118 return WEBKIT_VERSION_MAJOR; 158 return WEBKIT_VERSION_MAJOR;
119 } 159 }
120 160
121 int GetWebKitMinorVersion() { 161 int GetWebKitMinorVersion() {
122 return WEBKIT_VERSION_MINOR; 162 return WEBKIT_VERSION_MINOR;
123 } 163 }
124 164
125 std::string BuildUserAgentFromProduct(const std::string& product) { 165 std::string BuildUserAgentFromProduct(const std::string& product) {
126 const char kUserAgentPlatform[] = 166 const char kUserAgentPlatform[] =
(...skipping 22 matching lines...) Expand all
149 kUserAgentPlatform, 189 kUserAgentPlatform,
150 webkit_glue::BuildOSCpuInfo().c_str(), 190 webkit_glue::BuildOSCpuInfo().c_str(),
151 WEBKIT_VERSION_MAJOR, 191 WEBKIT_VERSION_MAJOR,
152 WEBKIT_VERSION_MINOR, 192 WEBKIT_VERSION_MINOR,
153 product.c_str(), 193 product.c_str(),
154 WEBKIT_VERSION_MAJOR, 194 WEBKIT_VERSION_MAJOR,
155 WEBKIT_VERSION_MINOR); 195 WEBKIT_VERSION_MINOR);
156 return user_agent; 196 return user_agent;
157 } 197 }
158 198
159 #if defined(OS_ANDROID)
160 void SetUserAgentOSInfo(const std::string& os_info) {
161 g_os_info.Get() = os_info;
162 }
163 #endif
164
165 } // namespace webkit_glue 199 } // namespace webkit_glue
OLDNEW
« webkit/glue/user_agent.h ('K') | « webkit/glue/user_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698