OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/common/user_agent/user_agent_util.h" | 5 #include "webkit/common/user_agent/user_agent_util.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> |
(...skipping 15 matching lines...) Expand all Loading... |
26 int32 major_os_version; | 26 int32 major_os_version; |
27 int32 minor_os_version; | 27 int32 minor_os_version; |
28 UAVersions ua_versions; | 28 UAVersions ua_versions; |
29 }; | 29 }; |
30 | 30 |
31 const UAVersions& GetUAVersionsForCurrentOS() { | 31 const UAVersions& GetUAVersionsForCurrentOS() { |
32 // The WebKit version can be extracted dynamically from UIWebView, but the | 32 // The WebKit version can be extracted dynamically from UIWebView, but the |
33 // Safari version can't be, so a lookup table is used instead (for both, since | 33 // Safari version can't be, so a lookup table is used instead (for both, since |
34 // the reported versions should stay in sync). | 34 // the reported versions should stay in sync). |
35 static const OSVersionMap version_map[] = { | 35 static const OSVersionMap version_map[] = { |
36 { 6, 0, { "8536.25", "536.26" } }, // TODO(ios): Update for 6.0 final. | 36 // TODO(stuartmorgan): Update for 7.0 final if necessary. |
| 37 { 7, 0, { "8536.25", "537.51.1" } }, |
| 38 // 6.1 has the same values as 6.0. |
| 39 { 6, 0, { "8536.25", "536.26" } }, |
37 // 5.1 has the same values as 5.0. | 40 // 5.1 has the same values as 5.0. |
38 { 5, 0, { "7534.48.3", "534.46" } }, | 41 { 5, 0, { "7534.48.3", "534.46" } }, |
39 { 4, 3, { "6533.18.5", "533.17.9" } }, | |
40 }; | 42 }; |
41 | 43 |
42 int32 os_major_version = 0; | 44 int32 os_major_version = 0; |
43 int32 os_minor_version = 0; | 45 int32 os_minor_version = 0; |
44 int32 os_bugfix_version = 0; | 46 int32 os_bugfix_version = 0; |
45 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 47 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
46 &os_minor_version, | 48 &os_minor_version, |
47 &os_bugfix_version); | 49 &os_bugfix_version); |
48 | 50 |
49 // Return the versions corresponding to the first (and thus highest) OS | 51 // Return the versions corresponding to the first (and thus highest) OS |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 95 |
94 std::string os_cpu; | 96 std::string os_cpu; |
95 base::StringAppendF( | 97 base::StringAppendF( |
96 &os_cpu, | 98 &os_cpu, |
97 "%s;%s CPU %sOS %s like Mac OS X", | 99 "%s;%s CPU %sOS %s like Mac OS X", |
98 platform.c_str(), | 100 platform.c_str(), |
99 (os_major_version < 5) ? " U;" : "", // iOS < 5 has a "U;" in the UA. | 101 (os_major_version < 5) ? " U;" : "", // iOS < 5 has a "U;" in the UA. |
100 (platform == "iPad") ? "" : "iPhone ", // iPad has an empty string here. | 102 (platform == "iPad") ? "" : "iPhone ", // iPad has an empty string here. |
101 os_version.c_str()); | 103 os_version.c_str()); |
102 | 104 |
103 // Up until iOS 5, the locale was included at the end of the Safari UA. | |
104 // TODO(stuartmorgan): Remove this once iOS 4.3 is no longer supported. | |
105 if (os_major_version < 5) { | |
106 // The locale string is not easy to set correctly. Safari uses a language | |
107 // code and a dialect code. However, there is no setting allowing the user | |
108 // to set the dialect code, and no API to retrieve it. | |
109 // Note: The NSLocale methods (currentIdentifier:, | |
110 // objectForKey:NSLocaleLanguageCode and objectForKey:NSLocaleCountryCode) | |
111 // are not useful here because they return information related to the | |
112 // "Region Format" setting, which is different from the "Language" setting. | |
113 base::scoped_nsobject<NSDictionary> dialects([[NSDictionary alloc] | |
114 initWithObjectsAndKeys: | |
115 @"ar", @"ar", // No dialect code in Safari. | |
116 @"ca-es", @"ca", | |
117 @"cs-cz", @"cs", | |
118 @"da-dk", @"da", | |
119 @"el-gr", @"el", | |
120 @"en-gb", @"en-GB", | |
121 @"en-us", @"en", | |
122 @"he-il", @"he", | |
123 @"id", @"id", // No dialect code in Safari. | |
124 @"ja-jp", @"ja", | |
125 @"ko-kr", @"ko", | |
126 @"nb-no", @"nb", | |
127 @"pt-br", @"pt", | |
128 @"pt-pt", @"pt-PT", | |
129 @"sv-se", @"sv", | |
130 @"uk-ua", @"uk", | |
131 @"vi-vn", @"vi", | |
132 @"zh-cn", @"zh-Hans", | |
133 @"zh-tw", @"zh-Hant", | |
134 nil]); | |
135 | |
136 NSArray* preferredLanguages = [NSLocale preferredLanguages]; | |
137 NSString* language = ([preferredLanguages count] > 0) ? | |
138 [preferredLanguages objectAtIndex:0] : @"en"; | |
139 NSString* localeIdentifier = [dialects objectForKey:language]; | |
140 if (!localeIdentifier) { | |
141 // No entry in the dictionary, so duplicate the language string. | |
142 localeIdentifier = | |
143 [NSString stringWithFormat:@"%@-%@", language, language]; | |
144 } | |
145 | |
146 base::StringAppendF(&os_cpu, "; %s", | |
147 base::SysNSStringToUTF8(localeIdentifier).c_str()); | |
148 } | |
149 | |
150 return os_cpu; | 105 return os_cpu; |
151 } | 106 } |
152 | 107 |
153 std::string BuildUserAgentFromProduct(const std::string& product) { | 108 std::string BuildUserAgentFromProduct(const std::string& product) { |
154 // Retrieve the kernel build number. | 109 // Retrieve the kernel build number. |
155 int mib[2] = {CTL_KERN, KERN_OSVERSION}; | 110 int mib[2] = {CTL_KERN, KERN_OSVERSION}; |
156 unsigned int namelen = sizeof(mib) / sizeof(mib[0]); | 111 unsigned int namelen = sizeof(mib) / sizeof(mib[0]); |
157 size_t bufferSize = 0; | 112 size_t bufferSize = 0; |
158 sysctl(mib, namelen, NULL, &bufferSize, NULL, 0); | 113 sysctl(mib, namelen, NULL, &bufferSize, NULL, 0); |
159 char kernel_version[bufferSize]; | 114 char kernel_version[bufferSize]; |
(...skipping 10 matching lines...) Expand all Loading... |
170 webkit_glue::BuildOSCpuInfo().c_str(), | 125 webkit_glue::BuildOSCpuInfo().c_str(), |
171 ua_versions.webkit_version_string, | 126 ua_versions.webkit_version_string, |
172 product.c_str(), | 127 product.c_str(), |
173 kernel_version, | 128 kernel_version, |
174 ua_versions.safari_version_string); | 129 ua_versions.safari_version_string); |
175 | 130 |
176 return user_agent; | 131 return user_agent; |
177 } | 132 } |
178 | 133 |
179 } // namespace webkit_glue | 134 } // namespace webkit_glue |
OLD | NEW |