OLD | NEW |
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() { |
41 return WEBKIT_SVN_REVISION; | 33 return WEBKIT_SVN_REVISION; |
42 } | 34 } |
43 | 35 |
44 std::string BuildOSCpuInfo() { | 36 std::string BuildOSCpuInfo() { |
45 std::string os_cpu; | 37 std::string os_cpu; |
46 | 38 |
47 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | 39 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) ||\ |
| 40 defined(OS_ANDROID) |
48 int32 os_major_version = 0; | 41 int32 os_major_version = 0; |
49 int32 os_minor_version = 0; | 42 int32 os_minor_version = 0; |
50 int32 os_bugfix_version = 0; | 43 int32 os_bugfix_version = 0; |
51 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 44 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
52 &os_minor_version, | 45 &os_minor_version, |
53 &os_bugfix_version); | 46 &os_bugfix_version); |
54 #endif | 47 #endif |
| 48 |
55 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 49 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
56 // Should work on any Posix system. | 50 // Should work on any Posix system. |
57 struct utsname unixinfo; | 51 struct utsname unixinfo; |
58 uname(&unixinfo); | 52 uname(&unixinfo); |
59 | 53 |
60 std::string cputype; | 54 std::string cputype; |
61 // special case for biarch systems | 55 // special case for biarch systems |
62 if (strcmp(unixinfo.machine, "x86_64") == 0 && | 56 if (strcmp(unixinfo.machine, "x86_64") == 0 && |
63 sizeof(void*) == sizeof(int32)) { // NOLINT | 57 sizeof(void*) == sizeof(int32)) { // NOLINT |
64 cputype.assign("i686 (x86_64)"); | 58 cputype.assign("i686 (x86_64)"); |
(...skipping 10 matching lines...) Expand all Loading... |
75 } else { | 69 } else { |
76 base::win::OSInfo::WindowsArchitecture windows_architecture = | 70 base::win::OSInfo::WindowsArchitecture windows_architecture = |
77 os_info->architecture(); | 71 os_info->architecture(); |
78 if (windows_architecture == base::win::OSInfo::X64_ARCHITECTURE) | 72 if (windows_architecture == base::win::OSInfo::X64_ARCHITECTURE) |
79 architecture_token = "; Win64; x64"; | 73 architecture_token = "; Win64; x64"; |
80 else if (windows_architecture == base::win::OSInfo::IA64_ARCHITECTURE) | 74 else if (windows_architecture == base::win::OSInfo::IA64_ARCHITECTURE) |
81 architecture_token = "; Win64; IA64"; | 75 architecture_token = "; Win64; IA64"; |
82 } | 76 } |
83 #endif | 77 #endif |
84 | 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 |
85 base::StringAppendF( | 101 base::StringAppendF( |
86 &os_cpu, | 102 &os_cpu, |
87 #if defined(OS_WIN) | 103 #if defined(OS_WIN) |
88 "Windows NT %d.%d%s", | 104 "Windows NT %d.%d%s", |
89 os_major_version, | 105 os_major_version, |
90 os_minor_version, | 106 os_minor_version, |
91 architecture_token.c_str() | 107 architecture_token.c_str() |
92 #elif defined(OS_MACOSX) | 108 #elif defined(OS_MACOSX) |
93 "Intel Mac OS X %d_%d_%d", | 109 "Intel Mac OS X %d_%d_%d", |
94 os_major_version, | 110 os_major_version, |
95 os_minor_version, | 111 os_minor_version, |
96 os_bugfix_version | 112 os_bugfix_version |
97 #elif defined(OS_CHROMEOS) | 113 #elif defined(OS_CHROMEOS) |
98 "CrOS " | 114 "CrOS " |
99 "%s %d.%d.%d", | 115 "%s %d.%d.%d", |
100 cputype.c_str(), // e.g. i686 | 116 cputype.c_str(), // e.g. i686 |
101 os_major_version, | 117 os_major_version, |
102 os_minor_version, | 118 os_minor_version, |
103 os_bugfix_version | 119 os_bugfix_version |
104 #elif defined(OS_ANDROID) | 120 #elif defined(OS_ANDROID) |
105 "Android %s", | 121 "Android %d.%d.%d%s", |
106 g_os_info.Get().c_str() | 122 os_major_version, |
| 123 os_minor_version, |
| 124 os_bugfix_version, |
| 125 android_info_str.c_str() |
107 #else | 126 #else |
108 "%s %s", | 127 "%s %s", |
109 unixinfo.sysname, // e.g. Linux | 128 unixinfo.sysname, // e.g. Linux |
110 cputype.c_str() // e.g. i686 | 129 cputype.c_str() // e.g. i686 |
111 #endif | 130 #endif |
112 ); // NOLINT | 131 ); // NOLINT |
113 | 132 |
114 return os_cpu; | 133 return os_cpu; |
115 } | 134 } |
116 | 135 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 kUserAgentPlatform, | 168 kUserAgentPlatform, |
150 webkit_glue::BuildOSCpuInfo().c_str(), | 169 webkit_glue::BuildOSCpuInfo().c_str(), |
151 WEBKIT_VERSION_MAJOR, | 170 WEBKIT_VERSION_MAJOR, |
152 WEBKIT_VERSION_MINOR, | 171 WEBKIT_VERSION_MINOR, |
153 product.c_str(), | 172 product.c_str(), |
154 WEBKIT_VERSION_MAJOR, | 173 WEBKIT_VERSION_MAJOR, |
155 WEBKIT_VERSION_MINOR); | 174 WEBKIT_VERSION_MINOR); |
156 return user_agent; | 175 return user_agent; |
157 } | 176 } |
158 | 177 |
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 | 178 } // namespace webkit_glue |
OLD | NEW |