OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/public/common/user_agent.h" | 5 #include "ios/web/public/user_agent.h" |
6 | 6 |
7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
8 | 8 |
9 #include <sys/sysctl.h> | 9 #include <sys/sysctl.h> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 for (unsigned int i = 0; i < arraysize(version_map); ++i) { | 51 for (unsigned int i = 0; i < arraysize(version_map); ++i) { |
52 if (os_major_version > version_map[i].major_os_version || | 52 if (os_major_version > version_map[i].major_os_version || |
53 (os_major_version == version_map[i].major_os_version && | 53 (os_major_version == version_map[i].major_os_version && |
54 os_minor_version >= version_map[i].minor_os_version)) | 54 os_minor_version >= version_map[i].minor_os_version)) |
55 return version_map[i].ua_versions; | 55 return version_map[i].ua_versions; |
56 } | 56 } |
57 NOTREACHED(); | 57 NOTREACHED(); |
58 return version_map[arraysize(version_map) - 1].ua_versions; | 58 return version_map[arraysize(version_map) - 1].ua_versions; |
59 } | 59 } |
60 | 60 |
61 } // namespace | |
62 | |
63 namespace content { | |
64 | |
65 std::string BuildOSCpuInfo() { | 61 std::string BuildOSCpuInfo() { |
66 int32 os_major_version = 0; | 62 int32 os_major_version = 0; |
67 int32 os_minor_version = 0; | 63 int32 os_minor_version = 0; |
68 int32 os_bugfix_version = 0; | 64 int32 os_bugfix_version = 0; |
69 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 65 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
70 &os_minor_version, | 66 &os_minor_version, |
71 &os_bugfix_version); | 67 &os_bugfix_version); |
72 std::string os_version; | 68 std::string os_version; |
73 if (os_bugfix_version == 0) { | 69 if (os_bugfix_version == 0) { |
74 base::StringAppendF(&os_version, | 70 base::StringAppendF(&os_version, |
(...skipping 20 matching lines...) Expand all Loading... |
95 base::StringAppendF( | 91 base::StringAppendF( |
96 &os_cpu, | 92 &os_cpu, |
97 "%s; CPU %s %s like Mac OS X", | 93 "%s; CPU %s %s like Mac OS X", |
98 platform.c_str(), | 94 platform.c_str(), |
99 (platform == "iPad") ? "OS" : "iPhone OS", | 95 (platform == "iPad") ? "OS" : "iPhone OS", |
100 os_version.c_str()); | 96 os_version.c_str()); |
101 | 97 |
102 return os_cpu; | 98 return os_cpu; |
103 } | 99 } |
104 | 100 |
| 101 } // namespace |
| 102 |
| 103 namespace web { |
| 104 |
105 std::string BuildUserAgentFromProduct(const std::string& product) { | 105 std::string BuildUserAgentFromProduct(const std::string& product) { |
106 // Retrieve the kernel build number. | 106 // Retrieve the kernel build number. |
107 int mib[2] = {CTL_KERN, KERN_OSVERSION}; | 107 int mib[2] = {CTL_KERN, KERN_OSVERSION}; |
108 unsigned int namelen = sizeof(mib) / sizeof(mib[0]); | 108 unsigned int namelen = sizeof(mib) / sizeof(mib[0]); |
109 size_t bufferSize = 0; | 109 size_t bufferSize = 0; |
110 sysctl(mib, namelen, NULL, &bufferSize, NULL, 0); | 110 sysctl(mib, namelen, NULL, &bufferSize, NULL, 0); |
111 char kernel_version[bufferSize]; | 111 char kernel_version[bufferSize]; |
112 int result = sysctl(mib, namelen, kernel_version, &bufferSize, NULL, 0); | 112 int result = sysctl(mib, namelen, kernel_version, &bufferSize, NULL, 0); |
113 DCHECK(result == 0); | 113 DCHECK(result == 0); |
114 | 114 |
115 UAVersions ua_versions = GetUAVersionsForCurrentOS(); | 115 UAVersions ua_versions = GetUAVersionsForCurrentOS(); |
116 | 116 |
117 std::string user_agent; | 117 std::string user_agent; |
118 base::StringAppendF(&user_agent, | 118 base::StringAppendF(&user_agent, |
119 "Mozilla/5.0 (%s) AppleWebKit/%s" | 119 "Mozilla/5.0 (%s) AppleWebKit/%s" |
120 " (KHTML, like Gecko) %s Mobile/%s Safari/%s", | 120 " (KHTML, like Gecko) %s Mobile/%s Safari/%s", |
121 BuildOSCpuInfo().c_str(), | 121 BuildOSCpuInfo().c_str(), |
122 ua_versions.webkit_version_string, | 122 ua_versions.webkit_version_string, |
123 product.c_str(), | 123 product.c_str(), |
124 kernel_version, | 124 kernel_version, |
125 ua_versions.safari_version_string); | 125 ua_versions.safari_version_string); |
126 | 126 |
127 return user_agent; | 127 return user_agent; |
128 } | 128 } |
129 | 129 |
130 } // namespace content | 130 } // namespace web |
OLD | NEW |