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

Side by Side Diff: chrome/browser/ui/webui/about_ui.cc

Issue 8623001: Move remaining about: handlers to webUI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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/ui/webui/about_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/i18n/number_formatting.h" 16 #include "base/i18n/number_formatting.h"
17 #include "base/json/json_writer.h" 17 #include "base/json/json_writer.h"
18 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
19 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
20 #include "base/metrics/stats_table.h" 20 #include "base/metrics/stats_table.h"
21 #include "base/path_service.h" 21 #include "base/path_service.h"
22 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
23 #include "base/string_piece.h" 23 #include "base/string_piece.h"
24 #include "base/string_util.h" 24 #include "base/string_util.h"
25 #include "base/stringprintf.h" 25 #include "base/stringprintf.h"
26 #include "base/threading/thread.h" 26 #include "base/threading/thread.h"
27 #include "base/utf_string_conversions.h" 27 #include "base/utf_string_conversions.h"
28 #include "base/values.h" 28 #include "base/values.h"
29 #include "chrome/browser/about_flags.h" 29 #include "chrome/browser/about_flags.h"
30 #include "chrome/browser/browser_about_handler.h"
30 #include "chrome/browser/browser_process.h" 31 #include "chrome/browser/browser_process.h"
31 #include "chrome/browser/defaults.h" 32 #include "chrome/browser/defaults.h"
32 #include "chrome/browser/memory_details.h" 33 #include "chrome/browser/memory_details.h"
33 #include "chrome/browser/metrics/histogram_synchronizer.h" 34 #include "chrome/browser/metrics/histogram_synchronizer.h"
34 #include "chrome/browser/net/predictor.h" 35 #include "chrome/browser/net/predictor.h"
35 #include "chrome/browser/net/url_fixer_upper.h" 36 #include "chrome/browser/net/url_fixer_upper.h"
36 #include "chrome/browser/plugin_prefs.h" 37 #include "chrome/browser/plugin_prefs.h"
37 #include "chrome/browser/profiles/profile.h" 38 #include "chrome/browser/profiles/profile.h"
38 #include "chrome/browser/profiles/profile_manager.h" 39 #include "chrome/browser/profiles/profile_manager.h"
39 #include "chrome/browser/ui/browser_dialogs.h" 40 #include "chrome/browser/ui/browser_dialogs.h"
40 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 41 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
41 #include "chrome/common/about_handler.h" 42 #include "chrome/common/about_handler.h"
42 #include "chrome/common/chrome_paths.h" 43 #include "chrome/common/chrome_paths.h"
43 #include "chrome/common/chrome_version_info.h" 44 #include "chrome/common/chrome_version_info.h"
44 #include "chrome/common/jstemplate_builder.h" 45 #include "chrome/common/jstemplate_builder.h"
45 #include "chrome/common/net/gaia/google_service_auth_error.h" 46 #include "chrome/common/net/gaia/google_service_auth_error.h"
46 #include "chrome/common/render_messages.h" 47 #include "chrome/common/render_messages.h"
47 #include "chrome/common/url_constants.h" 48 #include "chrome/common/url_constants.h"
48 #include "content/browser/gpu/gpu_process_host_ui_shim.h" 49 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
49 #include "content/browser/plugin_service.h" 50 #include "content/browser/plugin_service.h"
50 #include "content/browser/renderer_host/render_view_host.h" 51 #include "content/browser/renderer_host/render_view_host.h"
51 #include "content/browser/sensors/sensors_provider.h" 52 #include "content/browser/sensors/sensors_provider.h"
53 #include "content/browser/tab_contents/tab_contents.h"
52 #include "content/public/browser/browser_thread.h" 54 #include "content/public/browser/browser_thread.h"
53 #include "content/public/browser/render_process_host.h" 55 #include "content/public/browser/render_process_host.h"
54 #include "content/public/common/content_client.h" 56 #include "content/public/common/content_client.h"
55 #include "crypto/nss_util.h" 57 #include "crypto/nss_util.h"
56 #include "googleurl/src/gurl.h" 58 #include "googleurl/src/gurl.h"
57 #include "grit/browser_resources.h" 59 #include "grit/browser_resources.h"
58 #include "grit/chromium_strings.h" 60 #include "grit/chromium_strings.h"
59 #include "grit/generated_resources.h" 61 #include "grit/generated_resources.h"
60 #include "grit/locale_settings.h" 62 #include "grit/locale_settings.h"
61 #include "net/base/escape.h" 63 #include "net/base/escape.h"
(...skipping 21 matching lines...) Expand all
83 #endif 85 #endif
84 86
85 #if defined(USE_TCMALLOC) 87 #if defined(USE_TCMALLOC)
86 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" 88 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h"
87 #endif 89 #endif
88 90
89 using base::Time; 91 using base::Time;
90 using base::TimeDelta; 92 using base::TimeDelta;
91 using content::BrowserThread; 93 using content::BrowserThread;
92 94
93 #if defined(USE_TCMALLOC)
94 // static
95 AboutTcmallocOutputs* AboutTcmallocOutputs::GetInstance() {
96 return Singleton<AboutTcmallocOutputs>::get();
97 }
98
99 AboutTcmallocOutputs::AboutTcmallocOutputs() {}
100
101 AboutTcmallocOutputs::~AboutTcmallocOutputs() {}
102
103 // Glue between the callback task and the method in the singleton.
104 void AboutTcmallocRendererCallback(base::ProcessId pid,
105 const std::string& output) {
106 AboutTcmallocOutputs::GetInstance()->RendererCallback(pid, output);
107 }
108 #endif
109
110 namespace { 95 namespace {
111 96
112 // Add paths here to be included in chrome://chrome-urls (about:about).
113 // These paths will also be suggested by BuiltinProvider.
114 const char* const kChromePaths[] = {
115 chrome::kChromeUIAppCacheInternalsHost,
116 chrome::kChromeUIBlobInternalsHost,
117 chrome::kChromeUIBookmarksHost,
118 chrome::kChromeUICacheHost,
119 chrome::kChromeUIChromeURLsHost,
120 chrome::kChromeUICrashesHost,
121 chrome::kChromeUICreditsHost,
122 chrome::kChromeUIDNSHost,
123 chrome::kChromeUIDownloadsHost,
124 chrome::kChromeUIExtensionsHost,
125 chrome::kChromeUIFlagsHost,
126 chrome::kChromeUIFlashHost,
127 chrome::kChromeUIGpuInternalsHost,
128 chrome::kChromeUIHistogramsHost,
129 chrome::kChromeUIHistoryHost,
130 chrome::kChromeUIIPCHost,
131 chrome::kChromeUIMediaInternalsHost,
132 chrome::kChromeUIMemoryHost,
133 chrome::kChromeUINetInternalsHost,
134 chrome::kChromeUINetworkViewCacheHost,
135 chrome::kChromeUINewTabHost,
136 chrome::kChromeUIPluginsHost,
137 chrome::kChromeUIPrintHost,
138 chrome::kChromeUIProfilerHost,
139 chrome::kChromeUIQuotaInternalsHost,
140 chrome::kChromeUISessionsHost,
141 chrome::kChromeUISettingsHost,
142 chrome::kChromeUIStatsHost,
143 chrome::kChromeUISyncInternalsHost,
144 chrome::kChromeUITaskManagerHost,
145 chrome::kChromeUITCMallocHost,
146 chrome::kChromeUITermsHost,
147 chrome::kChromeUITracingHost,
148 chrome::kChromeUIVersionHost,
149 chrome::kChromeUIWorkersHost,
150 #if defined(OS_WIN)
151 chrome::kChromeUIConflictsHost,
152 #endif
153 #if defined(OS_LINUX) || defined(OS_OPENBSD)
154 chrome::kChromeUILinuxProxyConfigHost,
155 chrome::kChromeUISandboxHost,
156 #endif
157 #if defined(OS_CHROMEOS)
158 chrome::kChromeUIActiveDownloadsHost,
159 chrome::kChromeUIChooseMobileNetworkHost,
160 chrome::kChromeUICryptohomeHost,
161 chrome::kChromeUIDiscardsHost,
162 chrome::kChromeUIImageBurnerHost,
163 chrome::kChromeUIKeyboardOverlayHost,
164 chrome::kChromeUILoginHost,
165 chrome::kChromeUINetworkHost,
166 chrome::kChromeUIOobeHost,
167 chrome::kChromeUIOSCreditsHost,
168 chrome::kChromeUIProxySettingsHost,
169 chrome::kChromeUISystemInfoHost,
170 #endif
171 };
172
173 // AboutSource handles these chrome:// paths.
174 const char* const kAboutSourceNames[] = {
175 chrome::kChromeUIChromeURLsHost,
176 chrome::kChromeUICreditsHost,
177 chrome::kChromeUIDNSHost,
178 chrome::kChromeUIHistogramsHost,
179 chrome::kChromeUIMemoryHost,
180 chrome::kChromeUIMemoryRedirectHost,
181 chrome::kChromeUIStatsHost,
182 chrome::kChromeUITaskManagerHost,
183 chrome::kChromeUITermsHost,
184 chrome::kChromeUIVersionHost,
185 #if defined(USE_TCMALLOC)
186 chrome::kChromeUITCMallocHost,
187 #endif
188 #if defined(OS_LINUX) || defined(OS_OPENBSD)
189 chrome::kChromeUILinuxProxyConfigHost,
190 chrome::kChromeUISandboxHost,
191 #endif
192 #if defined(OS_CHROMEOS)
193 chrome::kChromeUICryptohomeHost,
194 chrome::kChromeUIDiscardsHost,
195 chrome::kChromeUINetworkHost,
196 chrome::kChromeUIOSCreditsHost,
197 #endif
198 };
199
200 const char kCreditsJsPath[] = "credits.js"; 97 const char kCreditsJsPath[] = "credits.js";
201 const char kMemoryJsPath[] = "memory.js"; 98 const char kMemoryJsPath[] = "memory.js";
202 const char kStatsJsPath[] = "stats.js"; 99 const char kStatsJsPath[] = "stats.js";
203 const char kStringsJsPath[] = "strings.js"; 100 const char kStringsJsPath[] = "strings.js";
204 const char kVersionJsPath[] = "version.js"; 101 const char kVersionJsPath[] = "version.js";
205 102
206 class AboutSource : public ChromeURLDataManager::DataSource { 103 class AboutSource : public ChromeURLDataManager::DataSource {
207 public: 104 public:
208 // Construct a data source for the specified |source_name|. 105 // Construct a data source for the specified |source_name|.
209 AboutSource(const std::string& source_name, Profile* profile); 106 AboutSource(const std::string& source_name, Profile* profile);
(...skipping 23 matching lines...) Expand all
233 // redirects you to the final page. This avoids the problem where typing 130 // redirects you to the final page. This avoids the problem where typing
234 // "about:memory" on the new tab page or any other page where a process 131 // "about:memory" on the new tab page or any other page where a process
235 // transition would occur to the about URL will cause some confusion. 132 // transition would occur to the about URL will cause some confusion.
236 // 133 //
237 // The problem is that during the processing of the memory page, there are two 134 // The problem is that during the processing of the memory page, there are two
238 // processes active, the original and the destination one. This can create the 135 // processes active, the original and the destination one. This can create the
239 // impression that we're using more resources than we actually are. This 136 // impression that we're using more resources than we actually are. This
240 // redirect solves the problem by eliminating the process transition during the 137 // redirect solves the problem by eliminating the process transition during the
241 // time that about memory is being computed. 138 // time that about memory is being computed.
242 std::string GetAboutMemoryRedirectResponse(Profile* profile) { 139 std::string GetAboutMemoryRedirectResponse(Profile* profile) {
243 InitializeAboutDataSource(chrome::kChromeUIMemoryRedirectHost, profile);
244 return StringPrintf("<meta http-equiv=\"refresh\" content=\"0;%s\">", 140 return StringPrintf("<meta http-equiv=\"refresh\" content=\"0;%s\">",
245 chrome::kChromeUIMemoryRedirectURL); 141 chrome::kChromeUIMemoryRedirectURL);
246 } 142 }
247 143
248 // Handling about:memory is complicated enough to encapsulate its related 144 // Handling about:memory is complicated enough to encapsulate its related
249 // methods into a single class. The user should create it (on the heap) and call 145 // methods into a single class. The user should create it (on the heap) and call
250 // its |StartFetch()| method. 146 // its |StartFetch()| method.
251 class AboutMemoryHandler : public MemoryDetails { 147 class AboutMemoryHandler : public MemoryDetails {
252 public: 148 public:
253 AboutMemoryHandler(AboutSource* source, int request_id) 149 AboutMemoryHandler(AboutSource* source, int request_id)
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 if (path == kCreditsJsPath || 1388 if (path == kCreditsJsPath ||
1493 path == kStatsJsPath || 1389 path == kStatsJsPath ||
1494 path == kStringsJsPath || 1390 path == kStringsJsPath ||
1495 path == kVersionJsPath || 1391 path == kVersionJsPath ||
1496 path == kMemoryJsPath) { 1392 path == kMemoryJsPath) {
1497 return "application/javascript"; 1393 return "application/javascript";
1498 } 1394 }
1499 return "text/html"; 1395 return "text/html";
1500 } 1396 }
1501 1397
1502 // ----------------------------------------------------------------------------- 1398 AboutUI::AboutUI(TabContents* contents, const std::string& name)
1503 1399 : ChromeWebUI(contents) {
1504 void InitializeAboutDataSource(const std::string& name, 1400 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
1505 content::BrowserContext* browser_context) { 1401 ChromeURLDataManager::DataSource* source = new AboutSource(name, profile);
1506 Profile* profile = static_cast<Profile*>(browser_context); 1402 if (source)
1507 ChromeURLDataManager* manager = profile->GetChromeURLDataManager(); 1403 profile->GetChromeURLDataManager()->AddDataSource(source);
1508 for (size_t i = 0; i < arraysize(kAboutSourceNames); i++) {
1509 if (name == kAboutSourceNames[i]) {
1510 manager->AddDataSource(new AboutSource(name, profile));
1511 return;
1512 }
1513 }
1514 } 1404 }
1515
1516 bool WillHandleBrowserAboutURL(GURL* url,
1517 content::BrowserContext* browser_context) {
1518 // TODO(msw): Eliminate "about:*" constants and literals from code and tests,
1519 // then hopefully we can remove this forced fixup.
1520 *url = URLFixerUpper::FixupURL(url->possibly_invalid_spec(), std::string());
1521
1522 // Check that about: URLs are fixed up to chrome: by URLFixerUpper::FixupURL.
1523 DCHECK((*url == GURL(chrome::kAboutBlankURL)) ||
1524 !url->SchemeIs(chrome::kAboutScheme));
1525
1526 // Only handle chrome://foo/, URLFixerUpper::FixupURL translates about:foo.
1527 // TAB_CONTENTS_WEB handles about:blank, which frames are allowed to access.
1528 if (!url->SchemeIs(chrome::kChromeUIScheme))
1529 return false;
1530
1531 // Circumvent processing URLs that the renderer process will handle.
1532 if (chrome_about_handler::WillHandle(*url))
1533 return false;
1534
1535 std::string host(url->host());
1536 std::string path;
1537 // Replace about with chrome-urls.
1538 if (host == chrome::kChromeUIAboutHost)
1539 host = chrome::kChromeUIChromeURLsHost;
1540 // Replace cache with view-http-cache.
1541 if (host == chrome::kChromeUICacheHost) {
1542 host = chrome::kChromeUINetworkViewCacheHost;
1543 // Replace gpu with gpu-internals.
1544 } else if (host == chrome::kChromeUIGpuHost) {
1545 host = chrome::kChromeUIGpuInternalsHost;
1546 // Replace sync with sync-internals (for legacy reasons).
1547 } else if (host == chrome::kChromeUISyncHost) {
1548 host = chrome::kChromeUISyncInternalsHost;
1549 // Redirect chrome://extensions to chrome://settings/extensions.
1550 } else if (host == chrome::kChromeUIExtensionsHost) {
1551 host = chrome::kChromeUISettingsHost;
1552 path = chrome::kExtensionsSubPage;
1553 }
1554 GURL::Replacements replacements;
1555 replacements.SetHostStr(host);
1556 if (!path.empty())
1557 replacements.SetPathStr(path);
1558 *url = url->ReplaceComponents(replacements);
1559
1560 // Handle URLs to crash the browser or wreck the gpu process.
1561 if (host == chrome::kChromeUIBrowserCrashHost) {
1562 // Induce an intentional crash in the browser process.
1563 CHECK(false);
1564 } else if (host == chrome::kChromeUIGpuCleanHost) {
1565 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::FromID(0);
1566 if (shim)
1567 shim->SimulateRemoveAllContext();
1568 } else if (host == chrome::kChromeUIGpuCrashHost) {
1569 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::FromID(0);
1570 if (shim)
1571 shim->SimulateCrash();
1572 } else if (host == chrome::kChromeUIGpuHangHost) {
1573 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::FromID(0);
1574 if (shim)
1575 shim->SimulateHang();
1576 #if defined(OS_CHROMEOS)
1577 } else if (host == chrome::kChromeUIRotateHost) {
1578 sensors::ScreenOrientation change;
1579 std::string query(url->query());
1580 if (query == "left") {
1581 change.upward = sensors::ScreenOrientation::LEFT;
1582 } else if (query == "right") {
1583 change.upward = sensors::ScreenOrientation::RIGHT;
1584 } else if (query == "top") {
1585 change.upward = sensors::ScreenOrientation::TOP;
1586 } else if (query == "bottom") {
1587 change.upward = sensors::ScreenOrientation::BOTTOM;
1588 } else {
1589 NOTREACHED() << "Unknown orientation";
1590 }
1591 sensors::Provider::GetInstance()->ScreenOrientationChanged(change);
1592 // Nothing to communicate to the user, so show a blank page.
1593 host = chrome::kChromeUIBlankHost;
1594 *url = GURL(chrome::kChromeUIBlankHost);
1595 #endif
1596 }
1597
1598 // Initialize any potentially corresponding AboutSource handler.
1599 InitializeAboutDataSource(host, browser_context);
1600 return true;
1601 }
1602
1603 bool HandleNonNavigationAboutURL(const GURL& url) {
1604 // chrome://ipc/ is currently buggy, so we disable it for official builds.
1605 #if !defined(OFFICIAL_BUILD)
1606
1607 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED)
1608 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) {
1609 // Run the dialog. This will re-use the existing one if it's already up.
1610 browser::ShowAboutIPCDialog();
1611 return true;
1612 }
1613 #endif
1614
1615 #endif // OFFICIAL_BUILD
1616
1617 return false;
1618 }
1619
1620 std::vector<std::string> ChromePaths() {
1621 std::vector<std::string> paths;
1622 paths.reserve(arraysize(kChromePaths));
1623 for (size_t i = 0; i < arraysize(kChromePaths); i++)
1624 paths.push_back(kChromePaths[i]);
1625 return paths;
1626 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698