#include "content/public/common/user_agent.h"
#include <stdint.h>
#include "base/containers/contains.h"
#include "base/logging.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/system/sys_info.h"
#include "build/build_config.h"
#include "build/util/chromium_git_revision.h"
#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#endif
#if BUILDFLAG(IS_IOS)
#include "ui/base/device_form_factor.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/win/windows_version.h"
#elif BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
#include <sys/utsname.h>
#endif
namespace content {
namespace {
const char kFrozenUserAgentTemplate[] = …;
std::string GetUserAgentPlatform() { … }
std::string GetUnifiedPlatform() { … }
}
std::string GetUnifiedPlatformForTesting() { … }
std::string GetWebKitVersion() { … }
std::string GetChromiumGitRevision() { … }
std::string BuildCpuInfo() { … }
std::string GetCpuArchitecture() { … }
std::string GetCpuBitness() { … }
std::string GetOSVersion(IncludeAndroidBuildNumber include_android_build_number,
IncludeAndroidModel include_android_model) { … }
std::string BuildOSCpuInfo(
IncludeAndroidBuildNumber include_android_build_number,
IncludeAndroidModel include_android_model) { … }
std::string BuildOSCpuInfoFromOSVersionAndCpuType(const std::string& os_version,
const std::string& cpu_type) { … }
std::string GetReducedUserAgent(bool mobile, std::string major_version) { … }
std::string BuildUnifiedPlatformUserAgentFromProduct(
const std::string& product) { … }
std::string BuildUserAgentFromProduct(const std::string& product) { … }
std::string BuildModelInfo() { … }
#if BUILDFLAG(IS_ANDROID)
std::string BuildUserAgentFromProductAndExtraOSInfo(
const std::string& product,
const std::string& extra_os_info,
IncludeAndroidBuildNumber include_android_build_number) {
std::string os_info;
base::StrAppend(&os_info, {GetUserAgentPlatform(),
BuildOSCpuInfo(include_android_build_number,
IncludeAndroidModel::Include),
extra_os_info});
return BuildUserAgentFromOSAndProduct(os_info, product);
}
std::string BuildUnifiedPlatformUAFromProductAndExtraOs(
const std::string& product,
const std::string& extra_os_info) {
std::string os_info;
base::StrAppend(&os_info, {GetUnifiedPlatform(), extra_os_info});
return BuildUserAgentFromOSAndProduct(os_info, product);
}
std::string GetAndroidOSInfo(
IncludeAndroidBuildNumber include_android_build_number,
IncludeAndroidModel include_android_model) {
std::string android_info_str;
bool semicolon_inserted = false;
if (include_android_model == IncludeAndroidModel::Include) {
std::string android_device_name = BuildModelInfo();
if (!android_device_name.empty()) {
android_info_str += "; " + android_device_name;
semicolon_inserted = true;
}
}
if (include_android_build_number == IncludeAndroidBuildNumber::Include) {
std::string android_build_id = base::SysInfo::GetAndroidBuildID();
if (!android_build_id.empty()) {
if (!semicolon_inserted)
android_info_str += ";";
android_info_str += " Build/" + android_build_id;
}
}
return android_info_str;
}
#endif
std::string BuildUserAgentFromOSAndProduct(const std::string& os_info,
const std::string& product) { … }
bool IsWoW64() { … }
}