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

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

Issue 7068007: Revise about: and chrome: url handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update special_tabs.py from Nirnimesh's codereview.chromium.org/6995057/. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/browser_about_handler.h" 5 #include "chrome/browser/browser_about_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 13 matching lines...) Expand all
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 96
96 // Glue between the callback task and the method in the singleton. 97 // Glue between the callback task and the method in the singleton.
97 void AboutTcmallocRendererCallback(base::ProcessId pid, 98 void AboutTcmallocRendererCallback(base::ProcessId pid,
98 const std::string& output) { 99 const std::string& output) {
99 AboutTcmallocOutputs::GetInstance()->RendererCallback(pid, output); 100 AboutTcmallocOutputs::GetInstance()->RendererCallback(pid, output);
100 } 101 }
101 #endif 102 #endif
102 103
103 namespace { 104 namespace {
104 105
105 // The (alphabetized) paths used for the about pages. 106 // Add paths here to be included in chrome://chrome-urls/.
106 // Note: Keep these in sync with url_constants.h 107 // These paths will also be suggested by BuiltinProvider.
107 const char kAppCacheInternalsPath[] = "appcache-internals"; 108 const char *kChromePaths[] = {
108 const char kBlobInternalsPath[] = "blob-internals"; 109 chrome::kChromeUIAppCacheInternalsHost,
109 const char kCreditsPath[] = "credits"; 110 chrome::kChromeUIBlobInternalsHost,
110 const char kCachePath[] = "view-http-cache"; 111 chrome::kChromeUIChromeURLsHost,
112 chrome::kChromeUICreditsHost,
113 chrome::kChromeUIDNSHost,
114 chrome::kChromeUIFlagsHost,
115 chrome::kChromeUIFlashHost,
116 chrome::kChromeUIGpuInternalsHost,
117 chrome::kChromeUIHistogramsHost,
118 chrome::kChromeUIMemoryHost,
119 chrome::kChromeUINetInternalsHost,
120 chrome::kChromeUINetworkViewCacheHost,
121 chrome::kChromeUIPluginsHost,
122 chrome::kChromeUIStatsHost,
123 chrome::kChromeUISyncInternalsHost,
124 chrome::kChromeUITCMallocHost,
125 chrome::kChromeUITermsHost,
126 chrome::kChromeUIVersionHost,
127 #ifdef TRACK_ALL_TASK_OBJECTS
128 chrome::kChromeUITasksHost,
129 #endif
111 #if defined(OS_WIN) 130 #if defined(OS_WIN)
112 const char kConflictsPath[] = "conflicts"; 131 chrome::kChromeUIConflictsHost,
113 #endif 132 #endif
114 const char kDnsPath[] = "dns";
115 const char kFlagsPath[] = "flags";
116 const char kFlashPath[] = "flash";
117 const char kGpuPath[] = "gpu-internals";
118 const char kHistogramsPath[] = "histograms";
119 const char kMemoryRedirectPath[] = "memory-redirect";
120 const char kMemoryPath[] = "memory";
121 const char kStatsPath[] = "stats";
122 const char kTasksPath[] = "tasks";
123 const char kTcmallocPath[] = "tcmalloc";
124 const char kTermsPath[] = "terms";
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 #if defined(OS_LINUX)
133 const char kLinuxProxyConfigPath[] = "linux-proxy-config"; 134 chrome::kChromeUISandboxHost,
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,
163 #ifdef TRACK_ALL_TASK_OBJECTS
164 kTasksPath,
165 #endif // TRACK_ALL_TASK_OBJECTS
166 kTcmallocPath,
167 kTermsPath,
168 kVersionPath,
169 #if defined(OS_LINUX)
170 kSandboxPath,
171 #endif 135 #endif
172 #if defined(OS_CHROMEOS) 136 #if defined(OS_CHROMEOS)
173 kNetworkPath, 137 chrome::kChromeUINetworkHost,
174 kOSCreditsPath, 138 chrome::kChromeUIOSCreditsHost,
175 #endif 139 #endif
176 }; 140 };
177 141
178 // When you type about:memory, it actually loads an intermediate URL that 142 // Debug paths, presented without links in chrome://about.
179 // redirects you to the final page. This avoids the problem where typing 143 // These paths will not be suggested by BuiltinProvider.
180 // "about:memory" on the new tab page or any other page where a process 144 const char *kDebugChromePaths[] = {
181 // transition would occur to the about URL will cause some confusion. 145 chrome::kChromeUICrashHost,
182 // 146 chrome::kChromeUIKillHost,
183 // The problem is that during the processing of the memory page, there are two 147 chrome::kChromeUIHangHost,
184 // processes active, the original and the destination one. This can create the 148 chrome::kChromeUIShorthangHost,
185 // impression that we're using more resources than we actually are. This 149 chrome::kChromeUIGpuCleanHost,
186 // redirect solves the problem by eliminating the process transition during the 150 chrome::kChromeUIGpuCrashHost,
187 // time that about memory is being computed. 151 chrome::kChromeUIGpuHangHost
188 std::string GetAboutMemoryRedirectResponse() { 152 };
189 return "<meta http-equiv=\"refresh\" " 153
190 "content=\"0;chrome://about/memory\">"; 154 // AboutSource handles these chrome:// paths.
191 } 155 const char *kAboutSourceNames[] = {
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 };
192 180
193 class AboutSource : public ChromeURLDataManager::DataSource { 181 class AboutSource : public ChromeURLDataManager::DataSource {
194 public: 182 public:
195 // Creates our datasource. 183 // Construct a data source for the specified |source_name|.
196 AboutSource(); 184 AboutSource(const std::string& source_name, Profile* profile);
197 explicit AboutSource(Profile* profile);
198 185
199 // Called when the network layer has requested a resource underneath 186 // Called when the network layer has requested a resource underneath
200 // the path we registered. 187 // the path we registered.
201 virtual void StartDataRequest(const std::string& path, 188 virtual void StartDataRequest(const std::string& path,
202 bool is_incognito, 189 bool is_incognito,
203 int request_id); 190 int request_id) OVERRIDE;
204 191
205 virtual std::string GetMimeType(const std::string&) const { 192 virtual std::string GetMimeType(const std::string&) const OVERRIDE {
206 return "text/html"; 193 return "text/html";
207 } 194 }
208 195
209 // Send the response data. 196 // Send the response data.
210 void FinishDataRequest(const std::string& html, int request_id); 197 void FinishDataRequest(const std::string& html, int request_id);
211 198
212 Profile* profile() { return profile_; } 199 Profile* profile() { return profile_; }
213 200
214 private: 201 private:
215 virtual ~AboutSource(); 202 virtual ~AboutSource();
216 203
217 Profile* profile_; 204 Profile* profile_;
218 205
219 DISALLOW_COPY_AND_ASSIGN(AboutSource); 206 DISALLOW_COPY_AND_ASSIGN(AboutSource);
220 }; 207 };
221 208
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
222 // Handling about:memory is complicated enough to encapsulate its related 237 // Handling about:memory is complicated enough to encapsulate its related
223 // methods into a single class. The user should create it (on the heap) and call 238 // methods into a single class. The user should create it (on the heap) and call
224 // its |StartFetch()| method. 239 // its |StartFetch()| method.
225 class AboutMemoryHandler : public MemoryDetails { 240 class AboutMemoryHandler : public MemoryDetails {
226 public: 241 public:
227 AboutMemoryHandler(AboutSource* source, int request_id) 242 AboutMemoryHandler(AboutSource* source, int request_id)
228 : source_(source), request_id_(request_id) {} 243 : source_(source),
229 244 request_id_(request_id) {
245 }
230 246
231 virtual void OnDetailsAvailable(); 247 virtual void OnDetailsAvailable();
232 248
233 private: 249 private:
234 ~AboutMemoryHandler() {} 250 ~AboutMemoryHandler() {}
235 251
236 void BindProcessMetrics(DictionaryValue* data, 252 void BindProcessMetrics(DictionaryValue* data,
237 ProcessMemoryInformation* info); 253 ProcessMemoryInformation* info);
238 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); 254 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info);
239 255
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 306
291 void StartOnUIThread() { 307 void StartOnUIThread() {
292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
293 BrowserThread::PostTask( 309 BrowserThread::PostTask(
294 BrowserThread::FILE, FROM_HERE, 310 BrowserThread::FILE, FROM_HERE,
295 NewRunnableMethod(this, &ChromeOSTermsHandler::LoadFileOnFileThread)); 311 NewRunnableMethod(this, &ChromeOSTermsHandler::LoadFileOnFileThread));
296 } 312 }
297 313
298 void LoadFileOnFileThread() { 314 void LoadFileOnFileThread() {
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
300 std::string path = StringPrintf(kEULAPathFormat, locale_.c_str()); 316 std::string path = StringPrintf(chrome::kEULAPathFormat, locale_.c_str());
301 if (!file_util::ReadFileToString(FilePath(path), &contents_)) { 317 if (!file_util::ReadFileToString(FilePath(path), &contents_)) {
302 // No EULA for given language - try en-US as default. 318 // No EULA for given language - try en-US as default.
303 path = StringPrintf(kEULAPathFormat, "en-US"); 319 path = StringPrintf(chrome::kEULAPathFormat, "en-US");
304 if (!file_util::ReadFileToString(FilePath(path), &contents_)) { 320 if (!file_util::ReadFileToString(FilePath(path), &contents_)) {
305 // File with EULA not found, ResponseOnUIThread will load EULA from 321 // File with EULA not found, ResponseOnUIThread will load EULA from
306 // resources if contents_ is empty. 322 // resources if contents_ is empty.
307 contents_.clear(); 323 contents_.clear();
308 } 324 }
309 } 325 }
310 BrowserThread::PostTask( 326 BrowserThread::PostTask(
311 BrowserThread::UI, FROM_HERE, 327 BrowserThread::UI, FROM_HERE,
312 NewRunnableMethod(this, &ChromeOSTermsHandler::ResponseOnUIThread)); 328 NewRunnableMethod(this, &ChromeOSTermsHandler::ResponseOnUIThread));
313 } 329 }
(...skipping 17 matching lines...) Expand all
331 347
332 std::string contents_; 348 std::string contents_;
333 349
334 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); 350 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler);
335 }; 351 };
336 352
337 #endif 353 #endif
338 354
339 // Individual about handlers --------------------------------------------------- 355 // Individual about handlers ---------------------------------------------------
340 356
341 std::string AboutAbout() { 357 std::string ChromeURLs() {
342 std::string html("<html><head><title>About Pages</title></head>\n" 358 std::string html("<html><head><title>Chrome URLs</title></head>\n"
343 "<body><h2>List of About pages</h2>\n<ul>"); 359 "<body><h2>List of Chrome URLs</h2>\n<ul>");
344 std::vector<std::string> paths(AboutPaths()); 360 std::vector<std::string> paths(ChromePaths());
345 for (std::vector<std::string>::const_iterator i = paths.begin(); 361 for (std::vector<std::string>::const_iterator i = paths.begin();
346 i != paths.end(); ++i) { 362 i != paths.end(); ++i)
347 html += "<li><a href='chrome://"; 363 html += "<li><a href='chrome://" + *i + "/'>chrome://" + *i + "</a></li>\n";
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" };
365 html += "</ul>\n<h2>For Debug</h2>\n" 364 html += "</ul>\n<h2>For Debug</h2>\n"
366 "<p>The following pages are for debugging purposes only. Because they " 365 "<p>The following pages are for debugging purposes only. Because they "
367 "crash or hang the renderer, they're not linked directly; you can type " 366 "crash or hang the renderer, they're not linked directly; you can type "
368 "them into the address bar if you need them.</p>\n<ul>"; 367 "them into the address bar if you need them.</p>\n<ul>";
369 for (size_t i = 0; i < arraysize(debug); i++) 368 for (size_t i = 0; i < arraysize(kDebugChromePaths); i++)
370 html += "<li>about:" + std::string(debug[i]) + "</li>\n"; 369 html += "<li>chrome://" + std::string(kDebugChromePaths[i]) + "</li>\n";
371 html += "</ul>\n</body></html>"; 370 html += "</ul>\n</body></html>";
372 return html; 371 return html;
373 } 372 }
374 373
375 #if defined(OS_CHROMEOS) 374 #if defined(OS_CHROMEOS)
376 375
377 // Html output helper functions 376 // Html output helper functions
378 // TODO(stevenjb): L10N this. 377 // TODO(stevenjb): L10N this.
379 378
380 // Helper function to wrap Html with <th> tag. 379 // Helper function to wrap Html with <th> tag.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // Where the results are fed to. 592 // Where the results are fed to.
594 scoped_refptr<AboutSource> source_; 593 scoped_refptr<AboutSource> source_;
595 594
596 // ID identifying the request. 595 // ID identifying the request.
597 int request_id_; 596 int request_id_;
598 597
599 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler); 598 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler);
600 }; 599 };
601 600
602 #if defined(USE_TCMALLOC) 601 #if defined(USE_TCMALLOC)
603 std::string AboutTcmalloc(const std::string& query) { 602 std::string AboutTcmalloc() {
604 std::string data; 603 std::string data;
605 AboutTcmallocOutputsType* outputs = 604 AboutTcmallocOutputsType* outputs =
606 AboutTcmallocOutputs::GetInstance()->outputs(); 605 AboutTcmallocOutputs::GetInstance()->outputs();
607 606
608 // Display any stats for which we sent off requests the last time. 607 // Display any stats for which we sent off requests the last time.
609 data.append("<html><head><title>About tcmalloc</title></head><body>\n"); 608 data.append("<html><head><title>About tcmalloc</title></head><body>\n");
610 data.append("<p>Stats as of last page load;"); 609 data.append("<p>Stats as of last page load;");
611 data.append("reload to get stats as of this page load.</p>\n"); 610 data.append("reload to get stats as of this page load.</p>\n");
612 data.append("<table width=\"100%\">\n"); 611 data.append("<table width=\"100%\">\n");
613 for (AboutTcmallocOutputsType::const_iterator oit = outputs->begin(); 612 for (AboutTcmallocOutputsType::const_iterator oit = outputs->begin();
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 base::StringPiece version_html( 1012 base::StringPiece version_html(
1014 ResourceBundle::GetSharedInstance().GetRawDataResource( 1013 ResourceBundle::GetSharedInstance().GetRawDataResource(
1015 IDR_ABOUT_VERSION_HTML)); 1014 IDR_ABOUT_VERSION_HTML));
1016 1015
1017 return jstemplate_builder::GetTemplatesHtml( 1016 return jstemplate_builder::GetTemplatesHtml(
1018 version_html, localized_strings, "t" /* template root node id */); 1017 version_html, localized_strings, "t" /* template root node id */);
1019 } 1018 }
1020 1019
1021 // AboutSource ----------------------------------------------------------------- 1020 // AboutSource -----------------------------------------------------------------
1022 1021
1023 AboutSource::AboutSource() 1022 AboutSource::AboutSource(const std::string& source_name, Profile* profile)
1024 : DataSource(chrome::kAboutScheme, MessageLoop::current()) { 1023 : DataSource(source_name, MessageLoop::current()),
1025 }
1026
1027 AboutSource::AboutSource(Profile* profile)
1028 : DataSource(chrome::kAboutScheme, MessageLoop::current()),
1029 profile_(profile) { 1024 profile_(profile) {
1030 } 1025 }
1031 1026
1032 AboutSource::~AboutSource() { 1027 AboutSource::~AboutSource() {
1033 } 1028 }
1034 1029
1035 void AboutSource::StartDataRequest(const std::string& path_raw, 1030 void AboutSource::StartDataRequest(const std::string& path,
1036 bool is_incognito, int request_id) { 1031 bool is_incognito,
1037 std::string path = path_raw; 1032 int request_id) {
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
1046 std::string response; 1033 std::string response;
1047 if (path == kDnsPath) { 1034 std::string host = source_name();
1035 if (host == chrome::kChromeUIDNSHost) {
1048 AboutDnsHandler::Start(this, request_id); 1036 AboutDnsHandler::Start(this, request_id);
1049 return; 1037 return;
1050 } else if (path == kHistogramsPath) { 1038 } else if (host == chrome::kChromeUIHistogramsHost) {
1051 response = AboutHistograms(info); 1039 response = AboutHistograms(path);
1052 } else if (path == kMemoryPath) { 1040 } else if (host == chrome::kChromeUIMemoryHost) {
1041 response = GetAboutMemoryRedirectResponse(profile());
1042 } else if (host == chrome::kChromeUIMemoryRedirectHost) {
1053 AboutMemory(this, request_id); 1043 AboutMemory(this, request_id);
1054 return; 1044 return;
1055 } else if (path == kMemoryRedirectPath) {
1056 response = GetAboutMemoryRedirectResponse();
1057 #ifdef TRACK_ALL_TASK_OBJECTS 1045 #ifdef TRACK_ALL_TASK_OBJECTS
1058 } else if (path == kTasksPath) { 1046 } else if (host == chrome::kChromeUITasksHost) {
1059 response = AboutObjects(info); 1047 response = AboutObjects(path);
1060 #endif 1048 #endif
1061 } else if (path == kStatsPath) { 1049 } else if (host == chrome::kChromeUIStatsHost) {
1062 response = AboutStats(info); 1050 response = AboutStats(path);
1063 #if defined(USE_TCMALLOC) 1051 #if defined(USE_TCMALLOC)
1064 } else if (path == kTcmallocPath) { 1052 } else if (host == chrome::kChromeUITCMallocHost) {
1065 response = AboutTcmalloc(info); 1053 response = AboutTcmalloc();
1066 #endif 1054 #endif
1067 } else if (path == kVersionPath || path.empty()) { 1055 } else if (host == chrome::kChromeUIVersionHost) {
1068 #if defined(OS_CHROMEOS) 1056 #if defined(OS_CHROMEOS)
1069 new ChromeOSAboutVersionHandler(this, request_id); 1057 new ChromeOSAboutVersionHandler(this, request_id);
1070 return; 1058 return;
1071 #else 1059 #else
1072 DictionaryValue localized_strings; 1060 DictionaryValue localized_strings;
1073 localized_strings.SetString("os_version", ""); 1061 localized_strings.SetString("os_version", "");
1074 response = AboutVersion(&localized_strings, profile_); 1062 response = AboutVersion(&localized_strings, profile_);
1075 #endif 1063 #endif
1076 } else if (path == kCreditsPath) { 1064 } else if (host == chrome::kChromeUICreditsHost) {
1077 response = ResourceBundle::GetSharedInstance().GetRawDataResource( 1065 response = ResourceBundle::GetSharedInstance().GetRawDataResource(
1078 IDR_CREDITS_HTML).as_string(); 1066 IDR_CREDITS_HTML).as_string();
1079 } else if (path == kAboutPath) { 1067 } else if (host == chrome::kChromeUIChromeURLsHost) {
1080 response = AboutAbout(); 1068 response = ChromeURLs();
1081 #if defined(OS_CHROMEOS) 1069 #if defined(OS_CHROMEOS)
1082 } else if (path == kOSCreditsPath) { 1070 } else if (host == chrome::kChromeUIOSCreditsHost) {
1083 response = ResourceBundle::GetSharedInstance().GetRawDataResource( 1071 response = ResourceBundle::GetSharedInstance().GetRawDataResource(
1084 IDR_OS_CREDITS_HTML).as_string(); 1072 IDR_OS_CREDITS_HTML).as_string();
1085 } else if (path == kNetworkPath) { 1073 } else if (host == chrome::kChromeUINetworkHost) {
1086 response = AboutNetwork(info); 1074 response = AboutNetwork(path);
1087 #endif 1075 #endif
1088 } else if (path == kTermsPath) { 1076 } else if (host == chrome::kChromeUITermsHost) {
1089 #if defined(OS_CHROMEOS) 1077 #if defined(OS_CHROMEOS)
1090 ChromeOSTermsHandler::Start(this, request_id); 1078 ChromeOSTermsHandler::Start(this, request_id);
1091 return; 1079 return;
1092 #else 1080 #else
1093 response = ResourceBundle::GetSharedInstance().GetRawDataResource( 1081 response = ResourceBundle::GetSharedInstance().GetRawDataResource(
1094 IDR_TERMS_HTML).as_string(); 1082 IDR_TERMS_HTML).as_string();
1095 #endif 1083 #endif
1096 #if defined(OS_LINUX) 1084 #if defined(OS_LINUX)
1097 } else if (path == kLinuxProxyConfigPath) { 1085 } else if (host == chrome::kChromeUILinuxProxyConfigHost) {
1098 response = AboutLinuxProxyConfig(); 1086 response = AboutLinuxProxyConfig();
1099 } else if (path == kSandboxPath) { 1087 } else if (host == chrome::kChromeUISandboxHost) {
1100 response = AboutSandbox(); 1088 response = AboutSandbox();
1101 #endif 1089 #endif
1102 } 1090 }
1103 1091
1104 FinishDataRequest(response, request_id); 1092 FinishDataRequest(response, request_id);
1105 } 1093 }
1106 1094
1107 void AboutSource::FinishDataRequest(const std::string& response, 1095 void AboutSource::FinishDataRequest(const std::string& html, int request_id) {
1108 int request_id) {
1109 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 1096 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
1110 html_bytes->data.resize(response.size()); 1097 html_bytes->data.resize(html.size());
1111 std::copy(response.begin(), response.end(), html_bytes->data.begin()); 1098 std::copy(html.begin(), html.end(), html_bytes->data.begin());
1112 SendResponse(request_id, html_bytes); 1099 SendResponse(request_id, html_bytes);
1113 } 1100 }
1114 1101
1115 // AboutMemoryHandler ---------------------------------------------------------- 1102 // AboutMemoryHandler ----------------------------------------------------------
1116 1103
1117 // Helper for AboutMemory to bind results from a ProcessMetrics object 1104 // Helper for AboutMemory to bind results from a ProcessMetrics object
1118 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects 1105 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects
1119 // can be used in caller's scope (e.g for appending to a net total). 1106 // can be used in caller's scope (e.g for appending to a net total).
1120 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data, 1107 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data,
1121 ProcessMemoryInformation* info) { 1108 ProcessMemoryInformation* info) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 source_->FinishDataRequest(AboutVersion(&localized_strings, 1252 source_->FinishDataRequest(AboutVersion(&localized_strings,
1266 source_->profile()), request_id_); 1253 source_->profile()), request_id_);
1267 1254
1268 // CancelableRequestProvider isn't happy when it's deleted and servicing a 1255 // CancelableRequestProvider isn't happy when it's deleted and servicing a
1269 // task, so we delay the deletion. 1256 // task, so we delay the deletion.
1270 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 1257 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
1271 } 1258 }
1272 1259
1273 #endif 1260 #endif
1274 1261
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
1292 } // namespace 1262 } // namespace
1293 1263
1294 // ----------------------------------------------------------------------------- 1264 // -----------------------------------------------------------------------------
1295 1265
1296 bool WillHandleBrowserAboutURL(GURL* url, Profile* profile) { 1266 bool WillHandleBrowserAboutURL(GURL* url, Profile* profile) {
1297 // We only handle about: schemes. 1267 // TODO(msw): Eliminate "about:*" constants and literals from code and tests,
1298 if (!url->SchemeIs(chrome::kAboutScheme)) 1268 // then hopefully we can remove this forced fixup.
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))
1299 return false; 1278 return false;
1300 1279
1301 // about:blank is special. Frames are allowed to access about:blank, 1280 // Circumvent processing URLs that the renderer process will handle.
1302 // but they are not allowed to access other types of about pages. 1281 if (chrome_about_handler::WillHandle(*url))
1303 // Just ignore the about:blank and let the TAB_CONTENTS_WEB handle it.
1304 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutBlankURL))
1305 return false; 1282 return false;
1306 1283
1307 // Rewrite about:cache/* URLs to chrome://view-http-cache/* 1284 std::string host(url->host());
1308 if (StartsWithAboutSpecifier(*url, chrome::kAboutCacheURL)) { 1285 // Replace about with chrome-urls.
1309 *url = RemapAboutURL(chrome::kNetworkViewCacheURL, *url); 1286 if (host == chrome::kChromeUIAboutHost)
1310 return true; 1287 host = chrome::kChromeUIChromeURLsHost;
1311 } 1288 // Replace cache with view-http-cache.
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);
1312 1300
1313 #if defined(OS_WIN) 1301 // Handle URLs to crash the browser or wreck the gpu process.
1314 // Rewrite about:conflicts/* URLs to chrome://conflicts/* 1302 if (host == chrome::kChromeUIBrowserCrashHost) {
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)) {
1367 // Induce an intentional crash in the browser process. 1303 // Induce an intentional crash in the browser process.
1368 int* bad_pointer = NULL; 1304 CHECK(false);
1369 *bad_pointer = 42; 1305 } else if (host == chrome::kChromeUIGpuCleanHost) {
1370 return true;
1371 }
1372
1373 // Handle URLs to wreck the gpu process.
1374 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutGpuCleanURL)) {
1375 GpuProcessHost::SendOnIO( 1306 GpuProcessHost::SendOnIO(
1376 0, content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, new GpuMsg_Clean()); 1307 0, content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, new GpuMsg_Clean());
1377 } 1308 } else if (host == chrome::kChromeUIGpuCrashHost) {
1378 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutGpuCrashURL)) {
1379 GpuProcessHost::SendOnIO( 1309 GpuProcessHost::SendOnIO(
1380 0, content::CAUSE_FOR_GPU_LAUNCH_ABOUT_GPUCRASH, new GpuMsg_Crash()); 1310 0, content::CAUSE_FOR_GPU_LAUNCH_ABOUT_GPUCRASH, new GpuMsg_Crash());
1381 } 1311 } else if (host == chrome::kChromeUIGpuHangHost) {
1382 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutGpuHangURL)) {
1383 GpuProcessHost::SendOnIO( 1312 GpuProcessHost::SendOnIO(
1384 0, content::CAUSE_FOR_GPU_LAUNCH_ABOUT_GPUHANG, new GpuMsg_Hang()); 1313 0, content::CAUSE_FOR_GPU_LAUNCH_ABOUT_GPUHANG, new GpuMsg_Hang());
1385 } 1314 }
1386 1315
1387 // There are a few about: URLs that we hand over to the renderer. If the 1316 // Initialize any potentially corresponding AboutSource handler.
1388 // renderer wants them, don't do any rewriting. 1317 InitializeAboutDataSource(host, profile);
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);
1408 return true; 1318 return true;
1409 } 1319 }
1410 1320
1411 void InitializeAboutDataSource(Profile* profile) {
1412 profile->GetChromeURLDataManager()->AddDataSource(new AboutSource(profile));
1413 }
1414
1415 bool HandleNonNavigationAboutURL(const GURL& url) { 1321 bool HandleNonNavigationAboutURL(const GURL& url) {
1416 // about:ipc is currently buggy, so we disable it for official builds. 1322 // chrome://ipc/ is currently buggy, so we disable it for official builds.
1417 #if !defined(OFFICIAL_BUILD) 1323 #if !defined(OFFICIAL_BUILD)
1418 1324
1419 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED) 1325 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED)
1420 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutIPCURL)) { 1326 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) {
1421 // Run the dialog. This will re-use the existing one if it's already up. 1327 // Run the dialog. This will re-use the existing one if it's already up.
1422 browser::ShowAboutIPCDialog(); 1328 browser::ShowAboutIPCDialog();
1423 return true; 1329 return true;
1424 } 1330 }
1425 #endif 1331 #endif
1426 1332
1427 #endif // OFFICIAL_BUILD 1333 #endif // OFFICIAL_BUILD
1428 1334
1429 return false; 1335 return false;
1430 } 1336 }
1431 1337
1432 std::vector<std::string> AboutPaths() { 1338 std::vector<std::string> ChromePaths() {
1433 std::vector<std::string> paths; 1339 std::vector<std::string> paths;
1434 paths.reserve(arraysize(kAllAboutPaths)); 1340 paths.reserve(arraysize(kChromePaths));
1435 for (size_t i = 0; i < arraysize(kAllAboutPaths); i++) 1341 for (size_t i = 0; i < arraysize(kChromePaths); i++)
1436 paths.push_back(kAllAboutPaths[i]); 1342 paths.push_back(kChromePaths[i]);
1437 return paths; 1343 return paths;
1438 } 1344 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_about_handler.h ('k') | chrome/browser/browser_about_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698