Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 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/file_util.h" | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
| 12 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | |
| 13 #include "chrome/browser/ui/webui/version_handler.h" | |
| 14 #include "chrome/common/chrome_version_info.h" | |
| 15 #include "chrome/common/jstemplate_builder.h" | |
| 16 #include "chrome/common/url_constants.h" | |
| 17 #include "content/public/browser/web_ui.h" | |
| 18 #include "content/public/common/content_client.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 "v8/include/v8.h" | |
| 24 #include "webkit/user_agent/user_agent_util.h" | |
| 25 | |
| 26 #if defined(ENABLE_THEMES) | |
| 27 #include "chrome/browser/ui/webui/theme_source.h" | |
| 28 #endif | |
| 29 | |
| 30 #if defined(OS_CHROMEOS) | |
| 31 #include "chrome/browser/ui/webui/version_handler_chromeos.h" | |
| 32 #endif | |
| 33 | |
| 34 namespace { | |
| 35 | |
| 36 ChromeWebUIDataSource* CreateVersionUIDataSource(Profile* profile) { | |
| 37 ChromeWebUIDataSource* html_source = | |
| 38 new ChromeWebUIDataSource(chrome::kChromeUIVersionHost); | |
| 39 | |
| 40 // Localized and data strings. | |
| 41 html_source->AddLocalizedString("title", IDS_ABOUT_VERSION_TITLE); | |
| 42 html_source->AddLocalizedString("name", IDS_PRODUCT_NAME); | |
| 43 chrome::VersionInfo version_info; | |
| 44 html_source->AddString("version", version_info.Version()); | |
| 45 // http://crbug.com/79458: Need to evaluate the use of getting the version | |
| 46 // string on this thread. | |
| 47 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
|
Lei Zhang
2012/09/25 18:45:19
this scope can be a bit more narrow maybe?
SteveT
2012/09/25 21:09:06
Seems like GetVersionStringModifier is the only th
| |
| 48 html_source->AddString("version_modifier", | |
| 49 chrome::VersionInfo::GetVersionStringModifier()); | |
| 50 html_source->AddLocalizedString("os_name", IDS_ABOUT_VERSION_OS); | |
| 51 html_source->AddLocalizedString("platform", IDS_PLATFORM_LABEL); | |
| 52 html_source->AddString("os_type", version_info.OSType()); | |
| 53 html_source->AddString("os_version", std::string()); | |
| 54 html_source->AddString("webkit_version", webkit_glue::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->AddString("flash_plugin", "Flash"); | |
| 60 // Note that the Flash version is retrieve asynchronously and returned in | |
| 61 // VersionHandler::OnGotPlugins. The area is initially blank. | |
| 62 html_source->AddString("flash_version", std::string()); | |
| 63 #endif | |
| 64 html_source->AddLocalizedString("company", IDS_ABOUT_VERSION_COMPANY_NAME); | |
| 65 html_source->AddLocalizedString("copyright", IDS_ABOUT_VERSION_COPYRIGHT); | |
| 66 html_source->AddString("cl", version_info.LastChange()); | |
| 67 html_source->AddLocalizedString("official", | |
| 68 version_info.IsOfficialBuild() ? IDS_ABOUT_VERSION_OFFICIAL : | |
| 69 IDS_ABOUT_VERSION_UNOFFICIAL); | |
| 70 html_source->AddLocalizedString("user_agent_name", | |
| 71 IDS_ABOUT_VERSION_USER_AGENT); | |
| 72 html_source->AddString("useragent", content::GetUserAgent(GURL())); | |
| 73 html_source->AddLocalizedString("command_line_name", | |
| 74 IDS_ABOUT_VERSION_COMMAND_LINE); | |
| 75 | |
| 76 #if defined(OS_WIN) | |
| 77 html_source->AddString("command_line", | |
| 78 WideToUTF16(CommandLine::ForCurrentProcess()->GetCommandLineString())); | |
| 79 #elif defined(OS_POSIX) | |
| 80 std::string command_line = ""; | |
|
Lei Zhang
2012/09/25 18:45:19
curious, why can't we use GetCommandLineString() o
SteveT
2012/09/25 21:09:06
I'm actually not sure - I haven't touched this cod
| |
| 81 typedef std::vector<std::string> ArgvList; | |
| 82 const ArgvList& argv = CommandLine::ForCurrentProcess()->argv(); | |
| 83 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++) | |
| 84 command_line += " " + *iter; | |
| 85 // TODO(viettrungluu): |command_line| could really have any encoding, whereas | |
| 86 // below we assumes it's UTF-8. | |
| 87 html_source->AddString("command_line", command_line); | |
| 88 #endif | |
| 89 | |
| 90 // Note that the executable path and profile path are retrieved asynchronously | |
| 91 // and returned in VersionHandler::OnGotFilePaths. The area is initially | |
| 92 // blank. | |
| 93 html_source->AddLocalizedString("executable_path_name", | |
| 94 IDS_ABOUT_VERSION_EXECUTABLE_PATH); | |
| 95 html_source->AddString("executable_path", std::string()); | |
| 96 | |
| 97 html_source->AddLocalizedString("profile_path_name", | |
| 98 IDS_ABOUT_VERSION_PROFILE_PATH); | |
| 99 html_source->AddString("profile_path", std::string()); | |
| 100 | |
| 101 html_source->AddLocalizedString("variations_name", | |
| 102 IDS_ABOUT_VERSION_VARIATIONS); | |
| 103 | |
| 104 html_source->set_use_json_js_format_v2(); | |
| 105 html_source->set_json_path("strings.js"); | |
| 106 html_source->add_resource_path("version.js", IDR_ABOUT_VERSION_JS); | |
| 107 html_source->set_default_resource(IDR_ABOUT_VERSION_HTML); | |
| 108 return html_source; | |
| 109 } | |
| 110 | |
| 111 } // namespace | |
| 112 | |
| 113 VersionUI::VersionUI(content::WebUI* web_ui) | |
| 114 : content::WebUIController(web_ui) { | |
| 115 Profile* profile = Profile::FromWebUI(web_ui); | |
| 116 | |
| 117 #if defined(OS_CHROMEOS) | |
| 118 web_ui->AddMessageHandler(new VersionHandlerChromeOS()); | |
| 119 #else | |
| 120 web_ui->AddMessageHandler(new VersionHandler()); | |
| 121 #endif | |
| 122 | |
| 123 #if defined(ENABLE_THEMES) | |
| 124 // Set up the chrome://theme/ source. | |
| 125 ThemeSource* theme = new ThemeSource(profile); | |
| 126 ChromeURLDataManager::AddDataSource(profile, theme); | |
| 127 #endif | |
| 128 | |
| 129 ChromeURLDataManager::AddDataSource(profile, | |
| 130 CreateVersionUIDataSource(profile)); | |
| 131 } | |
| 132 | |
| 133 VersionUI::~VersionUI() { | |
| 134 } | |
| OLD | NEW |