OLD | NEW |
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> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // redirects you to the final page. This avoids the problem where typing | 101 // redirects you to the final page. This avoids the problem where typing |
102 // "about:memory" on the new tab page or any other page where a process | 102 // "about:memory" on the new tab page or any other page where a process |
103 // transition would occur to the about URL will cause some confusion. | 103 // transition would occur to the about URL will cause some confusion. |
104 // | 104 // |
105 // The problem is that during the processing of the memory page, there are two | 105 // The problem is that during the processing of the memory page, there are two |
106 // processes active, the original and the destination one. This can create the | 106 // processes active, the original and the destination one. This can create the |
107 // impression that we're using more resources than we actually are. This | 107 // impression that we're using more resources than we actually are. This |
108 // redirect solves the problem by eliminating the process transition during the | 108 // redirect solves the problem by eliminating the process transition during the |
109 // time that about memory is being computed. | 109 // time that about memory is being computed. |
110 std::string GetAboutMemoryRedirectResponse(Profile* profile) { | 110 std::string GetAboutMemoryRedirectResponse(Profile* profile) { |
111 return StringPrintf("<meta http-equiv=\"refresh\" content=\"0;%s\">", | 111 return base::StringPrintf("<meta http-equiv=\"refresh\" content=\"0;%s\">", |
112 chrome::kChromeUIMemoryRedirectURL); | 112 chrome::kChromeUIMemoryRedirectURL); |
113 } | 113 } |
114 | 114 |
115 // Handling about:memory is complicated enough to encapsulate its related | 115 // Handling about:memory is complicated enough to encapsulate its related |
116 // methods into a single class. The user should create it (on the heap) and call | 116 // methods into a single class. The user should create it (on the heap) and call |
117 // its |StartFetch()| method. | 117 // its |StartFetch()| method. |
118 class AboutMemoryHandler : public MemoryDetails { | 118 class AboutMemoryHandler : public MemoryDetails { |
119 public: | 119 public: |
120 explicit AboutMemoryHandler( | 120 explicit AboutMemoryHandler( |
121 const content::URLDataSource::GotDataCallback& callback) | 121 const content::URLDataSource::GotDataCallback& callback) |
122 : callback_(callback) { | 122 : callback_(callback) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 base::FilePath oem_eula_file_path; | 176 base::FilePath oem_eula_file_path; |
177 if (net::FileURLToFilePath(GURL(customization->GetEULAPage(locale_)), | 177 if (net::FileURLToFilePath(GURL(customization->GetEULAPage(locale_)), |
178 &oem_eula_file_path)) { | 178 &oem_eula_file_path)) { |
179 if (!file_util::ReadFileToString(oem_eula_file_path, &contents_)) { | 179 if (!file_util::ReadFileToString(oem_eula_file_path, &contents_)) { |
180 contents_.clear(); | 180 contents_.clear(); |
181 } | 181 } |
182 } | 182 } |
183 } | 183 } |
184 } else { | 184 } else { |
185 std::string file_path = | 185 std::string file_path = |
186 StringPrintf(chrome::kEULAPathFormat, locale_.c_str()); | 186 base::StringPrintf(chrome::kEULAPathFormat, locale_.c_str()); |
187 if (!file_util::ReadFileToString(base::FilePath(file_path), &contents_)) { | 187 if (!file_util::ReadFileToString(base::FilePath(file_path), &contents_)) { |
188 // No EULA for given language - try en-US as default. | 188 // No EULA for given language - try en-US as default. |
189 file_path = StringPrintf(chrome::kEULAPathFormat, "en-US"); | 189 file_path = base::StringPrintf(chrome::kEULAPathFormat, "en-US"); |
190 if (!file_util::ReadFileToString(base::FilePath(file_path), | 190 if (!file_util::ReadFileToString(base::FilePath(file_path), |
191 &contents_)) { | 191 &contents_)) { |
192 // File with EULA not found, ResponseOnUIThread will load EULA from | 192 // File with EULA not found, ResponseOnUIThread will load EULA from |
193 // resources if contents_ is empty. | 193 // resources if contents_ is empty. |
194 contents_.clear(); | 194 contents_.clear(); |
195 } | 195 } |
196 } | 196 } |
197 } | 197 } |
198 BrowserThread::PostTask( | 198 BrowserThread::PostTask( |
199 BrowserThread::UI, FROM_HERE, | 199 BrowserThread::UI, FROM_HERE, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 row.append(WrapWithTD(name)); | 308 row.append(WrapWithTD(name)); |
309 row.append(WrapWithTD(value)); | 309 row.append(WrapWithTD(value)); |
310 return WrapWithTR(row); | 310 return WrapWithTR(row); |
311 } | 311 } |
312 | 312 |
313 // TODO(stevenjb): L10N AboutDiscards. | 313 // TODO(stevenjb): L10N AboutDiscards. |
314 | 314 |
315 std::string AboutDiscardsRun() { | 315 std::string AboutDiscardsRun() { |
316 std::string output; | 316 std::string output; |
317 AppendHeader(&output, 0, "About discards"); | 317 AppendHeader(&output, 0, "About discards"); |
318 output.append(StringPrintf("<meta http-equiv=\"refresh\" content=\"2;%s\">", | 318 output.append( |
319 chrome::kChromeUIDiscardsURL)); | 319 base::StringPrintf("<meta http-equiv=\"refresh\" content=\"2;%s\">", |
| 320 chrome::kChromeUIDiscardsURL)); |
320 output.append(WrapWithTag("p", "Discarding a tab...")); | 321 output.append(WrapWithTag("p", "Discarding a tab...")); |
321 g_browser_process->oom_priority_manager()->LogMemoryAndDiscardTab(); | 322 g_browser_process->oom_priority_manager()->LogMemoryAndDiscardTab(); |
322 AppendFooter(&output); | 323 AppendFooter(&output); |
323 return output; | 324 return output; |
324 } | 325 } |
325 | 326 |
326 std::string AboutDiscards(const std::string& path) { | 327 std::string AboutDiscards(const std::string& path) { |
327 std::string output; | 328 std::string output; |
328 const char kRunCommand[] = "run"; | 329 const char kRunCommand[] = "run"; |
329 if (path == kRunCommand) | 330 if (path == kRunCommand) |
(...skipping 11 matching lines...) Expand all Loading... |
341 output.append("<ul>"); | 342 output.append("<ul>"); |
342 std::vector<string16>::iterator it = titles.begin(); | 343 std::vector<string16>::iterator it = titles.begin(); |
343 for ( ; it != titles.end(); ++it) { | 344 for ( ; it != titles.end(); ++it) { |
344 std::string title = UTF16ToUTF8(*it); | 345 std::string title = UTF16ToUTF8(*it); |
345 output.append(WrapWithTag("li", title)); | 346 output.append(WrapWithTag("li", title)); |
346 } | 347 } |
347 output.append("</ul>"); | 348 output.append("</ul>"); |
348 } else { | 349 } else { |
349 output.append("<p>None found. Wait 10 seconds, then refresh.</p>"); | 350 output.append("<p>None found. Wait 10 seconds, then refresh.</p>"); |
350 } | 351 } |
351 output.append(StringPrintf("%d discards this session. ", | 352 output.append(base::StringPrintf("%d discards this session. ", |
352 oom->discard_count())); | 353 oom->discard_count())); |
353 output.append(StringPrintf("<a href='%s%s'>Discard tab now</a>", | 354 output.append(base::StringPrintf("<a href='%s%s'>Discard tab now</a>", |
354 chrome::kChromeUIDiscardsURL, | 355 chrome::kChromeUIDiscardsURL, |
355 kRunCommand)); | 356 kRunCommand)); |
356 | 357 |
357 base::SystemMemoryInfoKB meminfo; | 358 base::SystemMemoryInfoKB meminfo; |
358 base::GetSystemMemoryInfo(&meminfo); | 359 base::GetSystemMemoryInfo(&meminfo); |
359 output.append("<h3>System memory information in MB</h3>"); | 360 output.append("<h3>System memory information in MB</h3>"); |
360 output.append("<table>"); | 361 output.append("<table>"); |
361 // Start with summary statistics. | 362 // Start with summary statistics. |
362 output.append(AddStringRow( | 363 output.append(AddStringRow( |
363 "Total", base::IntToString(meminfo.total / 1024))); | 364 "Total", base::IntToString(meminfo.total / 1024))); |
364 output.append(AddStringRow( | 365 output.append(AddStringRow( |
365 "Free", base::IntToString(meminfo.free / 1024))); | 366 "Free", base::IntToString(meminfo.free / 1024))); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 | 398 |
398 // Adds an entry to the chrome://transparency page, with the format: | 399 // Adds an entry to the chrome://transparency page, with the format: |
399 // |label|: | 400 // |label|: |
400 // -- - |value|% + ++ | 401 // -- - |value|% + ++ |
401 // where --, -, +, and ++ are links to change the appropriate |key|. | 402 // where --, -, +, and ++ are links to change the appropriate |key|. |
402 // TODO(jamescook): Remove this temporary tool when we decide what the window | 403 // TODO(jamescook): Remove this temporary tool when we decide what the window |
403 // header opacity should be for Ash. | 404 // header opacity should be for Ash. |
404 std::string TransparencyLink(const std::string& label, | 405 std::string TransparencyLink(const std::string& label, |
405 int value, | 406 int value, |
406 const std::string& key) { | 407 const std::string& key) { |
407 return StringPrintf("<p>%s</p>" | 408 return base::StringPrintf("<p>%s</p>" |
408 "<p>" | 409 "<p>" |
409 "<a href='%s%s=%d'>--</a> " | 410 "<a href='%s%s=%d'>--</a> " |
410 "<a href='%s%s=%d'>-</a> " | 411 "<a href='%s%s=%d'>-</a> " |
411 "%d%% " | 412 "%d%% " |
412 "<a href='%s%s=%d'>+</a> " | 413 "<a href='%s%s=%d'>+</a> " |
413 "<a href='%s%s=%d'>++</a>" | 414 "<a href='%s%s=%d'>++</a>" |
414 "</p>", | 415 "</p>", |
415 label.c_str(), | 416 label.c_str(), |
416 chrome::kChromeUITransparencyURL, key.c_str(), value - 5, | 417 chrome::kChromeUITransparencyURL, key.c_str(), value - 5, |
417 chrome::kChromeUITransparencyURL, key.c_str(), value - 1, | 418 chrome::kChromeUITransparencyURL, key.c_str(), value - 1, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 output.append("<h3>Window header transparency</h3>"); | 467 output.append("<h3>Window header transparency</h3>"); |
467 output.append(TransparencyLink("Active window:", | 468 output.append(TransparencyLink("Active window:", |
468 TransparencyFromOpacity(ash::FramePainter::kActiveWindowOpacity), | 469 TransparencyFromOpacity(ash::FramePainter::kActiveWindowOpacity), |
469 kActive)); | 470 kActive)); |
470 output.append(TransparencyLink("Inactive window:", | 471 output.append(TransparencyLink("Inactive window:", |
471 TransparencyFromOpacity(ash::FramePainter::kInactiveWindowOpacity), | 472 TransparencyFromOpacity(ash::FramePainter::kInactiveWindowOpacity), |
472 kInactive)); | 473 kInactive)); |
473 output.append(TransparencyLink("Solo window:", | 474 output.append(TransparencyLink("Solo window:", |
474 TransparencyFromOpacity(ash::FramePainter::kSoloWindowOpacity), | 475 TransparencyFromOpacity(ash::FramePainter::kSoloWindowOpacity), |
475 kSolo)); | 476 kSolo)); |
476 output.append(StringPrintf( | 477 output.append(base::StringPrintf( |
477 "<p>Share: %s%s=%d&%s=%d&%s=%d</p>", | 478 "<p>Share: %s%s=%d&%s=%d&%s=%d</p>", |
478 chrome::kChromeUITransparencyURL, | 479 chrome::kChromeUITransparencyURL, |
479 kActive, | 480 kActive, |
480 TransparencyFromOpacity(ash::FramePainter::kActiveWindowOpacity), | 481 TransparencyFromOpacity(ash::FramePainter::kActiveWindowOpacity), |
481 kInactive, | 482 kInactive, |
482 TransparencyFromOpacity(ash::FramePainter::kInactiveWindowOpacity), | 483 TransparencyFromOpacity(ash::FramePainter::kInactiveWindowOpacity), |
483 kSolo, | 484 kSolo, |
484 TransparencyFromOpacity(ash::FramePainter::kSoloWindowOpacity))); | 485 TransparencyFromOpacity(ash::FramePainter::kSoloWindowOpacity))); |
485 output.append("<p>Reshape window to force a redraw.</p>"); | 486 output.append("<p>Reshape window to force a redraw.</p>"); |
486 AppendFooter(&output); | 487 AppendFooter(&output); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 base::JSONWriter::WriteWithOptions( | 682 base::JSONWriter::WriteWithOptions( |
682 &root, | 683 &root, |
683 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | | 684 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | |
684 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 685 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
685 &data); | 686 &data); |
686 if (query == kStringsJsPath) | 687 if (query == kStringsJsPath) |
687 data = "var templateData = " + data + ";"; | 688 data = "var templateData = " + data + ";"; |
688 } else if (query == "raw") { | 689 } else if (query == "raw") { |
689 // Dump the raw counters which have changed in text format. | 690 // Dump the raw counters which have changed in text format. |
690 data = "<pre>"; | 691 data = "<pre>"; |
691 data.append(StringPrintf("Counter changes in the last %ldms\n", | 692 data.append(base::StringPrintf("Counter changes in the last %ldms\n", |
692 static_cast<long int>(time_since_last_sample.InMilliseconds()))); | 693 static_cast<long int>(time_since_last_sample.InMilliseconds()))); |
693 for (size_t i = 0; i < counters->GetSize(); ++i) { | 694 for (size_t i = 0; i < counters->GetSize(); ++i) { |
694 Value* entry = NULL; | 695 Value* entry = NULL; |
695 bool rv = counters->Get(i, &entry); | 696 bool rv = counters->Get(i, &entry); |
696 if (!rv) | 697 if (!rv) |
697 continue; // None of these should fail. | 698 continue; // None of these should fail. |
698 DictionaryValue* counter = static_cast<DictionaryValue*>(entry); | 699 DictionaryValue* counter = static_cast<DictionaryValue*>(entry); |
699 int delta; | 700 int delta; |
700 rv = counter->GetInteger("delta", &delta); | 701 rv = counter->GetInteger("delta", &delta); |
701 if (!rv) | 702 if (!rv) |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 Profile* profile = Profile::FromWebUI(web_ui); | 1061 Profile* profile = Profile::FromWebUI(web_ui); |
1061 | 1062 |
1062 #if defined(ENABLE_THEMES) | 1063 #if defined(ENABLE_THEMES) |
1063 // Set up the chrome://theme/ source. | 1064 // Set up the chrome://theme/ source. |
1064 ThemeSource* theme = new ThemeSource(profile); | 1065 ThemeSource* theme = new ThemeSource(profile); |
1065 content::URLDataSource::Add(profile, theme); | 1066 content::URLDataSource::Add(profile, theme); |
1066 #endif | 1067 #endif |
1067 | 1068 |
1068 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); | 1069 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); |
1069 } | 1070 } |
OLD | NEW |