• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/ui/webui/version_ui.h"
6 
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/version_handler.h"
12 #include "chrome/common/chrome_content_client.h"
13 #include "chrome/common/chrome_version_info.h"
14 #include "chrome/common/url_constants.h"
15 #include "content/public/browser/url_data_source.h"
16 #include "content/public/browser/web_ui.h"
17 #include "content/public/browser/web_ui_data_source.h"
18 #include "content/public/common/user_agent.h"
19 #include "grit/browser_resources.h"
20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h"
22 #include "grit/google_chrome_strings.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "v8/include/v8.h"
25 
26 #if defined(ENABLE_THEMES)
27 #include "chrome/browser/ui/webui/theme_source.h"
28 #endif
29 
30 #if defined(OS_ANDROID)
31 #include "base/android/build_info.h"
32 #include "chrome/browser/ui/android/android_about_app_info.h"
33 #endif
34 
35 #if defined(OS_CHROMEOS)
36 #include "chrome/browser/ui/webui/version_handler_chromeos.h"
37 #endif
38 
39 namespace {
40 
CreateVersionUIDataSource(Profile * profile)41 content::WebUIDataSource* CreateVersionUIDataSource(Profile* profile) {
42   content::WebUIDataSource* html_source =
43       content::WebUIDataSource::Create(chrome::kChromeUIVersionHost);
44 
45   // Localized and data strings.
46   html_source->AddLocalizedString("title", IDS_ABOUT_VERSION_TITLE);
47   chrome::VersionInfo version_info;
48   html_source->AddString("version", version_info.Version());
49   html_source->AddString("version_modifier",
50                          chrome::VersionInfo::GetVersionStringModifier());
51   html_source->AddLocalizedString("os_name", IDS_ABOUT_VERSION_OS);
52   html_source->AddLocalizedString("platform", IDS_PLATFORM_LABEL);
53   html_source->AddString("os_type", version_info.OSType());
54   html_source->AddString("blink_version", content::GetWebKitVersion());
55   html_source->AddString("js_engine", "V8");
56   html_source->AddString("js_version", v8::V8::GetVersion());
57 
58 #if defined(OS_ANDROID)
59   html_source->AddLocalizedString("application_label",
60                                   IDS_ABOUT_VERSION_APPLICATION);
61   html_source->AddString("os_version", AndroidAboutAppInfo::GetOsInfo());
62   base::android::BuildInfo* android_build_info =
63       base::android::BuildInfo::GetInstance();
64   html_source->AddString("application_name",
65                          android_build_info->package_label());
66   html_source->AddString("application_version_name",
67                          android_build_info->package_version_name());
68   html_source->AddString("application_version_code",
69                          android_build_info->package_version_code());
70   html_source->AddLocalizedString("build_id_name",
71                                   IDS_ABOUT_VERSION_BUILD_ID);
72   html_source->AddString("build_id", CHROME_BUILD_ID);
73 #else
74   html_source->AddLocalizedString("application_label", IDS_PRODUCT_NAME);
75   html_source->AddString("os_version", std::string());
76   html_source->AddString("flash_plugin", "Flash");
77   // Note that the Flash version is retrieve asynchronously and returned in
78   // VersionHandler::OnGotPlugins. The area is initially blank.
79   html_source->AddString("flash_version", std::string());
80 #endif  // defined(OS_ANDROID)
81 
82   html_source->AddLocalizedString("company", IDS_ABOUT_VERSION_COMPANY_NAME);
83   base::Time::Exploded exploded_time;
84   base::Time::Now().LocalExplode(&exploded_time);
85   html_source->AddString(
86       "copyright",
87       l10n_util::GetStringFUTF16(IDS_ABOUT_VERSION_COPYRIGHT,
88                                  base::IntToString16(exploded_time.year)));
89   html_source->AddString("cl", version_info.LastChange());
90   html_source->AddLocalizedString("official",
91       version_info.IsOfficialBuild() ? IDS_ABOUT_VERSION_OFFICIAL :
92                                        IDS_ABOUT_VERSION_UNOFFICIAL);
93   html_source->AddLocalizedString("user_agent_name",
94                                   IDS_ABOUT_VERSION_USER_AGENT);
95   html_source->AddString("useragent", GetUserAgent());
96   html_source->AddLocalizedString("command_line_name",
97                                   IDS_ABOUT_VERSION_COMMAND_LINE);
98 
99 #if defined(OS_WIN)
100   html_source->AddString("command_line", base::WideToUTF16(
101       CommandLine::ForCurrentProcess()->GetCommandLineString()));
102 #elif defined(OS_POSIX)
103   std::string command_line;
104   typedef std::vector<std::string> ArgvList;
105   const ArgvList& argv = CommandLine::ForCurrentProcess()->argv();
106   for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++)
107     command_line += " " + *iter;
108   // TODO(viettrungluu): |command_line| could really have any encoding, whereas
109   // below we assumes it's UTF-8.
110   html_source->AddString("command_line", command_line);
111 #endif
112 
113   // Note that the executable path and profile path are retrieved asynchronously
114   // and returned in VersionHandler::OnGotFilePaths. The area is initially
115   // blank.
116   html_source->AddLocalizedString("executable_path_name",
117                                   IDS_ABOUT_VERSION_EXECUTABLE_PATH);
118   html_source->AddString("executable_path", std::string());
119 
120   html_source->AddLocalizedString("profile_path_name",
121                                   IDS_ABOUT_VERSION_PROFILE_PATH);
122   html_source->AddString("profile_path", std::string());
123 
124   html_source->AddLocalizedString("variations_name",
125                                   IDS_ABOUT_VERSION_VARIATIONS);
126 
127   html_source->SetUseJsonJSFormatV2();
128   html_source->SetJsonPath("strings.js");
129   html_source->AddResourcePath("version.js", IDR_ABOUT_VERSION_JS);
130   html_source->AddResourcePath("about_version.css", IDR_ABOUT_VERSION_CSS);
131   html_source->SetDefaultResource(IDR_ABOUT_VERSION_HTML);
132   return html_source;
133 }
134 
135 }  // namespace
136 
VersionUI(content::WebUI * web_ui)137 VersionUI::VersionUI(content::WebUI* web_ui)
138     : content::WebUIController(web_ui) {
139   Profile* profile = Profile::FromWebUI(web_ui);
140 
141 #if defined(OS_CHROMEOS)
142   web_ui->AddMessageHandler(new VersionHandlerChromeOS());
143 #else
144   web_ui->AddMessageHandler(new VersionHandler());
145 #endif
146 
147 #if defined(ENABLE_THEMES)
148   // Set up the chrome://theme/ source.
149   ThemeSource* theme = new ThemeSource(profile);
150   content::URLDataSource::Add(profile, theme);
151 #endif
152 
153   content::WebUIDataSource::Add(profile, CreateVersionUIDataSource(profile));
154 }
155 
~VersionUI()156 VersionUI::~VersionUI() {
157 }
158