Commit cb8d3ee2 authored by Aaron Tagliaboschi's avatar Aaron Tagliaboschi Committed by Commit Bot

[client-hints] Populate 'sec-ch-ua-model' and 'sec-ch-ua-arch'

A smidge of refactoring for the user agent string code as well.

(Relanding crrev.com/c/1951446 after fixing MacOSX cpuinfo)

Bug: 1001125
Change-Id: I237011f3d85bde2cfe8bcf40731b442df27fe481
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1955958Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Aaron Tagliaboschi <aarontag@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723035}
parent b6ca0955
...@@ -1112,10 +1112,8 @@ blink::UserAgentMetadata GetUserAgentMetadata() { ...@@ -1112,10 +1112,8 @@ blink::UserAgentMetadata GetUserAgentMetadata() {
metadata.full_version = version_info::GetVersionNumber(); metadata.full_version = version_info::GetVersionNumber();
metadata.major_version = version_info::GetMajorVersionNumber(); metadata.major_version = version_info::GetMajorVersionNumber();
metadata.platform = version_info::GetOSType(); metadata.platform = version_info::GetOSType();
metadata.architecture = content::BuildCpuInfo();
// TODO(mkwst): Poke at BuildUserAgentFromProduct to split out these pieces. metadata.model = content::BuildModelInfo();
metadata.architecture = "";
metadata.model = "";
return metadata; return metadata;
} }
......
...@@ -485,6 +485,6 @@ TEST(ChromeContentBrowserClientTest, UserAgentMetadata) { ...@@ -485,6 +485,6 @@ TEST(ChromeContentBrowserClientTest, UserAgentMetadata) {
EXPECT_EQ(metadata.full_version, version_info::GetVersionNumber()); EXPECT_EQ(metadata.full_version, version_info::GetVersionNumber());
EXPECT_EQ(metadata.major_version, version_info::GetMajorVersionNumber()); EXPECT_EQ(metadata.major_version, version_info::GetMajorVersionNumber());
EXPECT_EQ(metadata.platform, version_info::GetOSType()); EXPECT_EQ(metadata.platform, version_info::GetOSType());
EXPECT_EQ(metadata.architecture, ""); EXPECT_EQ(metadata.architecture, content::BuildCpuInfo());
EXPECT_EQ(metadata.model, ""); EXPECT_EQ(metadata.model, content::BuildModelInfo());
} }
...@@ -60,56 +60,68 @@ std::string GetWebKitRevision() { ...@@ -60,56 +60,68 @@ std::string GetWebKitRevision() {
return WEBKIT_SVN_REVISION; return WEBKIT_SVN_REVISION;
} }
std::string BuildOSCpuInfo(bool include_android_build_number) { std::string BuildCpuInfo() {
std::string os_cpu; std::string cpuinfo = "";
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) ||\ #if defined(OS_MACOSX)
defined(OS_ANDROID) cpuinfo = "Intel";
int32_t os_major_version = 0; #elif defined(OS_WIN)
int32_t os_minor_version = 0;
int32_t os_bugfix_version = 0;
base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
&os_minor_version,
&os_bugfix_version);
#endif
#if defined(OS_WIN)
std::string architecture_token;
base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); base::win::OSInfo* os_info = base::win::OSInfo::GetInstance();
if (os_info->wow64_status() == base::win::OSInfo::WOW64_ENABLED) { if (os_info->wow64_status() == base::win::OSInfo::WOW64_ENABLED) {
architecture_token = "; WOW64"; cpuinfo = "WOW64";
} else { } else {
base::win::OSInfo::WindowsArchitecture windows_architecture = base::win::OSInfo::WindowsArchitecture windows_architecture =
os_info->GetArchitecture(); os_info->GetArchitecture();
if (windows_architecture == base::win::OSInfo::X64_ARCHITECTURE) if (windows_architecture == base::win::OSInfo::X64_ARCHITECTURE)
architecture_token = "; Win64; x64"; cpuinfo = "Win64; x64";
else if (windows_architecture == base::win::OSInfo::IA64_ARCHITECTURE) else if (windows_architecture == base::win::OSInfo::IA64_ARCHITECTURE)
architecture_token = "; Win64; IA64"; cpuinfo = "Win64; IA64";
} }
#elif defined(OS_ANDROID)
std::string android_version_str = base::SysInfo::OperatingSystemVersion();
std::string android_info_str = GetAndroidOSInfo(include_android_build_number);
#elif defined(OS_POSIX) && !defined(OS_MACOSX) #elif defined(OS_POSIX) && !defined(OS_MACOSX)
// Should work on any Posix system. // Should work on any Posix system.
struct utsname unixinfo; struct utsname unixinfo;
uname(&unixinfo); uname(&unixinfo);
std::string cputype;
// special case for biarch systems // special case for biarch systems
if (strcmp(unixinfo.machine, "x86_64") == 0 && if (strcmp(unixinfo.machine, "x86_64") == 0 &&
sizeof(void*) == sizeof(int32_t)) { sizeof(void*) == sizeof(int32_t)) {
cputype.assign("i686 (x86_64)"); cpuinfo.assign("i686 (x86_64)");
} else { } else {
cputype.assign(unixinfo.machine); cpuinfo.assign(unixinfo.machine);
} }
#endif #endif
return cpuinfo;
}
std::string BuildOSCpuInfo(bool include_android_build_number) {
std::string cputype = BuildCpuInfo();
std::string os_cpu;
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) || \
defined(OS_ANDROID)
int32_t os_major_version = 0;
int32_t os_minor_version = 0;
int32_t os_bugfix_version = 0;
base::SysInfo::OperatingSystemVersionNumbers(
&os_major_version, &os_minor_version, &os_bugfix_version);
#endif
#if defined(OS_ANDROID)
std::string android_version_str = base::SysInfo::OperatingSystemVersion();
std::string android_info_str = GetAndroidOSInfo(include_android_build_number);
#elif defined(OS_POSIX) && !defined(OS_MACOSX)
// Should work on any Posix system.
struct utsname unixinfo;
uname(&unixinfo);
#endif
base::StringAppendF(&os_cpu, base::StringAppendF(&os_cpu,
#if defined(OS_WIN) #if defined(OS_WIN)
"Windows NT %d.%d%s", os_major_version, os_minor_version, "Windows NT %d.%d; %s", os_major_version,
architecture_token.c_str() os_minor_version, cputype.c_str()
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
"Intel Mac OS X %d_%d_%d", os_major_version, "%s Mac OS X %d_%d_%d", cputype.c_str(), os_major_version,
os_minor_version, os_bugfix_version os_minor_version, os_bugfix_version
#elif defined(OS_CHROMEOS) #elif defined(OS_CHROMEOS)
"CrOS " "CrOS "
...@@ -146,6 +158,17 @@ std::string BuildUserAgentFromProduct(const std::string& product) { ...@@ -146,6 +158,17 @@ std::string BuildUserAgentFromProduct(const std::string& product) {
return BuildUserAgentFromOSAndProduct(os_info, product); return BuildUserAgentFromOSAndProduct(os_info, product);
} }
std::string BuildModelInfo() {
std::string model = "";
#if defined(OS_ANDROID)
// Only send the model information if on the release build of Android,
// matching user agent behaviour.
if (base::SysInfo::GetAndroidBuildCodename() == "REL")
model = base::SysInfo::HardwareModelName();
#endif
return model;
}
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
std::string BuildUserAgentFromProductAndExtraOSInfo( std::string BuildUserAgentFromProductAndExtraOSInfo(
const std::string& product, const std::string& product,
...@@ -163,9 +186,8 @@ std::string GetAndroidOSInfo(bool include_android_build_number) { ...@@ -163,9 +186,8 @@ std::string GetAndroidOSInfo(bool include_android_build_number) {
// Send information about the device. // Send information about the device.
bool semicolon_inserted = false; bool semicolon_inserted = false;
std::string android_build_codename = base::SysInfo::GetAndroidBuildCodename(); std::string android_device_name = BuildModelInfo();
std::string android_device_name = base::SysInfo::HardwareModelName(); if (!android_device_name.empty()) {
if (!android_device_name.empty() && "REL" == android_build_codename) {
android_info_str += "; " + android_device_name; android_info_str += "; " + android_device_name;
semicolon_inserted = true; semicolon_inserted = true;
} }
......
...@@ -35,6 +35,10 @@ CONTENT_EXPORT std::string GetWebKitVersion(); ...@@ -35,6 +35,10 @@ CONTENT_EXPORT std::string GetWebKitVersion();
CONTENT_EXPORT std::string GetWebKitRevision(); CONTENT_EXPORT std::string GetWebKitRevision();
// Builds a string that describes the CPU type when available (or blank
// otherwise).
CONTENT_EXPORT std::string BuildCpuInfo();
// Builds a User-agent compatible string that describes the OS and CPU type. // Builds a User-agent compatible string that describes the OS and CPU type.
// On Android, the string will only include the build number if true is passed // On Android, the string will only include the build number if true is passed
// as an argument. // as an argument.
...@@ -49,6 +53,10 @@ CONTENT_EXPORT base::StringPiece GetFrozenUserAgent(bool mobile); ...@@ -49,6 +53,10 @@ CONTENT_EXPORT base::StringPiece GetFrozenUserAgent(bool mobile);
CONTENT_EXPORT std::string BuildUserAgentFromProduct( CONTENT_EXPORT std::string BuildUserAgentFromProduct(
const std::string& product); const std::string& product);
// Returns the model information. Returns a blank string if not on Android or
// if on a codenamed (i.e. not a release) build of an Android.
CONTENT_EXPORT std::string BuildModelInfo();
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Helper function to generate a full user agent string given a short // Helper function to generate a full user agent string given a short
// product name and some extra text to be added to the OS info. // product name and some extra text to be added to the OS info.
......
...@@ -189,10 +189,8 @@ blink::UserAgentMetadata GetShellUserAgentMetadata() { ...@@ -189,10 +189,8 @@ blink::UserAgentMetadata GetShellUserAgentMetadata() {
metadata.full_version = CONTENT_SHELL_VERSION; metadata.full_version = CONTENT_SHELL_VERSION;
metadata.major_version = CONTENT_SHELL_MAJOR_VERSION; metadata.major_version = CONTENT_SHELL_MAJOR_VERSION;
metadata.platform = BuildOSCpuInfo(false); metadata.platform = BuildOSCpuInfo(false);
metadata.architecture = BuildCpuInfo();
// TODO(mkwst): Split these out from BuildOSCpuInfo(). metadata.model = BuildModelInfo();
metadata.architecture = "";
metadata.model = "";
return metadata; return metadata;
} }
......
...@@ -173,9 +173,8 @@ blink::UserAgentMetadata ContentBrowserClientImpl::GetUserAgentMetadata() { ...@@ -173,9 +173,8 @@ blink::UserAgentMetadata ContentBrowserClientImpl::GetUserAgentMetadata() {
metadata.full_version = version_info::GetVersionNumber(); metadata.full_version = version_info::GetVersionNumber();
metadata.major_version = version_info::GetMajorVersionNumber(); metadata.major_version = version_info::GetMajorVersionNumber();
metadata.platform = version_info::GetOSType(); metadata.platform = version_info::GetOSType();
metadata.architecture = content::BuildCpuInfo();
metadata.architecture = ""; metadata.model = content::BuildModelInfo();
metadata.model = "";
return metadata; return metadata;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment