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/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"
17 #include "content/public/browser/url_data_source.h"
18 #include "content/public/browser/web_ui.h"
19 #include "content/public/browser/web_ui_data_source.h"
20 #include "content/public/common/user_agent.h"
21 #include "grit/browser_resources.h"
22 #include "grit/components_strings.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "v8/include/v8.h"
26 #if defined(ENABLE_THEMES)
27 #include "chrome/browser/ui/webui/theme_source.h"
30 #if defined(OS_ANDROID)
31 #include "base/android/build_info.h"
32 #include "chrome/browser/ui/android/android_about_app_info.h"
35 #if defined(OS_CHROMEOS)
36 #include "chrome/browser/ui/webui/version_handler_chromeos.h"
39 using content::WebUIDataSource
;
43 WebUIDataSource
* CreateVersionUIDataSource() {
44 WebUIDataSource
* html_source
=
45 WebUIDataSource::Create(chrome::kChromeUIVersionHost
);
47 // Localized and data strings.
48 html_source
->AddLocalizedString("title", IDS_ABOUT_VERSION_TITLE
);
49 html_source
->AddLocalizedString("application_label", IDS_PRODUCT_NAME
);
50 html_source
->AddString("version", version_info::GetVersionNumber());
51 html_source
->AddString("version_modifier", chrome::GetChannelString());
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::GetOSType());
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
);
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(
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::GetLastChange());
81 html_source
->AddLocalizedString("official",
82 version_info::IsOfficialBuild()
83 ? IDS_ABOUT_VERSION_OFFICIAL
84 : IDS_ABOUT_VERSION_UNOFFICIAL
);
85 #if defined(ARCH_CPU_64_BITS)
86 html_source
->AddLocalizedString("version_bitsize", IDS_ABOUT_VERSION_64BIT
);
88 html_source
->AddLocalizedString("version_bitsize", IDS_ABOUT_VERSION_32BIT
);
90 html_source
->AddLocalizedString("user_agent_name",
91 IDS_ABOUT_VERSION_USER_AGENT
);
92 html_source
->AddString("useragent", GetUserAgent());
93 html_source
->AddLocalizedString("command_line_name",
94 IDS_ABOUT_VERSION_COMMAND_LINE
);
97 html_source
->AddString(
99 base::CommandLine::ForCurrentProcess()->GetCommandLineString());
100 #elif defined(OS_POSIX)
101 std::string command_line
;
102 typedef std::vector
<std::string
> ArgvList
;
103 const ArgvList
& argv
= base::CommandLine::ForCurrentProcess()->argv();
104 for (ArgvList::const_iterator iter
= argv
.begin(); iter
!= argv
.end(); iter
++)
105 command_line
+= " " + *iter
;
106 // TODO(viettrungluu): |command_line| could really have any encoding, whereas
107 // below we assumes it's UTF-8.
108 html_source
->AddString("command_line", command_line
);
111 // Note that the executable path and profile path are retrieved asynchronously
112 // and returned in VersionHandler::OnGotFilePaths. The area is initially
114 html_source
->AddLocalizedString("executable_path_name",
115 IDS_ABOUT_VERSION_EXECUTABLE_PATH
);
116 html_source
->AddString("executable_path", std::string());
118 html_source
->AddLocalizedString("profile_path_name",
119 IDS_ABOUT_VERSION_PROFILE_PATH
);
120 html_source
->AddString("profile_path", std::string());
122 html_source
->AddLocalizedString("variations_name",
123 IDS_ABOUT_VERSION_VARIATIONS
);
125 html_source
->SetJsonPath("strings.js");
126 html_source
->AddResourcePath("version.js", IDR_ABOUT_VERSION_JS
);
127 html_source
->AddResourcePath("about_version.css", IDR_ABOUT_VERSION_CSS
);
128 html_source
->SetDefaultResource(IDR_ABOUT_VERSION_HTML
);
134 VersionUI::VersionUI(content::WebUI
* web_ui
)
135 : content::WebUIController(web_ui
) {
136 Profile
* profile
= Profile::FromWebUI(web_ui
);
138 #if defined(OS_CHROMEOS)
139 web_ui
->AddMessageHandler(new VersionHandlerChromeOS());
141 web_ui
->AddMessageHandler(new VersionHandler());
144 #if defined(ENABLE_THEMES)
145 // Set up the chrome://theme/ source.
146 ThemeSource
* theme
= new ThemeSource(profile
);
147 content::URLDataSource::Add(profile
, theme
);
150 WebUIDataSource::Add(profile
, CreateVersionUIDataSource());
153 VersionUI::~VersionUI() {