1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/version/version_ui.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/debug/debugging_buildflags.h"
#include "base/i18n/message_formatter.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/version/version_handler.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/embedder_support/user_agent_utils.h"
#include "components/grit/components_scaled_resources.h"
#include "components/grit/version_ui_resources.h"
#include "components/grit/version_ui_resources_map.h"
#include "components/strings/grit/components_branded_strings.h"
#include "components/strings/grit/components_strings.h"
#include "components/variations/service/variations_service.h"
#include "components/version_info/version_info.h"
#include "components/webui/version/version_handler_helper.h"
#include "components/webui/version/version_ui_constants.h"
#include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/webui/webui_util.h"
#include "v8/include/v8-version-string.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#include "chrome/browser/ui/android/android_about_app_info.h"
#else
#include "chrome/browser/ui/webui/theme_source.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "build/util/LASTCHANGE_commit_position.h"
#include "chrome/browser/ui/webui/version/version_handler_chromeos.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/win/windows_version.h"
#include "chrome/browser/ui/webui/version/version_handler_win.h"
#include "chrome/browser/ui/webui/version/version_util_win.h"
#endif
using content::WebUIDataSource;
namespace {
void CreateAndAddVersionUIDataSource(Profile* profile) {
WebUIDataSource* html_source =
WebUIDataSource::CreateAndAdd(profile, chrome::kChromeUIVersionHost);
// These localized strings are used to label version details.
static constexpr webui::LocalizedString kStrings[] = {
{version_ui::kTitle, IDS_VERSION_UI_TITLE},
{version_ui::kLogoAltText, IDS_SHORT_PRODUCT_LOGO_ALT_TEXT},
{version_ui::kApplicationLabel, IDS_PRODUCT_NAME},
{version_ui::kCompany, IDS_ABOUT_VERSION_COMPANY_NAME},
{version_ui::kCopyLabel, IDS_VERSION_UI_COPY_LABEL},
{version_ui::kCopyNotice, IDS_VERSION_UI_COPY_NOTICE},
{version_ui::kRevision, IDS_VERSION_UI_REVISION},
{version_ui::kUserAgentName, IDS_VERSION_UI_USER_AGENT},
{version_ui::kCommandLineName, IDS_VERSION_UI_COMMAND_LINE},
{version_ui::kExecutablePathName, IDS_VERSION_UI_EXECUTABLE_PATH},
{version_ui::kProfilePathName, IDS_VERSION_UI_PROFILE_PATH},
{version_ui::kVariationsName, IDS_VERSION_UI_VARIATIONS},
{version_ui::kVariationsCmdName, IDS_VERSION_UI_VARIATIONS_CMD},
{version_ui::kCopyVariationsLabel, IDS_VERSION_UI_COPY_VARIATIONS_LABEL},
{version_ui::kCopyVariationsNotice,
IDS_VERSION_UI_COPY_VARIATIONS_NOTICE},
{version_ui::kVariationsSeedName, IDS_VERSION_UI_VARIATIONS_SEED_NAME},
#if BUILDFLAG(IS_CHROMEOS)
{version_ui::kARC, IDS_ARC_LABEL},
{version_ui::kPlatform, IDS_PLATFORM_LABEL},
{version_ui::kCustomizationId, IDS_VERSION_UI_CUSTOMIZATION_ID},
{version_ui::kFirmwareVersion, IDS_VERSION_UI_FIRMWARE_VERSION},
#else
{version_ui::kOSName, IDS_VERSION_UI_OS},
#endif // BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(IS_ANDROID)
{version_ui::kGmsName, IDS_VERSION_UI_GMS},
#endif // BUILDFLAG(IS_ANDROID)
};
html_source->AddLocalizedStrings(kStrings);
VersionUI::AddVersionDetailStrings(html_source);
html_source->AddResourcePaths(kVersionUiResources);
html_source->AddResourcePath("", IDR_VERSION_UI_ABOUT_VERSION_HTML);
html_source->UseStringsJs();
#if BUILDFLAG(IS_ANDROID)
html_source->AddResourcePath("images/product_logo.png", IDR_PRODUCT_LOGO);
html_source->AddResourcePath("images/product_logo_white.png",
IDR_PRODUCT_LOGO_WHITE);
#endif // BUILDFLAG(IS_ANDROID)
}
std::string GetProductModifier() {
std::vector<std::string> modifier_parts;
if (std::string channel_name =
chrome::GetChannelName(chrome::WithExtendedStable(true));
!channel_name.empty()) {
modifier_parts.push_back(std::move(channel_name));
}
#if BUILDFLAG(DCHECK_IS_CONFIGURABLE)
modifier_parts.emplace_back("dcheck");
#endif // BUILDFLAG(DCHECK_IS_CONFIGURABLE)
return base::JoinString(modifier_parts, "-");
}
std::string GetVersionInformationalSuffix() {
#if BUILDFLAG(IS_CHROMEOS) && CHROMIUM_COMMIT_POSITION_IS_MAIN
// Adds the revision number as a suffix to the version number if the chrome
// is built from the main branch.
return "-r" CHROMIUM_COMMIT_POSITION_NUMBER;
#else
return "";
#endif
}
} // namespace
VersionUI::VersionUI(content::WebUI* web_ui)
: content::WebUIController(web_ui) {
Profile* profile = Profile::FromWebUI(web_ui);
#if BUILDFLAG(IS_CHROMEOS)
web_ui->AddMessageHandler(std::make_unique<VersionHandlerChromeOS>());
#elif BUILDFLAG(IS_WIN)
web_ui->AddMessageHandler(std::make_unique<VersionHandlerWindows>());
#else
web_ui->AddMessageHandler(std::make_unique<VersionHandler>());
#endif
#if !BUILDFLAG(IS_ANDROID)
// Set up the chrome://theme/ source.
content::URLDataSource::Add(profile, std::make_unique<ThemeSource>(profile));
#endif
CreateAndAddVersionUIDataSource(profile);
}
VersionUI::~VersionUI() = default;
// static
int VersionUI::VersionProcessorVariation() {
#if BUILDFLAG(IS_ANDROID)
// When building for Android, "unused" strings are removed. However, binaries
// of both bitnesses are stripped of strings based on string analysis of one
// bitness. Search the code for "generate_resource_allowlist" for more
// information. Therefore, make sure both the IDS_VERSION_UI_32BIT and
// IDS_VERSION_UI_64BIT strings are marked as always used so that they’re
// never stripped. https://crbug.com/1119479
IDS_VERSION_UI_32BIT;
IDS_VERSION_UI_64BIT;
#endif // BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_MAC)
switch (base::mac::GetCPUType()) {
case base::mac::CPUType::kIntel:
return IDS_VERSION_UI_64BIT_INTEL;
case base::mac::CPUType::kTranslatedIntel:
return IDS_VERSION_UI_64BIT_TRANSLATED_INTEL;
case base::mac::CPUType::kArm:
return IDS_VERSION_UI_64BIT_ARM;
}
#elif BUILDFLAG(IS_WIN)
#if defined(ARCH_CPU_ARM64)
return IDS_VERSION_UI_64BIT_ARM;
#else
bool emulated = base::win::OSInfo::IsRunningEmulatedOnArm64();
#if defined(ARCH_CPU_X86)
if (emulated) {
return IDS_VERSION_UI_32BIT_TRANSLATED_INTEL;
}
return IDS_VERSION_UI_32BIT;
#else // defined(ARCH_CPU_X86)
if (emulated) {
return IDS_VERSION_UI_64BIT_TRANSLATED_INTEL;
}
return IDS_VERSION_UI_64BIT;
#endif // defined(ARCH_CPU_X86)
#endif // defined(ARCH_CPU_ARM64)
#elif defined(ARCH_CPU_64_BITS)
return IDS_VERSION_UI_64BIT;
#elif defined(ARCH_CPU_32_BITS)
return IDS_VERSION_UI_32BIT;
#else
#error Update for a processor that is neither 32-bit nor 64-bit.
#endif
}
// static
void VersionUI::AddVersionDetailStrings(content::WebUIDataSource* html_source) {
html_source->AddLocalizedString(version_ui::kOfficial,
version_info::IsOfficialBuild()
? IDS_VERSION_UI_OFFICIAL
: IDS_VERSION_UI_UNOFFICIAL);
html_source->AddLocalizedString(version_ui::kVersionProcessorVariation,
VersionProcessorVariation());
// Data strings.
html_source->AddString(version_ui::kVersion,
version_info::GetVersionNumber());
html_source->AddString(version_ui::kVersionSuffix,
GetVersionInformationalSuffix());
html_source->AddString(version_ui::kVersionModifier, GetProductModifier());
html_source->AddString(version_ui::kJSEngine, "V8");
html_source->AddString(version_ui::kJSVersion, V8_VERSION_STRING);
html_source->AddString(
version_ui::kCopyright,
base::i18n::MessageFormatter::FormatWithNumberedArgs(
l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COPYRIGHT),
base::Time::Now()));
html_source->AddString(version_ui::kCL, version_info::GetLastChange());
html_source->AddString(version_ui::kUserAgent,
embedder_support::GetUserAgent());
// Note that the executable path and profile path are retrieved asynchronously
// and returned in VersionHandler::OnGotFilePaths. The area is initially
// blank.
html_source->AddString(version_ui::kExecutablePath, std::string_view());
html_source->AddString(version_ui::kProfilePath, std::string_view());
#if BUILDFLAG(IS_MAC)
html_source->AddString(version_ui::kOSType, base::mac::GetOSDisplayName());
#elif !BUILDFLAG(IS_CHROMEOS)
html_source->AddString(version_ui::kOSType, version_info::GetOSType());
#endif // BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_ANDROID)
std::string os_info = AndroidAboutAppInfo::GetOsInfo();
os_info += "; " + base::NumberToString(
base::android::BuildInfo::GetInstance()->sdk_int());
std::string code_name(base::android::BuildInfo::GetInstance()->codename());
os_info += "; " + code_name;
html_source->AddString(version_ui::kOSVersion, os_info);
html_source->AddString(
version_ui::kTargetSdkVersion,
base::NumberToString(
base::android::BuildInfo::GetInstance()->target_sdk_version()));
html_source->AddString(version_ui::kGmsVersion,
AndroidAboutAppInfo::GetGmsInfo());
html_source->AddString(
version_ui::kVersionCode,
base::android::BuildInfo::GetInstance()->package_version_code());
#endif // BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_WIN)
html_source->AddString(
version_ui::kCommandLine,
base::AsString16(
base::CommandLine::ForCurrentProcess()->GetCommandLineString()));
#else
std::string command_line;
using ArgvList = std::vector<std::string>;
const ArgvList& argv = base::CommandLine::ForCurrentProcess()->argv();
for (const auto& iter : argv) {
command_line += " " + iter;
}
// TODO(viettrungluu): |command_line| could really have any encoding, whereas
// below we assumes it's UTF-8.
html_source->AddString(version_ui::kCommandLine, command_line);
#endif
#if BUILDFLAG(IS_MAC)
html_source->AddString("linker", CHROMIUM_LINKER_NAME);
#endif // BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_WIN)
html_source->AddString(version_ui::kUpdateCohortName,
version_utils::win::GetCohortVersionInfo());
#endif // BUILDFLAG(IS_WIN)
html_source->AddString(
version_ui::kVariationsSeed,
g_browser_process->variations_service()
? version_ui::SeedTypeToUiString(
g_browser_process->variations_service()->GetSeedType())
: std::string());
html_source->AddString(version_ui::kSanitizer,
version_info::GetSanitizerList());
}
#if !BUILDFLAG(IS_ANDROID)
// static
std::u16string VersionUI::GetAnnotatedVersionStringForUi() {
return l10n_util::GetStringFUTF16(
IDS_SETTINGS_ABOUT_PAGE_BROWSER_VERSION,
base::UTF8ToUTF16(version_info::GetVersionNumber()),
base::UTF8ToUTF16(GetVersionInformationalSuffix()),
l10n_util::GetStringUTF16(version_info::IsOfficialBuild()
? IDS_VERSION_UI_OFFICIAL
: IDS_VERSION_UI_UNOFFICIAL),
base::UTF8ToUTF16(GetProductModifier()),
l10n_util::GetStringUTF16(VersionUI::VersionProcessorVariation()));
}
#endif // !BUILDFLAG(IS_ANDROID)
|