OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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/string_util.h" |
| 12 #include "base/sys_info.h" |
| 13 |
| 14 // Generated |
| 15 #include "webkit_version.h" // NOLINT |
| 16 |
| 17 namespace webkit_glue { |
| 18 |
| 19 // Forward declare GetProductVersionInfo. This is implemented in |
| 20 // renderer_glue.cc as part of the renderer lib. |
| 21 std::string GetProductVersion(); |
| 22 |
| 23 std::string BuildOSCpuInfo() { |
| 24 std::string os_cpu; |
| 25 |
| 26 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 27 int32 os_major_version = 0; |
| 28 int32 os_minor_version = 0; |
| 29 int32 os_bugfix_version = 0; |
| 30 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
| 31 &os_minor_version, |
| 32 &os_bugfix_version); |
| 33 #endif |
| 34 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 35 // Should work on any Posix system. |
| 36 struct utsname unixinfo; |
| 37 uname(&unixinfo); |
| 38 |
| 39 std::string cputype; |
| 40 // special case for biarch systems |
| 41 if (strcmp(unixinfo.machine, "x86_64") == 0 && |
| 42 sizeof(void*) == sizeof(int32)) { // NOLINT |
| 43 cputype.assign("i686 (x86_64)"); |
| 44 } else { |
| 45 cputype.assign(unixinfo.machine); |
| 46 } |
| 47 #endif |
| 48 |
| 49 StringAppendF( |
| 50 &os_cpu, |
| 51 #if defined(OS_WIN) |
| 52 "Windows NT %d.%d", |
| 53 os_major_version, |
| 54 os_minor_version |
| 55 #elif defined(OS_MACOSX) |
| 56 "Intel Mac OS X %d_%d_%d", |
| 57 os_major_version, |
| 58 os_minor_version, |
| 59 os_bugfix_version |
| 60 #elif defined(OS_CHROMEOS) |
| 61 "CrOS %s %d.%d.%d", |
| 62 cputype.c_str(), // e.g. i686 |
| 63 os_major_version, |
| 64 os_minor_version, |
| 65 os_bugfix_version |
| 66 #else |
| 67 "%s %s", |
| 68 unixinfo.sysname, // e.g. Linux |
| 69 cputype.c_str() // e.g. i686 |
| 70 #endif |
| 71 ); // NOLINT |
| 72 |
| 73 return os_cpu; |
| 74 } |
| 75 |
| 76 void BuildUserAgent(bool mimic_windows, std::string* result) { |
| 77 const char kUserAgentPlatform[] = |
| 78 #if defined(OS_WIN) |
| 79 "Windows"; |
| 80 #elif defined(OS_MACOSX) |
| 81 "Macintosh"; |
| 82 #elif defined(USE_X11) |
| 83 "X11"; // strange, but that's what Firefox uses |
| 84 #else |
| 85 "?"; |
| 86 #endif |
| 87 |
| 88 const char kUserAgentSecurity = 'U'; // "US" strength encryption |
| 89 |
| 90 // TODO(port): figure out correct locale |
| 91 const char kUserAgentLocale[] = "en-US"; |
| 92 |
| 93 // Get the product name and version, and replace Safari's Version/X string |
| 94 // with it. This is done to expose our product name in a manner that is |
| 95 // maximally compatible with Safari, we hope!! |
| 96 std::string product = GetProductVersion(); |
| 97 |
| 98 // Derived from Safari's UA string. |
| 99 StringAppendF( |
| 100 result, |
| 101 "Mozilla/5.0 (%s; %c; %s; %s) AppleWebKit/%d.%d" |
| 102 " (KHTML, like Gecko) %s Safari/%d.%d", |
| 103 mimic_windows ? "Windows" : kUserAgentPlatform, |
| 104 kUserAgentSecurity, |
| 105 ((mimic_windows ? "Windows " : "") + BuildOSCpuInfo()).c_str(), |
| 106 kUserAgentLocale, |
| 107 WEBKIT_VERSION_MAJOR, |
| 108 WEBKIT_VERSION_MINOR, |
| 109 product.c_str(), |
| 110 WEBKIT_VERSION_MAJOR, |
| 111 WEBKIT_VERSION_MINOR); |
| 112 } |
| 113 |
| 114 } // namespace webkit_glue |
| 115 |
OLD | NEW |