OLD | NEW |
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 13 matching lines...) Expand all Loading... |
24 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
25 #include "base/tracked_objects.h" | 25 #include "base/tracked_objects.h" |
26 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
27 #include "base/values.h" | 27 #include "base/values.h" |
28 #include "chrome/browser/about_flags.h" | 28 #include "chrome/browser/about_flags.h" |
29 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/defaults.h" | 30 #include "chrome/browser/defaults.h" |
31 #include "chrome/browser/memory_details.h" | 31 #include "chrome/browser/memory_details.h" |
32 #include "chrome/browser/metrics/histogram_synchronizer.h" | 32 #include "chrome/browser/metrics/histogram_synchronizer.h" |
33 #include "chrome/browser/net/predictor_api.h" | 33 #include "chrome/browser/net/predictor_api.h" |
| 34 #include "chrome/browser/net/url_fixer_upper.h" |
34 #include "chrome/browser/platform_util.h" | 35 #include "chrome/browser/platform_util.h" |
35 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
36 #include "chrome/browser/profiles/profile_manager.h" | 37 #include "chrome/browser/profiles/profile_manager.h" |
37 #include "chrome/browser/ui/browser_dialogs.h" | 38 #include "chrome/browser/ui/browser_dialogs.h" |
38 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 39 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
39 #include "chrome/common/about_handler.h" | 40 #include "chrome/common/about_handler.h" |
40 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" |
41 #include "chrome/common/chrome_version_info.h" | 42 #include "chrome/common/chrome_version_info.h" |
42 #include "chrome/common/jstemplate_builder.h" | 43 #include "chrome/common/jstemplate_builder.h" |
43 #include "chrome/common/net/gaia/google_service_auth_error.h" | 44 #include "chrome/common/net/gaia/google_service_auth_error.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 97 |
97 // Glue between the callback task and the method in the singleton. | 98 // Glue between the callback task and the method in the singleton. |
98 void AboutTcmallocRendererCallback(base::ProcessId pid, | 99 void AboutTcmallocRendererCallback(base::ProcessId pid, |
99 const std::string& output) { | 100 const std::string& output) { |
100 AboutTcmallocOutputs::GetInstance()->RendererCallback(pid, output); | 101 AboutTcmallocOutputs::GetInstance()->RendererCallback(pid, output); |
101 } | 102 } |
102 #endif | 103 #endif |
103 | 104 |
104 namespace { | 105 namespace { |
105 | 106 |
106 // The (alphabetized) paths used for the about pages. | 107 // Add paths here to be included in chrome://chrome-urls/. |
107 // Note: Keep these in sync with url_constants.h | 108 // These paths will also be suggested by BuiltinProvider. |
108 const char kAppCacheInternalsPath[] = "appcache-internals"; | 109 const char *kChromePaths[] = { |
109 const char kBlobInternalsPath[] = "blob-internals"; | 110 chrome::kChromeUIAppCacheInternalsHost, |
110 const char kCreditsPath[] = "credits"; | 111 chrome::kChromeUIBlobInternalsHost, |
111 const char kCachePath[] = "view-http-cache"; | 112 chrome::kChromeUIChromeURLsHost, |
| 113 chrome::kChromeUICreditsHost, |
| 114 chrome::kChromeUIDNSHost, |
| 115 chrome::kChromeUIFlagsHost, |
| 116 chrome::kChromeUIFlashHost, |
| 117 chrome::kChromeUIGpuInternalsHost, |
| 118 chrome::kChromeUIHistogramsHost, |
| 119 chrome::kChromeUIMemoryHost, |
| 120 chrome::kChromeUINetInternalsHost, |
| 121 chrome::kChromeUINetworkViewCacheHost, |
| 122 chrome::kChromeUIPluginsHost, |
| 123 chrome::kChromeUIStatsHost, |
| 124 chrome::kChromeUISyncInternalsHost, |
| 125 chrome::kChromeUITCMallocHost, |
| 126 chrome::kChromeUITermsHost, |
| 127 chrome::kChromeUIVersionHost, |
| 128 #ifdef TRACK_ALL_TASK_OBJECTS |
| 129 chrome::kChromeUITasksHost, |
| 130 #endif |
112 #if defined(OS_WIN) | 131 #if defined(OS_WIN) |
113 const char kConflictsPath[] = "conflicts"; | 132 chrome::kChromeUIConflictsHost, |
114 #endif | 133 #endif |
115 const char kDnsPath[] = "dns"; | |
116 const char kFlagsPath[] = "flags"; | |
117 const char kFlashPath[] = "flash"; | |
118 const char kGpuPath[] = "gpu-internals"; | |
119 const char kHistogramsPath[] = "histograms"; | |
120 const char kMemoryRedirectPath[] = "memory-redirect"; | |
121 const char kMemoryPath[] = "memory"; | |
122 const char kStatsPath[] = "stats"; | |
123 const char kTasksPath[] = "tasks"; | |
124 const char kTcmallocPath[] = "tcmalloc"; | |
125 const char kTermsPath[] = "terms"; | |
126 const char kVersionPath[] = "version"; | |
127 const char kAboutPath[] = "about"; | |
128 // Not about:* pages, but included to make about:about look nicer | |
129 const char kNetInternalsPath[] = "net-internals"; | |
130 const char kPluginsPath[] = "plugins"; | |
131 const char kSyncInternalsPath[] = "sync-internals"; | |
132 | |
133 #if defined(OS_LINUX) | 134 #if defined(OS_LINUX) |
134 const char kLinuxProxyConfigPath[] = "linux-proxy-config"; | 135 chrome::kChromeUISandboxHost, |
135 const char kSandboxPath[] = "sandbox"; | |
136 #endif | |
137 | |
138 #if defined(OS_CHROMEOS) | |
139 const char kNetworkPath[] = "network"; | |
140 const char kOSCreditsPath[] = "os-credits"; | |
141 const char kEULAPathFormat[] = "/usr/share/chromeos-assets/eula/%s/eula.html"; | |
142 #endif | |
143 | |
144 // Add path here to be included in about:about | |
145 const char *kAllAboutPaths[] = { | |
146 kAboutPath, | |
147 kAppCacheInternalsPath, | |
148 kBlobInternalsPath, | |
149 kCachePath, | |
150 kCreditsPath, | |
151 #if defined(OS_WIN) | |
152 kConflictsPath, | |
153 #endif | |
154 kDnsPath, | |
155 kFlagsPath, | |
156 kFlashPath, | |
157 kGpuPath, | |
158 kHistogramsPath, | |
159 kMemoryPath, | |
160 kNetInternalsPath, | |
161 kPluginsPath, | |
162 kStatsPath, | |
163 kSyncInternalsPath, | |
164 #ifdef TRACK_ALL_TASK_OBJECTS | |
165 kTasksPath, | |
166 #endif // TRACK_ALL_TASK_OBJECTS | |
167 kTcmallocPath, | |
168 kTermsPath, | |
169 kVersionPath, | |
170 #if defined(OS_LINUX) | |
171 kSandboxPath, | |
172 #endif | 136 #endif |
173 #if defined(OS_CHROMEOS) | 137 #if defined(OS_CHROMEOS) |
174 kNetworkPath, | 138 chrome::kChromeUINetworkHost, |
175 kOSCreditsPath, | 139 chrome::kChromeUIOSCreditsHost, |
176 #endif | 140 #endif |
177 }; | 141 }; |
178 | 142 |
179 // When you type about:memory, it actually loads an intermediate URL that | 143 // Debug paths, presented without links in chrome://about. |
180 // redirects you to the final page. This avoids the problem where typing | 144 // These paths will not be suggested by BuiltinProvider. |
181 // "about:memory" on the new tab page or any other page where a process | 145 const char *kDebugChromePaths[] = { |
182 // transition would occur to the about URL will cause some confusion. | 146 chrome::kChromeUICrashHost, |
183 // | 147 chrome::kChromeUIKillHost, |
184 // The problem is that during the processing of the memory page, there are two | 148 chrome::kChromeUIHangHost, |
185 // processes active, the original and the destination one. This can create the | 149 chrome::kChromeUIShorthangHost, |
186 // impression that we're using more resources than we actually are. This | 150 chrome::kChromeUIGpuCleanHost, |
187 // redirect solves the problem by eliminating the process transition during the | 151 chrome::kChromeUIGpuCrashHost, |
188 // time that about memory is being computed. | 152 chrome::kChromeUIGpuHangHost |
189 std::string GetAboutMemoryRedirectResponse() { | 153 }; |
190 return "<meta http-equiv=\"refresh\" " | 154 |
191 "content=\"0;chrome://about/memory\">"; | 155 // AboutSource handles these chrome:// paths. |
192 } | 156 const char *kAboutSourceNames[] = { |
| 157 chrome::kChromeUIChromeURLsHost, |
| 158 chrome::kChromeUICreditsHost, |
| 159 chrome::kChromeUIDNSHost, |
| 160 chrome::kChromeUIHistogramsHost, |
| 161 chrome::kChromeUIMemoryHost, |
| 162 chrome::kChromeUIMemoryRedirectHost, |
| 163 chrome::kChromeUIStatsHost, |
| 164 chrome::kChromeUITermsHost, |
| 165 chrome::kChromeUIVersionHost, |
| 166 #ifdef TRACK_ALL_TASK_OBJECTS |
| 167 chrome::kChromeUITasksHost, |
| 168 #endif |
| 169 #if defined(USE_TCMALLOC) |
| 170 chrome::kChromeUITCMallocHost, |
| 171 #endif |
| 172 #if defined(OS_LINUX) |
| 173 chrome::kChromeUILinuxProxyConfigHost, |
| 174 chrome::kChromeUISandboxHost, |
| 175 #endif |
| 176 #if defined(OS_CHROMEOS) |
| 177 chrome::kChromeUINetworkHost, |
| 178 chrome::kChromeUIOSCreditsHost, |
| 179 #endif |
| 180 }; |
193 | 181 |
194 class AboutSource : public ChromeURLDataManager::DataSource { | 182 class AboutSource : public ChromeURLDataManager::DataSource { |
195 public: | 183 public: |
196 // Creates our datasource. | 184 // Construct a data source for the specified |source_name|. |
197 AboutSource(); | 185 AboutSource(const std::string& source_name, Profile* profile); |
198 explicit AboutSource(Profile* profile); | |
199 | 186 |
200 // Called when the network layer has requested a resource underneath | 187 // Called when the network layer has requested a resource underneath |
201 // the path we registered. | 188 // the path we registered. |
202 virtual void StartDataRequest(const std::string& path, | 189 virtual void StartDataRequest(const std::string& path, |
203 bool is_incognito, | 190 bool is_incognito, |
204 int request_id); | 191 int request_id) OVERRIDE; |
205 | 192 |
206 virtual std::string GetMimeType(const std::string&) const { | 193 virtual std::string GetMimeType(const std::string&) const OVERRIDE { |
207 return "text/html"; | 194 return "text/html"; |
208 } | 195 } |
209 | 196 |
210 // Send the response data. | 197 // Send the response data. |
211 void FinishDataRequest(const std::string& html, int request_id); | 198 void FinishDataRequest(const std::string& html, int request_id); |
212 | 199 |
213 Profile* profile() { return profile_; } | 200 Profile* profile() { return profile_; } |
214 | 201 |
215 private: | 202 private: |
216 virtual ~AboutSource(); | 203 virtual ~AboutSource(); |
217 | 204 |
218 Profile* profile_; | 205 Profile* profile_; |
219 | 206 |
220 DISALLOW_COPY_AND_ASSIGN(AboutSource); | 207 DISALLOW_COPY_AND_ASSIGN(AboutSource); |
221 }; | 208 }; |
222 | 209 |
| 210 // Register a data source for a known source name. Safe to call multiple times. |
| 211 // |name| may be an unkown host (e.g. "chrome://foo/"); only handle known hosts. |
| 212 void InitializeAboutDataSource(const std::string& name, Profile* profile) { |
| 213 ChromeURLDataManager* manager = profile->GetChromeURLDataManager(); |
| 214 for (size_t i = 0; i < arraysize(kAboutSourceNames); i++) { |
| 215 if (name == kAboutSourceNames[i]) { |
| 216 manager->AddDataSource(new AboutSource(name, profile)); |
| 217 return; |
| 218 } |
| 219 } |
| 220 } |
| 221 |
| 222 // When you type about:memory, it actually loads this intermediate URL that |
| 223 // redirects you to the final page. This avoids the problem where typing |
| 224 // "about:memory" on the new tab page or any other page where a process |
| 225 // transition would occur to the about URL will cause some confusion. |
| 226 // |
| 227 // The problem is that during the processing of the memory page, there are two |
| 228 // processes active, the original and the destination one. This can create the |
| 229 // impression that we're using more resources than we actually are. This |
| 230 // redirect solves the problem by eliminating the process transition during the |
| 231 // time that about memory is being computed. |
| 232 std::string GetAboutMemoryRedirectResponse(Profile* profile) { |
| 233 InitializeAboutDataSource(chrome::kChromeUIMemoryRedirectHost, profile); |
| 234 return StringPrintf("<meta http-equiv=\"refresh\" content=\"0;%s\">", |
| 235 chrome::kChromeUIMemoryRedirectURL); |
| 236 } |
| 237 |
223 // Handling about:memory is complicated enough to encapsulate its related | 238 // Handling about:memory is complicated enough to encapsulate its related |
224 // methods into a single class. The user should create it (on the heap) and call | 239 // methods into a single class. The user should create it (on the heap) and call |
225 // its |StartFetch()| method. | 240 // its |StartFetch()| method. |
226 class AboutMemoryHandler : public MemoryDetails { | 241 class AboutMemoryHandler : public MemoryDetails { |
227 public: | 242 public: |
228 AboutMemoryHandler(AboutSource* source, int request_id) | 243 AboutMemoryHandler(AboutSource* source, int request_id) |
229 : source_(source), request_id_(request_id) {} | 244 : source_(source), |
230 | 245 request_id_(request_id) { |
| 246 } |
231 | 247 |
232 virtual void OnDetailsAvailable(); | 248 virtual void OnDetailsAvailable(); |
233 | 249 |
234 private: | 250 private: |
235 ~AboutMemoryHandler() {} | 251 ~AboutMemoryHandler() {} |
236 | 252 |
237 void BindProcessMetrics(DictionaryValue* data, | 253 void BindProcessMetrics(DictionaryValue* data, |
238 ProcessMemoryInformation* info); | 254 ProcessMemoryInformation* info); |
239 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); | 255 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); |
240 | 256 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 307 |
292 void StartOnUIThread() { | 308 void StartOnUIThread() { |
293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
294 BrowserThread::PostTask( | 310 BrowserThread::PostTask( |
295 BrowserThread::FILE, FROM_HERE, | 311 BrowserThread::FILE, FROM_HERE, |
296 NewRunnableMethod(this, &ChromeOSTermsHandler::LoadFileOnFileThread)); | 312 NewRunnableMethod(this, &ChromeOSTermsHandler::LoadFileOnFileThread)); |
297 } | 313 } |
298 | 314 |
299 void LoadFileOnFileThread() { | 315 void LoadFileOnFileThread() { |
300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
301 std::string path = StringPrintf(kEULAPathFormat, locale_.c_str()); | 317 std::string path = StringPrintf(chrome::kEULAPathFormat, locale_.c_str()); |
302 if (!file_util::ReadFileToString(FilePath(path), &contents_)) { | 318 if (!file_util::ReadFileToString(FilePath(path), &contents_)) { |
303 // No EULA for given language - try en-US as default. | 319 // No EULA for given language - try en-US as default. |
304 path = StringPrintf(kEULAPathFormat, "en-US"); | 320 path = StringPrintf(chrome::kEULAPathFormat, "en-US"); |
305 if (!file_util::ReadFileToString(FilePath(path), &contents_)) { | 321 if (!file_util::ReadFileToString(FilePath(path), &contents_)) { |
306 // File with EULA not found, ResponseOnUIThread will load EULA from | 322 // File with EULA not found, ResponseOnUIThread will load EULA from |
307 // resources if contents_ is empty. | 323 // resources if contents_ is empty. |
308 contents_.clear(); | 324 contents_.clear(); |
309 } | 325 } |
310 } | 326 } |
311 BrowserThread::PostTask( | 327 BrowserThread::PostTask( |
312 BrowserThread::UI, FROM_HERE, | 328 BrowserThread::UI, FROM_HERE, |
313 NewRunnableMethod(this, &ChromeOSTermsHandler::ResponseOnUIThread)); | 329 NewRunnableMethod(this, &ChromeOSTermsHandler::ResponseOnUIThread)); |
314 } | 330 } |
(...skipping 17 matching lines...) Expand all Loading... |
332 | 348 |
333 std::string contents_; | 349 std::string contents_; |
334 | 350 |
335 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); | 351 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); |
336 }; | 352 }; |
337 | 353 |
338 #endif | 354 #endif |
339 | 355 |
340 // Individual about handlers --------------------------------------------------- | 356 // Individual about handlers --------------------------------------------------- |
341 | 357 |
342 std::string AboutAbout() { | 358 std::string ChromeURLs() { |
343 std::string html("<html><head><title>About Pages</title></head>\n" | 359 std::string html("<html><head><title>Chrome URLs</title></head>\n" |
344 "<body><h2>List of About pages</h2>\n<ul>"); | 360 "<body><h2>List of Chrome URLs</h2>\n<ul>"); |
345 std::vector<std::string> paths(AboutPaths()); | 361 std::vector<std::string> paths(ChromePaths()); |
346 for (std::vector<std::string>::const_iterator i = paths.begin(); | 362 for (std::vector<std::string>::const_iterator i = paths.begin(); |
347 i != paths.end(); ++i) { | 363 i != paths.end(); ++i) |
348 html += "<li><a href='chrome://"; | 364 html += "<li><a href='chrome://" + *i + "/'>chrome://" + *i + "</a></li>\n"; |
349 if ((*i != kAppCacheInternalsPath) && | |
350 (*i != kBlobInternalsPath) && | |
351 (*i != kCachePath) && | |
352 #if defined(OS_WIN) | |
353 (*i != kConflictsPath) && | |
354 #endif | |
355 (*i != kFlagsPath) && | |
356 (*i != kFlashPath) && | |
357 (*i != kGpuPath) && | |
358 (*i != kNetInternalsPath) && | |
359 (*i != kPluginsPath)) { | |
360 html += "about/"; | |
361 } | |
362 html += *i + "/'>about:" + *i + "</a></li>\n"; | |
363 } | |
364 const char *debug[] = { "crash", "kill", "hang", "shorthang", | |
365 "gpuclean", "gpucrash", "gpuhang" }; | |
366 html += "</ul>\n<h2>For Debug</h2>\n" | 365 html += "</ul>\n<h2>For Debug</h2>\n" |
367 "<p>The following pages are for debugging purposes only. Because they " | 366 "<p>The following pages are for debugging purposes only. Because they " |
368 "crash or hang the renderer, they're not linked directly; you can type " | 367 "crash or hang the renderer, they're not linked directly; you can type " |
369 "them into the address bar if you need them.</p>\n<ul>"; | 368 "them into the address bar if you need them.</p>\n<ul>"; |
370 for (size_t i = 0; i < arraysize(debug); i++) | 369 for (size_t i = 0; i < arraysize(kDebugChromePaths); i++) |
371 html += "<li>about:" + std::string(debug[i]) + "</li>\n"; | 370 html += "<li>chrome://" + std::string(kDebugChromePaths[i]) + "</li>\n"; |
372 html += "</ul>\n</body></html>"; | 371 html += "</ul>\n</body></html>"; |
373 return html; | 372 return html; |
374 } | 373 } |
375 | 374 |
376 #if defined(OS_CHROMEOS) | 375 #if defined(OS_CHROMEOS) |
377 | 376 |
378 // Html output helper functions | 377 // Html output helper functions |
379 // TODO(stevenjb): L10N this. | 378 // TODO(stevenjb): L10N this. |
380 | 379 |
381 // Helper function to wrap Html with <th> tag. | 380 // Helper function to wrap Html with <th> tag. |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 // Where the results are fed to. | 593 // Where the results are fed to. |
595 scoped_refptr<AboutSource> source_; | 594 scoped_refptr<AboutSource> source_; |
596 | 595 |
597 // ID identifying the request. | 596 // ID identifying the request. |
598 int request_id_; | 597 int request_id_; |
599 | 598 |
600 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler); | 599 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler); |
601 }; | 600 }; |
602 | 601 |
603 #if defined(USE_TCMALLOC) | 602 #if defined(USE_TCMALLOC) |
604 std::string AboutTcmalloc(const std::string& query) { | 603 std::string AboutTcmalloc() { |
605 std::string data; | 604 std::string data; |
606 AboutTcmallocOutputsType* outputs = | 605 AboutTcmallocOutputsType* outputs = |
607 AboutTcmallocOutputs::GetInstance()->outputs(); | 606 AboutTcmallocOutputs::GetInstance()->outputs(); |
608 | 607 |
609 // Display any stats for which we sent off requests the last time. | 608 // Display any stats for which we sent off requests the last time. |
610 data.append("<html><head><title>About tcmalloc</title></head><body>\n"); | 609 data.append("<html><head><title>About tcmalloc</title></head><body>\n"); |
611 data.append("<p>Stats as of last page load;"); | 610 data.append("<p>Stats as of last page load;"); |
612 data.append("reload to get stats as of this page load.</p>\n"); | 611 data.append("reload to get stats as of this page load.</p>\n"); |
613 data.append("<table width=\"100%\">\n"); | 612 data.append("<table width=\"100%\">\n"); |
614 for (AboutTcmallocOutputsType::const_iterator oit = outputs->begin(); | 613 for (AboutTcmallocOutputsType::const_iterator oit = outputs->begin(); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 base::StringPiece version_html( | 1013 base::StringPiece version_html( |
1015 ResourceBundle::GetSharedInstance().GetRawDataResource( | 1014 ResourceBundle::GetSharedInstance().GetRawDataResource( |
1016 IDR_ABOUT_VERSION_HTML)); | 1015 IDR_ABOUT_VERSION_HTML)); |
1017 | 1016 |
1018 return jstemplate_builder::GetTemplatesHtml( | 1017 return jstemplate_builder::GetTemplatesHtml( |
1019 version_html, localized_strings, "t" /* template root node id */); | 1018 version_html, localized_strings, "t" /* template root node id */); |
1020 } | 1019 } |
1021 | 1020 |
1022 // AboutSource ----------------------------------------------------------------- | 1021 // AboutSource ----------------------------------------------------------------- |
1023 | 1022 |
1024 AboutSource::AboutSource() | 1023 AboutSource::AboutSource(const std::string& source_name, Profile* profile) |
1025 : DataSource(chrome::kAboutScheme, MessageLoop::current()) { | 1024 : DataSource(source_name, MessageLoop::current()), |
1026 } | |
1027 | |
1028 AboutSource::AboutSource(Profile* profile) | |
1029 : DataSource(chrome::kAboutScheme, MessageLoop::current()), | |
1030 profile_(profile) { | 1025 profile_(profile) { |
1031 } | 1026 } |
1032 | 1027 |
1033 AboutSource::~AboutSource() { | 1028 AboutSource::~AboutSource() { |
1034 } | 1029 } |
1035 | 1030 |
1036 void AboutSource::StartDataRequest(const std::string& path_raw, | 1031 void AboutSource::StartDataRequest(const std::string& path, |
1037 bool is_incognito, int request_id) { | 1032 bool is_incognito, |
1038 std::string path = path_raw; | 1033 int request_id) { |
1039 std::string info; | |
1040 if (path.find("/") != std::string::npos) { | |
1041 size_t pos = path.find("/"); | |
1042 info = path.substr(pos + 1, path.length() - (pos + 1)); | |
1043 path = path.substr(0, pos); | |
1044 } | |
1045 path = StringToLowerASCII(path); | |
1046 | |
1047 std::string response; | 1034 std::string response; |
1048 if (path == kDnsPath) { | 1035 std::string host = source_name(); |
| 1036 if (host == chrome::kChromeUIDNSHost) { |
1049 AboutDnsHandler::Start(this, request_id); | 1037 AboutDnsHandler::Start(this, request_id); |
1050 return; | 1038 return; |
1051 } else if (path == kHistogramsPath) { | 1039 } else if (host == chrome::kChromeUIHistogramsHost) { |
1052 response = AboutHistograms(info); | 1040 response = AboutHistograms(path); |
1053 } else if (path == kMemoryPath) { | 1041 } else if (host == chrome::kChromeUIMemoryHost) { |
| 1042 response = GetAboutMemoryRedirectResponse(profile()); |
| 1043 } else if (host == chrome::kChromeUIMemoryRedirectHost) { |
1054 AboutMemory(this, request_id); | 1044 AboutMemory(this, request_id); |
1055 return; | 1045 return; |
1056 } else if (path == kMemoryRedirectPath) { | |
1057 response = GetAboutMemoryRedirectResponse(); | |
1058 #ifdef TRACK_ALL_TASK_OBJECTS | 1046 #ifdef TRACK_ALL_TASK_OBJECTS |
1059 } else if (path == kTasksPath) { | 1047 } else if (host == chrome::kChromeUITasksHost) { |
1060 response = AboutObjects(info); | 1048 response = AboutObjects(path); |
1061 #endif | 1049 #endif |
1062 } else if (path == kStatsPath) { | 1050 } else if (host == chrome::kChromeUIStatsHost) { |
1063 response = AboutStats(info); | 1051 response = AboutStats(path); |
1064 #if defined(USE_TCMALLOC) | 1052 #if defined(USE_TCMALLOC) |
1065 } else if (path == kTcmallocPath) { | 1053 } else if (host == chrome::kChromeUITCMallocHost) { |
1066 response = AboutTcmalloc(info); | 1054 response = AboutTcmalloc(); |
1067 #endif | 1055 #endif |
1068 } else if (path == kVersionPath || path.empty()) { | 1056 } else if (host == chrome::kChromeUIVersionHost) { |
1069 #if defined(OS_CHROMEOS) | 1057 #if defined(OS_CHROMEOS) |
1070 new ChromeOSAboutVersionHandler(this, request_id); | 1058 new ChromeOSAboutVersionHandler(this, request_id); |
1071 return; | 1059 return; |
1072 #else | 1060 #else |
1073 DictionaryValue localized_strings; | 1061 DictionaryValue localized_strings; |
1074 localized_strings.SetString("os_version", ""); | 1062 localized_strings.SetString("os_version", ""); |
1075 response = AboutVersion(&localized_strings, profile_); | 1063 response = AboutVersion(&localized_strings, profile_); |
1076 #endif | 1064 #endif |
1077 } else if (path == kCreditsPath) { | 1065 } else if (host == chrome::kChromeUICreditsHost) { |
1078 response = ResourceBundle::GetSharedInstance().GetRawDataResource( | 1066 response = ResourceBundle::GetSharedInstance().GetRawDataResource( |
1079 IDR_CREDITS_HTML).as_string(); | 1067 IDR_CREDITS_HTML).as_string(); |
1080 } else if (path == kAboutPath) { | 1068 } else if (host == chrome::kChromeUIChromeURLsHost) { |
1081 response = AboutAbout(); | 1069 response = ChromeURLs(); |
1082 #if defined(OS_CHROMEOS) | 1070 #if defined(OS_CHROMEOS) |
1083 } else if (path == kOSCreditsPath) { | 1071 } else if (host == chrome::kChromeUIOSCreditsHost) { |
1084 response = ResourceBundle::GetSharedInstance().GetRawDataResource( | 1072 response = ResourceBundle::GetSharedInstance().GetRawDataResource( |
1085 IDR_OS_CREDITS_HTML).as_string(); | 1073 IDR_OS_CREDITS_HTML).as_string(); |
1086 } else if (path == kNetworkPath) { | 1074 } else if (host == chrome::kChromeUINetworkHost) { |
1087 response = AboutNetwork(info); | 1075 response = AboutNetwork(path); |
1088 #endif | 1076 #endif |
1089 } else if (path == kTermsPath) { | 1077 } else if (host == chrome::kChromeUITermsHost) { |
1090 #if defined(OS_CHROMEOS) | 1078 #if defined(OS_CHROMEOS) |
1091 ChromeOSTermsHandler::Start(this, request_id); | 1079 ChromeOSTermsHandler::Start(this, request_id); |
1092 return; | 1080 return; |
1093 #else | 1081 #else |
1094 response = ResourceBundle::GetSharedInstance().GetRawDataResource( | 1082 response = ResourceBundle::GetSharedInstance().GetRawDataResource( |
1095 IDR_TERMS_HTML).as_string(); | 1083 IDR_TERMS_HTML).as_string(); |
1096 #endif | 1084 #endif |
1097 #if defined(OS_LINUX) | 1085 #if defined(OS_LINUX) |
1098 } else if (path == kLinuxProxyConfigPath) { | 1086 } else if (host == chrome::kChromeUILinuxProxyConfigHost) { |
1099 response = AboutLinuxProxyConfig(); | 1087 response = AboutLinuxProxyConfig(); |
1100 } else if (path == kSandboxPath) { | 1088 } else if (host == chrome::kChromeUISandboxHost) { |
1101 response = AboutSandbox(); | 1089 response = AboutSandbox(); |
1102 #endif | 1090 #endif |
1103 } | 1091 } |
1104 | 1092 |
1105 FinishDataRequest(response, request_id); | 1093 FinishDataRequest(response, request_id); |
1106 } | 1094 } |
1107 | 1095 |
1108 void AboutSource::FinishDataRequest(const std::string& response, | 1096 void AboutSource::FinishDataRequest(const std::string& html, int request_id) { |
1109 int request_id) { | |
1110 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 1097 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
1111 html_bytes->data.resize(response.size()); | 1098 html_bytes->data.resize(html.size()); |
1112 std::copy(response.begin(), response.end(), html_bytes->data.begin()); | 1099 std::copy(html.begin(), html.end(), html_bytes->data.begin()); |
1113 SendResponse(request_id, html_bytes); | 1100 SendResponse(request_id, html_bytes); |
1114 } | 1101 } |
1115 | 1102 |
1116 // AboutMemoryHandler ---------------------------------------------------------- | 1103 // AboutMemoryHandler ---------------------------------------------------------- |
1117 | 1104 |
1118 // Helper for AboutMemory to bind results from a ProcessMetrics object | 1105 // Helper for AboutMemory to bind results from a ProcessMetrics object |
1119 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects | 1106 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects |
1120 // can be used in caller's scope (e.g for appending to a net total). | 1107 // can be used in caller's scope (e.g for appending to a net total). |
1121 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data, | 1108 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data, |
1122 ProcessMemoryInformation* info) { | 1109 ProcessMemoryInformation* info) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 source_->FinishDataRequest(AboutVersion(&localized_strings, | 1253 source_->FinishDataRequest(AboutVersion(&localized_strings, |
1267 source_->profile()), request_id_); | 1254 source_->profile()), request_id_); |
1268 | 1255 |
1269 // CancelableRequestProvider isn't happy when it's deleted and servicing a | 1256 // CancelableRequestProvider isn't happy when it's deleted and servicing a |
1270 // task, so we delay the deletion. | 1257 // task, so we delay the deletion. |
1271 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1258 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
1272 } | 1259 } |
1273 | 1260 |
1274 #endif | 1261 #endif |
1275 | 1262 |
1276 // Returns true if |url|'s spec starts with |about_specifier|, and is | |
1277 // terminated by the start of a path. | |
1278 bool StartsWithAboutSpecifier(const GURL& url, const char* about_specifier) { | |
1279 return StartsWithASCII(url.spec(), about_specifier, true) && | |
1280 (url.spec().size() == strlen(about_specifier) || | |
1281 url.spec()[strlen(about_specifier)] == '/'); | |
1282 } | |
1283 | |
1284 // Transforms a URL of the form "about:foo/XXX" to <url_prefix> + "XXX". | |
1285 GURL RemapAboutURL(const std::string& url_prefix, const GURL& url) { | |
1286 std::string path; | |
1287 size_t split = url.spec().find('/'); | |
1288 if (split != std::string::npos) | |
1289 path = url.spec().substr(split + 1); | |
1290 return GURL(url_prefix + path); | |
1291 } | |
1292 | |
1293 } // namespace | 1263 } // namespace |
1294 | 1264 |
1295 // ----------------------------------------------------------------------------- | 1265 // ----------------------------------------------------------------------------- |
1296 | 1266 |
1297 bool WillHandleBrowserAboutURL(GURL* url, Profile* profile) { | 1267 bool WillHandleBrowserAboutURL(GURL* url, Profile* profile) { |
1298 // We only handle about: schemes. | 1268 // TODO(msw): Eliminate "about:*" constants and literals from code and tests, |
1299 if (!url->SchemeIs(chrome::kAboutScheme)) | 1269 // then hopefully we can remove this forced fixup. |
| 1270 *url = URLFixerUpper::FixupURL(url->possibly_invalid_spec(), std::string()); |
| 1271 |
| 1272 // Check that about: URLs are fixed up to chrome: by URLFixerUpper::FixupURL. |
| 1273 DCHECK((*url == GURL(chrome::kAboutBlankURL)) || |
| 1274 !url->SchemeIs(chrome::kAboutScheme)); |
| 1275 |
| 1276 // Only handle chrome://foo/, URLFixerUpper::FixupURL translates about:foo. |
| 1277 // TAB_CONTENTS_WEB handles about:blank, which frames are allowed to access. |
| 1278 if (!url->SchemeIs(chrome::kChromeUIScheme)) |
1300 return false; | 1279 return false; |
1301 | 1280 |
1302 // about:blank is special. Frames are allowed to access about:blank, | 1281 // Circumvent processing URLs that the renderer process will handle. |
1303 // but they are not allowed to access other types of about pages. | 1282 if (chrome_about_handler::WillHandle(*url)) |
1304 // Just ignore the about:blank and let the TAB_CONTENTS_WEB handle it. | |
1305 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutBlankURL)) | |
1306 return false; | 1283 return false; |
1307 | 1284 |
1308 // Rewrite about:cache/* URLs to chrome://view-http-cache/* | 1285 std::string host(url->host()); |
1309 if (StartsWithAboutSpecifier(*url, chrome::kAboutCacheURL)) { | 1286 // Replace about with chrome-urls. |
1310 *url = RemapAboutURL(chrome::kNetworkViewCacheURL, *url); | 1287 if (host == chrome::kChromeUIAboutHost) |
1311 return true; | 1288 host = chrome::kChromeUIChromeURLsHost; |
1312 } | 1289 // Replace cache with view-http-cache. |
| 1290 if (host == chrome::kChromeUICacheHost) |
| 1291 host = chrome::kChromeUINetworkViewCacheHost; |
| 1292 // Replace gpu with gpu-internals. |
| 1293 else if (host == chrome::kChromeUIGpuHost) |
| 1294 host = chrome::kChromeUIGpuInternalsHost; |
| 1295 // Replace sync with sync-internals (for legacy reasons). |
| 1296 else if (host == chrome::kChromeUISyncHost) |
| 1297 host = chrome::kChromeUISyncInternalsHost; |
| 1298 GURL::Replacements replacements; |
| 1299 replacements.SetHostStr(host); |
| 1300 *url = url->ReplaceComponents(replacements); |
1313 | 1301 |
1314 #if defined(OS_WIN) | 1302 // Handle URLs to crash the browser or wreck the gpu process. |
1315 // Rewrite about:conflicts/* URLs to chrome://conflicts/* | 1303 if (host == chrome::kChromeUIBrowserCrashHost) { |
1316 if (StartsWithAboutSpecifier(*url, chrome::kAboutConflicts)) { | |
1317 *url = GURL(chrome::kChromeUIConflictsURL); | |
1318 return true; | |
1319 } | |
1320 #endif | |
1321 | |
1322 // Rewrite about:flags to chrome://flags/. | |
1323 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutFlagsURL)) { | |
1324 *url = GURL(chrome::kChromeUIFlagsURL); | |
1325 return true; | |
1326 } | |
1327 | |
1328 // Rewrite about:flash to chrome://flash/. | |
1329 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutFlashURL)) { | |
1330 *url = GURL(chrome::kChromeUIFlashURL); | |
1331 return true; | |
1332 } | |
1333 | |
1334 // Rewrite about:net-internals/* URLs to chrome://net-internals/* | |
1335 if (StartsWithAboutSpecifier(*url, chrome::kAboutNetInternalsURL)) { | |
1336 *url = RemapAboutURL(chrome::kNetworkViewInternalsURL, *url); | |
1337 return true; | |
1338 } | |
1339 | |
1340 // Rewrite about:gpu/* URLs to chrome://gpu-internals/* | |
1341 if (StartsWithAboutSpecifier(*url, chrome::kAboutGpuURL)) { | |
1342 *url = RemapAboutURL(chrome::kGpuInternalsURL, *url); | |
1343 return true; | |
1344 } | |
1345 | |
1346 // Rewrite about:appcache-internals/* URLs to chrome://appcache/* | |
1347 if (StartsWithAboutSpecifier(*url, chrome::kAboutAppCacheInternalsURL)) { | |
1348 *url = RemapAboutURL(chrome::kAppCacheViewInternalsURL, *url); | |
1349 return true; | |
1350 } | |
1351 | |
1352 // Rewrite about:sync-internals/* URLs (and about:sync, too, for | |
1353 // legacy reasons) to chrome://sync-internals/* | |
1354 if (StartsWithAboutSpecifier(*url, chrome::kAboutSyncInternalsURL) || | |
1355 StartsWithAboutSpecifier(*url, chrome::kAboutSyncURL)) { | |
1356 *url = RemapAboutURL(chrome::kSyncViewInternalsURL, *url); | |
1357 return true; | |
1358 } | |
1359 | |
1360 // Rewrite about:plugins to chrome://plugins/. | |
1361 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutPluginsURL)) { | |
1362 *url = GURL(chrome::kChromeUIPluginsURL); | |
1363 return true; | |
1364 } | |
1365 | |
1366 // Handle URL to crash the browser process. | |
1367 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutBrowserCrash)) { | |
1368 // Induce an intentional crash in the browser process. | 1304 // Induce an intentional crash in the browser process. |
1369 int* bad_pointer = NULL; | 1305 CHECK(false); |
1370 *bad_pointer = 42; | 1306 } else if (host == chrome::kChromeUIGpuCleanHost) { |
1371 return true; | |
1372 } | |
1373 | |
1374 // Handle URLs to wreck the gpu process. | |
1375 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutGpuCleanURL)) { | |
1376 GpuProcessHost::SendOnIO( | 1307 GpuProcessHost::SendOnIO( |
1377 0, content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, new GpuMsg_Clean()); | 1308 0, content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, new GpuMsg_Clean()); |
1378 } | 1309 } else if (host == chrome::kChromeUIGpuCrashHost) { |
1379 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutGpuCrashURL)) { | |
1380 GpuProcessHost::SendOnIO( | 1310 GpuProcessHost::SendOnIO( |
1381 0, content::CAUSE_FOR_GPU_LAUNCH_ABOUT_GPUCRASH, new GpuMsg_Crash()); | 1311 0, content::CAUSE_FOR_GPU_LAUNCH_ABOUT_GPUCRASH, new GpuMsg_Crash()); |
1382 } | 1312 } else if (host == chrome::kChromeUIGpuHangHost) { |
1383 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutGpuHangURL)) { | |
1384 GpuProcessHost::SendOnIO( | 1313 GpuProcessHost::SendOnIO( |
1385 0, content::CAUSE_FOR_GPU_LAUNCH_ABOUT_GPUHANG, new GpuMsg_Hang()); | 1314 0, content::CAUSE_FOR_GPU_LAUNCH_ABOUT_GPUHANG, new GpuMsg_Hang()); |
1386 } | 1315 } |
1387 | 1316 |
1388 // There are a few about: URLs that we hand over to the renderer. If the | 1317 // Initialize any potentially corresponding AboutSource handler. |
1389 // renderer wants them, don't do any rewriting. | 1318 InitializeAboutDataSource(host, profile); |
1390 if (chrome_about_handler::WillHandle(*url)) | |
1391 return false; | |
1392 | |
1393 // Anything else requires our special handler; make sure it's initialized. | |
1394 InitializeAboutDataSource(profile); | |
1395 | |
1396 // Special case about:memory to go through a redirect before ending up on | |
1397 // the final page. See GetAboutMemoryRedirectResponse above for why. | |
1398 if (LowerCaseEqualsASCII(url->path(), kMemoryPath)) { | |
1399 *url = GURL("chrome://about/memory-redirect"); | |
1400 return true; | |
1401 } | |
1402 | |
1403 // Rewrite the about URL to use chrome:. WebKit treats all about URLS the | |
1404 // same (blank page), so if we want to display content, we need another | |
1405 // scheme. | |
1406 std::string about_url = "chrome://about/"; | |
1407 about_url.append(url->path()); | |
1408 *url = GURL(about_url); | |
1409 return true; | 1319 return true; |
1410 } | 1320 } |
1411 | 1321 |
1412 void InitializeAboutDataSource(Profile* profile) { | |
1413 profile->GetChromeURLDataManager()->AddDataSource(new AboutSource(profile)); | |
1414 } | |
1415 | |
1416 bool HandleNonNavigationAboutURL(const GURL& url) { | 1322 bool HandleNonNavigationAboutURL(const GURL& url) { |
1417 // about:ipc is currently buggy, so we disable it for official builds. | 1323 // chrome://ipc/ is currently buggy, so we disable it for official builds. |
1418 #if !defined(OFFICIAL_BUILD) | 1324 #if !defined(OFFICIAL_BUILD) |
1419 | 1325 |
1420 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED) | 1326 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED) |
1421 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutIPCURL)) { | 1327 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) { |
1422 // Run the dialog. This will re-use the existing one if it's already up. | 1328 // Run the dialog. This will re-use the existing one if it's already up. |
1423 browser::ShowAboutIPCDialog(); | 1329 browser::ShowAboutIPCDialog(); |
1424 return true; | 1330 return true; |
1425 } | 1331 } |
1426 #endif | 1332 #endif |
1427 | 1333 |
1428 #endif // OFFICIAL_BUILD | 1334 #endif // OFFICIAL_BUILD |
1429 | 1335 |
1430 return false; | 1336 return false; |
1431 } | 1337 } |
1432 | 1338 |
1433 std::vector<std::string> AboutPaths() { | 1339 std::vector<std::string> ChromePaths() { |
1434 std::vector<std::string> paths; | 1340 std::vector<std::string> paths; |
1435 paths.reserve(arraysize(kAllAboutPaths)); | 1341 paths.reserve(arraysize(kChromePaths)); |
1436 for (size_t i = 0; i < arraysize(kAllAboutPaths); i++) | 1342 for (size_t i = 0; i < arraysize(kChromePaths); i++) |
1437 paths.push_back(kAllAboutPaths[i]); | 1343 paths.push_back(kChromePaths[i]); |
1438 return paths; | 1344 return paths; |
1439 } | 1345 } |
OLD | NEW |