Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: chrome/browser/ui/webui/about_ui.cc

Issue 10916182: Refactor the about:version code out of about_ui. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: rebase + lei nit Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
20 #include "base/memory/singleton.h" 19 #include "base/memory/singleton.h"
21 #include "base/metrics/field_trial.h"
22 #include "base/metrics/statistics_recorder.h" 20 #include "base/metrics/statistics_recorder.h"
23 #include "base/metrics/stats_table.h" 21 #include "base/metrics/stats_table.h"
24 #include "base/path_service.h" 22 #include "base/path_service.h"
25 #include "base/string_number_conversions.h" 23 #include "base/string_number_conversions.h"
26 #include "base/string_piece.h" 24 #include "base/string_piece.h"
27 #include "base/string_split.h"
28 #include "base/string_util.h" 25 #include "base/string_util.h"
29 #include "base/stringprintf.h" 26 #include "base/stringprintf.h"
30 #include "base/threading/thread.h" 27 #include "base/threading/thread.h"
31 #include "base/utf_string_conversions.h" 28 #include "base/utf_string_conversions.h"
32 #include "base/values.h" 29 #include "base/values.h"
33 #include "chrome/browser/about_flags.h" 30 #include "chrome/browser/about_flags.h"
34 #include "chrome/browser/browser_about_handler.h" 31 #include "chrome/browser/browser_about_handler.h"
35 #include "chrome/browser/browser_process.h" 32 #include "chrome/browser/browser_process.h"
36 #include "chrome/browser/defaults.h" 33 #include "chrome/browser/defaults.h"
37 #include "chrome/browser/memory_details.h" 34 #include "chrome/browser/memory_details.h"
38 #include "chrome/browser/net/predictor.h" 35 #include "chrome/browser/net/predictor.h"
39 #include "chrome/browser/net/url_fixer_upper.h" 36 #include "chrome/browser/net/url_fixer_upper.h"
40 #include "chrome/browser/plugins/plugin_prefs.h"
41 #include "chrome/browser/profiles/profile.h" 37 #include "chrome/browser/profiles/profile.h"
42 #include "chrome/browser/profiles/profile_manager.h" 38 #include "chrome/browser/profiles/profile_manager.h"
43 #include "chrome/browser/ui/browser_dialogs.h" 39 #include "chrome/browser/ui/browser_dialogs.h"
44 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 40 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
45 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 41 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
46 #include "chrome/common/chrome_paths.h" 42 #include "chrome/common/chrome_paths.h"
47 #include "chrome/common/chrome_version_info.h"
48 #include "chrome/common/jstemplate_builder.h" 43 #include "chrome/common/jstemplate_builder.h"
49 #include "chrome/common/metrics/variations/variations_util.h"
50 #include "chrome/common/render_messages.h" 44 #include "chrome/common/render_messages.h"
51 #include "chrome/common/url_constants.h" 45 #include "chrome/common/url_constants.h"
52 #include "content/public/browser/browser_thread.h" 46 #include "content/public/browser/browser_thread.h"
53 #include "content/public/browser/plugin_service.h"
54 #include "content/public/browser/render_process_host.h" 47 #include "content/public/browser/render_process_host.h"
55 #include "content/public/browser/render_view_host.h" 48 #include "content/public/browser/render_view_host.h"
56 #include "content/public/browser/web_contents.h" 49 #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" 50 #include "content/public/common/content_client.h"
60 #include "content/public/common/process_type.h" 51 #include "content/public/common/process_type.h"
61 #include "google_apis/gaia/google_service_auth_error.h" 52 #include "google_apis/gaia/google_service_auth_error.h"
62 #include "googleurl/src/gurl.h" 53 #include "googleurl/src/gurl.h"
63 #include "grit/browser_resources.h" 54 #include "grit/browser_resources.h"
64 #include "grit/chromium_strings.h" 55 #include "grit/chromium_strings.h"
65 #include "grit/generated_resources.h" 56 #include "grit/generated_resources.h"
66 #include "grit/locale_settings.h" 57 #include "grit/locale_settings.h"
67 #include "net/base/escape.h" 58 #include "net/base/escape.h"
68 #include "net/base/net_util.h" 59 #include "net/base/net_util.h"
69 #include "ui/base/l10n/l10n_util.h" 60 #include "ui/base/l10n/l10n_util.h"
70 #include "ui/base/layout.h" 61 #include "ui/base/layout.h"
71 #include "ui/base/resource/resource_bundle.h" 62 #include "ui/base/resource/resource_bundle.h"
72 #include "v8/include/v8.h"
73 #include "webkit/glue/webkit_glue.h"
74 #include "webkit/plugins/webplugininfo.h"
75 #include "webkit/user_agent/user_agent_util.h"
76 63
77 #if defined(ENABLE_THEMES) 64 #if defined(ENABLE_THEMES)
78 #include "chrome/browser/ui/webui/theme_source.h" 65 #include "chrome/browser/ui/webui/theme_source.h"
79 #endif 66 #endif
80 67
81 #if defined(OS_LINUX) || defined(OS_OPENBSD) 68 #if defined(OS_LINUX) || defined(OS_OPENBSD)
82 #include "content/public/browser/zygote_host_linux.h" 69 #include "content/public/browser/zygote_host_linux.h"
83 #include "content/public/common/sandbox_linux.h" 70 #include "content/public/common/sandbox_linux.h"
84 #endif 71 #endif
85 72
86 #if defined(OS_WIN) 73 #if defined(OS_WIN)
87 #include "chrome/browser/enumerate_modules_model_win.h" 74 #include "chrome/browser/enumerate_modules_model_win.h"
88 #endif 75 #endif
89 76
90 #if defined(OS_CHROMEOS) 77 #if defined(OS_CHROMEOS)
91 #include "chrome/browser/chromeos/cros/cros_library.h" 78 #include "chrome/browser/chromeos/cros/cros_library.h"
92 #include "chrome/browser/chromeos/cros/network_library.h" 79 #include "chrome/browser/chromeos/cros/network_library.h"
93 #include "chrome/browser/chromeos/customization_document.h" 80 #include "chrome/browser/chromeos/customization_document.h"
94 #include "chrome/browser/chromeos/login/wizard_controller.h" 81 #include "chrome/browser/chromeos/login/wizard_controller.h"
95 #include "chrome/browser/chromeos/oom_priority_manager.h" 82 #include "chrome/browser/chromeos/oom_priority_manager.h"
96 #include "chrome/browser/chromeos/version_loader.h"
97 #endif 83 #endif
98 84
99 #if defined(USE_ASH) 85 #if defined(USE_ASH)
100 #include "ash/wm/frame_painter.h" 86 #include "ash/wm/frame_painter.h"
101 #include "base/string_split.h" 87 #include "base/string_split.h"
102 #endif 88 #endif
103 89
104 using base::Time; 90 using base::Time;
105 using base::TimeDelta; 91 using base::TimeDelta;
106 using content::BrowserThread; 92 using content::BrowserThread;
107 using content::PluginService;
108 using content::WebContents; 93 using content::WebContents;
109 94
110 namespace { 95 namespace {
111 96
112 const char kCreditsJsPath[] = "credits.js"; 97 const char kCreditsJsPath[] = "credits.js";
113 const char kMemoryJsPath[] = "memory.js"; 98 const char kMemoryJsPath[] = "memory.js";
114 const char kStatsJsPath[] = "stats.js"; 99 const char kStatsJsPath[] = "stats.js";
115 const char kStringsJsPath[] = "strings.js"; 100 const char kStringsJsPath[] = "strings.js";
116 const char kVersionJsPath[] = "version.js";
117 101
118 // When you type about:memory, it actually loads this intermediate URL that 102 // When you type about:memory, it actually loads this intermediate URL that
119 // redirects you to the final page. This avoids the problem where typing 103 // redirects you to the final page. This avoids the problem where typing
120 // "about:memory" on the new tab page or any other page where a process 104 // "about:memory" on the new tab page or any other page where a process
121 // transition would occur to the about URL will cause some confusion. 105 // transition would occur to the about URL will cause some confusion.
122 // 106 //
123 // The problem is that during the processing of the memory page, there are two 107 // The problem is that during the processing of the memory page, there are two
124 // processes active, the original and the destination one. This can create the 108 // processes active, the original and the destination one. This can create the
125 // impression that we're using more resources than we actually are. This 109 // impression that we're using more resources than we actually are. This
126 // redirect solves the problem by eliminating the process transition during the 110 // redirect solves the problem by eliminating the process transition during the
(...skipping 22 matching lines...) Expand all
149 ProcessMemoryInformation* info); 133 ProcessMemoryInformation* info);
150 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); 134 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info);
151 135
152 scoped_refptr<AboutUIHTMLSource> source_; 136 scoped_refptr<AboutUIHTMLSource> source_;
153 int request_id_; 137 int request_id_;
154 138
155 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); 139 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler);
156 }; 140 };
157 141
158 #if defined(OS_CHROMEOS) 142 #if defined(OS_CHROMEOS)
159 // ChromeOSAboutVersionHandler is responsible for loading the Chrome OS
160 // version.
161 // ChromeOSAboutVersionHandler handles deleting itself once the version has
162 // been obtained and AboutUIHTMLSource notified.
163 class ChromeOSAboutVersionHandler {
164 public:
165 ChromeOSAboutVersionHandler(AboutUIHTMLSource* source, int request_id);
166
167 // Callback from chromeos::VersionLoader giving the version.
168 void OnVersion(chromeos::VersionLoader::Handle handle,
169 const std::string& version);
170
171 private:
172 // Where the results are fed to.
173 scoped_refptr<AboutUIHTMLSource> source_;
174
175 // ID identifying the request.
176 int request_id_;
177
178 // Handles asynchronously loading the version.
179 chromeos::VersionLoader loader_;
180
181 // Used to request the version.
182 CancelableRequestConsumer consumer_;
183
184 DISALLOW_COPY_AND_ASSIGN(ChromeOSAboutVersionHandler);
185 };
186
187 class ChromeOSTermsHandler 143 class ChromeOSTermsHandler
188 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { 144 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> {
189 public: 145 public:
190 static void Start(AboutUIHTMLSource* source, 146 static void Start(AboutUIHTMLSource* source,
191 const std::string& path, 147 const std::string& path,
192 int request_id) { 148 int request_id) {
193 scoped_refptr<ChromeOSTermsHandler> handler( 149 scoped_refptr<ChromeOSTermsHandler> handler(
194 new ChromeOSTermsHandler(source, path, request_id)); 150 new ChromeOSTermsHandler(source, path, request_id));
195 handler->StartOnUIThread(); 151 handler->StartOnUIThread();
196 } 152 }
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 data.append("<p style=\"color: red\">"); 955 data.append("<p style=\"color: red\">");
1000 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD)); 956 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD));
1001 } 957 }
1002 data.append("</p>"); 958 data.append("</p>");
1003 959
1004 AppendFooter(&data); 960 AppendFooter(&data);
1005 return data; 961 return data;
1006 } 962 }
1007 #endif 963 #endif
1008 964
1009 std::string AboutVersionStaticContent(const std::string& query) {
1010 return ResourceBundle::GetSharedInstance().GetRawDataResource(
1011 query == kVersionJsPath ?
1012 IDR_ABOUT_VERSION_JS :
1013 IDR_ABOUT_VERSION_HTML, ui::SCALE_FACTOR_NONE).as_string();
1014 }
1015
1016 std::string AboutVersionStrings(DictionaryValue* localized_strings,
1017 Profile* profile) {
1018 DCHECK(profile);
1019 localized_strings->SetString("title",
1020 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_TITLE));
1021 chrome::VersionInfo version_info;
1022
1023 localized_strings->SetString("name",
1024 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
1025 localized_strings->SetString("version", version_info.Version());
1026 // Bug 79458: Need to evaluate the use of getting the version string on
1027 // this thread.
1028 base::ThreadRestrictions::ScopedAllowIO allow_io;
1029 localized_strings->SetString("version_modifier",
1030 chrome::VersionInfo::GetVersionStringModifier());
1031 localized_strings->SetString("os_name",
1032 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_OS));
1033 localized_strings->SetString("platform",
1034 l10n_util::GetStringUTF16(IDS_PLATFORM_LABEL));
1035 localized_strings->SetString("os_type", version_info.OSType());
1036 localized_strings->SetString("webkit_version",
1037 webkit_glue::GetWebKitVersion());
1038 localized_strings->SetString("js_engine", "V8");
1039 localized_strings->SetString("js_version", v8::V8::GetVersion());
1040
1041 #if !defined(OS_ANDROID)
1042 // Obtain the version of the first enabled Flash plugin.
1043 std::vector<webkit::WebPluginInfo> info_array;
1044 PluginService::GetInstance()->GetPluginInfoArray(
1045 GURL(), "application/x-shockwave-flash", false, &info_array, NULL);
1046 string16 flash_version =
1047 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN);
1048 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
1049 if (plugin_prefs) {
1050 for (size_t i = 0; i < info_array.size(); ++i) {
1051 if (plugin_prefs->IsPluginEnabled(info_array[i])) {
1052 flash_version = info_array[i].version;
1053 break;
1054 }
1055 }
1056 }
1057 localized_strings->SetString("flash_plugin", "Flash");
1058 localized_strings->SetString("flash_version", flash_version);
1059 #endif
1060 localized_strings->SetString("company",
1061 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COMPANY_NAME));
1062 localized_strings->SetString("copyright",
1063 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COPYRIGHT));
1064 localized_strings->SetString("cl", version_info.LastChange());
1065 localized_strings->SetString("official",
1066 l10n_util::GetStringUTF16(
1067 version_info.IsOfficialBuild() ?
1068 IDS_ABOUT_VERSION_OFFICIAL
1069 : IDS_ABOUT_VERSION_UNOFFICIAL));
1070 localized_strings->SetString("user_agent_name",
1071 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_USER_AGENT));
1072 localized_strings->SetString("useragent", content::GetUserAgent(GURL()));
1073 localized_strings->SetString("command_line_name",
1074 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COMMAND_LINE));
1075
1076 #if defined(OS_WIN)
1077 localized_strings->SetString("command_line",
1078 WideToUTF16(CommandLine::ForCurrentProcess()->GetCommandLineString()));
1079 #elif defined(OS_POSIX)
1080 std::string command_line = "";
1081 typedef std::vector<std::string> ArgvList;
1082 const ArgvList& argv = CommandLine::ForCurrentProcess()->argv();
1083 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++)
1084 command_line += " " + *iter;
1085 // TODO(viettrungluu): |command_line| could really have any encoding, whereas
1086 // below we assumes it's UTF-8.
1087 localized_strings->SetString("command_line", command_line);
1088 #endif
1089
1090 // Allow IO temporarily based on allow_io (defined above)
1091 // since the following operation will complete quickly
1092 localized_strings->SetString("executable_path_name",
1093 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_EXECUTABLE_PATH));
1094 FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram();
1095 if (file_util::AbsolutePath(&executable_path)) {
1096 localized_strings->SetString("executable_path", executable_path.value());
1097 } else {
1098 localized_strings->SetString("executable_path",
1099 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND));
1100 }
1101 localized_strings->SetString("profile_path_name",
1102 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PROFILE_PATH));
1103 if (profile) {
1104 FilePath profile_path = profile->GetPath();
1105 if (file_util::AbsolutePath(&profile_path)) {
1106 localized_strings->SetString("profile_path", profile_path.value());
1107 } else {
1108 localized_strings->SetString("profile_path",
1109 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND));
1110 }
1111 } else {
1112 localized_strings->SetString("profile_path",
1113 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND));
1114 }
1115 ChromeWebUIDataSource::SetFontAndTextDirection(localized_strings);
1116
1117 localized_strings->SetString("variations_name",
1118 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_VARIATIONS));
1119
1120 std::string data;
1121 jstemplate_builder::AppendJsonJS(localized_strings, &data);
1122 return data;
1123 }
1124
1125 // Used as a callback for PluginService::GetPlugins().
1126 void HandleAboutVersionStrings(AboutUIHTMLSource* source,
1127 int request_id,
1128 const std::vector<webkit::WebPluginInfo>&) {
1129 #if defined(OS_CHROMEOS)
1130 new ChromeOSAboutVersionHandler(source, request_id);
1131 #else
1132 DictionaryValue localized_strings;
1133 localized_strings.SetString("os_version", "");
1134 source->FinishDataRequest(
1135 AboutVersionStrings(&localized_strings, source->profile()),
1136 request_id);
1137 #endif
1138 }
1139
1140 // AboutMemoryHandler ---------------------------------------------------------- 965 // AboutMemoryHandler ----------------------------------------------------------
1141 966
1142 // Helper for AboutMemory to bind results from a ProcessMetrics object 967 // Helper for AboutMemory to bind results from a ProcessMetrics object
1143 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects 968 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects
1144 // can be used in caller's scope (e.g for appending to a net total). 969 // can be used in caller's scope (e.g for appending to a net total).
1145 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data, 970 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data,
1146 ProcessMemoryInformation* info) { 971 ProcessMemoryInformation* info) {
1147 DCHECK(data && info); 972 DCHECK(data && info);
1148 973
1149 // Bind metrics to dictionary. 974 // Bind metrics to dictionary.
(...skipping 25 matching lines...) Expand all
1175 info->renderer_type)); 1000 info->renderer_type));
1176 if (info->is_diagnostics) 1001 if (info->is_diagnostics)
1177 child_label.append(" (diagnostics)"); 1002 child_label.append(" (diagnostics)");
1178 child->SetString("child_name", child_label); 1003 child->SetString("child_name", child_label);
1179 ListValue* titles = new ListValue(); 1004 ListValue* titles = new ListValue();
1180 child->Set("titles", titles); 1005 child->Set("titles", titles);
1181 for (size_t i = 0; i < info->titles.size(); ++i) 1006 for (size_t i = 0; i < info->titles.size(); ++i)
1182 titles->Append(new StringValue(info->titles[i])); 1007 titles->Append(new StringValue(info->titles[i]));
1183 } 1008 }
1184 1009
1185
1186 void AboutMemoryHandler::OnDetailsAvailable() { 1010 void AboutMemoryHandler::OnDetailsAvailable() {
1187 // the root of the JSON hierarchy for about:memory jstemplate 1011 // the root of the JSON hierarchy for about:memory jstemplate
1188 DictionaryValue root; 1012 DictionaryValue root;
1189 ListValue* browsers = new ListValue(); 1013 ListValue* browsers = new ListValue();
1190 root.Set("browsers", browsers); 1014 root.Set("browsers", browsers);
1191 1015
1192 const std::vector<ProcessData>& browser_processes = processes(); 1016 const std::vector<ProcessData>& browser_processes = processes();
1193 1017
1194 // Aggregate per-process data into browser summary data. 1018 // Aggregate per-process data into browser summary data.
1195 std::wstring log_string; 1019 std::wstring log_string;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 root.SetString("summary_desc", 1084 root.SetString("summary_desc",
1261 l10n_util::GetStringUTF16(IDS_MEMORY_USAGE_SUMMARY_DESC)); 1085 l10n_util::GetStringUTF16(IDS_MEMORY_USAGE_SUMMARY_DESC));
1262 1086
1263 ChromeWebUIDataSource::SetFontAndTextDirection(&root); 1087 ChromeWebUIDataSource::SetFontAndTextDirection(&root);
1264 1088
1265 std::string data; 1089 std::string data;
1266 jstemplate_builder::AppendJsonJS(&root, &data); 1090 jstemplate_builder::AppendJsonJS(&root, &data);
1267 source_->FinishDataRequest(data, request_id_); 1091 source_->FinishDataRequest(data, request_id_);
1268 } 1092 }
1269 1093
1270 #if defined(OS_CHROMEOS)
1271 // ChromeOSAboutVersionHandler -----------------------------------------------
1272
1273 ChromeOSAboutVersionHandler::ChromeOSAboutVersionHandler(
1274 AboutUIHTMLSource* source,
1275 int request_id)
1276 : source_(source),
1277 request_id_(request_id) {
1278 loader_.GetVersion(&consumer_,
1279 base::Bind(&ChromeOSAboutVersionHandler::OnVersion,
1280 base::Unretained(this)),
1281 chromeos::VersionLoader::VERSION_FULL);
1282 }
1283
1284 void ChromeOSAboutVersionHandler::OnVersion(
1285 chromeos::VersionLoader::Handle handle,
1286 const std::string& version) {
1287 DictionaryValue localized_strings;
1288 localized_strings.SetString("os_version", version);
1289 source_->FinishDataRequest(AboutVersionStrings(
1290 &localized_strings, source_->profile()), request_id_);
1291
1292 // CancelableRequestProvider isn't happy when it's deleted and servicing a
1293 // task, so we delay the deletion.
1294 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
1295 }
1296
1297 #endif
1298
1299 class VersionDOMHandler : public content::WebUIMessageHandler {
1300 public:
1301 VersionDOMHandler();
1302 virtual ~VersionDOMHandler();
1303
1304 // content::WebUIMessageHandler implementation.
1305 virtual void RegisterMessages() OVERRIDE;
1306
1307 // Callback for the "requestVariationsList" message. This requests the list of
1308 // variations from the client and sends it to the frontend.
1309 void HandleRequestVariationsList(const ListValue* args);
1310
1311 private:
1312 DISALLOW_COPY_AND_ASSIGN(VersionDOMHandler);
1313 };
1314
1315 VersionDOMHandler::VersionDOMHandler() {
1316 }
1317
1318 VersionDOMHandler::~VersionDOMHandler() {
1319 }
1320
1321 void VersionDOMHandler::RegisterMessages() {
1322 web_ui()->RegisterMessageCallback(
1323 "requestVariationsList",
1324 base::Bind(&VersionDOMHandler::HandleRequestVariationsList,
1325 base::Unretained(this)));
1326 }
1327
1328 void VersionDOMHandler::HandleRequestVariationsList(const ListValue* args) {
1329 scoped_ptr<ListValue> variations_list(new ListValue());
1330 std::vector<std::string> variations;
1331 #if !defined(NDEBUG)
1332 std::string variation_state;
1333 base::FieldTrialList::StatesToString(&variation_state);
1334
1335 std::vector<std::string> tokens;
1336 base::SplitString(variation_state,
1337 base::FieldTrialList::kPersistentStringSeparator,
1338 &tokens);
1339 // Since StatesToString appends a separator at the end, SplitString will
1340 // append an extra empty string in the vector. Drop it. There should
1341 // always be an even number of tokens left.
1342 tokens.pop_back();
1343 DCHECK_EQ(0U, tokens.size() % 2);
1344 for (size_t i = 0; i < tokens.size(); i += 2)
1345 variations.push_back(tokens[i] + ":" + tokens[i + 1]);
1346 #else
1347 // In release mode, display the hashes only.
1348 std::vector<string16> selected_groups;
1349 chrome_variations::GetFieldTrialSelectedGroupIdsAsStrings(&selected_groups);
1350 for (size_t i = 0; i < selected_groups.size(); ++i)
1351 variations.push_back(UTF16ToASCII(selected_groups[i]));
1352 #endif
1353
1354 for (std::vector<std::string>::const_iterator it = variations.begin();
1355 it != variations.end(); ++it) {
1356 variations_list->Append(Value::CreateStringValue(*it));
1357 }
1358
1359 web_ui()->CallJavascriptFunction("returnVariationsList",
1360 *variations_list.release());
1361 }
1362
1363 } // namespace 1094 } // namespace
1364 1095
1365 // AboutUIHTMLSource ---------------------------------------------------------- 1096 // AboutUIHTMLSource ----------------------------------------------------------
1366 1097
1367 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name, 1098 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name,
1368 Profile* profile) 1099 Profile* profile)
1369 : DataSource(source_name, MessageLoop::current()), 1100 : DataSource(source_name, MessageLoop::current()),
1370 profile_(profile) { 1101 profile_(profile) {
1371 } 1102 }
1372 1103
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 #endif 1149 #endif
1419 } else if (host == chrome::kChromeUIStatsHost) { 1150 } else if (host == chrome::kChromeUIStatsHost) {
1420 response = AboutStats(path); 1151 response = AboutStats(path);
1421 } else if (host == chrome::kChromeUITermsHost) { 1152 } else if (host == chrome::kChromeUITermsHost) {
1422 #if defined(OS_CHROMEOS) 1153 #if defined(OS_CHROMEOS)
1423 ChromeOSTermsHandler::Start(this, path, request_id); 1154 ChromeOSTermsHandler::Start(this, path, request_id);
1424 return; 1155 return;
1425 #else 1156 #else
1426 response = l10n_util::GetStringUTF8(IDS_TERMS_HTML); 1157 response = l10n_util::GetStringUTF8(IDS_TERMS_HTML);
1427 #endif 1158 #endif
1428 } else if (host == chrome::kChromeUIVersionHost) {
1429 if (path == kStringsJsPath) {
1430 // The Flash version information is needed on this page, so make sure
1431 // the plugins are loaded.
1432 PluginService::GetInstance()->GetPlugins(
1433 base::Bind(&HandleAboutVersionStrings,
1434 make_scoped_refptr(this), request_id));
1435 return;
1436 } else {
1437 response = AboutVersionStaticContent(path);
1438 }
1439 } 1159 }
1440 1160
1441 FinishDataRequest(response, request_id); 1161 FinishDataRequest(response, request_id);
1442 } 1162 }
1443 1163
1444 void AboutUIHTMLSource::FinishDataRequest(const std::string& html, 1164 void AboutUIHTMLSource::FinishDataRequest(const std::string& html,
1445 int request_id) { 1165 int request_id) {
1446 std::string html_copy(html); 1166 std::string html_copy(html);
1447 SendResponse(request_id, base::RefCountedString::TakeString(&html_copy)); 1167 SendResponse(request_id, base::RefCountedString::TakeString(&html_copy));
1448 } 1168 }
1449 1169
1450 std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const { 1170 std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const {
1451 if (path == kCreditsJsPath || 1171 if (path == kCreditsJsPath ||
1452 path == kStatsJsPath || 1172 path == kStatsJsPath ||
1453 path == kStringsJsPath || 1173 path == kStringsJsPath ||
1454 path == kVersionJsPath ||
1455 path == kMemoryJsPath) { 1174 path == kMemoryJsPath) {
1456 return "application/javascript"; 1175 return "application/javascript";
1457 } 1176 }
1458 return "text/html"; 1177 return "text/html";
1459 } 1178 }
1460 1179
1461 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name) 1180 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name)
1462 : WebUIController(web_ui) { 1181 : WebUIController(web_ui) {
1463 Profile* profile = Profile::FromWebUI(web_ui); 1182 Profile* profile = Profile::FromWebUI(web_ui);
1464 1183
1465 #if defined(ENABLE_THEMES) 1184 #if defined(ENABLE_THEMES)
1466 // Set up the chrome://theme/ source. 1185 // Set up the chrome://theme/ source.
1467 ThemeSource* theme = new ThemeSource(profile); 1186 ThemeSource* theme = new ThemeSource(profile);
1468 ChromeURLDataManager::AddDataSource(profile, theme); 1187 ChromeURLDataManager::AddDataSource(profile, theme);
1469 #endif 1188 #endif
1470 1189
1471 web_ui->AddMessageHandler(new VersionDOMHandler());
1472
1473 ChromeURLDataManager::DataSource* source = 1190 ChromeURLDataManager::DataSource* source =
1474 new AboutUIHTMLSource(name, profile); 1191 new AboutUIHTMLSource(name, profile);
1475 if (source) { 1192 if (source) {
1476 ChromeURLDataManager::AddDataSource(profile, source); 1193 ChromeURLDataManager::AddDataSource(profile, source);
1477 } 1194 }
1478 } 1195 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/about_version.js ('k') | chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698