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

Side by Side Diff: chrome/browser/browser_about_handler.cc

Issue 6894037: Add more information to about:version and "About Chromium" dialog (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Use ScopedAllowIO and directly call AbsolutePath() Created 9 years, 7 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
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/resources/about_version.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/browser_about_handler.h" 5 #include "chrome/browser/browser_about_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // time that about memory is being computed. 186 // time that about memory is being computed.
187 std::string GetAboutMemoryRedirectResponse() { 187 std::string GetAboutMemoryRedirectResponse() {
188 return "<meta http-equiv=\"refresh\" " 188 return "<meta http-equiv=\"refresh\" "
189 "content=\"0;chrome://about/memory\">"; 189 "content=\"0;chrome://about/memory\">";
190 } 190 }
191 191
192 class AboutSource : public ChromeURLDataManager::DataSource { 192 class AboutSource : public ChromeURLDataManager::DataSource {
193 public: 193 public:
194 // Creates our datasource. 194 // Creates our datasource.
195 AboutSource(); 195 AboutSource();
196 explicit AboutSource(Profile* profile);
196 197
197 // Called when the network layer has requested a resource underneath 198 // Called when the network layer has requested a resource underneath
198 // the path we registered. 199 // the path we registered.
199 virtual void StartDataRequest(const std::string& path, 200 virtual void StartDataRequest(const std::string& path,
200 bool is_incognito, 201 bool is_incognito,
201 int request_id); 202 int request_id);
202 203
203 virtual std::string GetMimeType(const std::string&) const { 204 virtual std::string GetMimeType(const std::string&) const {
204 return "text/html"; 205 return "text/html";
205 } 206 }
206 207
207 // Send the response data. 208 // Send the response data.
208 void FinishDataRequest(const std::string& html, int request_id); 209 void FinishDataRequest(const std::string& html, int request_id);
209 210
211 Profile* GetProfile() { return profile_; }
Evan Martin 2011/05/09 18:52:28 As a simple getter, this can be: Profile* profile
212
210 private: 213 private:
211 virtual ~AboutSource(); 214 virtual ~AboutSource();
212 215
216 Profile* profile_;
217
213 DISALLOW_COPY_AND_ASSIGN(AboutSource); 218 DISALLOW_COPY_AND_ASSIGN(AboutSource);
214 }; 219 };
215 220
216 // Handling about:memory is complicated enough to encapsulate its related 221 // Handling about:memory is complicated enough to encapsulate its related
217 // methods into a single class. The user should create it (on the heap) and call 222 // methods into a single class. The user should create it (on the heap) and call
218 // its |StartFetch()| method. 223 // its |StartFetch()| method.
219 class AboutMemoryHandler : public MemoryDetails { 224 class AboutMemoryHandler : public MemoryDetails {
220 public: 225 public:
221 AboutMemoryHandler(AboutSource* source, int request_id) 226 AboutMemoryHandler(AboutSource* source, int request_id)
222 : source_(source), request_id_(request_id) {} 227 : source_(source), request_id_(request_id) {}
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 data.append("<p style=\"color: red\">"); 904 data.append("<p style=\"color: red\">");
900 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD)); 905 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD));
901 } 906 }
902 data.append("</p>"); 907 data.append("</p>");
903 908
904 data.append("</body></html>\n"); 909 data.append("</body></html>\n");
905 return data; 910 return data;
906 } 911 }
907 #endif 912 #endif
908 913
909 std::string AboutVersion(DictionaryValue* localized_strings) { 914 std::string AboutVersion(DictionaryValue* localized_strings, Profile* profile) {
910 localized_strings->SetString("title", 915 localized_strings->SetString("title",
911 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_TITLE)); 916 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_TITLE));
912 chrome::VersionInfo version_info; 917 chrome::VersionInfo version_info;
913 918
914 std::string webkit_version = webkit_glue::GetWebKitVersion(); 919 std::string webkit_version = webkit_glue::GetWebKitVersion();
915 #ifdef CHROME_V8 920 #ifdef CHROME_V8
916 std::string js_version(v8::V8::GetVersion()); 921 std::string js_version(v8::V8::GetVersion());
917 std::string js_engine = "V8"; 922 std::string js_engine = "V8";
918 #else 923 #else
919 std::string js_version = webkit_version; 924 std::string js_version = webkit_version;
920 std::string js_engine = "JavaScriptCore"; 925 std::string js_engine = "JavaScriptCore";
921 #endif 926 #endif
922 927
923 localized_strings->SetString("name", 928 localized_strings->SetString("name",
924 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 929 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
925 localized_strings->SetString("version", version_info.Version()); 930 localized_strings->SetString("version", version_info.Version());
926 // Bug 79458: Need to evaluate the use of getting the version string on 931 // Bug 79458: Need to evaluate the use of getting the version string on
927 // this thread. 932 // this thread.
928 base::ThreadRestrictions::ScopedAllowIO allow_io; 933 base::ThreadRestrictions::ScopedAllowIO allow_io;
929 localized_strings->SetString("version_modifier", 934 localized_strings->SetString("version_modifier",
930 platform_util::GetVersionStringModifier()); 935 platform_util::GetVersionStringModifier());
936 localized_strings->SetString("os_name",
937 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_OS));
938 localized_strings->SetString("os_type", version_info.OSType());
939 localized_strings->SetString("webkit_version", webkit_version);
931 localized_strings->SetString("js_engine", js_engine); 940 localized_strings->SetString("js_engine", js_engine);
932 localized_strings->SetString("js_version", js_version); 941 localized_strings->SetString("js_version", js_version);
933 942
934 // Obtain the version of the first enabled Flash plugin. 943 // Obtain the version of the first enabled Flash plugin.
935 std::vector<webkit::npapi::WebPluginInfo> info_array; 944 std::vector<webkit::npapi::WebPluginInfo> info_array;
936 webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( 945 webkit::npapi::PluginList::Singleton()->GetPluginInfoArray(
937 GURL(), "application/x-shockwave-flash", false, &info_array, NULL); 946 GURL(), "application/x-shockwave-flash", false, &info_array, NULL);
938 string16 flash_version = 947 string16 flash_version =
939 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); 948 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN);
940 for (size_t i = 0; i < info_array.size(); ++i) { 949 for (size_t i = 0; i < info_array.size(); ++i) {
(...skipping 28 matching lines...) Expand all
969 std::string command_line = ""; 978 std::string command_line = "";
970 typedef std::vector<std::string> ArgvList; 979 typedef std::vector<std::string> ArgvList;
971 const ArgvList& argv = CommandLine::ForCurrentProcess()->argv(); 980 const ArgvList& argv = CommandLine::ForCurrentProcess()->argv();
972 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++) 981 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++)
973 command_line += " " + *iter; 982 command_line += " " + *iter;
974 // TODO(viettrungluu): |command_line| could really have any encoding, whereas 983 // TODO(viettrungluu): |command_line| could really have any encoding, whereas
975 // below we assumes it's UTF-8. 984 // below we assumes it's UTF-8.
976 localized_strings->SetString("command_line", command_line); 985 localized_strings->SetString("command_line", command_line);
977 #endif 986 #endif
978 987
988 // Allow IO temporarily based on allow_io (defined above)
989 // since the following operation will complete quickly
990 localized_strings->SetString("executable_path_name",
991 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_EXECUTABLE_PATH));
992 FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram();
993 if (file_util::AbsolutePath(&executable_path)) {
994 localized_strings->SetString("executable_path", executable_path.value());
995 } else {
996 localized_strings->SetString("executable_path",
997 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND));
998 }
999 localized_strings->SetString("profile_path_name",
1000 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PROFILE_PATH));
1001 if (profile) {
1002 FilePath profile_path = profile->GetPath();
1003 if (file_util::AbsolutePath(&profile_path)) {
1004 localized_strings->SetString("profile_path", profile_path.value());
1005 } else {
1006 localized_strings->SetString("profile_path",
1007 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND));
1008 }
1009 } else {
1010 localized_strings->SetString("profile_path",
1011 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND));
1012 }
1013
979 base::StringPiece version_html( 1014 base::StringPiece version_html(
980 ResourceBundle::GetSharedInstance().GetRawDataResource( 1015 ResourceBundle::GetSharedInstance().GetRawDataResource(
981 IDR_ABOUT_VERSION_HTML)); 1016 IDR_ABOUT_VERSION_HTML));
982 1017
983 return jstemplate_builder::GetTemplatesHtml( 1018 return jstemplate_builder::GetTemplatesHtml(
984 version_html, localized_strings, "t" /* template root node id */); 1019 version_html, localized_strings, "t" /* template root node id */);
985 } 1020 }
986 1021
987 // AboutSource ----------------------------------------------------------------- 1022 // AboutSource -----------------------------------------------------------------
988 1023
989 AboutSource::AboutSource() 1024 AboutSource::AboutSource()
990 : DataSource(chrome::kAboutScheme, MessageLoop::current()) { 1025 : DataSource(chrome::kAboutScheme, MessageLoop::current()) {
991 } 1026 }
992 1027
1028 AboutSource::AboutSource(Profile* profile)
1029 : DataSource(chrome::kAboutScheme, MessageLoop::current()),
1030 profile_(profile) {
1031 }
1032
993 AboutSource::~AboutSource() { 1033 AboutSource::~AboutSource() {
994 } 1034 }
995 1035
996 void AboutSource::StartDataRequest(const std::string& path_raw, 1036 void AboutSource::StartDataRequest(const std::string& path_raw,
997 bool is_incognito, int request_id) { 1037 bool is_incognito, int request_id) {
998 std::string path = path_raw; 1038 std::string path = path_raw;
999 std::string info; 1039 std::string info;
1000 if (path.find("/") != std::string::npos) { 1040 if (path.find("/") != std::string::npos) {
1001 size_t pos = path.find("/"); 1041 size_t pos = path.find("/");
1002 info = path.substr(pos + 1, path.length() - (pos + 1)); 1042 info = path.substr(pos + 1, path.length() - (pos + 1));
(...skipping 20 matching lines...) Expand all
1023 response = AboutStats(info); 1063 response = AboutStats(info);
1024 #if defined(USE_TCMALLOC) 1064 #if defined(USE_TCMALLOC)
1025 } else if (path == kTcmallocPath) { 1065 } else if (path == kTcmallocPath) {
1026 response = AboutTcmalloc(info); 1066 response = AboutTcmalloc(info);
1027 #endif 1067 #endif
1028 } else if (path == kVersionPath || path.empty()) { 1068 } else if (path == kVersionPath || path.empty()) {
1029 #if defined(OS_CHROMEOS) 1069 #if defined(OS_CHROMEOS)
1030 new ChromeOSAboutVersionHandler(this, request_id); 1070 new ChromeOSAboutVersionHandler(this, request_id);
1031 return; 1071 return;
1032 #else 1072 #else
1033 DictionaryValue value; 1073 DictionaryValue localized_strings;
1034 response = AboutVersion(&value); 1074 localized_strings.SetString("os_version", "");
1075 response = AboutVersion(&localized_strings, profile_);
1035 #endif 1076 #endif
1036 } else if (path == kCreditsPath) { 1077 } else if (path == kCreditsPath) {
1037 response = ResourceBundle::GetSharedInstance().GetRawDataResource( 1078 response = ResourceBundle::GetSharedInstance().GetRawDataResource(
1038 IDR_CREDITS_HTML).as_string(); 1079 IDR_CREDITS_HTML).as_string();
1039 } else if (path == kAboutPath) { 1080 } else if (path == kAboutPath) {
1040 response = AboutAbout(); 1081 response = AboutAbout();
1041 #if defined(OS_CHROMEOS) 1082 #if defined(OS_CHROMEOS)
1042 } else if (path == kOSCreditsPath) { 1083 } else if (path == kOSCreditsPath) {
1043 response = ResourceBundle::GetSharedInstance().GetRawDataResource( 1084 response = ResourceBundle::GetSharedInstance().GetRawDataResource(
1044 IDR_OS_CREDITS_HTML).as_string(); 1085 IDR_OS_CREDITS_HTML).as_string();
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 request_id_(request_id) { 1255 request_id_(request_id) {
1215 loader_.GetVersion(&consumer_, 1256 loader_.GetVersion(&consumer_,
1216 NewCallback(this, &ChromeOSAboutVersionHandler::OnVersion), 1257 NewCallback(this, &ChromeOSAboutVersionHandler::OnVersion),
1217 chromeos::VersionLoader::VERSION_FULL); 1258 chromeos::VersionLoader::VERSION_FULL);
1218 } 1259 }
1219 1260
1220 void ChromeOSAboutVersionHandler::OnVersion( 1261 void ChromeOSAboutVersionHandler::OnVersion(
1221 chromeos::VersionLoader::Handle handle, 1262 chromeos::VersionLoader::Handle handle,
1222 std::string version) { 1263 std::string version) {
1223 DictionaryValue localized_strings; 1264 DictionaryValue localized_strings;
1224 localized_strings.SetString("os_name",
1225 l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME));
1226 localized_strings.SetString("os_version", version); 1265 localized_strings.SetString("os_version", version);
1227 localized_strings.SetBoolean("is_chrome_os", true); 1266 source_->FinishDataRequest(AboutVersion(&localized_strings,
1228 source_->FinishDataRequest(AboutVersion(&localized_strings), request_id_); 1267 source_->GetProfile()), request_id_);
1229 1268
1230 // CancelableRequestProvider isn't happy when it's deleted and servicing a 1269 // CancelableRequestProvider isn't happy when it's deleted and servicing a
1231 // task, so we delay the deletion. 1270 // task, so we delay the deletion.
1232 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 1271 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
1233 } 1272 }
1234 1273
1235 #endif 1274 #endif
1236 1275
1237 // Returns true if |url|'s spec starts with |about_specifier|, and is 1276 // Returns true if |url|'s spec starts with |about_specifier|, and is
1238 // terminated by the start of a path. 1277 // terminated by the start of a path.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 // Rewrite the about URL to use chrome:. WebKit treats all about URLS the 1393 // Rewrite the about URL to use chrome:. WebKit treats all about URLS the
1355 // same (blank page), so if we want to display content, we need another 1394 // same (blank page), so if we want to display content, we need another
1356 // scheme. 1395 // scheme.
1357 std::string about_url = "chrome://about/"; 1396 std::string about_url = "chrome://about/";
1358 about_url.append(url->path()); 1397 about_url.append(url->path());
1359 *url = GURL(about_url); 1398 *url = GURL(about_url);
1360 return true; 1399 return true;
1361 } 1400 }
1362 1401
1363 void InitializeAboutDataSource(Profile* profile) { 1402 void InitializeAboutDataSource(Profile* profile) {
1364 profile->GetChromeURLDataManager()->AddDataSource(new AboutSource()); 1403 profile->GetChromeURLDataManager()->AddDataSource(new AboutSource(profile));
1365 } 1404 }
1366 1405
1367 // This function gets called with the fixed-up chrome: URLs, so we have to 1406 // This function gets called with the fixed-up chrome: URLs, so we have to
1368 // compare against those instead of "about:blah". 1407 // compare against those instead of "about:blah".
1369 bool HandleNonNavigationAboutURL(const GURL& url) { 1408 bool HandleNonNavigationAboutURL(const GURL& url) {
1370 // about:ipc is currently buggy, so we disable it for official builds. 1409 // about:ipc is currently buggy, so we disable it for official builds.
1371 #if !defined(OFFICIAL_BUILD) 1410 #if !defined(OFFICIAL_BUILD)
1372 1411
1373 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED) 1412 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED)
1374 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) { 1413 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) {
1375 // Run the dialog. This will re-use the existing one if it's already up. 1414 // Run the dialog. This will re-use the existing one if it's already up.
1376 browser::ShowAboutIPCDialog(); 1415 browser::ShowAboutIPCDialog();
1377 return true; 1416 return true;
1378 } 1417 }
1379 #endif 1418 #endif
1380 1419
1381 #endif // OFFICIAL_BUILD 1420 #endif // OFFICIAL_BUILD
1382 1421
1383 return false; 1422 return false;
1384 } 1423 }
1385 1424
1386 std::vector<std::string> AboutPaths() { 1425 std::vector<std::string> AboutPaths() {
1387 std::vector<std::string> paths; 1426 std::vector<std::string> paths;
1388 paths.reserve(arraysize(kAllAboutPaths)); 1427 paths.reserve(arraysize(kAllAboutPaths));
1389 for (size_t i = 0; i < arraysize(kAllAboutPaths); i++) 1428 for (size_t i = 0; i < arraysize(kAllAboutPaths); i++)
1390 paths.push_back(kAllAboutPaths[i]); 1429 paths.push_back(kAllAboutPaths[i]);
1391 return paths; 1430 return paths;
1392 } 1431 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/resources/about_version.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698