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