| 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/metrics/field_trial.h" |
| 10 #include "base/string_split.h" |
| 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 14 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 15 #include "chrome/browser/plugin_prefs.h" |
| 16 #include "chrome/common/chrome_version_info.h" |
| 17 #include "chrome/common/url_constants.h" |
| 18 #include "content/public/browser/plugin_service.h" |
| 19 #include "content/public/browser/web_ui.h" |
| 20 #include "content/public/browser/web_ui_message_handler.h" |
| 21 #include "content/public/common/content_client.h" |
| 22 #include "grit/browser_resources.h" |
| 23 #include "grit/chromium_strings.h" |
| 24 #include "grit/generated_resources.h" |
| 25 #include "grit/google_chrome_strings.h" |
| 26 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "v8/include/v8.h" |
| 28 #include "webkit/glue/user_agent.h" |
| 29 #include "webkit/plugins/webplugininfo.h" |
| 30 |
| 31 namespace { |
| 32 |
| 33 // Handler class for Version page operations. |
| 34 class VersionDOMHandler : public content::WebUIMessageHandler { |
| 35 public: |
| 36 VersionDOMHandler(); |
| 37 virtual ~VersionDOMHandler(); |
| 38 |
| 39 // content::WebUIMessageHandler implementation. |
| 40 virtual void RegisterMessages() OVERRIDE; |
| 41 |
| 42 // Callback for the "requestVariationsList" message. This requests the list of |
| 43 // variations from the client and sends it to the frontend. |
| 44 void HandleRequestVariationsList(const ListValue* args); |
| 45 |
| 46 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(VersionDOMHandler); |
| 48 }; |
| 49 |
| 50 VersionDOMHandler::VersionDOMHandler() { |
| 51 } |
| 52 |
| 53 VersionDOMHandler::~VersionDOMHandler() { |
| 54 } |
| 55 |
| 56 void VersionDOMHandler::RegisterMessages() { |
| 57 web_ui()->RegisterMessageCallback( |
| 58 "requestVariationsList", |
| 59 base::Bind(&VersionDOMHandler::HandleRequestVariationsList, |
| 60 base::Unretained(this))); |
| 61 } |
| 62 |
| 63 void VersionDOMHandler::HandleRequestVariationsList(const ListValue* args) { |
| 64 scoped_ptr<ListValue> variations_list(new ListValue()); |
| 65 #if !defined(NDEBUG) |
| 66 std::vector<std::string> variations; |
| 67 std::string variation_state; |
| 68 base::FieldTrialList::StatesToString(&variation_state); |
| 69 |
| 70 std::vector<std::string> tokens; |
| 71 base::SplitString(variation_state, |
| 72 base::FieldTrialList::kPersistentStringSeparator, |
| 73 &tokens); |
| 74 // Since StatesToString appends a separator at the end, SplitString will |
| 75 // append an extra empty string in the vector. Drop it. There should |
| 76 // always be an even number of tokens left. |
| 77 tokens.pop_back(); |
| 78 DCHECK_EQ(0U, tokens.size() % 2); |
| 79 for (size_t i = 0; i < tokens.size(); i += 2) |
| 80 variations.push_back(tokens[i] + ":" + tokens[i + 1]); |
| 81 |
| 82 for (std::vector<std::string>::const_iterator it = variations.begin(); |
| 83 it != variations.end(); ++it) { |
| 84 variations_list->Append(Value::CreateStringValue(*it)); |
| 85 } |
| 86 #endif |
| 87 // In release mode, this will return an empty list to clear the section. |
| 88 web_ui()->CallJavascriptFunction("returnVariationsList", |
| 89 *variations_list.release()); |
| 90 } |
| 91 |
| 92 ChromeWebUIDataSource* CreateVersionUIDataSource(Profile* profile) { |
| 93 // Set up the chrome://version source. |
| 94 ChromeWebUIDataSource* html_source = |
| 95 new ChromeWebUIDataSource(chrome::kChromeUIVersionHost); |
| 96 html_source->set_use_json_js_format_v2(); |
| 97 |
| 98 // Localized and data strings. |
| 99 html_source->AddLocalizedString("title", IDS_ABOUT_VERSION_TITLE); |
| 100 chrome::VersionInfo version_info; |
| 101 html_source->AddLocalizedString("name", IDS_PRODUCT_NAME); |
| 102 html_source->AddString("version", ASCIIToUTF16(version_info.Version())); |
| 103 // Bug 79458: Need to evaluate the use of getting the version string on |
| 104 // this thread. |
| 105 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 106 html_source->AddString("version_modifier", |
| 107 ASCIIToUTF16(chrome::VersionInfo::GetVersionStringModifier())); |
| 108 html_source->AddLocalizedString("os_name", IDS_ABOUT_VERSION_OS); |
| 109 html_source->AddLocalizedString("platform", IDS_PLATFORM_LABEL); |
| 110 html_source->AddString("os_type", ASCIIToUTF16(version_info.OSType())); |
| 111 html_source->AddString("os_version", string16()); |
| 112 html_source->AddString("webkit_version", |
| 113 ASCIIToUTF16(webkit_glue::GetWebKitVersion())); |
| 114 html_source->AddString("js_engine", ASCIIToUTF16("V8")); |
| 115 html_source->AddString("js_version", ASCIIToUTF16(v8::V8::GetVersion())); |
| 116 |
| 117 // Add required resources. |
| 118 html_source->set_json_path("strings.js"); |
| 119 html_source->add_resource_path("version.js", IDR_ABOUT_VERSION_JS); |
| 120 html_source->set_default_resource(IDR_ABOUT_VERSION_HTML); |
| 121 |
| 122 #if !defined(OS_ANDROID) |
| 123 // Obtain the version of the first enabled Flash plugin. |
| 124 std::vector<webkit::WebPluginInfo> info_array; |
| 125 content::PluginService::GetInstance()->GetPluginInfoArray( |
| 126 GURL(), "application/x-shockwave-flash", false, &info_array, NULL); |
| 127 string16 flash_version = |
| 128 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); |
| 129 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
| 130 if (plugin_prefs) { |
| 131 for (size_t i = 0; i < info_array.size(); ++i) { |
| 132 if (plugin_prefs->IsPluginEnabled(info_array[i])) { |
| 133 flash_version = info_array[i].version; |
| 134 break; |
| 135 } |
| 136 } |
| 137 } |
| 138 html_source->AddString("flash_plugin", ASCIIToUTF16("Flash")); |
| 139 html_source->AddString("flash_version", flash_version); |
| 140 #endif |
| 141 html_source->AddLocalizedString("company", IDS_ABOUT_VERSION_COMPANY_NAME); |
| 142 html_source->AddLocalizedString("copyright", IDS_ABOUT_VERSION_COPYRIGHT); |
| 143 html_source->AddString("cl", ASCIIToUTF16(version_info.LastChange())); |
| 144 html_source->AddLocalizedString("official", |
| 145 version_info.IsOfficialBuild() ? |
| 146 IDS_ABOUT_VERSION_OFFICIAL |
| 147 : IDS_ABOUT_VERSION_UNOFFICIAL); |
| 148 html_source->AddLocalizedString("user_agent_name", |
| 149 IDS_ABOUT_VERSION_USER_AGENT); |
| 150 html_source->AddString("useragent", |
| 151 ASCIIToUTF16(content::GetUserAgent(GURL()))); |
| 152 html_source->AddLocalizedString("command_line_name", |
| 153 IDS_ABOUT_VERSION_COMMAND_LINE); |
| 154 |
| 155 #if defined(OS_WIN) |
| 156 html_source->AddString("command_line", |
| 157 WideToUTF16(CommandLine::ForCurrentProcess()->GetCommandLineString())); |
| 158 #elif defined(OS_POSIX) |
| 159 std::string command_line = ""; |
| 160 typedef std::vector<std::string> ArgvList; |
| 161 const ArgvList& argv = CommandLine::ForCurrentProcess()->argv(); |
| 162 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++) |
| 163 command_line += " " + *iter; |
| 164 // TODO(viettrungluu): |command_line| could really have any encoding, whereas |
| 165 // below we assumes it's UTF-8. |
| 166 html_source->AddString("command_line", ASCIIToUTF16(command_line)); |
| 167 #endif |
| 168 |
| 169 // Allow IO temporarily based on allow_io (defined above) |
| 170 // since the following operation will complete quickly |
| 171 html_source->AddLocalizedString("executable_path_name", |
| 172 IDS_ABOUT_VERSION_EXECUTABLE_PATH); |
| 173 FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram(); |
| 174 if (file_util::AbsolutePath(&executable_path)) { |
| 175 html_source->AddString("executable_path", |
| 176 ASCIIToUTF16(executable_path.value())); |
| 177 } else { |
| 178 html_source->AddLocalizedString("executable_path", |
| 179 IDS_ABOUT_VERSION_PATH_NOTFOUND); |
| 180 } |
| 181 html_source->AddLocalizedString("profile_path_name", |
| 182 IDS_ABOUT_VERSION_PROFILE_PATH); |
| 183 if (profile) { |
| 184 FilePath profile_path = profile->GetPath(); |
| 185 if (file_util::AbsolutePath(&profile_path)) { |
| 186 html_source->AddString("profile_path", |
| 187 ASCIIToUTF16(profile_path.value())); |
| 188 } else { |
| 189 html_source->AddLocalizedString("profile_path", |
| 190 IDS_ABOUT_VERSION_PATH_NOTFOUND); |
| 191 } |
| 192 } else { |
| 193 html_source->AddLocalizedString("profile_path", |
| 194 IDS_ABOUT_VERSION_PATH_NOTFOUND); |
| 195 } |
| 196 // TODO(reviewer): Do I need some equivalent to this? |
| 197 // ChromeWebUIDataSource::SetFontAndTextDirection(localized_strings); |
| 198 |
| 199 #if !defined(NDEBUG) |
| 200 html_source->AddLocalizedString("variations_name", |
| 201 IDS_ABOUT_VERSION_VARIATIONS); |
| 202 #endif |
| 203 |
| 204 return html_source; |
| 205 } |
| 206 |
| 207 } // namespace |
| 208 |
| 209 VersionUI::VersionUI(content::WebUI* web_ui) |
| 210 : content::WebUIController(web_ui) { |
| 211 Profile* profile = Profile::FromWebUI(web_ui); |
| 212 |
| 213 web_ui->AddMessageHandler(new VersionDOMHandler()); |
| 214 |
| 215 ChromeURLDataManager::AddDataSource(profile, |
| 216 CreateVersionUIDataSource(profile)); |
| 217 } |
| 218 |
| 219 VersionUI::~VersionUI() { |
| 220 } |
| OLD | NEW |