[Extensions] Cleanup Extension Uninstall Dialog logic
[chromium-blink-merge.git] / chrome / browser / ui / webui / version_ui.cc
blobfef55fca2ec152f7cdda12e6b09423486fdd73a8
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/version_ui.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/webui/version_handler.h"
11 #include "chrome/common/chrome_content_client.h"
12 #include "chrome/common/chrome_version_info.h"
13 #include "chrome/common/url_constants.h"
14 #include "chrome/grit/chromium_strings.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "content/public/browser/url_data_source.h"
17 #include "content/public/browser/web_ui.h"
18 #include "content/public/browser/web_ui_data_source.h"
19 #include "content/public/common/user_agent.h"
20 #include "grit/browser_resources.h"
21 #include "ui/base/l10n/l10n_util.h"
22 #include "v8/include/v8.h"
24 #if defined(ENABLE_THEMES)
25 #include "chrome/browser/ui/webui/theme_source.h"
26 #endif
28 #if defined(OS_ANDROID)
29 #include "base/android/build_info.h"
30 #include "chrome/browser/ui/android/android_about_app_info.h"
31 #endif
33 #if defined(OS_CHROMEOS)
34 #include "chrome/browser/ui/webui/version_handler_chromeos.h"
35 #endif
37 using content::WebUIDataSource;
39 namespace {
41 WebUIDataSource* CreateVersionUIDataSource() {
42 WebUIDataSource* html_source =
43 WebUIDataSource::Create(chrome::kChromeUIVersionHost);
45 // Localized and data strings.
46 html_source->AddLocalizedString("title", IDS_ABOUT_VERSION_TITLE);
47 html_source->AddLocalizedString("application_label", IDS_PRODUCT_NAME);
48 chrome::VersionInfo version_info;
49 html_source->AddString("version", version_info.Version());
50 html_source->AddString("version_modifier",
51 chrome::VersionInfo::GetVersionStringModifier());
52 html_source->AddLocalizedString("os_name", IDS_ABOUT_VERSION_OS);
53 html_source->AddLocalizedString("platform", IDS_PLATFORM_LABEL);
54 html_source->AddString("os_type", version_info.OSType());
55 html_source->AddString("blink_version", content::GetWebKitVersion());
56 html_source->AddString("js_engine", "V8");
57 html_source->AddString("js_version", v8::V8::GetVersion());
59 #if defined(OS_ANDROID)
60 html_source->AddString("os_version", AndroidAboutAppInfo::GetOsInfo());
61 html_source->AddLocalizedString("build_id_name",
62 IDS_ABOUT_VERSION_BUILD_ID);
63 html_source->AddString("build_id", CHROME_BUILD_ID);
64 #else
65 html_source->AddString("os_version", std::string());
66 html_source->AddString("flash_plugin", "Flash");
67 // Note that the Flash version is retrieve asynchronously and returned in
68 // VersionHandler::OnGotPlugins. The area is initially blank.
69 html_source->AddString("flash_version", std::string());
70 #endif // defined(OS_ANDROID)
72 html_source->AddLocalizedString("company", IDS_ABOUT_VERSION_COMPANY_NAME);
73 base::Time::Exploded exploded_time;
74 base::Time::Now().LocalExplode(&exploded_time);
75 html_source->AddString(
76 "copyright",
77 l10n_util::GetStringFUTF16(IDS_ABOUT_VERSION_COPYRIGHT,
78 base::IntToString16(exploded_time.year)));
79 html_source->AddLocalizedString("revision", IDS_ABOUT_VERSION_REVISION);
80 html_source->AddString("cl", version_info.LastChange());
81 html_source->AddLocalizedString("official",
82 version_info.IsOfficialBuild() ? IDS_ABOUT_VERSION_OFFICIAL :
83 IDS_ABOUT_VERSION_UNOFFICIAL);
84 #if defined(ARCH_CPU_64_BITS)
85 html_source->AddLocalizedString("version_bitsize", IDS_ABOUT_VERSION_64BIT);
86 #else
87 html_source->AddLocalizedString("version_bitsize", IDS_ABOUT_VERSION_32BIT);
88 #endif
89 html_source->AddLocalizedString("user_agent_name",
90 IDS_ABOUT_VERSION_USER_AGENT);
91 html_source->AddString("useragent", GetUserAgent());
92 html_source->AddLocalizedString("command_line_name",
93 IDS_ABOUT_VERSION_COMMAND_LINE);
95 #if defined(OS_WIN)
96 html_source->AddString(
97 "command_line",
98 base::CommandLine::ForCurrentProcess()->GetCommandLineString());
99 #elif defined(OS_POSIX)
100 std::string command_line;
101 typedef std::vector<std::string> ArgvList;
102 const ArgvList& argv = base::CommandLine::ForCurrentProcess()->argv();
103 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++)
104 command_line += " " + *iter;
105 // TODO(viettrungluu): |command_line| could really have any encoding, whereas
106 // below we assumes it's UTF-8.
107 html_source->AddString("command_line", command_line);
108 #endif
110 // Note that the executable path and profile path are retrieved asynchronously
111 // and returned in VersionHandler::OnGotFilePaths. The area is initially
112 // blank.
113 html_source->AddLocalizedString("executable_path_name",
114 IDS_ABOUT_VERSION_EXECUTABLE_PATH);
115 html_source->AddString("executable_path", std::string());
117 html_source->AddLocalizedString("profile_path_name",
118 IDS_ABOUT_VERSION_PROFILE_PATH);
119 html_source->AddString("profile_path", std::string());
121 html_source->AddLocalizedString("variations_name",
122 IDS_ABOUT_VERSION_VARIATIONS);
124 html_source->SetJsonPath("strings.js");
125 html_source->AddResourcePath("version.js", IDR_ABOUT_VERSION_JS);
126 html_source->AddResourcePath("about_version.css", IDR_ABOUT_VERSION_CSS);
127 html_source->SetDefaultResource(IDR_ABOUT_VERSION_HTML);
128 return html_source;
131 } // namespace
133 VersionUI::VersionUI(content::WebUI* web_ui)
134 : content::WebUIController(web_ui) {
135 Profile* profile = Profile::FromWebUI(web_ui);
137 #if defined(OS_CHROMEOS)
138 web_ui->AddMessageHandler(new VersionHandlerChromeOS());
139 #else
140 web_ui->AddMessageHandler(new VersionHandler());
141 #endif
143 #if defined(ENABLE_THEMES)
144 // Set up the chrome://theme/ source.
145 ThemeSource* theme = new ThemeSource(profile);
146 content::URLDataSource::Add(profile, theme);
147 #endif
149 WebUIDataSource::Add(profile, CreateVersionUIDataSource());
152 VersionUI::~VersionUI() {