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

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

Powered by Google App Engine
This is Rietveld 408576698