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