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/ui/webui/about_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/i18n/number_formatting.h" | 16 #include "base/i18n/number_formatting.h" |
17 #include "base/json/json_writer.h" | 17 #include "base/json/json_writer.h" |
18 #include "base/memory/singleton.h" | 18 #include "base/memory/singleton.h" |
19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
20 #include "base/metrics/stats_table.h" | 20 #include "base/metrics/stats_table.h" |
21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
22 #include "base/string_number_conversions.h" | 22 #include "base/string_number_conversions.h" |
23 #include "base/string_piece.h" | 23 #include "base/string_piece.h" |
24 #include "base/string_util.h" | 24 #include "base/string_util.h" |
25 #include "base/stringprintf.h" | 25 #include "base/stringprintf.h" |
26 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
27 #include "base/utf_string_conversions.h" | 27 #include "base/utf_string_conversions.h" |
28 #include "base/values.h" | 28 #include "base/values.h" |
29 #include "chrome/browser/about_flags.h" | 29 #include "chrome/browser/about_flags.h" |
| 30 #include "chrome/browser/browser_about_handler.h" |
30 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
31 #include "chrome/browser/defaults.h" | 32 #include "chrome/browser/defaults.h" |
32 #include "chrome/browser/memory_details.h" | 33 #include "chrome/browser/memory_details.h" |
33 #include "chrome/browser/metrics/histogram_synchronizer.h" | 34 #include "chrome/browser/metrics/histogram_synchronizer.h" |
34 #include "chrome/browser/net/predictor.h" | 35 #include "chrome/browser/net/predictor.h" |
35 #include "chrome/browser/net/url_fixer_upper.h" | 36 #include "chrome/browser/net/url_fixer_upper.h" |
36 #include "chrome/browser/plugin_prefs.h" | 37 #include "chrome/browser/plugin_prefs.h" |
37 #include "chrome/browser/profiles/profile.h" | 38 #include "chrome/browser/profiles/profile.h" |
38 #include "chrome/browser/profiles/profile_manager.h" | 39 #include "chrome/browser/profiles/profile_manager.h" |
39 #include "chrome/browser/ui/browser_dialogs.h" | 40 #include "chrome/browser/ui/browser_dialogs.h" |
40 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 41 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
41 #include "chrome/common/about_handler.h" | 42 #include "chrome/common/about_handler.h" |
42 #include "chrome/common/chrome_paths.h" | 43 #include "chrome/common/chrome_paths.h" |
43 #include "chrome/common/chrome_version_info.h" | 44 #include "chrome/common/chrome_version_info.h" |
44 #include "chrome/common/jstemplate_builder.h" | 45 #include "chrome/common/jstemplate_builder.h" |
45 #include "chrome/common/net/gaia/google_service_auth_error.h" | 46 #include "chrome/common/net/gaia/google_service_auth_error.h" |
46 #include "chrome/common/render_messages.h" | 47 #include "chrome/common/render_messages.h" |
47 #include "chrome/common/url_constants.h" | 48 #include "chrome/common/url_constants.h" |
48 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 49 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
49 #include "content/browser/plugin_service.h" | 50 #include "content/browser/plugin_service.h" |
50 #include "content/browser/renderer_host/render_view_host.h" | 51 #include "content/browser/renderer_host/render_view_host.h" |
51 #include "content/browser/sensors/sensors_provider.h" | 52 #include "content/browser/sensors/sensors_provider.h" |
| 53 #include "content/browser/tab_contents/tab_contents.h" |
52 #include "content/public/browser/browser_thread.h" | 54 #include "content/public/browser/browser_thread.h" |
53 #include "content/public/browser/render_process_host.h" | 55 #include "content/public/browser/render_process_host.h" |
54 #include "content/public/common/content_client.h" | 56 #include "content/public/common/content_client.h" |
55 #include "crypto/nss_util.h" | 57 #include "crypto/nss_util.h" |
56 #include "googleurl/src/gurl.h" | 58 #include "googleurl/src/gurl.h" |
57 #include "grit/browser_resources.h" | 59 #include "grit/browser_resources.h" |
58 #include "grit/chromium_strings.h" | 60 #include "grit/chromium_strings.h" |
59 #include "grit/generated_resources.h" | 61 #include "grit/generated_resources.h" |
60 #include "grit/locale_settings.h" | 62 #include "grit/locale_settings.h" |
61 #include "net/base/escape.h" | 63 #include "net/base/escape.h" |
(...skipping 21 matching lines...) Expand all Loading... |
83 #endif | 85 #endif |
84 | 86 |
85 #if defined(USE_TCMALLOC) | 87 #if defined(USE_TCMALLOC) |
86 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" | 88 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" |
87 #endif | 89 #endif |
88 | 90 |
89 using base::Time; | 91 using base::Time; |
90 using base::TimeDelta; | 92 using base::TimeDelta; |
91 using content::BrowserThread; | 93 using content::BrowserThread; |
92 | 94 |
93 #if defined(USE_TCMALLOC) | |
94 // static | |
95 AboutTcmallocOutputs* AboutTcmallocOutputs::GetInstance() { | |
96 return Singleton<AboutTcmallocOutputs>::get(); | |
97 } | |
98 | |
99 AboutTcmallocOutputs::AboutTcmallocOutputs() {} | |
100 | |
101 AboutTcmallocOutputs::~AboutTcmallocOutputs() {} | |
102 | |
103 // Glue between the callback task and the method in the singleton. | |
104 void AboutTcmallocRendererCallback(base::ProcessId pid, | |
105 const std::string& output) { | |
106 AboutTcmallocOutputs::GetInstance()->RendererCallback(pid, output); | |
107 } | |
108 #endif | |
109 | |
110 namespace { | 95 namespace { |
111 | 96 |
112 // Add paths here to be included in chrome://chrome-urls (about:about). | |
113 // These paths will also be suggested by BuiltinProvider. | |
114 const char* const kChromePaths[] = { | |
115 chrome::kChromeUIAppCacheInternalsHost, | |
116 chrome::kChromeUIBlobInternalsHost, | |
117 chrome::kChromeUIBookmarksHost, | |
118 chrome::kChromeUICacheHost, | |
119 chrome::kChromeUIChromeURLsHost, | |
120 chrome::kChromeUICrashesHost, | |
121 chrome::kChromeUICreditsHost, | |
122 chrome::kChromeUIDNSHost, | |
123 chrome::kChromeUIDownloadsHost, | |
124 chrome::kChromeUIExtensionsHost, | |
125 chrome::kChromeUIFlagsHost, | |
126 chrome::kChromeUIFlashHost, | |
127 chrome::kChromeUIGpuInternalsHost, | |
128 chrome::kChromeUIHistogramsHost, | |
129 chrome::kChromeUIHistoryHost, | |
130 chrome::kChromeUIIPCHost, | |
131 chrome::kChromeUIMediaInternalsHost, | |
132 chrome::kChromeUIMemoryHost, | |
133 chrome::kChromeUINetInternalsHost, | |
134 chrome::kChromeUINetworkViewCacheHost, | |
135 chrome::kChromeUINewTabHost, | |
136 chrome::kChromeUIPluginsHost, | |
137 chrome::kChromeUIPrintHost, | |
138 chrome::kChromeUIProfilerHost, | |
139 chrome::kChromeUIQuotaInternalsHost, | |
140 chrome::kChromeUISessionsHost, | |
141 chrome::kChromeUISettingsHost, | |
142 chrome::kChromeUIStatsHost, | |
143 chrome::kChromeUISyncInternalsHost, | |
144 chrome::kChromeUITaskManagerHost, | |
145 chrome::kChromeUITCMallocHost, | |
146 chrome::kChromeUITermsHost, | |
147 chrome::kChromeUITracingHost, | |
148 chrome::kChromeUIVersionHost, | |
149 chrome::kChromeUIWorkersHost, | |
150 #if defined(OS_WIN) | |
151 chrome::kChromeUIConflictsHost, | |
152 #endif | |
153 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
154 chrome::kChromeUILinuxProxyConfigHost, | |
155 chrome::kChromeUISandboxHost, | |
156 #endif | |
157 #if defined(OS_CHROMEOS) | |
158 chrome::kChromeUIActiveDownloadsHost, | |
159 chrome::kChromeUIChooseMobileNetworkHost, | |
160 chrome::kChromeUICryptohomeHost, | |
161 chrome::kChromeUIDiscardsHost, | |
162 chrome::kChromeUIImageBurnerHost, | |
163 chrome::kChromeUIKeyboardOverlayHost, | |
164 chrome::kChromeUILoginHost, | |
165 chrome::kChromeUINetworkHost, | |
166 chrome::kChromeUIOobeHost, | |
167 chrome::kChromeUIOSCreditsHost, | |
168 chrome::kChromeUIProxySettingsHost, | |
169 chrome::kChromeUISystemInfoHost, | |
170 #endif | |
171 }; | |
172 | |
173 // AboutSource handles these chrome:// paths. | |
174 const char* const kAboutSourceNames[] = { | |
175 chrome::kChromeUIChromeURLsHost, | |
176 chrome::kChromeUICreditsHost, | |
177 chrome::kChromeUIDNSHost, | |
178 chrome::kChromeUIHistogramsHost, | |
179 chrome::kChromeUIMemoryHost, | |
180 chrome::kChromeUIMemoryRedirectHost, | |
181 chrome::kChromeUIStatsHost, | |
182 chrome::kChromeUITaskManagerHost, | |
183 chrome::kChromeUITermsHost, | |
184 chrome::kChromeUIVersionHost, | |
185 #if defined(USE_TCMALLOC) | |
186 chrome::kChromeUITCMallocHost, | |
187 #endif | |
188 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
189 chrome::kChromeUILinuxProxyConfigHost, | |
190 chrome::kChromeUISandboxHost, | |
191 #endif | |
192 #if defined(OS_CHROMEOS) | |
193 chrome::kChromeUICryptohomeHost, | |
194 chrome::kChromeUIDiscardsHost, | |
195 chrome::kChromeUINetworkHost, | |
196 chrome::kChromeUIOSCreditsHost, | |
197 #endif | |
198 }; | |
199 | |
200 const char kCreditsJsPath[] = "credits.js"; | 97 const char kCreditsJsPath[] = "credits.js"; |
201 const char kMemoryJsPath[] = "memory.js"; | 98 const char kMemoryJsPath[] = "memory.js"; |
202 const char kStatsJsPath[] = "stats.js"; | 99 const char kStatsJsPath[] = "stats.js"; |
203 const char kStringsJsPath[] = "strings.js"; | 100 const char kStringsJsPath[] = "strings.js"; |
204 const char kVersionJsPath[] = "version.js"; | 101 const char kVersionJsPath[] = "version.js"; |
205 | 102 |
206 class AboutSource : public ChromeURLDataManager::DataSource { | |
207 public: | |
208 // Construct a data source for the specified |source_name|. | |
209 AboutSource(const std::string& source_name, Profile* profile); | |
210 | |
211 // Called when the network layer has requested a resource underneath | |
212 // the path we registered. | |
213 virtual void StartDataRequest(const std::string& path, | |
214 bool is_incognito, | |
215 int request_id) OVERRIDE; | |
216 | |
217 virtual std::string GetMimeType(const std::string& path) const OVERRIDE; | |
218 | |
219 // Send the response data. | |
220 void FinishDataRequest(const std::string& html, int request_id); | |
221 | |
222 Profile* profile() { return profile_; } | |
223 | |
224 private: | |
225 virtual ~AboutSource(); | |
226 | |
227 Profile* profile_; | |
228 | |
229 DISALLOW_COPY_AND_ASSIGN(AboutSource); | |
230 }; | |
231 | |
232 // When you type about:memory, it actually loads this intermediate URL that | 103 // When you type about:memory, it actually loads this intermediate URL that |
233 // redirects you to the final page. This avoids the problem where typing | 104 // redirects you to the final page. This avoids the problem where typing |
234 // "about:memory" on the new tab page or any other page where a process | 105 // "about:memory" on the new tab page or any other page where a process |
235 // transition would occur to the about URL will cause some confusion. | 106 // transition would occur to the about URL will cause some confusion. |
236 // | 107 // |
237 // The problem is that during the processing of the memory page, there are two | 108 // The problem is that during the processing of the memory page, there are two |
238 // processes active, the original and the destination one. This can create the | 109 // processes active, the original and the destination one. This can create the |
239 // impression that we're using more resources than we actually are. This | 110 // impression that we're using more resources than we actually are. This |
240 // redirect solves the problem by eliminating the process transition during the | 111 // redirect solves the problem by eliminating the process transition during the |
241 // time that about memory is being computed. | 112 // time that about memory is being computed. |
242 std::string GetAboutMemoryRedirectResponse(Profile* profile) { | 113 std::string GetAboutMemoryRedirectResponse(Profile* profile) { |
243 InitializeAboutDataSource(chrome::kChromeUIMemoryRedirectHost, profile); | |
244 return StringPrintf("<meta http-equiv=\"refresh\" content=\"0;%s\">", | 114 return StringPrintf("<meta http-equiv=\"refresh\" content=\"0;%s\">", |
245 chrome::kChromeUIMemoryRedirectURL); | 115 chrome::kChromeUIMemoryRedirectURL); |
246 } | 116 } |
247 | 117 |
248 // Handling about:memory is complicated enough to encapsulate its related | 118 // Handling about:memory is complicated enough to encapsulate its related |
249 // methods into a single class. The user should create it (on the heap) and call | 119 // methods into a single class. The user should create it (on the heap) and call |
250 // its |StartFetch()| method. | 120 // its |StartFetch()| method. |
251 class AboutMemoryHandler : public MemoryDetails { | 121 class AboutMemoryHandler : public MemoryDetails { |
252 public: | 122 public: |
253 AboutMemoryHandler(AboutSource* source, int request_id) | 123 AboutMemoryHandler(AboutUIHTMLSource* source, int request_id) |
254 : source_(source), | 124 : source_(source), |
255 request_id_(request_id) { | 125 request_id_(request_id) { |
256 } | 126 } |
257 | 127 |
258 virtual void OnDetailsAvailable() OVERRIDE; | 128 virtual void OnDetailsAvailable() OVERRIDE; |
259 | 129 |
260 private: | 130 private: |
261 ~AboutMemoryHandler() {} | 131 ~AboutMemoryHandler() {} |
262 | 132 |
263 void BindProcessMetrics(DictionaryValue* data, | 133 void BindProcessMetrics(DictionaryValue* data, |
264 ProcessMemoryInformation* info); | 134 ProcessMemoryInformation* info); |
265 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); | 135 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); |
266 | 136 |
267 scoped_refptr<AboutSource> source_; | 137 scoped_refptr<AboutUIHTMLSource> source_; |
268 int request_id_; | 138 int request_id_; |
269 | 139 |
270 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); | 140 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); |
271 }; | 141 }; |
272 | 142 |
273 #if defined(OS_CHROMEOS) | 143 #if defined(OS_CHROMEOS) |
274 // ChromeOSAboutVersionHandler is responsible for loading the Chrome OS | 144 // ChromeOSAboutVersionHandler is responsible for loading the Chrome OS |
275 // version. | 145 // version. |
276 // ChromeOSAboutVersionHandler handles deleting itself once the version has | 146 // ChromeOSAboutVersionHandler handles deleting itself once the version has |
277 // been obtained and AboutSource notified. | 147 // been obtained and AboutUIHTMLSource notified. |
278 class ChromeOSAboutVersionHandler { | 148 class ChromeOSAboutVersionHandler { |
279 public: | 149 public: |
280 ChromeOSAboutVersionHandler(AboutSource* source, int request_id); | 150 ChromeOSAboutVersionHandler(AboutUIHTMLSource* source, int request_id); |
281 | 151 |
282 // Callback from chromeos::VersionLoader giving the version. | 152 // Callback from chromeos::VersionLoader giving the version. |
283 void OnVersion(chromeos::VersionLoader::Handle handle, | 153 void OnVersion(chromeos::VersionLoader::Handle handle, |
284 std::string version); | 154 std::string version); |
285 | 155 |
286 private: | 156 private: |
287 // Where the results are fed to. | 157 // Where the results are fed to. |
288 scoped_refptr<AboutSource> source_; | 158 scoped_refptr<AboutUIHTMLSource> source_; |
289 | 159 |
290 // ID identifying the request. | 160 // ID identifying the request. |
291 int request_id_; | 161 int request_id_; |
292 | 162 |
293 // Handles asynchronously loading the version. | 163 // Handles asynchronously loading the version. |
294 chromeos::VersionLoader loader_; | 164 chromeos::VersionLoader loader_; |
295 | 165 |
296 // Used to request the version. | 166 // Used to request the version. |
297 CancelableRequestConsumer consumer_; | 167 CancelableRequestConsumer consumer_; |
298 | 168 |
299 DISALLOW_COPY_AND_ASSIGN(ChromeOSAboutVersionHandler); | 169 DISALLOW_COPY_AND_ASSIGN(ChromeOSAboutVersionHandler); |
300 }; | 170 }; |
301 | 171 |
302 class ChromeOSTermsHandler | 172 class ChromeOSTermsHandler |
303 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { | 173 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { |
304 public: | 174 public: |
305 static void Start(AboutSource* source, | 175 static void Start(AboutUIHTMLSource* source, |
306 const std::string& path, | 176 const std::string& path, |
307 int request_id) { | 177 int request_id) { |
308 scoped_refptr<ChromeOSTermsHandler> handler( | 178 scoped_refptr<ChromeOSTermsHandler> handler( |
309 new ChromeOSTermsHandler(source, path, request_id)); | 179 new ChromeOSTermsHandler(source, path, request_id)); |
310 handler->StartOnUIThread(); | 180 handler->StartOnUIThread(); |
311 } | 181 } |
312 | 182 |
313 private: | 183 private: |
314 ChromeOSTermsHandler(AboutSource* source, | 184 ChromeOSTermsHandler(AboutUIHTMLSource* source, |
315 const std::string& path, | 185 const std::string& path, |
316 int request_id) | 186 int request_id) |
317 : source_(source), | 187 : source_(source), |
318 path_(path), | 188 path_(path), |
319 request_id_(request_id), | 189 request_id_(request_id), |
320 locale_(chromeos::WizardController::GetInitialLocale()) { | 190 locale_(chromeos::WizardController::GetInitialLocale()) { |
321 } | 191 } |
322 | 192 |
323 void StartOnUIThread() { | 193 void StartOnUIThread() { |
324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 // If we fail to load Chrome OS EULA from disk, load it from resources. | 234 // If we fail to load Chrome OS EULA from disk, load it from resources. |
365 // Do nothing if OEM EULA load failed. | 235 // Do nothing if OEM EULA load failed. |
366 if (contents_.empty() && path_ != chrome::kOemEulaURLPath) { | 236 if (contents_.empty() && path_ != chrome::kOemEulaURLPath) { |
367 contents_ = ResourceBundle::GetSharedInstance().GetRawDataResource( | 237 contents_ = ResourceBundle::GetSharedInstance().GetRawDataResource( |
368 IDR_TERMS_HTML).as_string(); | 238 IDR_TERMS_HTML).as_string(); |
369 } | 239 } |
370 source_->FinishDataRequest(contents_, request_id_); | 240 source_->FinishDataRequest(contents_, request_id_); |
371 } | 241 } |
372 | 242 |
373 // Where the results are fed to. | 243 // Where the results are fed to. |
374 scoped_refptr<AboutSource> source_; | 244 scoped_refptr<AboutUIHTMLSource> source_; |
375 | 245 |
376 // Path in the URL. | 246 // Path in the URL. |
377 std::string path_; | 247 std::string path_; |
378 | 248 |
379 // ID identifying the request. | 249 // ID identifying the request. |
380 int request_id_; | 250 int request_id_; |
381 | 251 |
382 // Locale of the EULA. | 252 // Locale of the EULA. |
383 std::string locale_; | 253 std::string locale_; |
384 | 254 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 AppendFooter(&output); | 609 AppendFooter(&output); |
740 return output; | 610 return output; |
741 } | 611 } |
742 | 612 |
743 #endif // OS_CHROMEOS | 613 #endif // OS_CHROMEOS |
744 | 614 |
745 // AboutDnsHandler bounces the request back to the IO thread to collect | 615 // AboutDnsHandler bounces the request back to the IO thread to collect |
746 // the DNS information. | 616 // the DNS information. |
747 class AboutDnsHandler : public base::RefCountedThreadSafe<AboutDnsHandler> { | 617 class AboutDnsHandler : public base::RefCountedThreadSafe<AboutDnsHandler> { |
748 public: | 618 public: |
749 static void Start(AboutSource* source, int request_id) { | 619 static void Start(AboutUIHTMLSource* source, int request_id) { |
750 scoped_refptr<AboutDnsHandler> handler( | 620 scoped_refptr<AboutDnsHandler> handler( |
751 new AboutDnsHandler(source, request_id)); | 621 new AboutDnsHandler(source, request_id)); |
752 handler->StartOnUIThread(); | 622 handler->StartOnUIThread(); |
753 } | 623 } |
754 | 624 |
755 private: | 625 private: |
756 AboutDnsHandler(AboutSource* source, int request_id) | 626 AboutDnsHandler(AboutUIHTMLSource* source, int request_id) |
757 : source_(source), | 627 : source_(source), |
758 request_id_(request_id) { | 628 request_id_(request_id) { |
759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
760 } | 630 } |
761 | 631 |
762 // Calls FinishOnUIThread() on completion. | 632 // Calls FinishOnUIThread() on completion. |
763 void StartOnUIThread() { | 633 void StartOnUIThread() { |
764 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
765 chrome_browser_net::Predictor* predictor = | 635 chrome_browser_net::Predictor* predictor = |
766 source_->profile()->GetNetworkPredictor(); | 636 source_->profile()->GetNetworkPredictor(); |
(...skipping 15 matching lines...) Expand all Loading... |
782 BrowserThread::UI, FROM_HERE, | 652 BrowserThread::UI, FROM_HERE, |
783 NewRunnableMethod(this, &AboutDnsHandler::FinishOnUIThread, data)); | 653 NewRunnableMethod(this, &AboutDnsHandler::FinishOnUIThread, data)); |
784 } | 654 } |
785 | 655 |
786 void FinishOnUIThread(const std::string& data) { | 656 void FinishOnUIThread(const std::string& data) { |
787 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
788 source_->FinishDataRequest(data, request_id_); | 658 source_->FinishDataRequest(data, request_id_); |
789 } | 659 } |
790 | 660 |
791 // Where the results are fed to. | 661 // Where the results are fed to. |
792 scoped_refptr<AboutSource> source_; | 662 scoped_refptr<AboutUIHTMLSource> source_; |
793 | 663 |
794 // ID identifying the request. | 664 // ID identifying the request. |
795 int request_id_; | 665 int request_id_; |
796 | 666 |
797 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler); | 667 DISALLOW_COPY_AND_ASSIGN(AboutDnsHandler); |
798 }; | 668 }; |
799 | 669 |
800 #if defined(USE_TCMALLOC) | 670 #if defined(USE_TCMALLOC) |
801 std::string AboutTcmalloc() { | 671 std::string AboutTcmalloc() { |
802 std::string data; | 672 std::string data; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 } | 733 } |
864 | 734 |
865 std::string data; | 735 std::string data; |
866 AppendHeader(&data, 0, unescaped_title); | 736 AppendHeader(&data, 0, unescaped_title); |
867 AppendBody(&data); | 737 AppendBody(&data); |
868 base::StatisticsRecorder::WriteHTMLGraph(unescaped_query, &data); | 738 base::StatisticsRecorder::WriteHTMLGraph(unescaped_query, &data); |
869 AppendFooter(&data); | 739 AppendFooter(&data); |
870 return data; | 740 return data; |
871 } | 741 } |
872 | 742 |
873 void AboutMemory(const std::string& path, AboutSource* source, int request_id) { | 743 void AboutMemory(const std::string& path, AboutUIHTMLSource* source, |
| 744 int request_id) { |
874 if (path == kStringsJsPath) { | 745 if (path == kStringsJsPath) { |
875 // The AboutMemoryHandler cleans itself up, but |StartFetch()| will want the | 746 // The AboutMemoryHandler cleans itself up, but |StartFetch()| will want |
876 // refcount to be greater than 0. | 747 // the refcount to be greater than 0. |
877 scoped_refptr<AboutMemoryHandler> | 748 scoped_refptr<AboutMemoryHandler> |
878 handler(new AboutMemoryHandler(source, request_id)); | 749 handler(new AboutMemoryHandler(source, request_id)); |
879 handler->StartFetch(); | 750 handler->StartFetch(); |
880 } else { | 751 } else { |
881 source->FinishDataRequest( | 752 source->FinishDataRequest( |
882 ResourceBundle::GetSharedInstance().GetRawDataResource( | 753 ResourceBundle::GetSharedInstance().GetRawDataResource( |
883 path == kMemoryJsPath ? IDR_ABOUT_MEMORY_JS : | 754 path == kMemoryJsPath ? IDR_ABOUT_MEMORY_JS : |
884 IDR_ABOUT_MEMORY_HTML).as_string(), request_id); | 755 IDR_ABOUT_MEMORY_HTML).as_string(), request_id); |
885 } | 756 } |
886 } | 757 } |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 localized_strings->SetString("profile_path", | 1093 localized_strings->SetString("profile_path", |
1223 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND)); | 1094 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND)); |
1224 } | 1095 } |
1225 | 1096 |
1226 std::string data; | 1097 std::string data; |
1227 jstemplate_builder::AppendJsonJS(localized_strings, &data); | 1098 jstemplate_builder::AppendJsonJS(localized_strings, &data); |
1228 return data; | 1099 return data; |
1229 } | 1100 } |
1230 | 1101 |
1231 // Used as a callback for PluginService::GetPlugins(). | 1102 // Used as a callback for PluginService::GetPlugins(). |
1232 void HandleAboutVersionStrings(AboutSource* source, | 1103 void HandleAboutVersionStrings(AboutUIHTMLSource* source, |
1233 int request_id, | 1104 int request_id, |
1234 const std::vector<webkit::WebPluginInfo>&) { | 1105 const std::vector<webkit::WebPluginInfo>&) { |
1235 #if defined(OS_CHROMEOS) | 1106 #if defined(OS_CHROMEOS) |
1236 new ChromeOSAboutVersionHandler(source, request_id); | 1107 new ChromeOSAboutVersionHandler(source, request_id); |
1237 #else | 1108 #else |
1238 DictionaryValue localized_strings; | 1109 DictionaryValue localized_strings; |
1239 localized_strings.SetString("os_version", ""); | 1110 localized_strings.SetString("os_version", ""); |
1240 source->FinishDataRequest( | 1111 source->FinishDataRequest( |
1241 AboutVersionStrings(&localized_strings, source->profile()), | 1112 AboutVersionStrings(&localized_strings, source->profile()), |
1242 request_id); | 1113 request_id); |
(...skipping 27 matching lines...) Expand all Loading... |
1270 void AboutMemoryHandler::AppendProcess(ListValue* child_data, | 1141 void AboutMemoryHandler::AppendProcess(ListValue* child_data, |
1271 ProcessMemoryInformation* info) { | 1142 ProcessMemoryInformation* info) { |
1272 DCHECK(child_data && info); | 1143 DCHECK(child_data && info); |
1273 | 1144 |
1274 // Append a new DictionaryValue for this renderer to our list. | 1145 // Append a new DictionaryValue for this renderer to our list. |
1275 DictionaryValue* child = new DictionaryValue(); | 1146 DictionaryValue* child = new DictionaryValue(); |
1276 child_data->Append(child); | 1147 child_data->Append(child); |
1277 BindProcessMetrics(child, info); | 1148 BindProcessMetrics(child, info); |
1278 | 1149 |
1279 std::string child_label( | 1150 std::string child_label( |
1280 ChildProcessInfo::GetFullTypeNameInEnglish(info->type, | 1151 ProcessMemoryInformation::GetFullTypeNameInEnglish(info->type, |
1281 info->renderer_type)); | 1152 info->renderer_type)); |
1282 if (info->is_diagnostics) | 1153 if (info->is_diagnostics) |
1283 child_label.append(" (diagnostics)"); | 1154 child_label.append(" (diagnostics)"); |
1284 child->SetString("child_name", child_label); | 1155 child->SetString("child_name", child_label); |
1285 ListValue* titles = new ListValue(); | 1156 ListValue* titles = new ListValue(); |
1286 child->Set("titles", titles); | 1157 child->Set("titles", titles); |
1287 for (size_t i = 0; i < info->titles.size(); ++i) | 1158 for (size_t i = 0; i < info->titles.size(); ++i) |
1288 titles->Append(new StringValue(info->titles[i])); | 1159 titles->Append(new StringValue(info->titles[i])); |
1289 } | 1160 } |
1290 | 1161 |
1291 | 1162 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 | 1237 |
1367 std::string data; | 1238 std::string data; |
1368 jstemplate_builder::AppendJsonJS(&root, &data); | 1239 jstemplate_builder::AppendJsonJS(&root, &data); |
1369 source_->FinishDataRequest(data, request_id_); | 1240 source_->FinishDataRequest(data, request_id_); |
1370 } | 1241 } |
1371 | 1242 |
1372 #if defined(OS_CHROMEOS) | 1243 #if defined(OS_CHROMEOS) |
1373 // ChromeOSAboutVersionHandler ----------------------------------------------- | 1244 // ChromeOSAboutVersionHandler ----------------------------------------------- |
1374 | 1245 |
1375 ChromeOSAboutVersionHandler::ChromeOSAboutVersionHandler( | 1246 ChromeOSAboutVersionHandler::ChromeOSAboutVersionHandler( |
1376 AboutSource* source, | 1247 AboutUIHTMLSource* source, |
1377 int request_id) | 1248 int request_id) |
1378 : source_(source), | 1249 : source_(source), |
1379 request_id_(request_id) { | 1250 request_id_(request_id) { |
1380 loader_.GetVersion(&consumer_, | 1251 loader_.GetVersion(&consumer_, |
1381 base::Bind(&ChromeOSAboutVersionHandler::OnVersion, | 1252 base::Bind(&ChromeOSAboutVersionHandler::OnVersion, |
1382 base::Unretained(this)), | 1253 base::Unretained(this)), |
1383 chromeos::VersionLoader::VERSION_FULL); | 1254 chromeos::VersionLoader::VERSION_FULL); |
1384 } | 1255 } |
1385 | 1256 |
1386 void ChromeOSAboutVersionHandler::OnVersion( | 1257 void ChromeOSAboutVersionHandler::OnVersion( |
1387 chromeos::VersionLoader::Handle handle, | 1258 chromeos::VersionLoader::Handle handle, |
1388 std::string version) { | 1259 std::string version) { |
1389 DictionaryValue localized_strings; | 1260 DictionaryValue localized_strings; |
1390 localized_strings.SetString("os_version", version); | 1261 localized_strings.SetString("os_version", version); |
1391 source_->FinishDataRequest(AboutVersionStrings( | 1262 source_->FinishDataRequest(AboutVersionStrings( |
1392 &localized_strings, source_->profile()), request_id_); | 1263 &localized_strings, source_->profile()), request_id_); |
1393 | 1264 |
1394 // CancelableRequestProvider isn't happy when it's deleted and servicing a | 1265 // CancelableRequestProvider isn't happy when it's deleted and servicing a |
1395 // task, so we delay the deletion. | 1266 // task, so we delay the deletion. |
1396 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1267 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
1397 } | 1268 } |
1398 | 1269 |
1399 #endif | 1270 #endif |
1400 | 1271 |
1401 } // namespace | 1272 } // namespace |
1402 | 1273 |
1403 // AboutSource ----------------------------------------------------------------- | 1274 // AboutUIHTMLSource ---------------------------------------------------------- |
1404 | 1275 |
1405 AboutSource::AboutSource(const std::string& source_name, Profile* profile) | 1276 AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name, |
| 1277 Profile* profile) |
1406 : DataSource(source_name, MessageLoop::current()), | 1278 : DataSource(source_name, MessageLoop::current()), |
1407 profile_(profile) { | 1279 profile_(profile) { |
1408 } | 1280 } |
1409 | 1281 |
1410 AboutSource::~AboutSource() { | 1282 AboutUIHTMLSource::~AboutUIHTMLSource() { |
1411 } | 1283 } |
1412 | 1284 |
1413 void AboutSource::StartDataRequest(const std::string& path, | 1285 void AboutUIHTMLSource::StartDataRequest(const std::string& path, |
1414 bool is_incognito, | 1286 bool is_incognito, |
1415 int request_id) { | 1287 int request_id) { |
1416 std::string response; | 1288 std::string response; |
1417 std::string host = source_name(); | 1289 std::string host = source_name(); |
1418 // Add your data source here, in alphabetical order. | 1290 // Add your data source here, in alphabetical order. |
1419 if (host == chrome::kChromeUIChromeURLsHost) { | 1291 if (host == chrome::kChromeUIChromeURLsHost) { |
1420 response = ChromeURLs(); | 1292 response = ChromeURLs(); |
1421 } else if (host == chrome::kChromeUICreditsHost) { | 1293 } else if (host == chrome::kChromeUICreditsHost) { |
1422 int idr = (path == kCreditsJsPath) ? IDR_CREDITS_JS : IDR_CREDITS_HTML; | 1294 int idr = (path == kCreditsJsPath) ? IDR_CREDITS_JS : IDR_CREDITS_HTML; |
1423 response = ResourceBundle::GetSharedInstance().GetRawDataResource( | 1295 response = ResourceBundle::GetSharedInstance().GetRawDataResource( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 make_scoped_refptr(this), request_id)); | 1348 make_scoped_refptr(this), request_id)); |
1477 return; | 1349 return; |
1478 } else { | 1350 } else { |
1479 response = AboutVersionStaticContent(path); | 1351 response = AboutVersionStaticContent(path); |
1480 } | 1352 } |
1481 } | 1353 } |
1482 | 1354 |
1483 FinishDataRequest(response, request_id); | 1355 FinishDataRequest(response, request_id); |
1484 } | 1356 } |
1485 | 1357 |
1486 void AboutSource::FinishDataRequest(const std::string& html, int request_id) { | 1358 void AboutUIHTMLSource::FinishDataRequest(const std::string& html, |
| 1359 int request_id) { |
1487 std::string html_copy(html); | 1360 std::string html_copy(html); |
1488 SendResponse(request_id, base::RefCountedString::TakeString(&html_copy)); | 1361 SendResponse(request_id, base::RefCountedString::TakeString(&html_copy)); |
1489 } | 1362 } |
1490 | 1363 |
1491 std::string AboutSource::GetMimeType(const std::string& path) const { | 1364 std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const { |
1492 if (path == kCreditsJsPath || | 1365 if (path == kCreditsJsPath || |
1493 path == kStatsJsPath || | 1366 path == kStatsJsPath || |
1494 path == kStringsJsPath || | 1367 path == kStringsJsPath || |
1495 path == kVersionJsPath || | 1368 path == kVersionJsPath || |
1496 path == kMemoryJsPath) { | 1369 path == kMemoryJsPath) { |
1497 return "application/javascript"; | 1370 return "application/javascript"; |
1498 } | 1371 } |
1499 return "text/html"; | 1372 return "text/html"; |
1500 } | 1373 } |
1501 | 1374 |
1502 // ----------------------------------------------------------------------------- | 1375 AboutUI::AboutUI(TabContents* contents, const std::string& name) |
1503 | 1376 : ChromeWebUI(contents) { |
1504 void InitializeAboutDataSource(const std::string& name, | 1377 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
1505 content::BrowserContext* browser_context) { | 1378 ChromeURLDataManager::DataSource* source = |
1506 Profile* profile = static_cast<Profile*>(browser_context); | 1379 new AboutUIHTMLSource(name, profile); |
1507 ChromeURLDataManager* manager = profile->GetChromeURLDataManager(); | 1380 if (source) |
1508 for (size_t i = 0; i < arraysize(kAboutSourceNames); i++) { | 1381 profile->GetChromeURLDataManager()->AddDataSource(source); |
1509 if (name == kAboutSourceNames[i]) { | |
1510 manager->AddDataSource(new AboutSource(name, profile)); | |
1511 return; | |
1512 } | |
1513 } | |
1514 } | 1382 } |
1515 | |
1516 bool WillHandleBrowserAboutURL(GURL* url, | |
1517 content::BrowserContext* browser_context) { | |
1518 // TODO(msw): Eliminate "about:*" constants and literals from code and tests, | |
1519 // then hopefully we can remove this forced fixup. | |
1520 *url = URLFixerUpper::FixupURL(url->possibly_invalid_spec(), std::string()); | |
1521 | |
1522 // Check that about: URLs are fixed up to chrome: by URLFixerUpper::FixupURL. | |
1523 DCHECK((*url == GURL(chrome::kAboutBlankURL)) || | |
1524 !url->SchemeIs(chrome::kAboutScheme)); | |
1525 | |
1526 // Only handle chrome://foo/, URLFixerUpper::FixupURL translates about:foo. | |
1527 // TAB_CONTENTS_WEB handles about:blank, which frames are allowed to access. | |
1528 if (!url->SchemeIs(chrome::kChromeUIScheme)) | |
1529 return false; | |
1530 | |
1531 // Circumvent processing URLs that the renderer process will handle. | |
1532 if (chrome_about_handler::WillHandle(*url)) | |
1533 return false; | |
1534 | |
1535 std::string host(url->host()); | |
1536 std::string path; | |
1537 // Replace about with chrome-urls. | |
1538 if (host == chrome::kChromeUIAboutHost) | |
1539 host = chrome::kChromeUIChromeURLsHost; | |
1540 // Replace cache with view-http-cache. | |
1541 if (host == chrome::kChromeUICacheHost) { | |
1542 host = chrome::kChromeUINetworkViewCacheHost; | |
1543 // Replace gpu with gpu-internals. | |
1544 } else if (host == chrome::kChromeUIGpuHost) { | |
1545 host = chrome::kChromeUIGpuInternalsHost; | |
1546 // Replace sync with sync-internals (for legacy reasons). | |
1547 } else if (host == chrome::kChromeUISyncHost) { | |
1548 host = chrome::kChromeUISyncInternalsHost; | |
1549 // Redirect chrome://extensions to chrome://settings/extensions. | |
1550 } else if (host == chrome::kChromeUIExtensionsHost) { | |
1551 host = chrome::kChromeUISettingsHost; | |
1552 path = chrome::kExtensionsSubPage; | |
1553 } | |
1554 GURL::Replacements replacements; | |
1555 replacements.SetHostStr(host); | |
1556 if (!path.empty()) | |
1557 replacements.SetPathStr(path); | |
1558 *url = url->ReplaceComponents(replacements); | |
1559 | |
1560 // Handle URLs to crash the browser or wreck the gpu process. | |
1561 if (host == chrome::kChromeUIBrowserCrashHost) { | |
1562 // Induce an intentional crash in the browser process. | |
1563 CHECK(false); | |
1564 } else if (host == chrome::kChromeUIGpuCleanHost) { | |
1565 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::FromID(0); | |
1566 if (shim) | |
1567 shim->SimulateRemoveAllContext(); | |
1568 } else if (host == chrome::kChromeUIGpuCrashHost) { | |
1569 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::FromID(0); | |
1570 if (shim) | |
1571 shim->SimulateCrash(); | |
1572 } else if (host == chrome::kChromeUIGpuHangHost) { | |
1573 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::FromID(0); | |
1574 if (shim) | |
1575 shim->SimulateHang(); | |
1576 #if defined(OS_CHROMEOS) | |
1577 } else if (host == chrome::kChromeUIRotateHost) { | |
1578 sensors::ScreenOrientation change; | |
1579 std::string query(url->query()); | |
1580 if (query == "left") { | |
1581 change.upward = sensors::ScreenOrientation::LEFT; | |
1582 } else if (query == "right") { | |
1583 change.upward = sensors::ScreenOrientation::RIGHT; | |
1584 } else if (query == "top") { | |
1585 change.upward = sensors::ScreenOrientation::TOP; | |
1586 } else if (query == "bottom") { | |
1587 change.upward = sensors::ScreenOrientation::BOTTOM; | |
1588 } else { | |
1589 NOTREACHED() << "Unknown orientation"; | |
1590 } | |
1591 sensors::Provider::GetInstance()->ScreenOrientationChanged(change); | |
1592 // Nothing to communicate to the user, so show a blank page. | |
1593 host = chrome::kChromeUIBlankHost; | |
1594 *url = GURL(chrome::kChromeUIBlankHost); | |
1595 #endif | |
1596 } | |
1597 | |
1598 // Initialize any potentially corresponding AboutSource handler. | |
1599 InitializeAboutDataSource(host, browser_context); | |
1600 return true; | |
1601 } | |
1602 | |
1603 bool HandleNonNavigationAboutURL(const GURL& url) { | |
1604 // chrome://ipc/ is currently buggy, so we disable it for official builds. | |
1605 #if !defined(OFFICIAL_BUILD) | |
1606 | |
1607 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED) | |
1608 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) { | |
1609 // Run the dialog. This will re-use the existing one if it's already up. | |
1610 browser::ShowAboutIPCDialog(); | |
1611 return true; | |
1612 } | |
1613 #endif | |
1614 | |
1615 #endif // OFFICIAL_BUILD | |
1616 | |
1617 return false; | |
1618 } | |
1619 | |
1620 std::vector<std::string> ChromePaths() { | |
1621 std::vector<std::string> paths; | |
1622 paths.reserve(arraysize(kChromePaths)); | |
1623 for (size_t i = 0; i < arraysize(kChromePaths); i++) | |
1624 paths.push_back(kChromePaths[i]); | |
1625 return paths; | |
1626 } | |
OLD | NEW |