| 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> |
| 10 #include <stdint.h> |
| 9 #include <sys/sysctl.h> | 11 #include <sys/sysctl.h> |
| 10 #include <string> | 12 #include <string> |
| 11 | 13 |
| 12 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
| 15 #include "base/macros.h" |
| 13 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
| 16 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
| 17 | 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 struct UAVersions { | 23 struct UAVersions { |
| 21 const char* safari_version_string; | 24 const char* safari_version_string; |
| 22 const char* webkit_version_string; | 25 const char* webkit_version_string; |
| 23 }; | 26 }; |
| 24 | 27 |
| 25 struct OSVersionMap { | 28 struct OSVersionMap { |
| 26 int32 major_os_version; | 29 int32_t major_os_version; |
| 27 int32 minor_os_version; | 30 int32_t minor_os_version; |
| 28 UAVersions ua_versions; | 31 UAVersions ua_versions; |
| 29 }; | 32 }; |
| 30 | 33 |
| 31 const UAVersions& GetUAVersionsForCurrentOS() { | 34 const UAVersions& GetUAVersionsForCurrentOS() { |
| 32 // The WebKit version can be extracted dynamically from UIWebView, but the | 35 // 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 | 36 // Safari version can't be, so a lookup table is used instead (for both, since |
| 34 // the reported versions should stay in sync). | 37 // the reported versions should stay in sync). |
| 35 static const OSVersionMap version_map[] = { | 38 static const OSVersionMap version_map[] = { |
| 36 {9, 0, {"601.1.46", "601.1"}}, | 39 {9, 0, {"601.1.46", "601.1"}}, |
| 37 {8, 0, {"600.1.4", "600.1.4"}}, | 40 {8, 0, {"600.1.4", "600.1.4"}}, |
| 38 {7, 1, {"9537.53", "537.51.2"}}, | 41 {7, 1, {"9537.53", "537.51.2"}}, |
| 39 {7, 0, {"9537.53", "537.51.1"}}, | 42 {7, 0, {"9537.53", "537.51.1"}}, |
| 40 }; | 43 }; |
| 41 | 44 |
| 42 int32 os_major_version = 0; | 45 int32_t os_major_version = 0; |
| 43 int32 os_minor_version = 0; | 46 int32_t os_minor_version = 0; |
| 44 int32 os_bugfix_version = 0; | 47 int32_t os_bugfix_version = 0; |
| 45 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 48 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
| 46 &os_minor_version, | 49 &os_minor_version, |
| 47 &os_bugfix_version); | 50 &os_bugfix_version); |
| 48 | 51 |
| 49 // Return the versions corresponding to the first (and thus highest) OS | 52 // Return the versions corresponding to the first (and thus highest) OS |
| 50 // version less than or equal to the given OS version. | 53 // version less than or equal to the given OS version. |
| 51 for (unsigned int i = 0; i < arraysize(version_map); ++i) { | 54 for (unsigned int i = 0; i < arraysize(version_map); ++i) { |
| 52 if (os_major_version > version_map[i].major_os_version || | 55 if (os_major_version > version_map[i].major_os_version || |
| 53 (os_major_version == version_map[i].major_os_version && | 56 (os_major_version == version_map[i].major_os_version && |
| 54 os_minor_version >= version_map[i].minor_os_version)) | 57 os_minor_version >= version_map[i].minor_os_version)) |
| 55 return version_map[i].ua_versions; | 58 return version_map[i].ua_versions; |
| 56 } | 59 } |
| 57 NOTREACHED(); | 60 NOTREACHED(); |
| 58 return version_map[arraysize(version_map) - 1].ua_versions; | 61 return version_map[arraysize(version_map) - 1].ua_versions; |
| 59 } | 62 } |
| 60 | 63 |
| 61 } // namespace | 64 } // namespace |
| 62 | 65 |
| 63 namespace web { | 66 namespace web { |
| 64 | 67 |
| 65 std::string BuildOSCpuInfo() { | 68 std::string BuildOSCpuInfo() { |
| 66 int32 os_major_version = 0; | 69 int32_t os_major_version = 0; |
| 67 int32 os_minor_version = 0; | 70 int32_t os_minor_version = 0; |
| 68 int32 os_bugfix_version = 0; | 71 int32_t os_bugfix_version = 0; |
| 69 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 72 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
| 70 &os_minor_version, | 73 &os_minor_version, |
| 71 &os_bugfix_version); | 74 &os_bugfix_version); |
| 72 std::string os_version; | 75 std::string os_version; |
| 73 if (os_bugfix_version == 0) { | 76 if (os_bugfix_version == 0) { |
| 74 base::StringAppendF(&os_version, | 77 base::StringAppendF(&os_version, |
| 75 "%d_%d", | 78 "%d_%d", |
| 76 os_major_version, | 79 os_major_version, |
| 77 os_minor_version); | 80 os_minor_version); |
| 78 } else { | 81 } else { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 BuildOSCpuInfo().c_str(), | 124 BuildOSCpuInfo().c_str(), |
| 122 ua_versions.webkit_version_string, | 125 ua_versions.webkit_version_string, |
| 123 product.c_str(), | 126 product.c_str(), |
| 124 kernel_version, | 127 kernel_version, |
| 125 ua_versions.safari_version_string); | 128 ua_versions.safari_version_string); |
| 126 | 129 |
| 127 return user_agent; | 130 return user_agent; |
| 128 } | 131 } |
| 129 | 132 |
| 130 } // namespace web | 133 } // namespace web |
| OLD | NEW |