| 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/ui/webui/tracing_ui.h" | 5 #include "chrome/browser/ui/webui/tracing_ui.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/select_file_dialog.h" | 17 #include "chrome/browser/ui/select_file_dialog.h" |
| 18 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 18 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 19 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "content/browser/gpu/gpu_data_manager.h" | 21 #include "content/browser/gpu/gpu_data_manager.h" |
| 22 #include "content/browser/renderer_host/render_view_host.h" | 22 #include "content/browser/renderer_host/render_view_host.h" |
| 23 #include "content/browser/tab_contents/tab_contents.h" | |
| 24 #include "content/browser/tab_contents/tab_contents_view.h" | 23 #include "content/browser/tab_contents/tab_contents_view.h" |
| 25 #include "content/browser/trace_controller.h" | 24 #include "content/browser/trace_controller.h" |
| 26 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/web_contents.h" |
| 27 #include "grit/browser_resources.h" | 27 #include "grit/browser_resources.h" |
| 28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 | 30 |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 using content::WebContents; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 ChromeWebUIDataSource* CreateTracingHTMLSource() { | 36 ChromeWebUIDataSource* CreateTracingHTMLSource() { |
| 36 ChromeWebUIDataSource* source = | 37 ChromeWebUIDataSource* source = |
| 37 new ChromeWebUIDataSource(chrome::kChromeUITracingHost); | 38 new ChromeWebUIDataSource(chrome::kChromeUITracingHost); |
| 38 | 39 |
| 39 source->set_json_path("strings.js"); | 40 source->set_json_path("strings.js"); |
| 40 source->add_resource_path("tracing.js", IDR_TRACING_JS); | 41 source->add_resource_path("tracing.js", IDR_TRACING_JS); |
| 41 source->set_default_resource(IDR_TRACING_HTML); | 42 source->set_default_resource(IDR_TRACING_HTML); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 void TracingMessageHandler::OnLoadTraceFile(const ListValue* list) { | 299 void TracingMessageHandler::OnLoadTraceFile(const ListValue* list) { |
| 299 // Only allow a single dialog at a time. | 300 // Only allow a single dialog at a time. |
| 300 if (select_trace_file_dialog_.get()) | 301 if (select_trace_file_dialog_.get()) |
| 301 return; | 302 return; |
| 302 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; | 303 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; |
| 303 select_trace_file_dialog_ = SelectFileDialog::Create(this); | 304 select_trace_file_dialog_ = SelectFileDialog::Create(this); |
| 304 select_trace_file_dialog_->SelectFile( | 305 select_trace_file_dialog_->SelectFile( |
| 305 SelectFileDialog::SELECT_OPEN_FILE, | 306 SelectFileDialog::SELECT_OPEN_FILE, |
| 306 string16(), | 307 string16(), |
| 307 FilePath(), | 308 FilePath(), |
| 308 NULL, 0, FILE_PATH_LITERAL(""), web_ui()->tab_contents(), | 309 NULL, 0, FILE_PATH_LITERAL(""), web_ui()->web_contents(), |
| 309 web_ui()->tab_contents()->GetView()->GetTopLevelNativeWindow(), NULL); | 310 web_ui()->web_contents()->GetView()->GetTopLevelNativeWindow(), NULL); |
| 310 } | 311 } |
| 311 | 312 |
| 312 void TracingMessageHandler::LoadTraceFileComplete(std::string* file_contents) { | 313 void TracingMessageHandler::LoadTraceFileComplete(std::string* file_contents) { |
| 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 314 std::string javascript = "tracingController.onLoadTraceFileComplete(" | 315 std::string javascript = "tracingController.onLoadTraceFileComplete(" |
| 315 + *file_contents + ");"; | 316 + *file_contents + ");"; |
| 316 | 317 |
| 317 web_ui()->tab_contents()->GetRenderViewHost()-> | 318 web_ui()->web_contents()->GetRenderViewHost()-> |
| 318 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(javascript)); | 319 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(javascript)); |
| 319 } | 320 } |
| 320 | 321 |
| 321 void TracingMessageHandler::OnSaveTraceFile(const ListValue* list) { | 322 void TracingMessageHandler::OnSaveTraceFile(const ListValue* list) { |
| 322 // Only allow a single dialog at a time. | 323 // Only allow a single dialog at a time. |
| 323 if (select_trace_file_dialog_.get()) | 324 if (select_trace_file_dialog_.get()) |
| 324 return; | 325 return; |
| 325 | 326 |
| 326 DCHECK(list->GetSize() == 1); | 327 DCHECK(list->GetSize() == 1); |
| 327 | 328 |
| 328 std::string* trace_data = new std::string(); | 329 std::string* trace_data = new std::string(); |
| 329 bool ok = list->GetString(0, trace_data); | 330 bool ok = list->GetString(0, trace_data); |
| 330 DCHECK(ok); | 331 DCHECK(ok); |
| 331 trace_data_to_save_.reset(trace_data); | 332 trace_data_to_save_.reset(trace_data); |
| 332 | 333 |
| 333 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE; | 334 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE; |
| 334 select_trace_file_dialog_ = SelectFileDialog::Create(this); | 335 select_trace_file_dialog_ = SelectFileDialog::Create(this); |
| 335 select_trace_file_dialog_->SelectFile( | 336 select_trace_file_dialog_->SelectFile( |
| 336 SelectFileDialog::SELECT_SAVEAS_FILE, | 337 SelectFileDialog::SELECT_SAVEAS_FILE, |
| 337 string16(), | 338 string16(), |
| 338 FilePath(), | 339 FilePath(), |
| 339 NULL, 0, FILE_PATH_LITERAL(""), web_ui()->tab_contents(), | 340 NULL, 0, FILE_PATH_LITERAL(""), web_ui()->web_contents(), |
| 340 web_ui()->tab_contents()->GetView()->GetTopLevelNativeWindow(), NULL); | 341 web_ui()->web_contents()->GetView()->GetTopLevelNativeWindow(), NULL); |
| 341 } | 342 } |
| 342 | 343 |
| 343 void TracingMessageHandler::SaveTraceFileComplete() { | 344 void TracingMessageHandler::SaveTraceFileComplete() { |
| 344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 345 web_ui()->CallJavascriptFunction("tracingController.onSaveTraceFileComplete"); | 346 web_ui()->CallJavascriptFunction("tracingController.onSaveTraceFileComplete"); |
| 346 } | 347 } |
| 347 | 348 |
| 348 void TracingMessageHandler::OnBeginTracing(const ListValue* args) { | 349 void TracingMessageHandler::OnBeginTracing(const ListValue* args) { |
| 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 350 trace_enabled_ = true; | 351 trace_enabled_ = true; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 381 | 382 |
| 382 base::debug::TraceResultBuffer::SimpleOutput output; | 383 base::debug::TraceResultBuffer::SimpleOutput output; |
| 383 base::debug::TraceResultBuffer trace_buffer; | 384 base::debug::TraceResultBuffer trace_buffer; |
| 384 trace_buffer.SetOutputCallback(output.GetCallback()); | 385 trace_buffer.SetOutputCallback(output.GetCallback()); |
| 385 output.Append("tracingController.onTraceDataCollected("); | 386 output.Append("tracingController.onTraceDataCollected("); |
| 386 trace_buffer.Start(); | 387 trace_buffer.Start(); |
| 387 trace_buffer.AddFragment(trace_fragment); | 388 trace_buffer.AddFragment(trace_fragment); |
| 388 trace_buffer.Finish(); | 389 trace_buffer.Finish(); |
| 389 output.Append(");"); | 390 output.Append(");"); |
| 390 | 391 |
| 391 web_ui()->tab_contents()->GetRenderViewHost()-> | 392 web_ui()->web_contents()->GetRenderViewHost()-> |
| 392 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(output.json_output)); | 393 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(output.json_output)); |
| 393 } | 394 } |
| 394 | 395 |
| 395 void TracingMessageHandler::OnTraceBufferPercentFullReply(float percent_full) { | 396 void TracingMessageHandler::OnTraceBufferPercentFullReply(float percent_full) { |
| 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 397 web_ui()->CallJavascriptFunction( | 398 web_ui()->CallJavascriptFunction( |
| 398 "tracingController.onRequestBufferPercentFullComplete", | 399 "tracingController.onRequestBufferPercentFullComplete", |
| 399 *scoped_ptr<Value>(Value::CreateDoubleValue(percent_full))); | 400 *scoped_ptr<Value>(Value::CreateDoubleValue(percent_full))); |
| 400 } | 401 } |
| 401 | 402 |
| 402 } // namespace | 403 } // namespace |
| 403 | 404 |
| 404 | 405 |
| 405 //////////////////////////////////////////////////////////////////////////////// | 406 //////////////////////////////////////////////////////////////////////////////// |
| 406 // | 407 // |
| 407 // TracingUI | 408 // TracingUI |
| 408 // | 409 // |
| 409 //////////////////////////////////////////////////////////////////////////////// | 410 //////////////////////////////////////////////////////////////////////////////// |
| 410 | 411 |
| 411 TracingUI::TracingUI(TabContents* contents) : ChromeWebUI(contents) { | 412 TracingUI::TracingUI(WebContents* contents) : ChromeWebUI(contents) { |
| 412 AddMessageHandler(new TracingMessageHandler()); | 413 AddMessageHandler(new TracingMessageHandler()); |
| 413 | 414 |
| 414 // Set up the chrome://tracing/ source. | 415 // Set up the chrome://tracing/ source. |
| 415 Profile::FromBrowserContext(contents->GetBrowserContext())-> | 416 Profile::FromBrowserContext(contents->GetBrowserContext())-> |
| 416 GetChromeURLDataManager()->AddDataSource(CreateTracingHTMLSource()); | 417 GetChromeURLDataManager()->AddDataSource(CreateTracingHTMLSource()); |
| 417 } | 418 } |
| OLD | NEW |