Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/ui/webui/version_ui.h" | 5 #include "ios/chrome/browser/ui/webui/version_ui.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/ui/webui/version_handler.h" | |
| 11 #include "chrome/common/channel_info.h" | |
| 12 #include "chrome/common/chrome_content_client.h" | |
| 13 #include "chrome/common/url_constants.h" | |
| 14 #include "chrome/grit/chromium_strings.h" | |
| 15 #include "chrome/grit/generated_resources.h" | |
| 16 #include "components/version_info/version_info.h" | 10 #include "components/version_info/version_info.h" |
| 17 #include "components/version_ui/version_ui_constants.h" | 11 #include "components/version_ui/version_ui_constants.h" |
| 18 #include "content/public/browser/url_data_source.h" | |
| 19 #include "content/public/browser/web_ui.h" | |
| 20 #include "content/public/browser/web_ui_data_source.h" | |
| 21 #include "content/public/common/user_agent.h" | |
| 22 #include "grit/browser_resources.h" | |
| 23 #include "grit/components_chromium_strings.h" | 12 #include "grit/components_chromium_strings.h" |
| 24 #include "grit/components_google_chrome_strings.h" | 13 #include "grit/components_google_chrome_strings.h" |
| 25 #include "grit/components_resources.h" | 14 #include "grit/components_resources.h" |
| 26 #include "grit/components_strings.h" | 15 #include "grit/components_strings.h" |
| 16 #include "ios/chrome/browser/chrome_url_constants.h" | |
| 17 #include "ios/chrome/browser/ui/ui_util.h" | |
| 18 #include "ios/chrome/browser/ui/webui/version_handler.h" | |
| 19 #include "ios/chrome/common/channel_info.h" | |
| 20 #include "ios/chrome/grit/ios_chromium_strings.h" | |
| 21 #include "ios/chrome/grit/ios_google_chrome_strings.h" | |
| 22 #include "ios/chrome/grit/ios_strings.h" | |
| 23 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state. h" | |
| 24 #include "ios/public/provider/web/web_ui_ios.h" | |
| 25 #include "ios/web/public/web_client.h" | |
| 26 #include "ios/web/public/web_ui_ios_data_source.h" | |
| 27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "v8/include/v8.h" | |
| 29 | |
| 30 #if defined(ENABLE_THEMES) | |
| 31 #include "chrome/browser/ui/webui/theme_source.h" | |
| 32 #endif | |
| 33 | |
| 34 #if defined(OS_ANDROID) | |
| 35 #include "base/android/build_info.h" | |
| 36 #include "chrome/browser/ui/android/android_about_app_info.h" | |
| 37 #endif | |
| 38 | |
| 39 #if defined(OS_CHROMEOS) | |
| 40 #include "chrome/browser/ui/webui/version_handler_chromeos.h" | |
| 41 #endif | |
| 42 | |
| 43 using content::WebUIDataSource; | |
| 44 | 28 |
| 45 namespace { | 29 namespace { |
| 46 | 30 |
| 47 WebUIDataSource* CreateVersionUIDataSource() { | 31 web::WebUIIOSDataSource* CreateVersionUIDataSource() { |
| 48 WebUIDataSource* html_source = | 32 web::WebUIIOSDataSource* html_source = |
| 49 WebUIDataSource::Create(chrome::kChromeUIVersionHost); | 33 web::WebUIIOSDataSource::Create(kChromeUIVersionHost); |
| 50 | 34 |
| 51 // Localized and data strings. | 35 // Localized and data strings. |
| 52 html_source->AddLocalizedString(version_ui::kTitle, IDS_VERSION_UI_TITLE); | 36 html_source->AddLocalizedString(version_ui::kTitle, IDS_VERSION_UI_TITLE); |
| 53 html_source->AddLocalizedString(version_ui::kApplicationLabel, | 37 html_source->AddLocalizedString(version_ui::kApplicationLabel, |
| 54 IDS_PRODUCT_NAME); | 38 IDS_IOS_PRODUCT_NAME); |
| 55 html_source->AddString(version_ui::kVersion, | 39 html_source->AddString(version_ui::kVersion, |
| 56 version_info::GetVersionNumber()); | 40 version_info::GetVersionNumber()); |
| 57 html_source->AddString(version_ui::kVersionModifier, | 41 html_source->AddString(version_ui::kVersionModifier, |
| 58 chrome::GetChannelString()); | 42 GetChannelString(GetChannel())); |
| 59 html_source->AddLocalizedString(version_ui::kOSName, IDS_VERSION_UI_OS); | 43 html_source->AddLocalizedString(version_ui::kOSName, IDS_VERSION_UI_OS); |
| 60 html_source->AddLocalizedString(version_ui::kPlatform, IDS_PLATFORM_LABEL); | 44 html_source->AddLocalizedString(version_ui::kPlatform, |
| 45 IDS_IOS_PLATFORM_LABEL); | |
| 61 html_source->AddString(version_ui::kOSType, version_info::GetOSType()); | 46 html_source->AddString(version_ui::kOSType, version_info::GetOSType()); |
| 62 html_source->AddString(version_ui::kBlinkVersion, | |
| 63 content::GetWebKitVersion()); | |
| 64 html_source->AddString(version_ui::kJSEngine, "V8"); | |
| 65 html_source->AddString(version_ui::kJSVersion, v8::V8::GetVersion()); | |
| 66 | |
| 67 #if defined(OS_ANDROID) | |
| 68 html_source->AddString(version_ui::kOSVersion, | |
| 69 AndroidAboutAppInfo::GetOsInfo()); | |
| 70 html_source->AddLocalizedString(version_ui::kBuildIDName, | |
| 71 IDS_VERSION_UI_BUILD_ID); | |
| 72 html_source->AddString(version_ui::kBuildID, CHROME_BUILD_ID); | |
| 73 #else | |
| 74 html_source->AddString(version_ui::kOSVersion, std::string()); | 47 html_source->AddString(version_ui::kOSVersion, std::string()); |
| 75 html_source->AddString(version_ui::kFlashPlugin, "Flash"); | |
| 76 // Note that the Flash version is retrieve asynchronously and returned in | |
| 77 // VersionHandler::OnGotPlugins. The area is initially blank. | |
| 78 html_source->AddString(version_ui::kFlashVersion, std::string()); | |
| 79 #endif // defined(OS_ANDROID) | |
| 80 | 48 |
| 81 html_source->AddLocalizedString(version_ui::kCompany, | 49 html_source->AddLocalizedString(version_ui::kCompany, |
| 82 IDS_ABOUT_VERSION_COMPANY_NAME); | 50 IDS_IOS_ABOUT_VERSION_COMPANY_NAME); |
| 83 base::Time::Exploded exploded_time; | 51 base::Time::Exploded exploded_time; |
| 84 base::Time::Now().LocalExplode(&exploded_time); | 52 base::Time::Now().LocalExplode(&exploded_time); |
| 85 html_source->AddString( | 53 html_source->AddString( |
| 86 version_ui::kCopyright, | 54 version_ui::kCopyright, |
| 87 l10n_util::GetStringFUTF16(IDS_ABOUT_VERSION_COPYRIGHT, | 55 l10n_util::GetStringFUTF16(IDS_IOS_ABOUT_VERSION_COPYRIGHT, |
| 88 base::IntToString16(exploded_time.year))); | 56 base::IntToString16(exploded_time.year))); |
| 89 html_source->AddLocalizedString(version_ui::kRevision, | 57 html_source->AddLocalizedString(version_ui::kRevision, |
| 90 IDS_VERSION_UI_REVISION); | 58 IDS_VERSION_UI_REVISION); |
| 91 html_source->AddString(version_ui::kCL, version_info::GetLastChange()); | 59 std::string last_change = version_info::GetLastChange(); |
| 60 // On iOS, shorten the git hash to display it correctly on small devices. | |
|
blundell
2015/10/27 10:09:59
nit: s/"On iOS, "//
| |
| 61 if (!IsIPadIdiom() && last_change.length() > 12) { | |
| 62 last_change = | |
| 63 base::StringPrintf("%s...", last_change.substr(0, 12).c_str()); | |
| 64 } | |
| 65 html_source->AddString(version_ui::kCL, last_change); | |
| 92 html_source->AddLocalizedString(version_ui::kOfficial, | 66 html_source->AddLocalizedString(version_ui::kOfficial, |
| 93 version_info::IsOfficialBuild() | 67 version_info::IsOfficialBuild() |
| 94 ? IDS_VERSION_UI_OFFICIAL | 68 ? IDS_VERSION_UI_OFFICIAL |
| 95 : IDS_VERSION_UI_UNOFFICIAL); | 69 : IDS_VERSION_UI_UNOFFICIAL); |
| 96 #if defined(ARCH_CPU_64_BITS) | 70 #if defined(ARCH_CPU_64_BITS) |
| 97 html_source->AddLocalizedString(version_ui::kVersionBitSize, | 71 html_source->AddLocalizedString(version_ui::kVersionBitSize, |
| 98 IDS_VERSION_UI_64BIT); | 72 IDS_VERSION_UI_64BIT); |
| 99 #else | 73 #else |
| 100 html_source->AddLocalizedString(version_ui::kVersionBitSize, | 74 html_source->AddLocalizedString(version_ui::kVersionBitSize, |
| 101 IDS_VERSION_UI_32BIT); | 75 IDS_VERSION_UI_32BIT); |
| 102 #endif | 76 #endif |
| 103 html_source->AddLocalizedString(version_ui::kUserAgentName, | 77 html_source->AddLocalizedString(version_ui::kUserAgentName, |
| 104 IDS_VERSION_UI_USER_AGENT); | 78 IDS_VERSION_UI_USER_AGENT); |
| 105 html_source->AddString(version_ui::kUserAgent, GetUserAgent()); | 79 html_source->AddString(version_ui::kUserAgent, |
| 80 web::GetWebClient()->GetUserAgent(false)); | |
| 106 html_source->AddLocalizedString(version_ui::kCommandLineName, | 81 html_source->AddLocalizedString(version_ui::kCommandLineName, |
| 107 IDS_VERSION_UI_COMMAND_LINE); | 82 IDS_VERSION_UI_COMMAND_LINE); |
| 108 | 83 |
| 109 #if defined(OS_WIN) | |
| 110 html_source->AddString( | |
| 111 version_ui::kCommandLine, | |
| 112 base::CommandLine::ForCurrentProcess()->GetCommandLineString()); | |
| 113 #elif defined(OS_POSIX) | |
| 114 std::string command_line; | 84 std::string command_line; |
| 115 typedef std::vector<std::string> ArgvList; | 85 typedef std::vector<std::string> ArgvList; |
| 116 const ArgvList& argv = base::CommandLine::ForCurrentProcess()->argv(); | 86 const ArgvList& argv = base::CommandLine::ForCurrentProcess()->argv(); |
| 117 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++) | 87 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++) |
| 118 command_line += " " + *iter; | 88 command_line += " " + *iter; |
| 119 // TODO(viettrungluu): |command_line| could really have any encoding, whereas | 89 // TODO(viettrungluu): |command_line| could really have any encoding, whereas |
| 120 // below we assumes it's UTF-8. | 90 // below we assumes it's UTF-8. |
| 121 html_source->AddString(version_ui::kCommandLine, command_line); | 91 html_source->AddString(version_ui::kCommandLine, command_line); |
| 122 #endif | |
| 123 | |
| 124 // Note that the executable path and profile path are retrieved asynchronously | |
| 125 // and returned in VersionHandler::OnGotFilePaths. The area is initially | |
| 126 // blank. | |
| 127 html_source->AddLocalizedString(version_ui::kExecutablePathName, | |
| 128 IDS_VERSION_UI_EXECUTABLE_PATH); | |
| 129 html_source->AddString(version_ui::kExecutablePath, std::string()); | |
| 130 | |
| 131 html_source->AddLocalizedString(version_ui::kProfilePathName, | |
| 132 IDS_VERSION_UI_PROFILE_PATH); | |
| 133 html_source->AddString(version_ui::kProfilePath, std::string()); | |
| 134 | 92 |
| 135 html_source->AddLocalizedString(version_ui::kVariationsName, | 93 html_source->AddLocalizedString(version_ui::kVariationsName, |
| 136 IDS_VERSION_UI_VARIATIONS); | 94 IDS_VERSION_UI_VARIATIONS); |
| 137 | 95 |
| 138 #if defined(OS_WIN) | |
| 139 #if defined(__clang__) | |
| 140 html_source->AddString("compiler", "clang"); | |
| 141 #else | |
| 142 html_source->AddString("compiler", "MSVC"); | |
| 143 #endif | |
| 144 #endif | |
| 145 | |
| 146 html_source->SetJsonPath("strings.js"); | 96 html_source->SetJsonPath("strings.js"); |
| 147 html_source->AddResourcePath(version_ui::kVersionJS, IDR_VERSION_UI_JS); | 97 html_source->AddResourcePath(version_ui::kVersionJS, IDR_VERSION_UI_JS); |
| 148 html_source->AddResourcePath(version_ui::kAboutVersionCSS, | 98 html_source->AddResourcePath(version_ui::kAboutVersionCSS, |
| 149 IDR_VERSION_UI_CSS); | 99 IDR_VERSION_UI_CSS); |
| 150 html_source->SetDefaultResource(IDR_VERSION_UI_HTML); | 100 html_source->SetDefaultResource(IDR_VERSION_UI_HTML); |
| 151 return html_source; | 101 return html_source; |
| 152 } | 102 } |
| 153 | 103 |
| 154 } // namespace | 104 } // namespace |
| 155 | 105 |
| 156 VersionUI::VersionUI(content::WebUI* web_ui) | 106 VersionUI::VersionUI(web::WebUIIOS* web_ui) : web::WebUIIOSController(web_ui) { |
| 157 : content::WebUIController(web_ui) { | |
| 158 Profile* profile = Profile::FromWebUI(web_ui); | |
| 159 | |
| 160 #if defined(OS_CHROMEOS) | |
| 161 web_ui->AddMessageHandler(new VersionHandlerChromeOS()); | |
| 162 #else | |
| 163 web_ui->AddMessageHandler(new VersionHandler()); | 107 web_ui->AddMessageHandler(new VersionHandler()); |
| 164 #endif | 108 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui), |
| 165 | 109 CreateVersionUIDataSource()); |
| 166 #if defined(ENABLE_THEMES) | |
| 167 // Set up the chrome://theme/ source. | |
| 168 ThemeSource* theme = new ThemeSource(profile); | |
| 169 content::URLDataSource::Add(profile, theme); | |
| 170 #endif | |
| 171 | |
| 172 WebUIDataSource::Add(profile, CreateVersionUIDataSource()); | |
| 173 } | 110 } |
| 174 | 111 |
| 175 VersionUI::~VersionUI() { | 112 VersionUI::~VersionUI() {} |
| 176 } | |
| OLD | NEW |