OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_version_info.h" | 10 #include "base/file_version_info.h" |
11 #include "base/histogram.h" | 11 #include "base/histogram.h" |
12 #include "base/platform_thread.h" | 12 #include "base/platform_thread.h" |
13 #include "base/stats_table.h" | 13 #include "base/stats_table.h" |
14 #include "base/string_piece.h" | 14 #include "base/string_piece.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/thread.h" | 16 #include "base/thread.h" |
17 #include "base/tracked_objects.h" | 17 #include "base/tracked_objects.h" |
18 #include "chrome/browser/browser.h" | 18 #include "chrome/browser/browser.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 20 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
21 #include "chrome/browser/memory_details.h" | 21 #include "chrome/browser/memory_details.h" |
22 #include "chrome/browser/net/dns_global.h" | 22 #include "chrome/browser/net/dns_global.h" |
23 #include "chrome/browser/profile.h" | |
24 #include "chrome/browser/profile_manager.h" | |
25 #include "chrome/browser/renderer_host/render_process_host.h" | 23 #include "chrome/browser/renderer_host/render_process_host.h" |
26 #include "chrome/browser/renderer_host/render_view_host.h" | 24 #include "chrome/browser/renderer_host/render_view_host.h" |
27 #include "chrome/common/jstemplate_builder.h" | 25 #include "chrome/common/jstemplate_builder.h" |
28 #include "chrome/common/l10n_util.h" | 26 #include "chrome/common/l10n_util.h" |
29 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
30 #include "chrome/common/pref_service.h" | 28 #include "chrome/common/pref_service.h" |
31 #include "chrome/common/render_messages.h" | 29 #include "chrome/common/render_messages.h" |
32 #include "chrome/common/resource_bundle.h" | 30 #include "chrome/common/resource_bundle.h" |
33 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
34 #include "chrome/renderer/about_handler.h" | 32 #include "chrome/renderer/about_handler.h" |
35 #include "googleurl/src/gurl.h" | 33 #include "googleurl/src/gurl.h" |
36 #include "grit/browser_resources.h" | 34 #include "grit/browser_resources.h" |
37 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
38 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
39 #include "grit/locale_settings.h" | 37 #include "grit/locale_settings.h" |
40 #include "webkit/glue/webkit_glue.h" | 38 #include "webkit/glue/webkit_glue.h" |
41 #ifdef CHROME_V8 | 39 #ifdef CHROME_V8 |
42 #include "v8/include/v8.h" | 40 #include "v8/include/v8.h" |
43 #endif | 41 #endif |
44 | 42 |
45 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
46 #include "chrome/browser/views/about_ipc_dialog.h" | 44 #include "chrome/browser/views/about_ipc_dialog.h" |
47 #include "chrome/browser/views/about_network_dialog.h" | 45 #include "chrome/browser/views/about_network_dialog.h" |
48 #endif | 46 #endif |
49 | 47 |
50 // The URL scheme used for the about ui. | 48 namespace { |
51 static const char kAboutScheme[] = "about"; | |
52 | 49 |
53 // The paths used for the about pages. | 50 // The paths used for the about pages. |
54 static const char kCachePath[] = "cache"; | 51 const char kCachePath[] = "cache"; |
55 static const char kDnsPath[] = "dns"; | 52 const char kDnsPath[] = "dns"; |
56 static const char kHistogramsPath[] = "histograms"; | 53 const char kHistogramsPath[] = "histograms"; |
57 static const char kObjectsPath[] = "objects"; | 54 const char kObjectsPath[] = "objects"; |
58 static const char kMemoryPath[] = "memory"; | 55 const char kMemoryRedirectPath[] = "memory-redirect"; |
59 static const char kPluginsPath[] = "plugins"; | 56 const char kMemoryPath[] = "memory"; |
60 static const char kStatsPath[] = "stats"; | 57 const char kPluginsPath[] = "plugins"; |
61 static const char kVersionPath[] = "version"; | 58 const char kStatsPath[] = "stats"; |
62 static const char kCreditsPath[] = "credits"; | 59 const char kVersionPath[] = "version"; |
63 static const char kTermsPath[] = "terms"; | 60 const char kCreditsPath[] = "credits"; |
64 static const char kLinuxSplash[] = "linux-splash"; | 61 const char kTermsPath[] = "terms"; |
| 62 const char kLinuxSplash[] = "linux-splash"; |
| 63 |
| 64 // Points to the singleton AboutSource object, if any. |
| 65 ChromeURLDataManager::DataSource* about_source = NULL; |
| 66 |
| 67 // When you type about:memory, it actually loads an intermediate URL that |
| 68 // redirects you to the final page. This avoids the problem where typing |
| 69 // "about:memory" on the new tab page or any other page where a process |
| 70 // transition would occur to the about URL will cause some confusion. |
| 71 // |
| 72 // The problem is that during the processing of the memory page, there are two |
| 73 // processes active, the original and the destination one. This can create the |
| 74 // impression that we're using more resources than we actually are. This |
| 75 // redirect solves the problem by eliminating the process transition during the |
| 76 // time that about memory is being computed. |
| 77 std::string GetAboutMemoryRedirectResponse() { |
| 78 return "<meta http-equiv=\"refresh\" " |
| 79 "content=\"0;chrome-ui://about/memory\">"; |
| 80 } |
65 | 81 |
66 class AboutSource : public ChromeURLDataManager::DataSource { | 82 class AboutSource : public ChromeURLDataManager::DataSource { |
67 public: | 83 public: |
68 // Creates our datasource. | 84 // Creates our datasource. |
69 AboutSource(); | 85 AboutSource(); |
70 virtual ~AboutSource(); | 86 virtual ~AboutSource(); |
71 | 87 |
72 // Called when the network layer has requested a resource underneath | 88 // Called when the network layer has requested a resource underneath |
73 // the path we registered. | 89 // the path we registered. |
74 virtual void StartDataRequest(const std::string& path, int request_id); | 90 virtual void StartDataRequest(const std::string& path, int request_id); |
(...skipping 18 matching lines...) Expand all Loading... |
93 virtual void OnDetailsAvailable(); | 109 virtual void OnDetailsAvailable(); |
94 | 110 |
95 private: | 111 private: |
96 void BindProcessMetrics(DictionaryValue* data, | 112 void BindProcessMetrics(DictionaryValue* data, |
97 ProcessMemoryInformation* info); | 113 ProcessMemoryInformation* info); |
98 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); | 114 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); |
99 void FinishAboutMemory(); | 115 void FinishAboutMemory(); |
100 | 116 |
101 AboutSource* source_; | 117 AboutSource* source_; |
102 int request_id_; | 118 int request_id_; |
| 119 |
103 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); | 120 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); |
104 }; | 121 }; |
105 | 122 |
106 AboutSource::AboutSource() | 123 // Individual about handlers --------------------------------------------------- |
107 : DataSource(kAboutScheme, MessageLoop::current()) { | |
108 } | |
109 | 124 |
110 AboutSource::~AboutSource() { | 125 std::string AboutCredits() { |
111 } | |
112 | |
113 void AboutSource::StartDataRequest(const std::string& path_raw, | |
114 int request_id) { | |
115 std::string path = path_raw; | |
116 std::string info; | |
117 if (path.find("/") != std::string::npos) { | |
118 size_t pos = path.find("/"); | |
119 info = path.substr(pos + 1, path.length() - (pos + 1)); | |
120 path = path.substr(0, pos); | |
121 } | |
122 path = StringToLowerASCII(path); | |
123 | |
124 std::string response; | |
125 if (path == kDnsPath) { | |
126 response = BrowserAboutHandler::AboutDns(); | |
127 } else if (path == kHistogramsPath) { | |
128 response = BrowserAboutHandler::AboutHistograms(info); | |
129 } else if (path == kMemoryPath) { | |
130 BrowserAboutHandler::AboutMemory(this, request_id); | |
131 return; | |
132 } else if (path == kObjectsPath) { | |
133 response = BrowserAboutHandler::AboutObjects(info); | |
134 } else if (path == kPluginsPath) { | |
135 response = BrowserAboutHandler::AboutPlugins(); | |
136 } else if (path == kStatsPath) { | |
137 response = BrowserAboutHandler::AboutStats(); | |
138 } else if (path == kVersionPath || path.empty()) { | |
139 response = BrowserAboutHandler::AboutVersion(); | |
140 } else if (path == kCreditsPath) { | |
141 response = BrowserAboutHandler::AboutCredits(); | |
142 } else if (path == kTermsPath) { | |
143 response = BrowserAboutHandler::AboutTerms(); | |
144 } | |
145 #if defined(OS_LINUX) | |
146 else if (path == kLinuxSplash) { | |
147 response = BrowserAboutHandler::AboutLinuxSplash(); | |
148 } | |
149 #endif | |
150 | |
151 FinishDataRequest(response, request_id); | |
152 } | |
153 | |
154 void AboutSource::FinishDataRequest(const std::string& response, | |
155 int request_id) { | |
156 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | |
157 html_bytes->data.resize(response.size()); | |
158 std::copy(response.begin(), response.end(), html_bytes->data.begin()); | |
159 SendResponse(request_id, html_bytes); | |
160 } | |
161 | |
162 // This is the top-level URL handler for chrome-internal: URLs, and exposed in | |
163 // our header file. | |
164 bool BrowserAboutHandler::MaybeHandle(GURL* url, | |
165 TabContentsType* result_type) { | |
166 if (!url->SchemeIs(kAboutScheme)) | |
167 return false; | |
168 | |
169 // about:blank is special. Frames are allowed to access about:blank, | |
170 // but they are not allowed to access other types of about pages. | |
171 // Just ignore the about:blank and let the TAB_CONTENTS_WEB handle it. | |
172 if (StringToLowerASCII(url->path()) == "blank") { | |
173 return false; | |
174 } | |
175 | |
176 // We create an about:cache mapping to the view-cache: internal URL. | |
177 if (StringToLowerASCII(url->path()) == kCachePath) { | |
178 *url = GURL("view-cache:"); | |
179 *result_type = TAB_CONTENTS_WEB; | |
180 return true; | |
181 } | |
182 | |
183 if (LowerCaseEqualsASCII(url->path(), "network")) { | |
184 #if defined(OS_WIN) | |
185 // Run the dialog. This will re-use the existing one if it's already up. | |
186 AboutNetworkDialog::RunDialog(); | |
187 #else | |
188 NOTIMPLEMENTED(); | |
189 // TODO(port) Implement this. | |
190 #endif | |
191 | |
192 // Navigate the renderer to about:blank. This is kind of stupid but is the | |
193 // easiest thing to do in this situation without adding a lot of complexity | |
194 // for this developer-only feature. | |
195 *url = GURL("about:blank"); | |
196 return false; | |
197 } | |
198 | |
199 #ifdef IPC_MESSAGE_LOG_ENABLED | |
200 if (LowerCaseEqualsASCII(url->path(), "ipc")) { | |
201 #if defined(OS_WIN) | |
202 // Run the dialog. This will re-use the existing one if it's already up. | |
203 AboutIPCDialog::RunDialog(); | |
204 #else | |
205 NOTIMPLEMENTED(); | |
206 // TODO(port) Implement this. | |
207 #endif | |
208 *url = GURL("about:blank"); | |
209 return false; | |
210 } | |
211 #endif | |
212 | |
213 // There are a few about URLs that we hand over to the renderer. | |
214 // If the renderer wants them, let it have them. | |
215 if (AboutHandler::WillHandle(*url)) | |
216 return false; | |
217 | |
218 *result_type = TAB_CONTENTS_ABOUT_UI; | |
219 std::string about_url = "chrome-ui://about/"; | |
220 about_url.append(url->path()); | |
221 *url = GURL(about_url); | |
222 return true; | |
223 } | |
224 | |
225 BrowserAboutHandler::BrowserAboutHandler(Profile* profile, | |
226 SiteInstance* instance, | |
227 RenderViewHostFactory* render_view_factory) : | |
228 WebContents(profile, instance, render_view_factory, MSG_ROUTING_NONE, NULL) { | |
229 set_type(TAB_CONTENTS_ABOUT_UI); | |
230 | |
231 // We only need to register the AboutSource once and it is | |
232 // kept globally. There is currently no way to remove a data source. | |
233 static bool initialized = false; | |
234 if (!initialized) { | |
235 about_source_ = new AboutSource(); | |
236 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | |
237 NewRunnableMethod(&chrome_url_data_manager, | |
238 &ChromeURLDataManager::AddDataSource, | |
239 about_source_)); | |
240 initialized = true; | |
241 } | |
242 } | |
243 | |
244 bool BrowserAboutHandler::SupportsURL(GURL* url) { | |
245 // Enable this tab contents to access javascript urls. | |
246 if (url->SchemeIs(chrome::kJavaScriptScheme)) | |
247 return true; | |
248 return WebContents::SupportsURL(url); | |
249 } | |
250 | |
251 | |
252 // static | |
253 std::string BrowserAboutHandler::AboutVersion() { | |
254 // Strings used in the JsTemplate file. | |
255 DictionaryValue localized_strings; | |
256 localized_strings.SetString(L"title", | |
257 l10n_util::GetString(IDS_ABOUT_VERSION_TITLE)); | |
258 scoped_ptr<FileVersionInfo> version_info( | |
259 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); | |
260 if (version_info == NULL) { | |
261 DLOG(ERROR) << "Unable to create FileVersionInfo object"; | |
262 return std::string(); | |
263 } | |
264 | |
265 std::wstring webkit_version = UTF8ToWide(webkit_glue::GetWebKitVersion()); | |
266 #ifdef CHROME_V8 | |
267 const char* v8_vers = v8::V8::GetVersion(); | |
268 std::wstring js_version = UTF8ToWide(v8_vers); | |
269 std::wstring js_engine = L"V8"; | |
270 #else | |
271 std::wstring js_version = webkit_version; | |
272 std::wstring js_engine = L"JavaScriptCore"; | |
273 #endif | |
274 | |
275 localized_strings.SetString(L"name", | |
276 l10n_util::GetString(IDS_PRODUCT_NAME)); | |
277 localized_strings.SetString(L"version", version_info->file_version()); | |
278 localized_strings.SetString(L"js_engine", js_engine); | |
279 localized_strings.SetString(L"js_version", js_version); | |
280 localized_strings.SetString(L"webkit_version", webkit_version); | |
281 localized_strings.SetString(L"company", | |
282 l10n_util::GetString(IDS_ABOUT_VERSION_COMPANY_NAME)); | |
283 localized_strings.SetString(L"copyright", | |
284 l10n_util::GetString(IDS_ABOUT_VERSION_COPYRIGHT)); | |
285 localized_strings.SetString(L"cl", version_info->last_change()); | |
286 if (version_info->is_official_build()) { | |
287 localized_strings.SetString(L"official", | |
288 l10n_util::GetString(IDS_ABOUT_VERSION_OFFICIAL)); | |
289 } else { | |
290 localized_strings.SetString(L"official", | |
291 l10n_util::GetString(IDS_ABOUT_VERSION_UNOFFICIAL)); | |
292 } | |
293 localized_strings.SetString(L"useragent", | |
294 UTF8ToWide(webkit_glue::GetUserAgent(GURL()))); | |
295 | |
296 static const StringPiece version_html( | |
297 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
298 IDR_ABOUT_VERSION_HTML)); | |
299 | |
300 return jstemplate_builder::GetTemplateHtml( | |
301 version_html, &localized_strings, "t" /* template root node id */); | |
302 } | |
303 | |
304 // static | |
305 std::string BrowserAboutHandler::AboutCredits() { | |
306 static const std::string credits_html = | 126 static const std::string credits_html = |
307 ResourceBundle::GetSharedInstance().GetDataResource( | 127 ResourceBundle::GetSharedInstance().GetDataResource( |
308 IDR_CREDITS_HTML); | 128 IDR_CREDITS_HTML); |
309 | 129 |
310 return credits_html; | 130 return credits_html; |
311 } | 131 } |
312 | 132 |
313 // static | 133 std::string AboutDns() { |
314 std::string BrowserAboutHandler::AboutLinuxSplash() { | 134 std::string data; |
| 135 chrome_browser_net::DnsPrefetchGetHtmlInfo(&data); |
| 136 return data; |
| 137 } |
| 138 |
| 139 std::string AboutHistograms(const std::string& query) { |
| 140 std::string data; |
| 141 for (RenderProcessHost::iterator it = RenderProcessHost::begin(); |
| 142 it != RenderProcessHost::end(); ++it) { |
| 143 it->second->Send(new ViewMsg_GetRendererHistograms()); |
| 144 } |
| 145 |
| 146 // TODO(raman): Delay page layout until we get respnoses |
| 147 // back from renderers, and not have to use a fixed size delay. |
| 148 PlatformThread::Sleep(1000); |
| 149 |
| 150 StatisticsRecorder::WriteHTMLGraph(query, &data); |
| 151 return data; |
| 152 } |
| 153 |
| 154 std::string AboutLinuxSplash() { |
315 static const std::string linux_splash_html = | 155 static const std::string linux_splash_html = |
316 ResourceBundle::GetSharedInstance().GetDataResource( | 156 ResourceBundle::GetSharedInstance().GetDataResource( |
317 IDR_LINUX_SPLASH_HTML); | 157 IDR_LINUX_SPLASH_HTML); |
318 | 158 |
319 return linux_splash_html; | 159 return linux_splash_html; |
320 } | 160 } |
321 | 161 |
322 // static | 162 void AboutMemory(AboutSource* source, int request_id) { |
323 std::string BrowserAboutHandler::AboutTerms() { | 163 // The AboutMemoryHandler cleans itself up. |
324 static const std::string terms_html = | 164 new AboutMemoryHandler(source, request_id); |
325 ResourceBundle::GetSharedInstance().GetDataResource( | |
326 IDR_TERMS_HTML); | |
327 | |
328 return terms_html; | |
329 } | 165 } |
330 | 166 |
331 // static | 167 std::string AboutObjects(const std::string& query) { |
332 std::string BrowserAboutHandler::AboutPlugins() { | 168 std::string data; |
| 169 tracked_objects::ThreadData::WriteHTML(query, &data); |
| 170 return data; |
| 171 } |
| 172 |
| 173 std::string AboutPlugins() { |
333 // Strings used in the JsTemplate file. | 174 // Strings used in the JsTemplate file. |
334 DictionaryValue localized_strings; | 175 DictionaryValue localized_strings; |
335 localized_strings.SetString(L"title", | 176 localized_strings.SetString(L"title", |
336 l10n_util::GetString(IDS_ABOUT_PLUGINS_TITLE)); | 177 l10n_util::GetString(IDS_ABOUT_PLUGINS_TITLE)); |
337 localized_strings.SetString(L"headingPlugs", | 178 localized_strings.SetString(L"headingPlugs", |
338 l10n_util::GetString(IDS_ABOUT_PLUGINS_HEADING_PLUGS)); | 179 l10n_util::GetString(IDS_ABOUT_PLUGINS_HEADING_PLUGS)); |
339 localized_strings.SetString(L"headingNoPlugs", | 180 localized_strings.SetString(L"headingNoPlugs", |
340 l10n_util::GetString(IDS_ABOUT_PLUGINS_HEADING_NOPLUGS)); | 181 l10n_util::GetString(IDS_ABOUT_PLUGINS_HEADING_NOPLUGS)); |
341 localized_strings.SetString(L"filename", | 182 localized_strings.SetString(L"filename", |
342 l10n_util::GetString(IDS_ABOUT_PLUGINS_FILENAME_LABEL)); | 183 l10n_util::GetString(IDS_ABOUT_PLUGINS_FILENAME_LABEL)); |
(...skipping 11 matching lines...) Expand all Loading... |
354 l10n_util::GetString(IDS_ABOUT_PLUGINS_ENABLED_NO)); | 195 l10n_util::GetString(IDS_ABOUT_PLUGINS_ENABLED_NO)); |
355 | 196 |
356 static const StringPiece plugins_html( | 197 static const StringPiece plugins_html( |
357 ResourceBundle::GetSharedInstance().GetRawDataResource( | 198 ResourceBundle::GetSharedInstance().GetRawDataResource( |
358 IDR_ABOUT_PLUGINS_HTML)); | 199 IDR_ABOUT_PLUGINS_HTML)); |
359 | 200 |
360 return jstemplate_builder::GetTemplateHtml( | 201 return jstemplate_builder::GetTemplateHtml( |
361 plugins_html, &localized_strings, "t" /* template root node id */); | 202 plugins_html, &localized_strings, "t" /* template root node id */); |
362 } | 203 } |
363 | 204 |
364 // static | 205 std::string AboutStats() { |
365 std::string BrowserAboutHandler::AboutHistograms(const std::string& query) { | |
366 std::string data; | |
367 for (RenderProcessHost::iterator it = RenderProcessHost::begin(); | |
368 it != RenderProcessHost::end(); ++it) { | |
369 it->second->Send(new ViewMsg_GetRendererHistograms()); | |
370 } | |
371 | |
372 // TODO(raman): Delay page layout until we get respnoses | |
373 // back from renderers, and not have to use a fixed size delay. | |
374 PlatformThread::Sleep(1000); | |
375 | |
376 StatisticsRecorder::WriteHTMLGraph(query, &data); | |
377 return data; | |
378 } | |
379 | |
380 // static | |
381 std::string BrowserAboutHandler::AboutObjects(const std::string& query) { | |
382 std::string data; | |
383 tracked_objects::ThreadData::WriteHTML(query, &data); | |
384 return data; | |
385 } | |
386 | |
387 // static | |
388 std::string BrowserAboutHandler::AboutDns() { | |
389 std::string data; | |
390 chrome_browser_net::DnsPrefetchGetHtmlInfo(&data); | |
391 return data; | |
392 } | |
393 | |
394 // static | |
395 std::string BrowserAboutHandler::AboutStats() { | |
396 // We keep the DictionaryValue tree live so that we can do delta | 206 // We keep the DictionaryValue tree live so that we can do delta |
397 // stats computations across runs. | 207 // stats computations across runs. |
398 static DictionaryValue root; | 208 static DictionaryValue root; |
399 | 209 |
400 StatsTable* table = StatsTable::current(); | 210 StatsTable* table = StatsTable::current(); |
401 if (!table) | 211 if (!table) |
402 return std::string(); | 212 return std::string(); |
403 | 213 |
404 // We maintain two lists - one for counters and one for timers. | 214 // We maintain two lists - one for counters and one for timers. |
405 // Timers actually get stored on both lists. | 215 // Timers actually get stored on both lists. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 index--) { | 308 index--) { |
499 Value* value; | 309 Value* value; |
500 timers->Remove(index, &value); | 310 timers->Remove(index, &value); |
501 // We don't care about the value pointer; it's still tracked | 311 // We don't care about the value pointer; it's still tracked |
502 // on the counters list. | 312 // on the counters list. |
503 } | 313 } |
504 | 314 |
505 return data; | 315 return data; |
506 } | 316 } |
507 | 317 |
| 318 std::string AboutTerms() { |
| 319 static const std::string terms_html = |
| 320 ResourceBundle::GetSharedInstance().GetDataResource( |
| 321 IDR_TERMS_HTML); |
| 322 |
| 323 return terms_html; |
| 324 } |
| 325 |
| 326 std::string AboutVersion() { |
| 327 // Strings used in the JsTemplate file. |
| 328 DictionaryValue localized_strings; |
| 329 localized_strings.SetString(L"title", |
| 330 l10n_util::GetString(IDS_ABOUT_VERSION_TITLE)); |
| 331 scoped_ptr<FileVersionInfo> version_info( |
| 332 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
| 333 if (version_info == NULL) { |
| 334 DLOG(ERROR) << "Unable to create FileVersionInfo object"; |
| 335 return std::string(); |
| 336 } |
| 337 |
| 338 std::wstring webkit_version = UTF8ToWide(webkit_glue::GetWebKitVersion()); |
| 339 #ifdef CHROME_V8 |
| 340 const char* v8_vers = v8::V8::GetVersion(); |
| 341 std::wstring js_version = UTF8ToWide(v8_vers); |
| 342 std::wstring js_engine = L"V8"; |
| 343 #else |
| 344 std::wstring js_version = webkit_version; |
| 345 std::wstring js_engine = L"JavaScriptCore"; |
| 346 #endif |
| 347 |
| 348 localized_strings.SetString(L"name", |
| 349 l10n_util::GetString(IDS_PRODUCT_NAME)); |
| 350 localized_strings.SetString(L"version", version_info->file_version()); |
| 351 localized_strings.SetString(L"js_engine", js_engine); |
| 352 localized_strings.SetString(L"js_version", js_version); |
| 353 localized_strings.SetString(L"webkit_version", webkit_version); |
| 354 localized_strings.SetString(L"company", |
| 355 l10n_util::GetString(IDS_ABOUT_VERSION_COMPANY_NAME)); |
| 356 localized_strings.SetString(L"copyright", |
| 357 l10n_util::GetString(IDS_ABOUT_VERSION_COPYRIGHT)); |
| 358 localized_strings.SetString(L"cl", version_info->last_change()); |
| 359 if (version_info->is_official_build()) { |
| 360 localized_strings.SetString(L"official", |
| 361 l10n_util::GetString(IDS_ABOUT_VERSION_OFFICIAL)); |
| 362 } else { |
| 363 localized_strings.SetString(L"official", |
| 364 l10n_util::GetString(IDS_ABOUT_VERSION_UNOFFICIAL)); |
| 365 } |
| 366 localized_strings.SetString(L"useragent", |
| 367 UTF8ToWide(webkit_glue::GetUserAgent(GURL()))); |
| 368 |
| 369 static const StringPiece version_html( |
| 370 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 371 IDR_ABOUT_VERSION_HTML)); |
| 372 |
| 373 return jstemplate_builder::GetTemplateHtml( |
| 374 version_html, &localized_strings, "t" /* template root node id */); |
| 375 } |
| 376 |
| 377 // AboutSource ----------------------------------------------------------------- |
| 378 |
| 379 AboutSource::AboutSource() |
| 380 : DataSource(chrome::kAboutScheme, MessageLoop::current()) { |
| 381 // This should be a singleton. |
| 382 DCHECK(!about_source); |
| 383 about_source = this; |
| 384 |
| 385 // Add us to the global URL handler on the IO thread. |
| 386 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 387 NewRunnableMethod(&chrome_url_data_manager, |
| 388 &ChromeURLDataManager::AddDataSource, this)); |
| 389 } |
| 390 |
| 391 AboutSource::~AboutSource() { |
| 392 about_source = NULL; |
| 393 } |
| 394 |
| 395 void AboutSource::StartDataRequest(const std::string& path_raw, |
| 396 int request_id) { |
| 397 std::string path = path_raw; |
| 398 std::string info; |
| 399 if (path.find("/") != std::string::npos) { |
| 400 size_t pos = path.find("/"); |
| 401 info = path.substr(pos + 1, path.length() - (pos + 1)); |
| 402 path = path.substr(0, pos); |
| 403 } |
| 404 path = StringToLowerASCII(path); |
| 405 |
| 406 std::string response; |
| 407 if (path == kDnsPath) { |
| 408 response = AboutDns(); |
| 409 } else if (path == kHistogramsPath) { |
| 410 response = AboutHistograms(info); |
| 411 } else if (path == kMemoryPath) { |
| 412 AboutMemory(this, request_id); |
| 413 return; |
| 414 } else if (path == kMemoryRedirectPath) { |
| 415 response = GetAboutMemoryRedirectResponse(); |
| 416 } else if (path == kObjectsPath) { |
| 417 response = AboutObjects(info); |
| 418 } else if (path == kPluginsPath) { |
| 419 response = AboutPlugins(); |
| 420 } else if (path == kStatsPath) { |
| 421 response = AboutStats(); |
| 422 } else if (path == kVersionPath || path.empty()) { |
| 423 response = AboutVersion(); |
| 424 } else if (path == kCreditsPath) { |
| 425 response = AboutCredits(); |
| 426 } else if (path == kTermsPath) { |
| 427 response = AboutTerms(); |
| 428 } |
| 429 #if defined(OS_LINUX) |
| 430 else if (path == kLinuxSplash) { |
| 431 response = AboutLinuxSplash(); |
| 432 } |
| 433 #endif |
| 434 |
| 435 FinishDataRequest(response, request_id); |
| 436 } |
| 437 |
| 438 void AboutSource::FinishDataRequest(const std::string& response, |
| 439 int request_id) { |
| 440 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| 441 html_bytes->data.resize(response.size()); |
| 442 std::copy(response.begin(), response.end(), html_bytes->data.begin()); |
| 443 SendResponse(request_id, html_bytes); |
| 444 } |
| 445 |
| 446 // AboutMemoryHandler ---------------------------------------------------------- |
| 447 |
508 AboutMemoryHandler::AboutMemoryHandler(AboutSource* source, int request_id) | 448 AboutMemoryHandler::AboutMemoryHandler(AboutSource* source, int request_id) |
509 : source_(source), | 449 : source_(source), |
510 request_id_(request_id) { | 450 request_id_(request_id) { |
511 StartFetch(); | 451 StartFetch(); |
512 } | 452 } |
513 | 453 |
514 // Helper for AboutMemory to bind results from a ProcessMetrics object | 454 // Helper for AboutMemory to bind results from a ProcessMetrics object |
515 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects | 455 // to a DictionaryValue. Fills ws_usage and comm_usage so that the objects |
516 // can be used in caller's scope (e.g for appending to a net total). | 456 // can be used in caller's scope (e.g for appending to a net total). |
517 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data, | 457 void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data, |
518 ProcessMemoryInformation* info) { | 458 ProcessMemoryInformation* info) { |
519 DCHECK(data && info); | 459 DCHECK(data && info); |
520 | 460 |
521 // Bind metrics to dictionary. | 461 // Bind metrics to dictionary. |
522 data->SetInteger(L"ws_priv", static_cast<int>(info->working_set.priv)); | 462 data->SetInteger(L"ws_priv", static_cast<int>(info->working_set.priv)); |
523 data->SetInteger(L"ws_shareable", | 463 data->SetInteger(L"ws_shareable", |
524 static_cast<int>(info->working_set.shareable)); | 464 static_cast<int>(info->working_set.shareable)); |
525 data->SetInteger(L"ws_shared", static_cast<int>(info->working_set.shared)); | 465 data->SetInteger(L"ws_shared", static_cast<int>(info->working_set.shared)); |
526 data->SetInteger(L"comm_priv", static_cast<int>(info->committed.priv)); | 466 data->SetInteger(L"comm_priv", static_cast<int>(info->committed.priv)); |
527 data->SetInteger(L"comm_map", static_cast<int>(info->committed.mapped)); | 467 data->SetInteger(L"comm_map", static_cast<int>(info->committed.mapped)); |
528 data->SetInteger(L"comm_image", static_cast<int>(info->committed.image)); | 468 data->SetInteger(L"comm_image", static_cast<int>(info->committed.image)); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 | 562 |
623 // Get about_memory.html | 563 // Get about_memory.html |
624 static const StringPiece memory_html( | 564 static const StringPiece memory_html( |
625 ResourceBundle::GetSharedInstance().GetRawDataResource( | 565 ResourceBundle::GetSharedInstance().GetRawDataResource( |
626 IDR_ABOUT_MEMORY_HTML)); | 566 IDR_ABOUT_MEMORY_HTML)); |
627 | 567 |
628 // Create jstemplate and return. | 568 // Create jstemplate and return. |
629 std::string template_html = jstemplate_builder::GetTemplateHtml( | 569 std::string template_html = jstemplate_builder::GetTemplateHtml( |
630 memory_html, &root, "t" /* template root node id */); | 570 memory_html, &root, "t" /* template root node id */); |
631 | 571 |
632 AboutSource* about_source = static_cast<AboutSource*>(source_); | 572 AboutSource* src = static_cast<AboutSource*>(source_); |
633 about_source->FinishDataRequest(template_html, request_id_); | 573 src->FinishDataRequest(template_html, request_id_); |
634 } | 574 } |
635 | 575 |
636 // static | 576 } // namespace |
637 void BrowserAboutHandler::AboutMemory(AboutSource* source, int request_id) { | 577 |
638 // The AboutMemoryHandler cleans itself up. | 578 // ----------------------------------------------------------------------------- |
639 new AboutMemoryHandler(source, request_id); | 579 |
| 580 bool WillHandleBrowserAboutURL(GURL* url, TabContentsType* type) { |
| 581 // We only handle about: schemes. |
| 582 if (!url->SchemeIs(chrome::kAboutScheme)) |
| 583 return false; |
| 584 |
| 585 // about:blank is special. Frames are allowed to access about:blank, |
| 586 // but they are not allowed to access other types of about pages. |
| 587 // Just ignore the about:blank and let the TAB_CONTENTS_WEB handle it. |
| 588 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutBlankURL)) |
| 589 return false; |
| 590 |
| 591 // Handle rewriting view-cache URLs. This allows us to load about:cache. |
| 592 if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutCacheURL)) { |
| 593 // Create an mapping from about:cache to the view-cache: internal URL. |
| 594 *url = GURL(std::string(chrome::kViewCacheScheme) + ":"); |
| 595 *type = TAB_CONTENTS_WEB; |
| 596 return true; |
| 597 } |
| 598 |
| 599 // There are a few about: URLs that we hand over to the renderer. If the |
| 600 // renderer wants them, don't do any rewriting. |
| 601 if (AboutHandler::WillHandle(*url)) |
| 602 return false; |
| 603 |
| 604 // Anything else requires our special handler, make sure its initialized. |
| 605 // We only need to register the AboutSource once and it is kept globally. |
| 606 // There is currently no way to remove a data source. |
| 607 static bool initialized = false; |
| 608 if (!initialized) { |
| 609 about_source = new AboutSource(); |
| 610 initialized = true; |
| 611 } |
| 612 |
| 613 // Special case about:memory to go through a redirect before ending up on |
| 614 // the final page. See GetAboutMemoryRedirectResponse above for why. |
| 615 if (LowerCaseEqualsASCII(url->path(), kMemoryPath)) { |
| 616 *url = GURL("chrome-ui://about/memory-redirect"); |
| 617 *type = TAB_CONTENTS_WEB; |
| 618 return true; |
| 619 } |
| 620 |
| 621 // Rewrite the about URL to use chrome-ui. WebKit treats all about URLS the |
| 622 // same (blank page), so if we want to display content, we need another |
| 623 // scheme. |
| 624 std::string about_url = "chrome-ui://about/"; |
| 625 about_url.append(url->path()); |
| 626 *url = GURL(about_url); |
| 627 *type = TAB_CONTENTS_WEB; |
| 628 return true; |
640 } | 629 } |
| 630 |
| 631 // This function gets called with the fixed-up chrome-ui URLs, so we have to |
| 632 // compare against those instead of "about:blah". |
| 633 bool HandleNonNavigationAboutURL(const GURL& url) { |
| 634 #if defined(OS_WIN) |
| 635 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUINetworkURL)) { |
| 636 // Run the dialog. This will re-use the existing one if it's already up. |
| 637 AboutNetworkDialog::RunDialog(); |
| 638 return true; |
| 639 } |
| 640 |
| 641 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 642 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) { |
| 643 // Run the dialog. This will re-use the existing one if it's already up. |
| 644 AboutIPCDialog::RunDialog(); |
| 645 return true; |
| 646 } |
| 647 #endif |
| 648 |
| 649 #else |
| 650 // TODO(port) Implement this. |
| 651 #endif |
| 652 return false; |
| 653 } |
OLD | NEW |