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 "ios/web/public/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 <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 #include <sys/sysctl.h> | 11 #include <sys/sysctl.h> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #import "base/mac/scoped_nsobject.h" | 14 #import "base/mac/scoped_nsobject.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
19 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
20 | 20 |
21 #if !defined(__has_feature) || !__has_feature(objc_arc) | 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
22 #error "This file requires ARC support." | 22 #error "This file requires ARC support." |
23 #endif | 23 #endif |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
| 27 // UserAgentType description strings. |
| 28 const char kUserAgentTypeNoneDescription[] = "NONE"; |
| 29 const char kUserAgentTypeMobileDescription[] = "MOBILE"; |
| 30 const char kUserAgentTypeDesktopDescription[] = "DESKTOP"; |
| 31 |
27 struct UAVersions { | 32 struct UAVersions { |
28 const char* safari_version_string; | 33 const char* safari_version_string; |
29 const char* webkit_version_string; | 34 const char* webkit_version_string; |
30 }; | 35 }; |
31 | 36 |
32 struct OSVersionMap { | 37 struct OSVersionMap { |
33 int32_t major_os_version; | 38 int32_t major_os_version; |
34 int32_t minor_os_version; | 39 int32_t minor_os_version; |
35 UAVersions ua_versions; | 40 UAVersions ua_versions; |
36 }; | 41 }; |
(...skipping 26 matching lines...) Expand all Loading... |
63 return version_map[i].ua_versions; | 68 return version_map[i].ua_versions; |
64 } | 69 } |
65 NOTREACHED(); | 70 NOTREACHED(); |
66 return version_map[arraysize(version_map) - 1].ua_versions; | 71 return version_map[arraysize(version_map) - 1].ua_versions; |
67 } | 72 } |
68 | 73 |
69 } // namespace | 74 } // namespace |
70 | 75 |
71 namespace web { | 76 namespace web { |
72 | 77 |
| 78 std::string GetUserAgentTypeDescription(UserAgentType type) { |
| 79 switch (type) { |
| 80 case UserAgentType::NONE: |
| 81 return std::string(kUserAgentTypeNoneDescription); |
| 82 break; |
| 83 case UserAgentType::MOBILE: |
| 84 return std::string(kUserAgentTypeMobileDescription); |
| 85 break; |
| 86 case UserAgentType::DESKTOP: |
| 87 return std::string(kUserAgentTypeDesktopDescription); |
| 88 } |
| 89 } |
| 90 |
| 91 UserAgentType GetUserAgentTypeWithDescription(const std::string& description) { |
| 92 if (description == std::string(kUserAgentTypeMobileDescription)) |
| 93 return UserAgentType::MOBILE; |
| 94 if (description == std::string(kUserAgentTypeDesktopDescription)) |
| 95 return UserAgentType::DESKTOP; |
| 96 return UserAgentType::NONE; |
| 97 } |
| 98 |
73 std::string BuildOSCpuInfo() { | 99 std::string BuildOSCpuInfo() { |
74 int32_t os_major_version = 0; | 100 int32_t os_major_version = 0; |
75 int32_t os_minor_version = 0; | 101 int32_t os_minor_version = 0; |
76 int32_t os_bugfix_version = 0; | 102 int32_t os_bugfix_version = 0; |
77 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 103 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
78 &os_minor_version, | 104 &os_minor_version, |
79 &os_bugfix_version); | 105 &os_bugfix_version); |
80 std::string os_version; | 106 std::string os_version; |
81 if (os_bugfix_version == 0) { | 107 if (os_bugfix_version == 0) { |
82 base::StringAppendF(&os_version, | 108 base::StringAppendF(&os_version, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 BuildOSCpuInfo().c_str(), | 155 BuildOSCpuInfo().c_str(), |
130 ua_versions.webkit_version_string, | 156 ua_versions.webkit_version_string, |
131 product.c_str(), | 157 product.c_str(), |
132 kernel_version, | 158 kernel_version, |
133 ua_versions.safari_version_string); | 159 ua_versions.safari_version_string); |
134 | 160 |
135 return user_agent; | 161 return user_agent; |
136 } | 162 } |
137 | 163 |
138 } // namespace web | 164 } // namespace web |
OLD | NEW |