Home | History | Annotate | Download | only in webui
      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 "chrome/grit/chromium_strings.h"
     16 #include "chrome/grit/generated_resources.h"
     17 #include "chrome/grit/google_chrome_strings.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 "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 
     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   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());
     58 
     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)
     71 
     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   html_source->AddLocalizedString("user_agent_name",
     85                                   IDS_ABOUT_VERSION_USER_AGENT);
     86   html_source->AddString("useragent", GetUserAgent());
     87   html_source->AddLocalizedString("command_line_name",
     88                                   IDS_ABOUT_VERSION_COMMAND_LINE);
     89 
     90 #if defined(OS_WIN)
     91   html_source->AddString("command_line", base::WideToUTF16(
     92       CommandLine::ForCurrentProcess()->GetCommandLineString()));
     93 #elif defined(OS_POSIX)
     94   std::string command_line;
     95   typedef std::vector<std::string> ArgvList;
     96   const ArgvList& argv = CommandLine::ForCurrentProcess()->argv();
     97   for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++)
     98     command_line += " " + *iter;
     99   // TODO(viettrungluu): |command_line| could really have any encoding, whereas
    100   // below we assumes it's UTF-8.
    101   html_source->AddString("command_line", command_line);
    102 #endif
    103 
    104   // Note that the executable path and profile path are retrieved asynchronously
    105   // and returned in VersionHandler::OnGotFilePaths. The area is initially
    106   // blank.
    107   html_source->AddLocalizedString("executable_path_name",
    108                                   IDS_ABOUT_VERSION_EXECUTABLE_PATH);
    109   html_source->AddString("executable_path", std::string());
    110 
    111   html_source->AddLocalizedString("profile_path_name",
    112                                   IDS_ABOUT_VERSION_PROFILE_PATH);
    113   html_source->AddString("profile_path", std::string());
    114 
    115   html_source->AddLocalizedString("variations_name",
    116                                   IDS_ABOUT_VERSION_VARIATIONS);
    117 
    118   html_source->SetUseJsonJSFormatV2();
    119   html_source->SetJsonPath("strings.js");
    120   html_source->AddResourcePath("version.js", IDR_ABOUT_VERSION_JS);
    121   html_source->AddResourcePath("about_version.css", IDR_ABOUT_VERSION_CSS);
    122   html_source->SetDefaultResource(IDR_ABOUT_VERSION_HTML);
    123   return html_source;
    124 }
    125 
    126 }  // namespace
    127 
    128 VersionUI::VersionUI(content::WebUI* web_ui)
    129     : content::WebUIController(web_ui) {
    130   Profile* profile = Profile::FromWebUI(web_ui);
    131 
    132 #if defined(OS_CHROMEOS)
    133   web_ui->AddMessageHandler(new VersionHandlerChromeOS());
    134 #else
    135   web_ui->AddMessageHandler(new VersionHandler());
    136 #endif
    137 
    138 #if defined(ENABLE_THEMES)
    139   // Set up the chrome://theme/ source.
    140   ThemeSource* theme = new ThemeSource(profile);
    141   content::URLDataSource::Add(profile, theme);
    142 #endif
    143 
    144   content::WebUIDataSource::Add(profile, CreateVersionUIDataSource(profile));
    145 }
    146 
    147 VersionUI::~VersionUI() {
    148 }
    149