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

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

Issue 7215034: Apply CSP to chrome: and about: pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 | « base/tracked_objects.cc ('k') | chrome/browser/browser_resources.grd » ('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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 void AboutTcmallocRendererCallback(base::ProcessId pid, 99 void AboutTcmallocRendererCallback(base::ProcessId pid,
100 const std::string& output) { 100 const std::string& output) {
101 AboutTcmallocOutputs::GetInstance()->RendererCallback(pid, output); 101 AboutTcmallocOutputs::GetInstance()->RendererCallback(pid, output);
102 } 102 }
103 #endif 103 #endif
104 104
105 namespace { 105 namespace {
106 106
107 // Add paths here to be included in chrome://chrome-urls/. 107 // Add paths here to be included in chrome://chrome-urls/.
108 // These paths will also be suggested by BuiltinProvider. 108 // These paths will also be suggested by BuiltinProvider.
109 const char* kChromePaths[] = { 109 const char* const kChromePaths[] = {
110 chrome::kChromeUIAppCacheInternalsHost, 110 chrome::kChromeUIAppCacheInternalsHost,
111 chrome::kChromeUIBlobInternalsHost, 111 chrome::kChromeUIBlobInternalsHost,
112 chrome::kChromeUIChromeURLsHost, 112 chrome::kChromeUIChromeURLsHost,
113 chrome::kChromeUICrashesHost, 113 chrome::kChromeUICrashesHost,
114 chrome::kChromeUICreditsHost, 114 chrome::kChromeUICreditsHost,
115 chrome::kChromeUIDNSHost, 115 chrome::kChromeUIDNSHost,
116 chrome::kChromeUIFlagsHost, 116 chrome::kChromeUIFlagsHost,
117 chrome::kChromeUIFlashHost, 117 chrome::kChromeUIFlashHost,
118 chrome::kChromeUIGpuInternalsHost, 118 chrome::kChromeUIGpuInternalsHost,
119 chrome::kChromeUIHistogramsHost, 119 chrome::kChromeUIHistogramsHost,
(...skipping 18 matching lines...) Expand all
138 #endif 138 #endif
139 #if defined(OS_CHROMEOS) 139 #if defined(OS_CHROMEOS)
140 chrome::kChromeUINetworkHost, 140 chrome::kChromeUINetworkHost,
141 chrome::kChromeUICryptohomeHost, 141 chrome::kChromeUICryptohomeHost,
142 chrome::kChromeUIOSCreditsHost, 142 chrome::kChromeUIOSCreditsHost,
143 #endif 143 #endif
144 }; 144 };
145 145
146 // Debug paths, presented without links in chrome://about. 146 // Debug paths, presented without links in chrome://about.
147 // These paths will not be suggested by BuiltinProvider. 147 // These paths will not be suggested by BuiltinProvider.
148 const char* kDebugChromePaths[] = { 148 const char* const kDebugChromePaths[] = {
149 chrome::kChromeUICrashHost, 149 chrome::kChromeUICrashHost,
150 chrome::kChromeUIKillHost, 150 chrome::kChromeUIKillHost,
151 chrome::kChromeUIHangHost, 151 chrome::kChromeUIHangHost,
152 chrome::kChromeUIShorthangHost, 152 chrome::kChromeUIShorthangHost,
153 chrome::kChromeUIGpuCleanHost, 153 chrome::kChromeUIGpuCleanHost,
154 chrome::kChromeUIGpuCrashHost, 154 chrome::kChromeUIGpuCrashHost,
155 chrome::kChromeUIGpuHangHost 155 chrome::kChromeUIGpuHangHost
156 }; 156 };
157 157
158 // AboutSource handles these chrome:// paths. 158 // AboutSource handles these chrome:// paths.
159 const char *kAboutSourceNames[] = { 159 const char* const kAboutSourceNames[] = {
160 chrome::kChromeUIChromeURLsHost, 160 chrome::kChromeUIChromeURLsHost,
161 chrome::kChromeUICreditsHost, 161 chrome::kChromeUICreditsHost,
162 chrome::kChromeUIDNSHost, 162 chrome::kChromeUIDNSHost,
163 chrome::kChromeUIHistogramsHost, 163 chrome::kChromeUIHistogramsHost,
164 chrome::kChromeUIMemoryHost, 164 chrome::kChromeUIMemoryHost,
165 chrome::kChromeUIMemoryRedirectHost, 165 chrome::kChromeUIMemoryRedirectHost,
166 chrome::kChromeUIStatsHost, 166 chrome::kChromeUIStatsHost,
167 chrome::kChromeUITermsHost, 167 chrome::kChromeUITermsHost,
168 chrome::kChromeUIVersionHost, 168 chrome::kChromeUIVersionHost,
169 #ifdef TRACK_ALL_TASK_OBJECTS 169 #ifdef TRACK_ALL_TASK_OBJECTS
170 chrome::kChromeUITasksHost, 170 chrome::kChromeUITasksHost,
171 #endif 171 #endif
172 #if defined(USE_TCMALLOC) 172 #if defined(USE_TCMALLOC)
173 chrome::kChromeUITCMallocHost, 173 chrome::kChromeUITCMallocHost,
174 #endif 174 #endif
175 #if defined(OS_LINUX) 175 #if defined(OS_LINUX)
176 chrome::kChromeUILinuxProxyConfigHost, 176 chrome::kChromeUILinuxProxyConfigHost,
177 chrome::kChromeUISandboxHost, 177 chrome::kChromeUISandboxHost,
178 #endif 178 #endif
179 #if defined(OS_CHROMEOS) 179 #if defined(OS_CHROMEOS)
180 chrome::kChromeUINetworkHost, 180 chrome::kChromeUINetworkHost,
181 chrome::kChromeUICryptohomeHost, 181 chrome::kChromeUICryptohomeHost,
182 chrome::kChromeUIOSCreditsHost, 182 chrome::kChromeUIOSCreditsHost,
183 #endif 183 #endif
184 }; 184 };
185 185
186 const char kCreditsJsPath[] = "credits.js";
187 const char kMemoryJsPath[] = "memory.js";
188 const char kStatsJsPath[] = "stats.js";
189 const char kStringsJsPath[] = "strings.js";
190 const char kVersionJsPath[] = "version.js";
191
192 } // namespace
jar (doing other things) 2011/06/27 18:50:19 I find this jumping in and out of annonymous names
193
186 class AboutSource : public ChromeURLDataManager::DataSource { 194 class AboutSource : public ChromeURLDataManager::DataSource {
187 public: 195 public:
188 // Construct a data source for the specified |source_name|. 196 // Construct a data source for the specified |source_name|.
189 AboutSource(const std::string& source_name, Profile* profile); 197 AboutSource(const std::string& source_name, Profile* profile);
190 198
191 // Called when the network layer has requested a resource underneath 199 // Called when the network layer has requested a resource underneath
192 // the path we registered. 200 // the path we registered.
193 virtual void StartDataRequest(const std::string& path, 201 virtual void StartDataRequest(const std::string& path,
194 bool is_incognito, 202 bool is_incognito,
195 int request_id) OVERRIDE; 203 int request_id) OVERRIDE;
196 204
197 virtual std::string GetMimeType(const std::string&) const OVERRIDE { 205 virtual std::string GetMimeType(const std::string& path) const OVERRIDE;
198 return "text/html";
199 }
200 206
201 // Send the response data. 207 // Send the response data.
202 void FinishDataRequest(const std::string& html, int request_id); 208 void FinishDataRequest(const std::string& html, int request_id);
203 209
204 Profile* profile() { return profile_; } 210 Profile* profile() { return profile_; }
205 211
206 private: 212 private:
207 virtual ~AboutSource(); 213 virtual ~AboutSource();
208 214
209 Profile* profile_; 215 Profile* profile_;
210 216
211 DISALLOW_COPY_AND_ASSIGN(AboutSource); 217 DISALLOW_COPY_AND_ASSIGN(AboutSource);
212 }; 218 };
213 219
220 namespace {
221
214 // Register a data source for a known source name. Safe to call multiple times. 222 // Register a data source for a known source name. Safe to call multiple times.
215 // |name| may be an unkown host (e.g. "chrome://foo/"); only handle known hosts. 223 // |name| may be an unkown host (e.g. "chrome://foo/"); only handle known hosts.
216 void InitializeAboutDataSource(const std::string& name, Profile* profile) { 224 void InitializeAboutDataSource(const std::string& name, Profile* profile) {
217 ChromeURLDataManager* manager = profile->GetChromeURLDataManager(); 225 ChromeURLDataManager* manager = profile->GetChromeURLDataManager();
218 for (size_t i = 0; i < arraysize(kAboutSourceNames); i++) { 226 for (size_t i = 0; i < arraysize(kAboutSourceNames); i++) {
219 if (name == kAboutSourceNames[i]) { 227 if (name == kAboutSourceNames[i]) {
220 manager->AddDataSource(new AboutSource(name, profile)); 228 manager->AddDataSource(new AboutSource(name, profile));
221 return; 229 return;
222 } 230 }
223 } 231 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 360
353 std::string contents_; 361 std::string contents_;
354 362
355 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); 363 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler);
356 }; 364 };
357 365
358 #endif 366 #endif
359 367
360 // Individual about handlers --------------------------------------------------- 368 // Individual about handlers ---------------------------------------------------
361 369
370 namespace {
371
372 void AppendHeader(std::string* output, int refresh,
373 const std::string& unescaped_title) {
374 output->append("<!DOCTYPE HTML>\n<html>\n<head>\n");
375 if (!unescaped_title.empty()) {
376 output->append("<title>");
377 output->append(EscapeForHTML(unescaped_title));
378 output->append("</title>\n");
379 }
380 output->append(
381 "<meta charset=\"utf-8\">\n<meta http-equiv=\"X-WebKit-CSP\" "
382 "content=\"object-src 'none'; script-src 'self' 'unsafe-eval'\">\n");
383 if (refresh > 0) {
384 output->append("<meta http-equiv=\"refresh\" content=\"");
385 output->append(base::IntToString(refresh));
386 output->append("\"/>\n");
387 }
388 }
389
390 void AppendBody(std::string *output) {
391 output->append("</head>\n<body>\n");
392 }
393
394 void AppendFooter(std::string *output) {
395 output->append("</body>\n</html>\n");
396 }
397
362 std::string ChromeURLs() { 398 std::string ChromeURLs() {
363 std::string html("<html><head><title>Chrome URLs</title></head>\n" 399 std::string html;
364 "<body><h2>List of Chrome URLs</h2>\n<ul>"); 400 AppendHeader(&html, 0, "Chrome URLs");
401 AppendBody(&html);
402 html += "<h2>List of Chrome URLs</h2>\n<ul>\n";
365 std::vector<std::string> paths(ChromePaths()); 403 std::vector<std::string> paths(ChromePaths());
366 for (std::vector<std::string>::const_iterator i = paths.begin(); 404 for (std::vector<std::string>::const_iterator i = paths.begin();
367 i != paths.end(); ++i) 405 i != paths.end(); ++i)
368 html += "<li><a href='chrome://" + *i + "/'>chrome://" + *i + "</a></li>\n"; 406 html += "<li><a href='chrome://" + *i + "/'>chrome://" + *i + "</a></li>\n";
369 html += "</ul>\n<h2>For Debug</h2>\n" 407 html += "</ul>\n<h2>For Debug</h2>\n"
370 "<p>The following pages are for debugging purposes only. Because they " 408 "<p>The following pages are for debugging purposes only. Because they "
371 "crash or hang the renderer, they're not linked directly; you can type " 409 "crash or hang the renderer, they're not linked directly; you can type "
372 "them into the address bar if you need them.</p>\n<ul>"; 410 "them into the address bar if you need them.</p>\n<ul>";
373 for (size_t i = 0; i < arraysize(kDebugChromePaths); i++) 411 for (size_t i = 0; i < arraysize(kDebugChromePaths); i++)
374 html += "<li>chrome://" + std::string(kDebugChromePaths[i]) + "</li>\n"; 412 html += "<li>chrome://" + std::string(kDebugChromePaths[i]) + "</li>\n";
375 html += "</ul>\n</body></html>"; 413 html += "</ul>\n";
414 AppendFooter(&html);
376 return html; 415 return html;
377 } 416 }
378 417
379 #if defined(OS_CHROMEOS) 418 #if defined(OS_CHROMEOS)
380 419
381 namespace {
382 // Html output helper functions 420 // Html output helper functions
383 // TODO(stevenjb): L10N this. 421 // TODO(stevenjb): L10N this.
384 422
385 // Helper function to wrap Html with <th> tag. 423 // Helper function to wrap Html with <th> tag.
386 std::string WrapWithTH(const std::string& text) { 424 std::string WrapWithTH(const std::string& text) {
387 return "<th>" + text + "</th>"; 425 return "<th>" + text + "</th>";
388 } 426 }
389 427
390 // Helper function to wrap Html with <td> tag. 428 // Helper function to wrap Html with <td> tag.
391 std::string WrapWithTD(const std::string& text) { 429 std::string WrapWithTD(const std::string& text) {
392 return "<td>" + text + "</td>"; 430 return "<td>" + text + "</td>";
393 } 431 }
394 432
395 // Helper function to wrap Html with <tr> tag. 433 // Helper function to wrap Html with <tr> tag.
396 std::string WrapWithTR(const std::string& text) { 434 std::string WrapWithTR(const std::string& text) {
397 return "<tr>" + text + "</tr>"; 435 return "<tr>" + text + "</tr>";
398 } 436 }
399 437
400 std::string AboutHeader(int refresh, const std::string& name) { 438 void AppendRefresh(std::string *output, int refresh, const std::string& name) {
401 std::string output;
402 output.append("<head>");
403 output.append("<title>About " + name + "</title>");
404 if (refresh > 0)
405 output.append("<meta http-equiv=\"refresh\" content=\"" +
406 base::IntToString(refresh) + "\"/>");
407 output.append("</head>");
408 return output;
409 }
410
411 std::string AboutRefresh(int refresh, const std::string& name) {
412 std::string output;
413 if (refresh > 0) { 439 if (refresh > 0) {
414 output.append("(Auto-refreshing page every " + 440 output->append("(Auto-refreshing page every ");
415 base::IntToString(refresh) + "s)"); 441 output->append(base::IntToString(refresh));
442 output->append("s)");
416 } else { 443 } else {
417 output.append("(To auto-refresh this page: about:" + name 444 output->append("(To auto-refresh this page: about:");
418 + "/&lt;secs&gt;)"); 445 output->append(name);
446 output->append("/&lt;secs&gt;)");
419 } 447 }
420 return output;
421 } 448 }
422 449
423 // Helper function to create an Html table header for a Network. 450 // Helper function to create an Html table header for a Network.
424 std::string ToHtmlTableHeader(const chromeos::Network* network) { 451 std::string ToHtmlTableHeader(const chromeos::Network* network) {
425 std::string str = 452 std::string str =
426 WrapWithTH("Name") + 453 WrapWithTH("Name") +
427 WrapWithTH("Active") + 454 WrapWithTH("Active") +
428 WrapWithTH("State"); 455 WrapWithTH("State");
429 if (network->type() == chromeos::TYPE_WIFI || 456 if (network->type() == chromeos::TYPE_WIFI ||
430 network->type() == chromeos::TYPE_CELLULAR) { 457 network->type() == chromeos::TYPE_CELLULAR) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 519 }
493 str += WrapWithTD(network->failed() ? network->GetErrorString() : ""); 520 str += WrapWithTD(network->failed() ? network->GetErrorString() : "");
494 str += WrapWithTD(network->ip_address()); 521 str += WrapWithTD(network->ip_address());
495 return WrapWithTR(str); 522 return WrapWithTR(str);
496 } 523 }
497 524
498 std::string GetNetworkHtmlInfo(int refresh) { 525 std::string GetNetworkHtmlInfo(int refresh) {
499 chromeos::NetworkLibrary* cros = 526 chromeos::NetworkLibrary* cros =
500 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 527 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
501 std::string output; 528 std::string output;
502 output.append("<html>"); 529 AppendHeader(&output, refresh, "About Network");
503 output.append(AboutHeader(refresh, "Network")); 530 AppendBody(&output);
504 output.append("<body>"); 531 AppendRefresh(&output, refresh, "network");
505 output.append(AboutRefresh(refresh, "network"));
506 532
507 if (cros->ethernet_enabled()) { 533 if (cros->ethernet_enabled()) {
508 output.append("<h3>Ethernet:</h3><table border=1>"); 534 output.append("<h3>Ethernet:</h3><table border=1>");
509 const chromeos::EthernetNetwork* ethernet = cros->ethernet_network(); 535 const chromeos::EthernetNetwork* ethernet = cros->ethernet_network();
510 if (ethernet) { 536 if (ethernet) {
511 output.append(ToHtmlTableHeader(ethernet)); 537 output.append(ToHtmlTableHeader(ethernet));
512 output.append(ToHtmlTableRow(ethernet)); 538 output.append(ToHtmlTableRow(ethernet));
513 } 539 }
514 } 540 }
515 541
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 const chromeos::WifiNetworkVector& remembered_wifi_networks = 577 const chromeos::WifiNetworkVector& remembered_wifi_networks =
552 cros->remembered_wifi_networks(); 578 cros->remembered_wifi_networks();
553 for (size_t i = 0; i < remembered_wifi_networks.size(); ++i) { 579 for (size_t i = 0; i < remembered_wifi_networks.size(); ++i) {
554 if (i == 0) 580 if (i == 0)
555 output.append( 581 output.append(
556 ToHtmlTableHeader(remembered_wifi_networks[i])); 582 ToHtmlTableHeader(remembered_wifi_networks[i]));
557 output.append(ToHtmlTableRow(remembered_wifi_networks[i])); 583 output.append(ToHtmlTableRow(remembered_wifi_networks[i]));
558 } 584 }
559 } 585 }
560 586
561 output.append("</table></body></html>"); 587 output.append("</table>");
588 AppendFooter(&output);
562 return output; 589 return output;
563 } 590 }
564 591
565 std::string AboutNetwork(const std::string& query) { 592 std::string AboutNetwork(const std::string& query) {
566 int refresh; 593 int refresh;
567 base::StringToInt(query, &refresh); 594 base::StringToInt(query, &refresh);
568 return GetNetworkHtmlInfo(refresh); 595 return GetNetworkHtmlInfo(refresh);
569 } 596 }
570 597
571 std::string AddBoolRow(const std::string& name, bool value) { 598 std::string AddBoolRow(const std::string& name, bool value) {
572 std::string row; 599 std::string row;
573 row.append(WrapWithTD(name)); 600 row.append(WrapWithTD(name));
574 row.append(WrapWithTD(value ? "true" : "false")); 601 row.append(WrapWithTD(value ? "true" : "false"));
575 return WrapWithTR(row); 602 return WrapWithTR(row);
576 } 603 }
577 604
578 std::string AddStringRow(const std::string& name, const std::string& value) { 605 std::string AddStringRow(const std::string& name, const std::string& value) {
579 std::string row; 606 std::string row;
580 row.append(WrapWithTD(name)); 607 row.append(WrapWithTD(name));
581 row.append(WrapWithTD(value)); 608 row.append(WrapWithTD(value));
582 return WrapWithTR(row); 609 return WrapWithTR(row);
583 } 610 }
584 611
585 std::string GetCryptohomeHtmlInfo(int refresh) { 612 std::string GetCryptohomeHtmlInfo(int refresh) {
586 chromeos::CryptohomeLibrary* cryptohome = 613 chromeos::CryptohomeLibrary* cryptohome =
587 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); 614 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary();
588 std::string output; 615 std::string output;
589 output.append("<html>"); 616 AppendHeader(&output, refresh, "About Cryptohome");
590 output.append(AboutHeader(refresh, "Cryptohome")); 617 AppendBody(&output);
591 output.append("<body>"); 618 AppendRefresh(&output, refresh, "cryptohome");
592 output.append(AboutRefresh(refresh, "cryptohome"));
593 619
594 output.append("<h3>CryptohomeLibrary:</h3>"); 620 output.append("<h3>CryptohomeLibrary:</h3>");
595 output.append("<table>"); 621 output.append("<table>");
596 output.append(AddBoolRow("IsMounted", cryptohome->IsMounted())); 622 output.append(AddBoolRow("IsMounted", cryptohome->IsMounted()));
597 output.append(AddBoolRow("TpmIsReady", cryptohome->TpmIsReady())); 623 output.append(AddBoolRow("TpmIsReady", cryptohome->TpmIsReady()));
598 output.append(AddBoolRow("TpmIsEnabled", cryptohome->TpmIsEnabled())); 624 output.append(AddBoolRow("TpmIsEnabled", cryptohome->TpmIsEnabled()));
599 output.append(AddBoolRow("TpmIsOwned", cryptohome->TpmIsOwned())); 625 output.append(AddBoolRow("TpmIsOwned", cryptohome->TpmIsOwned()));
600 output.append(AddBoolRow("TpmIsBeingOwned", cryptohome->TpmIsBeingOwned())); 626 output.append(AddBoolRow("TpmIsBeingOwned", cryptohome->TpmIsBeingOwned()));
601 output.append(AddBoolRow("Pkcs11IsTpmTokenReady", 627 output.append(AddBoolRow("Pkcs11IsTpmTokenReady",
602 cryptohome->Pkcs11IsTpmTokenReady())); 628 cryptohome->Pkcs11IsTpmTokenReady()));
603 output.append("</table>"); 629 output.append("</table>");
604 630
605 std::string token_name, user_pin; 631 std::string token_name, user_pin;
606 crypto::GetTPMTokenInfo(&token_name, &user_pin); 632 crypto::GetTPMTokenInfo(&token_name, &user_pin);
607 output.append("<h3>crypto:</h3>"); 633 output.append("<h3>crypto:</h3>");
608 output.append("<table>"); 634 output.append("<table>");
609 output.append(AddBoolRow("IsTPMTokenReady", crypto::IsTPMTokenReady())); 635 output.append(AddBoolRow("IsTPMTokenReady", crypto::IsTPMTokenReady()));
610 output.append(AddStringRow("token_name", token_name)); 636 output.append(AddStringRow("token_name", token_name));
611 output.append(AddStringRow("user_pin", std::string(user_pin.length(), '*'))); 637 output.append(AddStringRow("user_pin", std::string(user_pin.length(), '*')));
612 output.append("</table>"); 638 output.append("</table>");
639 AppendFooter(&output);
613 640
614 output.append("</body>");
615 output.append("</html>");
616 return output; 641 return output;
617 } 642 }
618 643
619 std::string AboutCryptohome(const std::string& query) { 644 std::string AboutCryptohome(const std::string& query) {
620 int refresh; 645 int refresh;
621 base::StringToInt(query, &refresh); 646 base::StringToInt(query, &refresh);
622 return GetCryptohomeHtmlInfo(refresh); 647 return GetCryptohomeHtmlInfo(refresh);
623 } 648 }
624 649
650 #endif // OS_CHROMEOS
651
625 } // namespace 652 } // namespace
626 #endif
627 653
628 // AboutDnsHandler bounces the request back to the IO thread to collect 654 // AboutDnsHandler bounces the request back to the IO thread to collect
629 // the DNS information. 655 // the DNS information.
630 class AboutDnsHandler : public base::RefCountedThreadSafe<AboutDnsHandler> { 656 class AboutDnsHandler : public base::RefCountedThreadSafe<AboutDnsHandler> {
631 public: 657 public:
632 static void Start(AboutSource* source, int request_id) { 658 static void Start(AboutSource* source, int request_id) {
633 scoped_refptr<AboutDnsHandler> handler( 659 scoped_refptr<AboutDnsHandler> handler(
634 new AboutDnsHandler(source, request_id)); 660 new AboutDnsHandler(source, request_id));
635 handler->StartOnUIThread(); 661 handler->StartOnUIThread();
636 } 662 }
(...skipping 10 matching lines...) Expand all
647 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 673 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
648 BrowserThread::PostTask( 674 BrowserThread::PostTask(
649 BrowserThread::IO, FROM_HERE, 675 BrowserThread::IO, FROM_HERE,
650 NewRunnableMethod(this, &AboutDnsHandler::StartOnIOThread)); 676 NewRunnableMethod(this, &AboutDnsHandler::StartOnIOThread));
651 } 677 }
652 678
653 void StartOnIOThread() { 679 void StartOnIOThread() {
654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 680 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
655 681
656 std::string data; 682 std::string data;
683 AppendHeader(&data, 0, "About DNS");
684 AppendBody(&data);
657 chrome_browser_net::PredictorGetHtmlInfo(&data); 685 chrome_browser_net::PredictorGetHtmlInfo(&data);
686 AppendFooter(&data);
658 687
659 BrowserThread::PostTask( 688 BrowserThread::PostTask(
660 BrowserThread::UI, FROM_HERE, 689 BrowserThread::UI, FROM_HERE,
661 NewRunnableMethod(this, &AboutDnsHandler::FinishOnUIThread, data)); 690 NewRunnableMethod(this, &AboutDnsHandler::FinishOnUIThread, data));
662 } 691 }
663 692
664 void FinishOnUIThread(const std::string& data) { 693 void FinishOnUIThread(const std::string& data) {
665 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
666 source_->FinishDataRequest(data, request_id_); 695 source_->FinishDataRequest(data, request_id_);
667 } 696 }
668 697
669 // Where the results are fed to. 698 // Where the results are fed to.
670 scoped_refptr<AboutSource> source_; 699 scoped_refptr<AboutSource> source_;
671 700
672 // ID identifying the request. 701 // ID identifying the request.
673 int request_id_; 702 int request_id_;
674 703
675 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler); 704 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler);
676 }; 705 };
677 706
678 #if defined(USE_TCMALLOC) 707 #if defined(USE_TCMALLOC)
679 std::string AboutTcmalloc() { 708 std::string AboutTcmalloc() {
680 std::string data; 709 std::string data;
681 AboutTcmallocOutputsType* outputs = 710 AboutTcmallocOutputsType* outputs =
682 AboutTcmallocOutputs::GetInstance()->outputs(); 711 AboutTcmallocOutputs::GetInstance()->outputs();
683 712
684 // Display any stats for which we sent off requests the last time. 713 // Display any stats for which we sent off requests the last time.
685 data.append("<html><head><title>About tcmalloc</title></head><body>\n"); 714 AppendHeader(&data, 0, "About tcmalloc");
715 AppendBody(&data);
686 data.append("<p>Stats as of last page load;"); 716 data.append("<p>Stats as of last page load;");
687 data.append("reload to get stats as of this page load.</p>\n"); 717 data.append("reload to get stats as of this page load.</p>\n");
688 data.append("<table width=\"100%\">\n"); 718 data.append("<table width=\"100%\">\n");
689 for (AboutTcmallocOutputsType::const_iterator oit = outputs->begin(); 719 for (AboutTcmallocOutputsType::const_iterator oit = outputs->begin();
690 oit != outputs->end(); 720 oit != outputs->end();
691 oit++) { 721 oit++) {
692 data.append("<tr><td bgcolor=\"yellow\">"); 722 data.append("<tr><td bgcolor=\"yellow\">");
693 data.append(oit->first); 723 data.append(oit->first);
694 data.append("</td></tr>\n"); 724 data.append("</td></tr>\n");
695 data.append("<tr><td><pre>\n"); 725 data.append("<tr><td><pre>\n");
696 data.append(oit->second); 726 data.append(oit->second);
697 data.append("</pre></td></tr>\n"); 727 data.append("</pre></td></tr>\n");
698 } 728 }
699 data.append("</table>\n"); 729 data.append("</table>\n");
700 data.append("</body></html>\n"); 730 AppendFooter(&data);
701 731
702 // Reset our collector singleton. 732 // Reset our collector singleton.
703 outputs->clear(); 733 outputs->clear();
704 734
705 // Populate the collector with stats from the local browser process 735 // Populate the collector with stats from the local browser process
706 // and send off requests to all the renderer processes. 736 // and send off requests to all the renderer processes.
707 char buffer[1024 * 32]; 737 char buffer[1024 * 32];
708 MallocExtension::instance()->GetStats(buffer, sizeof(buffer)); 738 MallocExtension::instance()->GetStats(buffer, sizeof(buffer));
709 std::string browser("Browser"); 739 std::string browser("Browser");
710 AboutTcmallocOutputs::GetInstance()->SetOutput(browser, buffer); 740 AboutTcmallocOutputs::GetInstance()->SetOutput(browser, buffer);
711 RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); 741 RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
712 while (!it.IsAtEnd()) { 742 while (!it.IsAtEnd()) {
713 it.GetCurrentValue()->Send(new ViewMsg_GetRendererTcmalloc); 743 it.GetCurrentValue()->Send(new ViewMsg_GetRendererTcmalloc);
714 it.Advance(); 744 it.Advance();
715 } 745 }
716 746
717 return data; 747 return data;
718 } 748 }
719 #endif 749 #endif
720 750
721 std::string AboutHistograms(const std::string& query) { 751 std::string AboutHistograms(const std::string& query) {
722 TimeDelta wait_time = TimeDelta::FromMilliseconds(10000); 752 TimeDelta wait_time = TimeDelta::FromMilliseconds(10000);
723 753
724 HistogramSynchronizer* current_synchronizer = 754 HistogramSynchronizer* current_synchronizer =
725 HistogramSynchronizer::CurrentSynchronizer(); 755 HistogramSynchronizer::CurrentSynchronizer();
726 DCHECK(current_synchronizer != NULL); 756 DCHECK(current_synchronizer != NULL);
727 current_synchronizer->FetchRendererHistogramsSynchronously(wait_time); 757 current_synchronizer->FetchRendererHistogramsSynchronously(wait_time);
728 758
759 std::string unescaped_query;
760 std::string unescaped_title("About Histograms");
761 if (!query.empty()) {
762 unescaped_query = UnescapeURLComponent(query, UnescapeRule::NORMAL);
763 unescaped_title += " - " + unescaped_query;
764 }
765
729 std::string data; 766 std::string data;
730 base::StatisticsRecorder::WriteHTMLGraph(query, &data); 767 AppendHeader(&data, 0, unescaped_title);
768 AppendBody(&data);
769 base::StatisticsRecorder::WriteHTMLGraph(unescaped_query, &data);
770 AppendFooter(&data);
731 return data; 771 return data;
732 } 772 }
733 773
734 void AboutMemory(AboutSource* source, int request_id) { 774 void AboutMemory(const std::string& path, AboutSource* source, int request_id) {
735 // The AboutMemoryHandler cleans itself up, but |StartFetch()| will want the 775 if (path == kStringsJsPath) {
736 // refcount to be greater than 0. 776 // The AboutMemoryHandler cleans itself up, but |StartFetch()| will want the
737 scoped_refptr<AboutMemoryHandler> 777 // refcount to be greater than 0.
738 handler(new AboutMemoryHandler(source, request_id)); 778 scoped_refptr<AboutMemoryHandler>
739 handler->StartFetch(); 779 handler(new AboutMemoryHandler(source, request_id));
780 handler->StartFetch();
781 } else {
782 source->FinishDataRequest(
783 ResourceBundle::GetSharedInstance().GetRawDataResource(
784 path == kMemoryJsPath ? IDR_ABOUT_MEMORY_JS :
785 IDR_ABOUT_MEMORY_HTML).as_string(), request_id);
786 }
740 } 787 }
741 788
742 #ifdef TRACK_ALL_TASK_OBJECTS 789 #ifdef TRACK_ALL_TASK_OBJECTS
743 static std::string AboutObjects(const std::string& query) { 790 static std::string AboutObjects(const std::string& query) {
791 std::string unescaped_title("About Histograms");
792 if (!query.empty()) {
793 unescaped_title += " - ";
794 unescaped_title += UnescapeURLComponent(query, UnescapeRule::NORMAL);
795 }
744 std::string data; 796 std::string data;
797 AppendHeader(&data, 0, unescaped_title);
798 AppendBody(&data);
745 tracked_objects::ThreadData::WriteHTML(query, &data); 799 tracked_objects::ThreadData::WriteHTML(query, &data);
800 AppendFooter(&data);
746 return data; 801 return data;
747 } 802 }
748 #endif // TRACK_ALL_TASK_OBJECTS 803 #endif // TRACK_ALL_TASK_OBJECTS
749 804
750 // Handler for filling in the "about:stats" page, as called by the browser's 805 // Handler for filling in the "about:stats" page, as called by the browser's
751 // About handler processing. 806 // About handler processing.
752 // |query| is roughly the query string of the about:stats URL. 807 // |query| is roughly the query string of the about:stats URL.
753 // Returns a string containing the HTML to render for the about:stats page. 808 // Returns a string containing the HTML to render for the about:stats page.
754 // Conditional Output: 809 // Conditional Output:
755 // if |query| is "json", returns a JSON format of all counters. 810 // if |query| is "json", returns a JSON format of all counters.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 // Store this on the timers list as well. 900 // Store this on the timers list as well.
846 timers->Append(counter); 901 timers->Append(counter);
847 } 902 }
848 break; 903 break;
849 default: 904 default:
850 NOTREACHED(); 905 NOTREACHED();
851 } 906 }
852 } 907 }
853 908
854 std::string data; 909 std::string data;
855 if (query == "json") { 910 if (query == "json" || query == kStringsJsPath) {
856 base::JSONWriter::WriteWithOptionalEscape(&root, true, false, &data); 911 base::JSONWriter::WriteWithOptionalEscape(&root, true, false, &data);
912 if (query == kStringsJsPath)
913 data = "var templateData = " + data + ";";
857 } else if (query == "raw") { 914 } else if (query == "raw") {
858 // Dump the raw counters which have changed in text format. 915 // Dump the raw counters which have changed in text format.
859 data = "<pre>"; 916 data = "<pre>";
860 data.append(StringPrintf("Counter changes in the last %ldms\n", 917 data.append(StringPrintf("Counter changes in the last %ldms\n",
861 static_cast<long int>(time_since_last_sample.InMilliseconds()))); 918 static_cast<long int>(time_since_last_sample.InMilliseconds())));
862 for (size_t i = 0; i < counters->GetSize(); ++i) { 919 for (size_t i = 0; i < counters->GetSize(); ++i) {
863 Value* entry = NULL; 920 Value* entry = NULL;
864 bool rv = counters->Get(i, &entry); 921 bool rv = counters->Get(i, &entry);
865 if (!rv) 922 if (!rv)
866 continue; // None of these should fail. 923 continue; // None of these should fail.
(...skipping 12 matching lines...) Expand all
879 if (!rv) 936 if (!rv)
880 continue; 937 continue;
881 data.append(name); 938 data.append(name);
882 data.append(":"); 939 data.append(":");
883 data.append(base::IntToString(delta)); 940 data.append(base::IntToString(delta));
884 data.append("\n"); 941 data.append("\n");
885 } 942 }
886 } 943 }
887 data.append("</pre>"); 944 data.append("</pre>");
888 } else { 945 } else {
889 // Get about_stats.html and process a pretty page. 946 // Get about_stats.html/js from resource bundle.
890 static const base::StringPiece stats_html( 947 data = ResourceBundle::GetSharedInstance().GetRawDataResource(
891 ResourceBundle::GetSharedInstance().GetRawDataResource( 948 (query == kStatsJsPath ? IDR_ABOUT_STATS_JS : IDR_ABOUT_STATS_HTML)).
892 IDR_ABOUT_STATS_HTML)); 949 as_string();
893 950
894 // Create jstemplate and return. 951 if (query != kStatsJsPath) {
895 data = jstemplate_builder::GetTemplateHtml( 952 // Clear the timer list since we stored the data in the timers list
896 stats_html, &root, "t" /* template root node id */); 953 // as well.
897 954 for (int index = static_cast<int>(timers->GetSize())-1; index >= 0;
898 // Clear the timer list since we stored the data in the timers list as well. 955 index--) {
899 for (int index = static_cast<int>(timers->GetSize())-1; index >= 0; 956 Value* value;
900 index--) { 957 timers->Remove(index, &value);
901 Value* value; 958 // We don't care about the value pointer; it's still tracked
902 timers->Remove(index, &value); 959 // on the counters list.
903 // We don't care about the value pointer; it's still tracked 960 }
904 // on the counters list.
905 } 961 }
906 } 962 }
907 963
908 return data; 964 return data;
909 } 965 }
910 966
911 #if defined(OS_LINUX) 967 #if defined(OS_LINUX)
912 std::string AboutLinuxProxyConfig() { 968 std::string AboutLinuxProxyConfig() {
913 std::string data; 969 std::string data;
914 data.append("<!DOCTYPE HTML>\n"); 970 AppendHeader(&data, 0,
915 data.append("<html><head><meta charset=\"utf-8\"><title>"); 971 l10n_util::GetStringUTF8(IDS_ABOUT_LINUX_PROXY_CONFIG_TITLE));
916 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_LINUX_PROXY_CONFIG_TITLE));
917 data.append("</title>");
918 data.append("<style>body { max-width: 70ex; padding: 2ex 5ex; }</style>"); 972 data.append("<style>body { max-width: 70ex; padding: 2ex 5ex; }</style>");
919 data.append("</head><body>\n"); 973 AppendBody(&data);
920 FilePath binary = CommandLine::ForCurrentProcess()->GetProgram(); 974 FilePath binary = CommandLine::ForCurrentProcess()->GetProgram();
921 data.append(l10n_util::GetStringFUTF8( 975 data.append(l10n_util::GetStringFUTF8(
922 IDS_ABOUT_LINUX_PROXY_CONFIG_BODY, 976 IDS_ABOUT_LINUX_PROXY_CONFIG_BODY,
923 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), 977 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
924 ASCIIToUTF16(binary.BaseName().value()))); 978 ASCIIToUTF16(binary.BaseName().value())));
925 data.append("</body></html>\n"); 979 AppendFooter(&data);
926 return data; 980 return data;
927 } 981 }
928 982
929 void AboutSandboxRow(std::string* data, const std::string& prefix, int name_id, 983 void AboutSandboxRow(std::string* data, const std::string& prefix, int name_id,
930 bool good) { 984 bool good) {
931 data->append("<tr><td>"); 985 data->append("<tr><td>");
932 data->append(prefix); 986 data->append(prefix);
933 data->append(l10n_util::GetStringUTF8(name_id)); 987 data->append(l10n_util::GetStringUTF8(name_id));
934 if (good) { 988 if (good) {
935 data->append("</td><td style=\"color: green;\">"); 989 data->append("</td><td style=\"color: green;\">");
936 data->append( 990 data->append(
937 l10n_util::GetStringUTF8(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL)); 991 l10n_util::GetStringUTF8(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL));
938 } else { 992 } else {
939 data->append("</td><td style=\"color: red;\">"); 993 data->append("</td><td style=\"color: red;\">");
940 data->append( 994 data->append(
941 l10n_util::GetStringUTF8(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)); 995 l10n_util::GetStringUTF8(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL));
942 } 996 }
943 data->append("</td></tr>"); 997 data->append("</td></tr>");
944 } 998 }
945 999
946 std::string AboutSandbox() { 1000 std::string AboutSandbox() {
947 std::string data; 1001 std::string data;
948 data.append("<!DOCTYPE HTML>\n"); 1002 AppendHeader(&data, 0, l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_TITLE));
949 data.append("<html><head><meta charset=\"utf-8\"><title>"); 1003 AppendBody(&data);
950 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_TITLE));
951 data.append("</title>");
952 data.append("</head><body>\n");
953 data.append("<h1>"); 1004 data.append("<h1>");
954 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_TITLE)); 1005 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_TITLE));
955 data.append("</h1>"); 1006 data.append("</h1>");
956 1007
957 const int status = ZygoteHost::GetInstance()->sandbox_status(); 1008 const int status = ZygoteHost::GetInstance()->sandbox_status();
958 1009
959 data.append("<table>"); 1010 data.append("<table>");
960 1011
961 AboutSandboxRow(&data, "", IDS_ABOUT_SANDBOX_SUID_SANDBOX, 1012 AboutSandboxRow(&data, "", IDS_ABOUT_SANDBOX_SUID_SANDBOX,
962 status & ZygoteHost::kSandboxSUID); 1013 status & ZygoteHost::kSandboxSUID);
(...skipping 11 matching lines...) Expand all
974 (status & ZygoteHost::kSandboxSeccomp); 1025 (status & ZygoteHost::kSandboxSeccomp);
975 if (good) { 1026 if (good) {
976 data.append("<p style=\"color: green\">"); 1027 data.append("<p style=\"color: green\">");
977 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_OK)); 1028 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_OK));
978 } else { 1029 } else {
979 data.append("<p style=\"color: red\">"); 1030 data.append("<p style=\"color: red\">");
980 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD)); 1031 data.append(l10n_util::GetStringUTF8(IDS_ABOUT_SANDBOX_BAD));
981 } 1032 }
982 data.append("</p>"); 1033 data.append("</p>");
983 1034
984 data.append("</body></html>\n"); 1035 AppendFooter(&data);
985 return data; 1036 return data;
986 } 1037 }
987 #endif 1038 #endif
988 1039
989 std::string AboutVersion(DictionaryValue* localized_strings, Profile* profile) { 1040 std::string AboutVersionStaticContent(const std::string& query) {
1041 return ResourceBundle::GetSharedInstance().GetRawDataResource(
1042 query == kVersionJsPath ?
1043 IDR_ABOUT_VERSION_JS :
1044 IDR_ABOUT_VERSION_HTML).as_string();
1045 }
1046
1047 std::string AboutVersionStrings(DictionaryValue* localized_strings,
1048 Profile* profile) {
990 localized_strings->SetString("title", 1049 localized_strings->SetString("title",
991 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_TITLE)); 1050 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_TITLE));
992 chrome::VersionInfo version_info; 1051 chrome::VersionInfo version_info;
993 1052
994 std::string webkit_version = webkit_glue::GetWebKitVersion(); 1053 std::string webkit_version = webkit_glue::GetWebKitVersion();
995 #ifdef CHROME_V8 1054 #ifdef CHROME_V8
996 std::string js_version(v8::V8::GetVersion()); 1055 std::string js_version(v8::V8::GetVersion());
997 std::string js_engine = "V8"; 1056 std::string js_engine = "V8";
998 #else 1057 #else
999 std::string js_version = webkit_version; 1058 std::string js_version = webkit_version;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 localized_strings->SetString("profile_path", profile_path.value()); 1138 localized_strings->SetString("profile_path", profile_path.value());
1080 } else { 1139 } else {
1081 localized_strings->SetString("profile_path", 1140 localized_strings->SetString("profile_path",
1082 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND)); 1141 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND));
1083 } 1142 }
1084 } else { 1143 } else {
1085 localized_strings->SetString("profile_path", 1144 localized_strings->SetString("profile_path",
1086 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND)); 1145 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND));
1087 } 1146 }
1088 1147
1089 base::StringPiece version_html( 1148 std::string data;
1090 ResourceBundle::GetSharedInstance().GetRawDataResource( 1149 jstemplate_builder::AppendJsonJS(localized_strings, &data);
1091 IDR_ABOUT_VERSION_HTML)); 1150 return data;
1151 }
1092 1152
1093 return jstemplate_builder::GetTemplatesHtml( 1153 } // namespace
1094 version_html, localized_strings, "t" /* template root node id */);
1095 }
1096 1154
1097 // AboutSource ----------------------------------------------------------------- 1155 // AboutSource -----------------------------------------------------------------
1098 1156
1099 AboutSource::AboutSource(const std::string& source_name, Profile* profile) 1157 AboutSource::AboutSource(const std::string& source_name, Profile* profile)
1100 : DataSource(source_name, MessageLoop::current()), 1158 : DataSource(source_name, MessageLoop::current()),
1101 profile_(profile) { 1159 profile_(profile) {
1102 } 1160 }
1103 1161
1104 AboutSource::~AboutSource() { 1162 AboutSource::~AboutSource() {
1105 } 1163 }
1106 1164
1107 void AboutSource::StartDataRequest(const std::string& path, 1165 void AboutSource::StartDataRequest(const std::string& path,
1108 bool is_incognito, 1166 bool is_incognito,
1109 int request_id) { 1167 int request_id) {
1110 std::string response; 1168 std::string response;
1111 std::string host = source_name(); 1169 std::string host = source_name();
1112 if (host == chrome::kChromeUIDNSHost) { 1170 if (host == chrome::kChromeUIDNSHost) {
1113 AboutDnsHandler::Start(this, request_id); 1171 AboutDnsHandler::Start(this, request_id);
1114 return; 1172 return;
1115 } else if (host == chrome::kChromeUIHistogramsHost) { 1173 } else if (host == chrome::kChromeUIHistogramsHost) {
1116 response = AboutHistograms(path); 1174 response = AboutHistograms(path);
1117 } else if (host == chrome::kChromeUIMemoryHost) { 1175 } else if (host == chrome::kChromeUIMemoryHost) {
1118 response = GetAboutMemoryRedirectResponse(profile()); 1176 response = GetAboutMemoryRedirectResponse(profile());
1119 } else if (host == chrome::kChromeUIMemoryRedirectHost) { 1177 } else if (host == chrome::kChromeUIMemoryRedirectHost) {
1120 AboutMemory(this, request_id); 1178 AboutMemory(path, this, request_id);
1121 return; 1179 return;
1122 #ifdef TRACK_ALL_TASK_OBJECTS 1180 #ifdef TRACK_ALL_TASK_OBJECTS
1123 } else if (host == chrome::kChromeUITasksHost) { 1181 } else if (host == chrome::kChromeUITasksHost) {
1124 response = AboutObjects(path); 1182 response = AboutObjects(path);
1125 #endif 1183 #endif
1126 } else if (host == chrome::kChromeUIStatsHost) { 1184 } else if (host == chrome::kChromeUIStatsHost) {
1127 response = AboutStats(path); 1185 response = AboutStats(path);
1128 #if defined(USE_TCMALLOC) 1186 #if defined(USE_TCMALLOC)
1129 } else if (host == chrome::kChromeUITCMallocHost) { 1187 } else if (host == chrome::kChromeUITCMallocHost) {
1130 response = AboutTcmalloc(); 1188 response = AboutTcmalloc();
1131 #endif 1189 #endif
1132 } else if (host == chrome::kChromeUIVersionHost) { 1190 } else if (host == chrome::kChromeUIVersionHost) {
1191 if (path == kStringsJsPath) {
1133 #if defined(OS_CHROMEOS) 1192 #if defined(OS_CHROMEOS)
1134 new ChromeOSAboutVersionHandler(this, request_id); 1193 new ChromeOSAboutVersionHandler(this, request_id);
1135 return; 1194 return;
1136 #else 1195 #else
1137 DictionaryValue localized_strings; 1196 DictionaryValue localized_strings;
1138 localized_strings.SetString("os_version", ""); 1197 localized_strings.SetString("os_version", "");
1139 response = AboutVersion(&localized_strings, profile_); 1198 response = AboutVersionStrings(&localized_strings, profile_);
1140 #endif 1199 #endif
1200 } else {
1201 response = AboutVersionStaticContent(path);
1202 }
1141 } else if (host == chrome::kChromeUICreditsHost) { 1203 } else if (host == chrome::kChromeUICreditsHost) {
1204 int idr = (path == kCreditsJsPath) ? IDR_CREDITS_JS : IDR_CREDITS_HTML;
1142 response = ResourceBundle::GetSharedInstance().GetRawDataResource( 1205 response = ResourceBundle::GetSharedInstance().GetRawDataResource(
1143 IDR_CREDITS_HTML).as_string(); 1206 idr).as_string();
1144 } else if (host == chrome::kChromeUIChromeURLsHost) { 1207 } else if (host == chrome::kChromeUIChromeURLsHost) {
1145 response = ChromeURLs(); 1208 response = ChromeURLs();
1146 #if defined(OS_CHROMEOS) 1209 #if defined(OS_CHROMEOS)
1147 } else if (host == chrome::kChromeUIOSCreditsHost) { 1210 } else if (host == chrome::kChromeUIOSCreditsHost) {
1148 response = ResourceBundle::GetSharedInstance().GetRawDataResource( 1211 response = ResourceBundle::GetSharedInstance().GetRawDataResource(
1149 IDR_OS_CREDITS_HTML).as_string(); 1212 IDR_OS_CREDITS_HTML).as_string();
1150 } else if (host == chrome::kChromeUINetworkHost) { 1213 } else if (host == chrome::kChromeUINetworkHost) {
1151 response = AboutNetwork(path); 1214 response = AboutNetwork(path);
1152 } else if (host == chrome::kChromeUICryptohomeHost) { 1215 } else if (host == chrome::kChromeUICryptohomeHost) {
1153 response = AboutCryptohome(path); 1216 response = AboutCryptohome(path);
(...skipping 17 matching lines...) Expand all
1171 FinishDataRequest(response, request_id); 1234 FinishDataRequest(response, request_id);
1172 } 1235 }
1173 1236
1174 void AboutSource::FinishDataRequest(const std::string& html, int request_id) { 1237 void AboutSource::FinishDataRequest(const std::string& html, int request_id) {
1175 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 1238 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
1176 html_bytes->data.resize(html.size()); 1239 html_bytes->data.resize(html.size());
1177 std::copy(html.begin(), html.end(), html_bytes->data.begin()); 1240 std::copy(html.begin(), html.end(), html_bytes->data.begin());
1178 SendResponse(request_id, html_bytes); 1241 SendResponse(request_id, html_bytes);
1179 } 1242 }
1180 1243
1244 std::string AboutSource::GetMimeType(const std::string& path) const {
1245 if (path == kCreditsJsPath ||
1246 path == kStatsJsPath ||
1247 path == kStringsJsPath ||
1248 path == kVersionJsPath ||
1249 path == kMemoryJsPath) {
1250 return "application/javascript";
1251 }
1252 return "text/html";
1253 }
1254
1255 namespace {
jar (doing other things) 2011/06/27 18:50:19 Where is the matching curly?
1256
1181 // AboutMemoryHandler ---------------------------------------------------------- 1257 // AboutMemoryHandler ----------------------------------------------------------
1182 1258
1183 // Helper for AboutMemory to bind results from a ProcessMetrics object 1259 // Helper for AboutMemory to bind results from a ProcessMetrics object
1184 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects 1260 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects
1185 // can be used in caller's scope (e.g for appending to a net total). 1261 // can be used in caller's scope (e.g for appending to a net total).
1186 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data, 1262 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data,
1187 ProcessMemoryInformation* info) { 1263 ProcessMemoryInformation* info) {
1188 DCHECK(data && info); 1264 DCHECK(data && info);
1189 1265
1190 // Bind metrics to dictionary. 1266 // Bind metrics to dictionary.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 for (size_t index = 0; index < process.processes.size(); index++) { 1368 for (size_t index = 0; index < process.processes.size(); index++) {
1293 if (process.processes[index].type == ChildProcessInfo::BROWSER_PROCESS) 1369 if (process.processes[index].type == ChildProcessInfo::BROWSER_PROCESS)
1294 BindProcessMetrics(browser_data, &process.processes[index]); 1370 BindProcessMetrics(browser_data, &process.processes[index]);
1295 else 1371 else
1296 AppendProcess(child_data, &process.processes[index]); 1372 AppendProcess(child_data, &process.processes[index]);
1297 } 1373 }
1298 1374
1299 root.SetBoolean("show_other_browsers", 1375 root.SetBoolean("show_other_browsers",
1300 browser_defaults::kShowOtherBrowsersInAboutMemory); 1376 browser_defaults::kShowOtherBrowsersInAboutMemory);
1301 1377
1302 // Get about_memory.html 1378 std::string data;
1303 static const base::StringPiece memory_html( 1379 jstemplate_builder::AppendJsonJS(&root, &data);
1304 ResourceBundle::GetSharedInstance().GetRawDataResource( 1380 source_->FinishDataRequest(data, request_id_);
1305 IDR_ABOUT_MEMORY_HTML));
1306
1307 // Create jstemplate and return.
1308 std::string template_html = jstemplate_builder::GetTemplateHtml(
1309 memory_html, &root, "t" /* template root node id */);
1310
1311 source_->FinishDataRequest(template_html, request_id_);
1312 } 1381 }
1313 1382
1314 #if defined(OS_CHROMEOS) 1383 #if defined(OS_CHROMEOS)
1315 // ChromeOSAboutVersionHandler ----------------------------------------------- 1384 // ChromeOSAboutVersionHandler -----------------------------------------------
1316 1385
1317 ChromeOSAboutVersionHandler::ChromeOSAboutVersionHandler(AboutSource* source, 1386 ChromeOSAboutVersionHandler::ChromeOSAboutVersionHandler(
1318 int request_id) 1387 AboutSource* source,
1388 int request_id)
1319 : source_(source), 1389 : source_(source),
1320 request_id_(request_id) { 1390 request_id_(request_id) {
1321 loader_.EnablePlatformVersions(true); 1391 loader_.EnablePlatformVersions(true);
1322 loader_.GetVersion(&consumer_, 1392 loader_.GetVersion(&consumer_,
1323 NewCallback(this, &ChromeOSAboutVersionHandler::OnVersion), 1393 NewCallback(this, &ChromeOSAboutVersionHandler::OnVersion),
1324 chromeos::VersionLoader::VERSION_FULL); 1394 chromeos::VersionLoader::VERSION_FULL);
1325 } 1395 }
1326 1396
1327 void ChromeOSAboutVersionHandler::OnVersion( 1397 void ChromeOSAboutVersionHandler::OnVersion(
1328 chromeos::VersionLoader::Handle handle, 1398 chromeos::VersionLoader::Handle handle,
1329 std::string version) { 1399 std::string version) {
1330 DictionaryValue localized_strings; 1400 DictionaryValue localized_strings;
1331 localized_strings.SetString("os_version", version); 1401 localized_strings.SetString("os_version", version);
1332 source_->FinishDataRequest(AboutVersion(&localized_strings, 1402 source_->FinishDataRequest(AboutVersionStrings(
1333 source_->profile()), request_id_); 1403 &localized_strings, source_->profile()), request_id_);
1334 1404
1335 // CancelableRequestProvider isn't happy when it's deleted and servicing a 1405 // CancelableRequestProvider isn't happy when it's deleted and servicing a
1336 // task, so we delay the deletion. 1406 // task, so we delay the deletion.
1337 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 1407 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
1338 } 1408 }
1339 1409
1340 #endif 1410 #endif
1341 1411
1342 } // namespace 1412 } // namespace
1343 1413
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 return false; 1485 return false;
1416 } 1486 }
1417 1487
1418 std::vector<std::string> ChromePaths() { 1488 std::vector<std::string> ChromePaths() {
1419 std::vector<std::string> paths; 1489 std::vector<std::string> paths;
1420 paths.reserve(arraysize(kChromePaths)); 1490 paths.reserve(arraysize(kChromePaths));
1421 for (size_t i = 0; i < arraysize(kChromePaths); i++) 1491 for (size_t i = 0; i < arraysize(kChromePaths); i++)
1422 paths.push_back(kChromePaths[i]); 1492 paths.push_back(kChromePaths[i]);
1423 return paths; 1493 return paths;
1424 } 1494 }
OLDNEW
« no previous file with comments | « base/tracked_objects.cc ('k') | chrome/browser/browser_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698