Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/about_ui.h" | 5 #include "chrome/browser/ui/webui/about_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/i18n/number_formatting.h" | 17 #include "base/i18n/number_formatting.h" |
| 18 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
| 19 #include "base/memory/ref_counted_memory.h" | 19 #include "base/memory/ref_counted_memory.h" |
| 20 #include "base/memory/singleton.h" | 20 #include "base/memory/singleton.h" |
| 21 #include "base/metrics/field_trial.h" | |
| 22 #include "base/metrics/statistics_recorder.h" | 21 #include "base/metrics/statistics_recorder.h" |
| 23 #include "base/metrics/stats_table.h" | 22 #include "base/metrics/stats_table.h" |
| 24 #include "base/path_service.h" | 23 #include "base/path_service.h" |
| 25 #include "base/string_number_conversions.h" | 24 #include "base/string_number_conversions.h" |
| 26 #include "base/string_piece.h" | 25 #include "base/string_piece.h" |
| 27 #include "base/string_split.h" | |
| 28 #include "base/string_util.h" | 26 #include "base/string_util.h" |
| 29 #include "base/stringprintf.h" | 27 #include "base/stringprintf.h" |
| 30 #include "base/threading/thread.h" | 28 #include "base/threading/thread.h" |
| 31 #include "base/utf_string_conversions.h" | 29 #include "base/utf_string_conversions.h" |
| 32 #include "base/values.h" | 30 #include "base/values.h" |
| 33 #include "chrome/browser/about_flags.h" | 31 #include "chrome/browser/about_flags.h" |
| 34 #include "chrome/browser/browser_about_handler.h" | 32 #include "chrome/browser/browser_about_handler.h" |
| 35 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
| 36 #include "chrome/browser/defaults.h" | 34 #include "chrome/browser/defaults.h" |
| 37 #include "chrome/browser/memory_details.h" | 35 #include "chrome/browser/memory_details.h" |
| 38 #include "chrome/browser/net/predictor.h" | 36 #include "chrome/browser/net/predictor.h" |
| 39 #include "chrome/browser/net/url_fixer_upper.h" | 37 #include "chrome/browser/net/url_fixer_upper.h" |
| 40 #include "chrome/browser/plugin_prefs.h" | 38 #include "chrome/browser/plugin_prefs.h" |
| 41 #include "chrome/browser/profiles/profile.h" | 39 #include "chrome/browser/profiles/profile.h" |
| 42 #include "chrome/browser/profiles/profile_manager.h" | 40 #include "chrome/browser/profiles/profile_manager.h" |
| 43 #include "chrome/browser/ui/browser_dialogs.h" | 41 #include "chrome/browser/ui/browser_dialogs.h" |
| 44 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 42 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 45 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 43 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 46 #include "chrome/common/chrome_paths.h" | 44 #include "chrome/common/chrome_paths.h" |
| 47 #include "chrome/common/chrome_version_info.h" | 45 #include "chrome/common/chrome_version_info.h" |
| 48 #include "chrome/common/jstemplate_builder.h" | 46 #include "chrome/common/jstemplate_builder.h" |
| 49 #include "chrome/common/net/gaia/google_service_auth_error.h" | 47 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 50 #include "chrome/common/render_messages.h" | 48 #include "chrome/common/render_messages.h" |
| 51 #include "chrome/common/url_constants.h" | 49 #include "chrome/common/url_constants.h" |
| 52 #include "content/public/browser/browser_thread.h" | 50 #include "content/public/browser/browser_thread.h" |
| 53 #include "content/public/browser/plugin_service.h" | 51 #include "content/public/browser/plugin_service.h" |
| 54 #include "content/public/browser/render_process_host.h" | 52 #include "content/public/browser/render_process_host.h" |
| 55 #include "content/public/browser/render_view_host.h" | 53 #include "content/public/browser/render_view_host.h" |
| 56 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
| 57 #include "content/public/browser/web_ui.h" | |
| 58 #include "content/public/browser/web_ui_message_handler.h" | |
| 59 #include "content/public/common/content_client.h" | 55 #include "content/public/common/content_client.h" |
| 60 #include "content/public/common/process_type.h" | 56 #include "content/public/common/process_type.h" |
| 61 #include "googleurl/src/gurl.h" | 57 #include "googleurl/src/gurl.h" |
| 62 #include "grit/browser_resources.h" | 58 #include "grit/browser_resources.h" |
| 63 #include "grit/chromium_strings.h" | 59 #include "grit/chromium_strings.h" |
| 64 #include "grit/generated_resources.h" | 60 #include "grit/generated_resources.h" |
| 65 #include "grit/locale_settings.h" | 61 #include "grit/locale_settings.h" |
| 66 #include "net/base/escape.h" | 62 #include "net/base/escape.h" |
| 67 #include "net/base/net_util.h" | 63 #include "net/base/net_util.h" |
| 68 #include "ui/base/l10n/l10n_util.h" | 64 #include "ui/base/l10n/l10n_util.h" |
| 69 #include "ui/base/layout.h" | 65 #include "ui/base/layout.h" |
| 70 #include "ui/base/resource/resource_bundle.h" | 66 #include "ui/base/resource/resource_bundle.h" |
| 71 #include "v8/include/v8.h" | 67 #include "v8/include/v8.h" |
| 72 #include "webkit/glue/user_agent.h" | 68 #include "webkit/glue/user_agent.h" |
| 73 #include "webkit/glue/webkit_glue.h" | |
| 74 #include "webkit/plugins/webplugininfo.h" | 69 #include "webkit/plugins/webplugininfo.h" |
| 75 | 70 |
| 76 #if defined(ENABLE_THEMES) | 71 #if defined(ENABLE_THEMES) |
| 77 #include "chrome/browser/ui/webui/theme_source.h" | 72 #include "chrome/browser/ui/webui/theme_source.h" |
| 78 #endif | 73 #endif |
| 79 | 74 |
| 80 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 75 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
| 81 #include "content/public/browser/zygote_host_linux.h" | 76 #include "content/public/browser/zygote_host_linux.h" |
| 82 #include "content/public/common/sandbox_linux.h" | 77 #include "content/public/common/sandbox_linux.h" |
| 83 #endif | 78 #endif |
| (...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1123 return data; | 1118 return data; |
| 1124 } | 1119 } |
| 1125 | 1120 |
| 1126 // Used as a callback for PluginService::GetPlugins(). | 1121 // Used as a callback for PluginService::GetPlugins(). |
| 1127 void HandleAboutVersionStrings(AboutUIHTMLSource* source, | 1122 void HandleAboutVersionStrings(AboutUIHTMLSource* source, |
| 1128 int request_id, | 1123 int request_id, |
| 1129 const std::vector<webkit::WebPluginInfo>&) { | 1124 const std::vector<webkit::WebPluginInfo>&) { |
| 1130 #if defined(OS_CHROMEOS) | 1125 #if defined(OS_CHROMEOS) |
| 1131 new ChromeOSAboutVersionHandler(source, request_id); | 1126 new ChromeOSAboutVersionHandler(source, request_id); |
| 1132 #else | 1127 #else |
| 1133 DictionaryValue localized_strings; | 1128 // All other platforms are handled by VersionUI. |
| 1134 localized_strings.SetString("os_version", ""); | |
| 1135 source->FinishDataRequest( | |
| 1136 AboutVersionStrings(&localized_strings, source->profile()), | |
| 1137 request_id); | |
| 1138 #endif | 1129 #endif |
| 1139 } | 1130 } |
| 1140 | 1131 |
| 1141 // AboutMemoryHandler ---------------------------------------------------------- | 1132 // AboutMemoryHandler ---------------------------------------------------------- |
| 1142 | 1133 |
| 1143 // Helper for AboutMemory to bind results from a ProcessMetrics object | 1134 // Helper for AboutMemory to bind results from a ProcessMetrics object |
| 1144 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects | 1135 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects |
| 1145 // can be used in caller's scope (e.g for appending to a net total). | 1136 // can be used in caller's scope (e.g for appending to a net total). |
| 1146 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data, | 1137 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data, |
| 1147 ProcessMemoryInformation* info) { | 1138 ProcessMemoryInformation* info) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1290 source_->FinishDataRequest(AboutVersionStrings( | 1281 source_->FinishDataRequest(AboutVersionStrings( |
| 1291 &localized_strings, source_->profile()), request_id_); | 1282 &localized_strings, source_->profile()), request_id_); |
| 1292 | 1283 |
| 1293 // CancelableRequestProvider isn't happy when it's deleted and servicing a | 1284 // CancelableRequestProvider isn't happy when it's deleted and servicing a |
| 1294 // task, so we delay the deletion. | 1285 // task, so we delay the deletion. |
| 1295 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1286 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 1296 } | 1287 } |
| 1297 | 1288 |
| 1298 #endif | 1289 #endif |
| 1299 | 1290 |
| 1300 class VersionDOMHandler : public content::WebUIMessageHandler { | |
| 1301 public: | |
| 1302 VersionDOMHandler(); | |
| 1303 virtual ~VersionDOMHandler(); | |
| 1304 | |
| 1305 // content::WebUIMessageHandler implementation. | |
| 1306 virtual void RegisterMessages() OVERRIDE; | |
| 1307 | |
| 1308 // Callback for the "requestVariationsList" message. This requests the list of | |
| 1309 // variations from the client and sends it to the frontend. | |
| 1310 void HandleRequestVariationsList(const ListValue* args); | |
| 1311 | |
| 1312 private: | |
| 1313 DISALLOW_COPY_AND_ASSIGN(VersionDOMHandler); | |
| 1314 }; | |
| 1315 | |
| 1316 VersionDOMHandler::VersionDOMHandler() { | |
| 1317 } | |
| 1318 | |
| 1319 VersionDOMHandler::~VersionDOMHandler() { | |
| 1320 } | |
| 1321 | |
| 1322 void VersionDOMHandler::RegisterMessages() { | |
| 1323 web_ui()->RegisterMessageCallback( | |
| 1324 "requestVariationsList", | |
| 1325 base::Bind(&VersionDOMHandler::HandleRequestVariationsList, | |
| 1326 base::Unretained(this))); | |
| 1327 } | |
| 1328 | |
| 1329 void VersionDOMHandler::HandleRequestVariationsList(const ListValue* args) { | |
| 1330 scoped_ptr<ListValue> variations_list(new ListValue()); | |
| 1331 #if !defined(NDEBUG) | |
| 1332 std::vector<std::string> variations; | |
| 1333 std::string variation_state; | |
| 1334 base::FieldTrialList::StatesToString(&variation_state); | |
| 1335 | |
| 1336 std::vector<std::string> tokens; | |
| 1337 base::SplitString(variation_state, | |
| 1338 base::FieldTrialList::kPersistentStringSeparator, | |
| 1339 &tokens); | |
| 1340 // Since StatesToString appends a separator at the end, SplitString will | |
| 1341 // append an extra empty string in the vector. Drop it. There should | |
| 1342 // always be an even number of tokens left. | |
| 1343 tokens.pop_back(); | |
| 1344 DCHECK_EQ(0U, tokens.size() % 2); | |
| 1345 for (size_t i = 0; i < tokens.size(); i += 2) | |
| 1346 variations.push_back(tokens[i] + ":" + tokens[i + 1]); | |
| 1347 | |
| 1348 for (std::vector<std::string>::const_iterator it = variations.begin(); | |
| 1349 it != variations.end(); ++it) { | |
| 1350 variations_list->Append(Value::CreateStringValue(*it)); | |
| 1351 } | |
| 1352 #endif | |
| 1353 // In release mode, this will return an empty list to clear the section. | |
| 1354 web_ui()->CallJavascriptFunction("returnVariationsList", | |
| 1355 *variations_list.release()); | |
| 1356 } | |
| 1357 | |
| 1358 } // namespace | 1291 } // namespace |
| 1359 | 1292 |
| 1360 // AboutUIHTMLSource ---------------------------------------------------------- | 1293 // AboutUIHTMLSource ---------------------------------------------------------- |
| 1361 | 1294 |
| 1362 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name, | 1295 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name, |
| 1363 Profile* profile) | 1296 Profile* profile) |
| 1364 : DataSource(source_name, MessageLoop::current()), | 1297 : DataSource(source_name, MessageLoop::current()), |
| 1365 profile_(profile) { | 1298 profile_(profile) { |
| 1366 } | 1299 } |
| 1367 | 1300 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1418 ChromeOSTermsHandler::Start(this, path, request_id); | 1351 ChromeOSTermsHandler::Start(this, path, request_id); |
| 1419 return; | 1352 return; |
| 1420 #else | 1353 #else |
| 1421 response = l10n_util::GetStringUTF8(IDS_TERMS_HTML); | 1354 response = l10n_util::GetStringUTF8(IDS_TERMS_HTML); |
| 1422 #endif | 1355 #endif |
| 1423 } else if (host == chrome::kChromeUIVersionHost) { | 1356 } else if (host == chrome::kChromeUIVersionHost) { |
| 1424 if (path == kStringsJsPath) { | 1357 if (path == kStringsJsPath) { |
| 1425 // The Flash version information is needed on this page, so make sure | 1358 // The Flash version information is needed on this page, so make sure |
| 1426 // the plugins are loaded. | 1359 // the plugins are loaded. |
| 1427 PluginService::GetInstance()->GetPlugins( | 1360 PluginService::GetInstance()->GetPlugins( |
| 1428 base::Bind(&HandleAboutVersionStrings, | 1361 base::Bind(&HandleAboutVersionStrings, |
|
SteveT
2012/09/10 15:40:00
I just realized that this bit here that handles ab
Evan Stade
2012/09/10 17:07:23
that's not true. Look at favicon_source; that load
| |
| 1429 make_scoped_refptr(this), request_id)); | 1362 make_scoped_refptr(this), request_id)); |
| 1430 return; | 1363 return; |
| 1431 } else { | 1364 } else { |
| 1432 response = AboutVersionStaticContent(path); | 1365 response = AboutVersionStaticContent(path); |
| 1433 } | 1366 } |
| 1434 } | 1367 } |
| 1435 | 1368 |
| 1436 FinishDataRequest(response, request_id); | 1369 FinishDataRequest(response, request_id); |
| 1437 } | 1370 } |
| 1438 | 1371 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1456 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name) | 1389 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name) |
| 1457 : WebUIController(web_ui) { | 1390 : WebUIController(web_ui) { |
| 1458 Profile* profile = Profile::FromWebUI(web_ui); | 1391 Profile* profile = Profile::FromWebUI(web_ui); |
| 1459 | 1392 |
| 1460 #if defined(ENABLE_THEMES) | 1393 #if defined(ENABLE_THEMES) |
| 1461 // Set up the chrome://theme/ source. | 1394 // Set up the chrome://theme/ source. |
| 1462 ThemeSource* theme = new ThemeSource(profile); | 1395 ThemeSource* theme = new ThemeSource(profile); |
| 1463 ChromeURLDataManager::AddDataSource(profile, theme); | 1396 ChromeURLDataManager::AddDataSource(profile, theme); |
| 1464 #endif | 1397 #endif |
| 1465 | 1398 |
| 1466 web_ui->AddMessageHandler(new VersionDOMHandler()); | |
| 1467 | |
| 1468 ChromeURLDataManager::DataSource* source = | 1399 ChromeURLDataManager::DataSource* source = |
| 1469 new AboutUIHTMLSource(name, profile); | 1400 new AboutUIHTMLSource(name, profile); |
| 1470 if (source) { | 1401 if (source) { |
| 1471 ChromeURLDataManager::AddDataSource(profile, source); | 1402 ChromeURLDataManager::AddDataSource(profile, source); |
| 1472 } | 1403 } |
| 1473 } | 1404 } |
| OLD | NEW |