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

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: Created 9 years, 8 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) 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // time that about memory is being computed. 183 // time that about memory is being computed.
184 std::string GetAboutMemoryRedirectResponse() { 184 std::string GetAboutMemoryRedirectResponse() {
185 return "<meta http-equiv=\"refresh\" " 185 return "<meta http-equiv=\"refresh\" "
186 "content=\"0;chrome://about/memory\">"; 186 "content=\"0;chrome://about/memory\">";
187 } 187 }
188 188
189 class AboutSource : public ChromeURLDataManager::DataSource { 189 class AboutSource : public ChromeURLDataManager::DataSource {
190 public: 190 public:
191 // Creates our datasource. 191 // Creates our datasource.
192 AboutSource(); 192 AboutSource();
193 explicit AboutSource(Profile* profile);
193 194
194 // Called when the network layer has requested a resource underneath 195 // Called when the network layer has requested a resource underneath
195 // the path we registered. 196 // the path we registered.
196 virtual void StartDataRequest(const std::string& path, 197 virtual void StartDataRequest(const std::string& path,
197 bool is_incognito, 198 bool is_incognito,
198 int request_id); 199 int request_id);
199 200
200 virtual std::string GetMimeType(const std::string&) const { 201 virtual std::string GetMimeType(const std::string&) const {
201 return "text/html"; 202 return "text/html";
202 } 203 }
203 204
204 // Send the response data. 205 // Send the response data.
205 void FinishDataRequest(const std::string& html, int request_id); 206 void FinishDataRequest(const std::string& html, int request_id);
206 207
208 Profile* GetProfile() { return profile_; }
209
207 private: 210 private:
208 virtual ~AboutSource(); 211 virtual ~AboutSource();
209 212
213 Profile* profile_;
214
210 DISALLOW_COPY_AND_ASSIGN(AboutSource); 215 DISALLOW_COPY_AND_ASSIGN(AboutSource);
211 }; 216 };
212 217
213 // Handling about:memory is complicated enough to encapsulate its related 218 // Handling about:memory is complicated enough to encapsulate its related
214 // methods into a single class. The user should create it (on the heap) and call 219 // methods into a single class. The user should create it (on the heap) and call
215 // its |StartFetch()| method. 220 // its |StartFetch()| method.
216 class AboutMemoryHandler : public MemoryDetails { 221 class AboutMemoryHandler : public MemoryDetails {
217 public: 222 public:
218 AboutMemoryHandler(AboutSource* source, int request_id) 223 AboutMemoryHandler(AboutSource* source, int request_id)
219 : source_(source), request_id_(request_id) {} 224 : source_(source), request_id_(request_id) {}
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 data.append("<p style=\"color: red\">"); 901 data.append("<p style=\"color: red\">");
897 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD)); 902 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD));
898 } 903 }
899 data.append("</p>"); 904 data.append("</p>");
900 905
901 data.append("</body></html>\n"); 906 data.append("</body></html>\n");
902 return data; 907 return data;
903 } 908 }
904 #endif 909 #endif
905 910
906 std::string AboutVersion(DictionaryValue* localized_strings) { 911 std::string AboutVersion(DictionaryValue* localized_strings, Profile* profile) {
907 localized_strings->SetString("title", 912 localized_strings->SetString("title",
908 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_TITLE)); 913 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_TITLE));
909 chrome::VersionInfo version_info; 914 chrome::VersionInfo version_info;
910 915
911 std::string webkit_version = webkit_glue::GetWebKitVersion(); 916 std::string webkit_version = webkit_glue::GetWebKitVersion();
912 #ifdef CHROME_V8 917 #ifdef CHROME_V8
913 std::string js_version(v8::V8::GetVersion()); 918 std::string js_version(v8::V8::GetVersion());
914 std::string js_engine = "V8"; 919 std::string js_engine = "V8";
915 #else 920 #else
916 std::string js_version = webkit_version; 921 std::string js_version = webkit_version;
917 std::string js_engine = "JavaScriptCore"; 922 std::string js_engine = "JavaScriptCore";
918 #endif 923 #endif
919 924
920 localized_strings->SetString("name", 925 localized_strings->SetString("name",
921 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 926 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
922 localized_strings->SetString("version", version_info.Version()); 927 localized_strings->SetString("version", version_info.Version());
923 localized_strings->SetString("version_modifier", 928 localized_strings->SetString("version_modifier",
924 platform_util::GetVersionStringModifier()); 929 platform_util::GetVersionStringModifier());
930 localized_strings->SetString("os_name",
931 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_OS));
932 localized_strings->SetString("os_type", version_info.OSType());
933 localized_strings->SetString("webkit_name",
934 l10n_util::GetStringUTF16(
935 IDS_ABOUT_VERSION_WEBKIT));
936 localized_strings->SetString("webkit_version", webkit_version);
937 localized_strings->SetString("js_name",
938 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_JS));
925 localized_strings->SetString("js_engine", js_engine); 939 localized_strings->SetString("js_engine", js_engine);
926 localized_strings->SetString("js_version", js_version); 940 localized_strings->SetString("js_version", js_version);
927 localized_strings->SetString("webkit_version", webkit_version);
928 localized_strings->SetString("company", 941 localized_strings->SetString("company",
929 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COMPANY_NAME)); 942 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COMPANY_NAME));
930 localized_strings->SetString("copyright", 943 localized_strings->SetString("copyright",
931 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COPYRIGHT)); 944 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COPYRIGHT));
932 localized_strings->SetString("cl", version_info.LastChange()); 945 localized_strings->SetString("cl", version_info.LastChange());
933 localized_strings->SetString("official", 946 localized_strings->SetString("official",
934 l10n_util::GetStringUTF16( 947 l10n_util::GetStringUTF16(
935 version_info.IsOfficialBuild() ? 948 version_info.IsOfficialBuild() ?
936 IDS_ABOUT_VERSION_OFFICIAL 949 IDS_ABOUT_VERSION_OFFICIAL
937 : IDS_ABOUT_VERSION_UNOFFICIAL)); 950 : IDS_ABOUT_VERSION_UNOFFICIAL));
(...skipping 10 matching lines...) Expand all
948 std::string command_line = ""; 961 std::string command_line = "";
949 typedef std::vector<std::string> ArgvList; 962 typedef std::vector<std::string> ArgvList;
950 const ArgvList& argv = CommandLine::ForCurrentProcess()->argv(); 963 const ArgvList& argv = CommandLine::ForCurrentProcess()->argv();
951 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++) 964 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++)
952 command_line += " " + *iter; 965 command_line += " " + *iter;
953 // TODO(viettrungluu): |command_line| could really have any encoding, whereas 966 // TODO(viettrungluu): |command_line| could really have any encoding, whereas
954 // below we assumes it's UTF-8. 967 // below we assumes it's UTF-8.
955 localized_strings->SetString("command_line", command_line); 968 localized_strings->SetString("command_line", command_line);
956 #endif 969 #endif
957 970
971 // Allow IO temporarily since the following operation will complete quickly
972 bool io_allowed = base::ThreadRestrictions::SetIOAllowed(true);
Evan Martin 2011/04/22 22:36:41 I don't like this. Why not just not call Absolute
973 localized_strings->SetString("executable_path_name",
974 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_EXECUTABLE_PATH));
975 FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram();
976 if (file_util::AbsolutePath(&executable_path)) {
977 localized_strings->SetString("executable_path", executable_path.value());
978 } else {
979 localized_strings->SetString("executable_path", "No such file");
980 }
981 localized_strings->SetString("profile_path_name",
982 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PROFILE_PATH));
983 if (profile) {
984 FilePath profile_path = profile->GetPath();
985 if (file_util::AbsolutePath(&profile_path)) {
986 localized_strings->SetString("profile_path", profile_path.value());
987 } else {
988 localized_strings->SetString("profile_path", "No such file");
989 }
990 } else {
991 localized_strings->SetString("profile_path", "No such file");
992 }
993 base::ThreadRestrictions::SetIOAllowed(io_allowed);
994
958 base::StringPiece version_html( 995 base::StringPiece version_html(
959 ResourceBundle::GetSharedInstance().GetRawDataResource( 996 ResourceBundle::GetSharedInstance().GetRawDataResource(
960 IDR_ABOUT_VERSION_HTML)); 997 IDR_ABOUT_VERSION_HTML));
961 998
962 return jstemplate_builder::GetTemplatesHtml( 999 return jstemplate_builder::GetTemplatesHtml(
963 version_html, localized_strings, "t" /* template root node id */); 1000 version_html, localized_strings, "t" /* template root node id */);
964 } 1001 }
965 1002
966 std::string VersionNumberToString(uint32 value) { 1003 std::string VersionNumberToString(uint32 value) {
967 int hi = (value >> 8) & 0xff; 1004 int hi = (value >> 8) & 0xff;
968 int low = value & 0xff; 1005 int low = value & 0xff;
969 return base::IntToString(hi) + "." + base::IntToString(low); 1006 return base::IntToString(hi) + "." + base::IntToString(low);
970 } 1007 }
971 1008
972 // AboutSource ----------------------------------------------------------------- 1009 // AboutSource -----------------------------------------------------------------
973 1010
974 AboutSource::AboutSource() 1011 AboutSource::AboutSource()
975 : DataSource(chrome::kAboutScheme, MessageLoop::current()) { 1012 : DataSource(chrome::kAboutScheme, MessageLoop::current()) {
976 } 1013 }
977 1014
1015 AboutSource::AboutSource(Profile* profile)
1016 : DataSource(chrome::kAboutScheme, MessageLoop::current()),
1017 profile_(profile) {
1018 }
1019
978 AboutSource::~AboutSource() { 1020 AboutSource::~AboutSource() {
979 } 1021 }
980 1022
981 void AboutSource::StartDataRequest(const std::string& path_raw, 1023 void AboutSource::StartDataRequest(const std::string& path_raw,
982 bool is_incognito, int request_id) { 1024 bool is_incognito, int request_id) {
983 std::string path = path_raw; 1025 std::string path = path_raw;
984 std::string info; 1026 std::string info;
985 if (path.find("/") != std::string::npos) { 1027 if (path.find("/") != std::string::npos) {
986 size_t pos = path.find("/"); 1028 size_t pos = path.find("/");
987 info = path.substr(pos + 1, path.length() - (pos + 1)); 1029 info = path.substr(pos + 1, path.length() - (pos + 1));
(...skipping 20 matching lines...) Expand all
1008 response = AboutStats(info); 1050 response = AboutStats(info);
1009 #if defined(USE_TCMALLOC) 1051 #if defined(USE_TCMALLOC)
1010 } else if (path == kTcmallocPath) { 1052 } else if (path == kTcmallocPath) {
1011 response = AboutTcmalloc(info); 1053 response = AboutTcmalloc(info);
1012 #endif 1054 #endif
1013 } else if (path == kVersionPath || path.empty()) { 1055 } else if (path == kVersionPath || path.empty()) {
1014 #if defined(OS_CHROMEOS) 1056 #if defined(OS_CHROMEOS)
1015 new ChromeOSAboutVersionHandler(this, request_id); 1057 new ChromeOSAboutVersionHandler(this, request_id);
1016 return; 1058 return;
1017 #else 1059 #else
1018 DictionaryValue value; 1060 DictionaryValue localized_strings;
1019 response = AboutVersion(&value); 1061 localized_strings.SetString("os_version", "");
1062 response = AboutVersion(&localized_strings, profile_);
1020 #endif 1063 #endif
1021 } else if (path == kCreditsPath) { 1064 } else if (path == kCreditsPath) {
1022 response = ResourceBundle::GetSharedInstance().GetRawDataResource( 1065 response = ResourceBundle::GetSharedInstance().GetRawDataResource(
1023 IDR_CREDITS_HTML).as_string(); 1066 IDR_CREDITS_HTML).as_string();
1024 } else if (path == kAboutPath) { 1067 } else if (path == kAboutPath) {
1025 response = AboutAbout(); 1068 response = AboutAbout();
1026 #if defined(OS_CHROMEOS) 1069 #if defined(OS_CHROMEOS)
1027 } else if (path == kOSCreditsPath) { 1070 } else if (path == kOSCreditsPath) {
1028 response = ResourceBundle::GetSharedInstance().GetRawDataResource( 1071 response = ResourceBundle::GetSharedInstance().GetRawDataResource(
1029 IDR_OS_CREDITS_HTML).as_string(); 1072 IDR_OS_CREDITS_HTML).as_string();
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 request_id_(request_id) { 1242 request_id_(request_id) {
1200 loader_.GetVersion(&consumer_, 1243 loader_.GetVersion(&consumer_,
1201 NewCallback(this, &ChromeOSAboutVersionHandler::OnVersion), 1244 NewCallback(this, &ChromeOSAboutVersionHandler::OnVersion),
1202 chromeos::VersionLoader::VERSION_FULL); 1245 chromeos::VersionLoader::VERSION_FULL);
1203 } 1246 }
1204 1247
1205 void ChromeOSAboutVersionHandler::OnVersion( 1248 void ChromeOSAboutVersionHandler::OnVersion(
1206 chromeos::VersionLoader::Handle handle, 1249 chromeos::VersionLoader::Handle handle,
1207 std::string version) { 1250 std::string version) {
1208 DictionaryValue localized_strings; 1251 DictionaryValue localized_strings;
1209 localized_strings.SetString("os_name",
1210 l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME));
1211 localized_strings.SetString("os_version", version); 1252 localized_strings.SetString("os_version", version);
1212 localized_strings.SetBoolean("is_chrome_os", true); 1253 source_->FinishDataRequest(AboutVersion(&localized_strings,
1213 source_->FinishDataRequest(AboutVersion(&localized_strings), request_id_); 1254 source_->GetProfile()), request_id_);
1214 1255
1215 // CancelableRequestProvider isn't happy when it's deleted and servicing a 1256 // CancelableRequestProvider isn't happy when it's deleted and servicing a
1216 // task, so we delay the deletion. 1257 // task, so we delay the deletion.
1217 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 1258 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
1218 } 1259 }
1219 1260
1220 #endif 1261 #endif
1221 1262
1222 // Returns true if |url|'s spec starts with |about_specifier|, and is 1263 // Returns true if |url|'s spec starts with |about_specifier|, and is
1223 // terminated by the start of a path. 1264 // terminated by the start of a path.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 // Rewrite the about URL to use chrome:. WebKit treats all about URLS the 1390 // Rewrite the about URL to use chrome:. WebKit treats all about URLS the
1350 // same (blank page), so if we want to display content, we need another 1391 // same (blank page), so if we want to display content, we need another
1351 // scheme. 1392 // scheme.
1352 std::string about_url = "chrome://about/"; 1393 std::string about_url = "chrome://about/";
1353 about_url.append(url->path()); 1394 about_url.append(url->path());
1354 *url = GURL(about_url); 1395 *url = GURL(about_url);
1355 return true; 1396 return true;
1356 } 1397 }
1357 1398
1358 void InitializeAboutDataSource(Profile* profile) { 1399 void InitializeAboutDataSource(Profile* profile) {
1359 profile->GetChromeURLDataManager()->AddDataSource(new AboutSource()); 1400 profile->GetChromeURLDataManager()->AddDataSource(new AboutSource(profile));
1360 } 1401 }
1361 1402
1362 // This function gets called with the fixed-up chrome: URLs, so we have to 1403 // This function gets called with the fixed-up chrome: URLs, so we have to
1363 // compare against those instead of "about:blah". 1404 // compare against those instead of "about:blah".
1364 bool HandleNonNavigationAboutURL(const GURL& url) { 1405 bool HandleNonNavigationAboutURL(const GURL& url) {
1365 // about:ipc is currently buggy, so we disable it for official builds. 1406 // about:ipc is currently buggy, so we disable it for official builds.
1366 #if !defined(OFFICIAL_BUILD) 1407 #if !defined(OFFICIAL_BUILD)
1367 1408
1368 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED) 1409 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED)
1369 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) { 1410 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) {
1370 // Run the dialog. This will re-use the existing one if it's already up. 1411 // Run the dialog. This will re-use the existing one if it's already up.
1371 browser::ShowAboutIPCDialog(); 1412 browser::ShowAboutIPCDialog();
1372 return true; 1413 return true;
1373 } 1414 }
1374 #endif 1415 #endif
1375 1416
1376 #endif // OFFICIAL_BUILD 1417 #endif // OFFICIAL_BUILD
1377 1418
1378 return false; 1419 return false;
1379 } 1420 }
1380 1421
1381 std::vector<std::string> AboutPaths() { 1422 std::vector<std::string> AboutPaths() {
1382 std::vector<std::string> paths; 1423 std::vector<std::string> paths;
1383 paths.reserve(arraysize(kAllAboutPaths)); 1424 paths.reserve(arraysize(kAllAboutPaths));
1384 for (size_t i = 0; i < arraysize(kAllAboutPaths); i++) 1425 for (size_t i = 0; i < arraysize(kAllAboutPaths); i++)
1385 paths.push_back(kAllAboutPaths[i]); 1426 paths.push_back(kAllAboutPaths[i]);
1386 return paths; 1427 return paths;
1387 } 1428 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698