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

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: Win fixes Created 8 years, 3 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/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/render_messages.h" 44 #include "chrome/common/render_messages.h"
50 #include "chrome/common/url_constants.h" 45 #include "chrome/common/url_constants.h"
51 #include "content/public/browser/browser_thread.h" 46 #include "content/public/browser/browser_thread.h"
52 #include "content/public/browser/plugin_service.h"
53 #include "content/public/browser/render_process_host.h" 47 #include "content/public/browser/render_process_host.h"
54 #include "content/public/browser/render_view_host.h" 48 #include "content/public/browser/render_view_host.h"
55 #include "content/public/browser/web_contents.h" 49 #include "content/public/browser/web_contents.h"
56 #include "content/public/browser/web_ui.h"
57 #include "content/public/browser/web_ui_message_handler.h"
58 #include "content/public/common/content_client.h" 50 #include "content/public/common/content_client.h"
59 #include "content/public/common/process_type.h" 51 #include "content/public/common/process_type.h"
60 #include "google_apis/gaia/google_service_auth_error.h" 52 #include "google_apis/gaia/google_service_auth_error.h"
61 #include "googleurl/src/gurl.h" 53 #include "googleurl/src/gurl.h"
62 #include "grit/browser_resources.h" 54 #include "grit/browser_resources.h"
63 #include "grit/chromium_strings.h" 55 #include "grit/chromium_strings.h"
64 #include "grit/generated_resources.h" 56 #include "grit/generated_resources.h"
65 #include "grit/locale_settings.h" 57 #include "grit/locale_settings.h"
66 #include "net/base/escape.h" 58 #include "net/base/escape.h"
67 #include "net/base/net_util.h" 59 #include "net/base/net_util.h"
68 #include "ui/base/l10n/l10n_util.h" 60 #include "ui/base/l10n/l10n_util.h"
69 #include "ui/base/layout.h" 61 #include "ui/base/layout.h"
70 #include "ui/base/resource/resource_bundle.h" 62 #include "ui/base/resource/resource_bundle.h"
71 #include "v8/include/v8.h"
72 #include "webkit/glue/webkit_glue.h"
73 #include "webkit/plugins/webplugininfo.h"
74 #include "webkit/user_agent/user_agent_util.h"
75 63
76 #if defined(ENABLE_THEMES) 64 #if defined(ENABLE_THEMES)
77 #include "chrome/browser/ui/webui/theme_source.h" 65 #include "chrome/browser/ui/webui/theme_source.h"
78 #endif 66 #endif
79 67
80 #if defined(OS_LINUX) || defined(OS_OPENBSD) 68 #if defined(OS_LINUX) || defined(OS_OPENBSD)
81 #include "content/public/browser/zygote_host_linux.h" 69 #include "content/public/browser/zygote_host_linux.h"
82 #include "content/public/common/sandbox_linux.h" 70 #include "content/public/common/sandbox_linux.h"
83 #endif 71 #endif
84 72
85 #if defined(OS_WIN) 73 #if defined(OS_WIN)
86 #include "chrome/browser/enumerate_modules_model_win.h" 74 #include "chrome/browser/enumerate_modules_model_win.h"
87 #endif 75 #endif
88 76
89 #if defined(OS_CHROMEOS) 77 #if defined(OS_CHROMEOS)
90 #include "chrome/browser/chromeos/cros/cros_library.h" 78 #include "chrome/browser/chromeos/cros/cros_library.h"
91 #include "chrome/browser/chromeos/cros/network_library.h" 79 #include "chrome/browser/chromeos/cros/network_library.h"
92 #include "chrome/browser/chromeos/customization_document.h" 80 #include "chrome/browser/chromeos/customization_document.h"
93 #include "chrome/browser/chromeos/login/wizard_controller.h" 81 #include "chrome/browser/chromeos/login/wizard_controller.h"
94 #include "chrome/browser/chromeos/oom_priority_manager.h" 82 #include "chrome/browser/chromeos/oom_priority_manager.h"
95 #include "chrome/browser/chromeos/version_loader.h"
96 #endif 83 #endif
97 84
98 #if defined(USE_ASH) 85 #if defined(USE_ASH)
99 #include "ash/wm/frame_painter.h" 86 #include "ash/wm/frame_painter.h"
100 #include "base/string_split.h" 87 #include "base/string_split.h"
101 #endif 88 #endif
102 89
103 using base::Time; 90 using base::Time;
104 using base::TimeDelta; 91 using base::TimeDelta;
105 using content::BrowserThread; 92 using content::BrowserThread;
106 using content::PluginService;
107 using content::WebContents; 93 using content::WebContents;
108 94
109 namespace { 95 namespace {
110 96
111 const char kCreditsJsPath[] = "credits.js"; 97 const char kCreditsJsPath[] = "credits.js";
112 const char kMemoryJsPath[] = "memory.js"; 98 const char kMemoryJsPath[] = "memory.js";
113 const char kStatsJsPath[] = "stats.js"; 99 const char kStatsJsPath[] = "stats.js";
114 const char kStringsJsPath[] = "strings.js"; 100 const char kStringsJsPath[] = "strings.js";
115 const char kVersionJsPath[] = "version.js";
116 101
117 // 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
118 // 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
119 // "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
120 // transition would occur to the about URL will cause some confusion. 105 // transition would occur to the about URL will cause some confusion.
121 // 106 //
122 // 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
123 // 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
124 // 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
125 // 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
148 ProcessMemoryInformation* info); 133 ProcessMemoryInformation* info);
149 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); 134 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info);
150 135
151 scoped_refptr<AboutUIHTMLSource> source_; 136 scoped_refptr<AboutUIHTMLSource> source_;
152 int request_id_; 137 int request_id_;
153 138
154 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); 139 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler);
155 }; 140 };
156 141
157 #if defined(OS_CHROMEOS) 142 #if defined(OS_CHROMEOS)
158 // ChromeOSAboutVersionHandler is responsible for loading the Chrome OS
159 // version.
160 // ChromeOSAboutVersionHandler handles deleting itself once the version has
161 // been obtained and AboutUIHTMLSource notified.
162 class ChromeOSAboutVersionHandler {
163 public:
164 ChromeOSAboutVersionHandler(AboutUIHTMLSource* source, int request_id);
165
166 // Callback from chromeos::VersionLoader giving the version.
167 void OnVersion(chromeos::VersionLoader::Handle handle,
168 const std::string& version);
169
170 private:
171 // Where the results are fed to.
172 scoped_refptr<AboutUIHTMLSource> source_;
173
174 // ID identifying the request.
175 int request_id_;
176
177 // Handles asynchronously loading the version.
178 chromeos::VersionLoader loader_;
179
180 // Used to request the version.
181 CancelableRequestConsumer consumer_;
182
183 DISALLOW_COPY_AND_ASSIGN(ChromeOSAboutVersionHandler);
184 };
185
186 class ChromeOSTermsHandler 143 class ChromeOSTermsHandler
187 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { 144 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> {
188 public: 145 public:
189 static void Start(AboutUIHTMLSource* source, 146 static void Start(AboutUIHTMLSource* source,
190 const std::string& path, 147 const std::string& path,
191 int request_id) { 148 int request_id) {
192 scoped_refptr<ChromeOSTermsHandler> handler( 149 scoped_refptr<ChromeOSTermsHandler> handler(
193 new ChromeOSTermsHandler(source, path, request_id)); 150 new ChromeOSTermsHandler(source, path, request_id));
194 handler->StartOnUIThread(); 151 handler->StartOnUIThread();
195 } 152 }
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 data.append("<p style=\"color: red\">"); 955 data.append("<p style=\"color: red\">");
999 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD)); 956 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD));
1000 } 957 }
1001 data.append("</p>"); 958 data.append("</p>");
1002 959
1003 AppendFooter(&data); 960 AppendFooter(&data);
1004 return data; 961 return data;
1005 } 962 }
1006 #endif 963 #endif
1007 964
1008 std::string AboutVersionStaticContent(const std::string& query) {
1009 return ResourceBundle::GetSharedInstance().GetRawDataResource(
1010 query == kVersionJsPath ?
1011 IDR_ABOUT_VERSION_JS :
1012 IDR_ABOUT_VERSION_HTML, ui::SCALE_FACTOR_NONE).as_string();
1013 }
1014
1015 std::string AboutVersionStrings(DictionaryValue* localized_strings,
1016 Profile* profile) {
1017 DCHECK(profile);
1018 localized_strings->SetString("title",
1019 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_TITLE));
1020 chrome::VersionInfo version_info;
1021
1022 localized_strings->SetString("name",
1023 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
1024 localized_strings->SetString("version", version_info.Version());
1025 // Bug 79458: Need to evaluate the use of getting the version string on
1026 // this thread.
1027 base::ThreadRestrictions::ScopedAllowIO allow_io;
1028 localized_strings->SetString("version_modifier",
1029 chrome::VersionInfo::GetVersionStringModifier());
1030 localized_strings->SetString("os_name",
1031 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_OS));
1032 localized_strings->SetString("platform",
1033 l10n_util::GetStringUTF16(IDS_PLATFORM_LABEL));
1034 localized_strings->SetString("os_type", version_info.OSType());
1035 localized_strings->SetString("webkit_version",
1036 webkit_glue::GetWebKitVersion());
1037 localized_strings->SetString("js_engine", "V8");
1038 localized_strings->SetString("js_version", v8::V8::GetVersion());
1039
1040 #if !defined(OS_ANDROID)
1041 // Obtain the version of the first enabled Flash plugin.
1042 std::vector<webkit::WebPluginInfo> info_array;
1043 PluginService::GetInstance()->GetPluginInfoArray(
1044 GURL(), "application/x-shockwave-flash", false, &info_array, NULL);
1045 string16 flash_version =
1046 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN);
1047 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
1048 if (plugin_prefs) {
1049 for (size_t i = 0; i < info_array.size(); ++i) {
1050 if (plugin_prefs->IsPluginEnabled(info_array[i])) {
1051 flash_version = info_array[i].version;
1052 break;
1053 }
1054 }
1055 }
1056 localized_strings->SetString("flash_plugin", "Flash");
1057 localized_strings->SetString("flash_version", flash_version);
1058 #endif
1059 localized_strings->SetString("company",
1060 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COMPANY_NAME));
1061 localized_strings->SetString("copyright",
1062 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COPYRIGHT));
1063 localized_strings->SetString("cl", version_info.LastChange());
1064 localized_strings->SetString("official",
1065 l10n_util::GetStringUTF16(
1066 version_info.IsOfficialBuild() ?
1067 IDS_ABOUT_VERSION_OFFICIAL
1068 : IDS_ABOUT_VERSION_UNOFFICIAL));
1069 localized_strings->SetString("user_agent_name",
1070 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_USER_AGENT));
1071 localized_strings->SetString("useragent", content::GetUserAgent(GURL()));
1072 localized_strings->SetString("command_line_name",
1073 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COMMAND_LINE));
1074
1075 #if defined(OS_WIN)
1076 localized_strings->SetString("command_line",
1077 WideToUTF16(CommandLine::ForCurrentProcess()->GetCommandLineString()));
1078 #elif defined(OS_POSIX)
1079 std::string command_line = "";
1080 typedef std::vector<std::string> ArgvList;
1081 const ArgvList& argv = CommandLine::ForCurrentProcess()->argv();
1082 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++)
1083 command_line += " " + *iter;
1084 // TODO(viettrungluu): |command_line| could really have any encoding, whereas
1085 // below we assumes it's UTF-8.
1086 localized_strings->SetString("command_line", command_line);
1087 #endif
1088
1089 // Allow IO temporarily based on allow_io (defined above)
1090 // since the following operation will complete quickly
1091 localized_strings->SetString("executable_path_name",
1092 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_EXECUTABLE_PATH));
1093 FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram();
1094 if (file_util::AbsolutePath(&executable_path)) {
1095 localized_strings->SetString("executable_path", executable_path.value());
1096 } else {
1097 localized_strings->SetString("executable_path",
1098 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND));
1099 }
1100 localized_strings->SetString("profile_path_name",
1101 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PROFILE_PATH));
1102 if (profile) {
1103 FilePath profile_path = profile->GetPath();
1104 if (file_util::AbsolutePath(&profile_path)) {
1105 localized_strings->SetString("profile_path", profile_path.value());
1106 } else {
1107 localized_strings->SetString("profile_path",
1108 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND));
1109 }
1110 } else {
1111 localized_strings->SetString("profile_path",
1112 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND));
1113 }
1114 ChromeWebUIDataSource::SetFontAndTextDirection(localized_strings);
1115
1116 #if !defined(NDEBUG)
1117 localized_strings->SetString("variations_name",
1118 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_VARIATIONS));
1119 #endif
1120
1121 std::string data;
1122 jstemplate_builder::AppendJsonJS(localized_strings, &data);
1123 return data;
1124 }
1125
1126 // Used as a callback for PluginService::GetPlugins().
1127 void HandleAboutVersionStrings(AboutUIHTMLSource* source,
1128 int request_id,
1129 const std::vector<webkit::WebPluginInfo>&) {
1130 #if defined(OS_CHROMEOS)
1131 new ChromeOSAboutVersionHandler(source, request_id);
1132 #else
1133 DictionaryValue localized_strings;
1134 localized_strings.SetString("os_version", "");
1135 source->FinishDataRequest(
1136 AboutVersionStrings(&localized_strings, source->profile()),
1137 request_id);
1138 #endif
1139 }
1140
1141 // AboutMemoryHandler ---------------------------------------------------------- 965 // AboutMemoryHandler ----------------------------------------------------------
1142 966
1143 // Helper for AboutMemory to bind results from a ProcessMetrics object 967 // Helper for AboutMemory to bind results from a ProcessMetrics object
1144 // 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
1145 // 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).
1146 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data, 970 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data,
1147 ProcessMemoryInformation* info) { 971 ProcessMemoryInformation* info) {
1148 DCHECK(data && info); 972 DCHECK(data && info);
1149 973
1150 // Bind metrics to dictionary. 974 // Bind metrics to dictionary.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 root.SetString("summary_desc", 1085 root.SetString("summary_desc",
1262 l10n_util::GetStringUTF16(IDS_MEMORY_USAGE_SUMMARY_DESC)); 1086 l10n_util::GetStringUTF16(IDS_MEMORY_USAGE_SUMMARY_DESC));
1263 1087
1264 ChromeWebUIDataSource::SetFontAndTextDirection(&root); 1088 ChromeWebUIDataSource::SetFontAndTextDirection(&root);
1265 1089
1266 std::string data; 1090 std::string data;
1267 jstemplate_builder::AppendJsonJS(&root, &data); 1091 jstemplate_builder::AppendJsonJS(&root, &data);
1268 source_->FinishDataRequest(data, request_id_); 1092 source_->FinishDataRequest(data, request_id_);
1269 } 1093 }
1270 1094
1271 #if defined(OS_CHROMEOS)
1272 // ChromeOSAboutVersionHandler -----------------------------------------------
1273
1274 ChromeOSAboutVersionHandler::ChromeOSAboutVersionHandler(
1275 AboutUIHTMLSource* source,
1276 int request_id)
1277 : source_(source),
1278 request_id_(request_id) {
1279 loader_.GetVersion(&consumer_,
1280 base::Bind(&ChromeOSAboutVersionHandler::OnVersion,
1281 base::Unretained(this)),
1282 chromeos::VersionLoader::VERSION_FULL);
1283 }
1284
1285 void ChromeOSAboutVersionHandler::OnVersion(
1286 chromeos::VersionLoader::Handle handle,
1287 const std::string& version) {
1288 DictionaryValue localized_strings;
1289 localized_strings.SetString("os_version", version);
1290 source_->FinishDataRequest(AboutVersionStrings(
1291 &localized_strings, source_->profile()), request_id_);
1292
1293 // CancelableRequestProvider isn't happy when it's deleted and servicing a
1294 // task, so we delay the deletion.
1295 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
1296 }
1297
1298 #endif
1299
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 1095 } // namespace
1359 1096
1360 // AboutUIHTMLSource ---------------------------------------------------------- 1097 // AboutUIHTMLSource ----------------------------------------------------------
1361 1098
1362 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name, 1099 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name,
1363 Profile* profile) 1100 Profile* profile)
1364 : DataSource(source_name, MessageLoop::current()), 1101 : DataSource(source_name, MessageLoop::current()),
1365 profile_(profile) { 1102 profile_(profile) {
1366 } 1103 }
1367 1104
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 #endif 1150 #endif
1414 } else if (host == chrome::kChromeUIStatsHost) { 1151 } else if (host == chrome::kChromeUIStatsHost) {
1415 response = AboutStats(path); 1152 response = AboutStats(path);
1416 } else if (host == chrome::kChromeUITermsHost) { 1153 } else if (host == chrome::kChromeUITermsHost) {
1417 #if defined(OS_CHROMEOS) 1154 #if defined(OS_CHROMEOS)
1418 ChromeOSTermsHandler::Start(this, path, request_id); 1155 ChromeOSTermsHandler::Start(this, path, request_id);
1419 return; 1156 return;
1420 #else 1157 #else
1421 response = l10n_util::GetStringUTF8(IDS_TERMS_HTML); 1158 response = l10n_util::GetStringUTF8(IDS_TERMS_HTML);
1422 #endif 1159 #endif
1423 } else if (host == chrome::kChromeUIVersionHost) {
1424 if (path == kStringsJsPath) {
1425 // The Flash version information is needed on this page, so make sure
1426 // the plugins are loaded.
1427 PluginService::GetInstance()->GetPlugins(
1428 base::Bind(&HandleAboutVersionStrings,
1429 make_scoped_refptr(this), request_id));
1430 return;
1431 } else {
1432 response = AboutVersionStaticContent(path);
1433 }
1434 } 1160 }
1435 1161
1436 FinishDataRequest(response, request_id); 1162 FinishDataRequest(response, request_id);
1437 } 1163 }
1438 1164
1439 void AboutUIHTMLSource::FinishDataRequest(const std::string& html, 1165 void AboutUIHTMLSource::FinishDataRequest(const std::string& html,
1440 int request_id) { 1166 int request_id) {
1441 std::string html_copy(html); 1167 std::string html_copy(html);
1442 SendResponse(request_id, base::RefCountedString::TakeString(&html_copy)); 1168 SendResponse(request_id, base::RefCountedString::TakeString(&html_copy));
1443 } 1169 }
1444 1170
1445 std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const { 1171 std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const {
1446 if (path == kCreditsJsPath || 1172 if (path == kCreditsJsPath ||
1447 path == kStatsJsPath || 1173 path == kStatsJsPath ||
1448 path == kStringsJsPath || 1174 path == kStringsJsPath ||
1449 path == kVersionJsPath ||
1450 path == kMemoryJsPath) { 1175 path == kMemoryJsPath) {
1451 return "application/javascript"; 1176 return "application/javascript";
1452 } 1177 }
1453 return "text/html"; 1178 return "text/html";
1454 } 1179 }
1455 1180
1456 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name) 1181 AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name)
1457 : WebUIController(web_ui) { 1182 : WebUIController(web_ui) {
1458 Profile* profile = Profile::FromWebUI(web_ui); 1183 Profile* profile = Profile::FromWebUI(web_ui);
1459 1184
1460 #if defined(ENABLE_THEMES) 1185 #if defined(ENABLE_THEMES)
1461 // Set up the chrome://theme/ source. 1186 // Set up the chrome://theme/ source.
1462 ThemeSource* theme = new ThemeSource(profile); 1187 ThemeSource* theme = new ThemeSource(profile);
1463 ChromeURLDataManager::AddDataSource(profile, theme); 1188 ChromeURLDataManager::AddDataSource(profile, theme);
1464 #endif 1189 #endif
1465 1190
1466 web_ui->AddMessageHandler(new VersionDOMHandler());
1467
1468 ChromeURLDataManager::DataSource* source = 1191 ChromeURLDataManager::DataSource* source =
1469 new AboutUIHTMLSource(name, profile); 1192 new AboutUIHTMLSource(name, profile);
1470 if (source) { 1193 if (source) {
1471 ChromeURLDataManager::AddDataSource(profile, source); 1194 ChromeURLDataManager::AddDataSource(profile, source);
1472 } 1195 }
1473 } 1196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698