| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/gpu_blacklist.h" | 17 #include "chrome/browser/gpu_blacklist.h" |
| 18 #include "chrome/browser/gpu_util.h" | 18 #include "chrome/browser/gpu_util.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/chrome_select_file_policy.h" | |
| 21 #include "chrome/browser/ui/select_file_dialog.h" | 20 #include "chrome/browser/ui/select_file_dialog.h" |
| 22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 21 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 22 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 24 #include "chrome/common/chrome_version_info.h" | 23 #include "chrome/common/chrome_version_info.h" |
| 25 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 26 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/gpu_data_manager.h" | 26 #include "content/public/browser/gpu_data_manager.h" |
| 28 #include "content/public/browser/gpu_data_manager_observer.h" | 27 #include "content/public/browser/gpu_data_manager_observer.h" |
| 29 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
| 30 #include "content/public/browser/trace_controller.h" | 29 #include "content/public/browser/trace_controller.h" |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 web_ui()->CallJavascriptFunction( | 330 web_ui()->CallJavascriptFunction( |
| 332 "tracingController.onSaveTraceFileCanceled"); | 331 "tracingController.onSaveTraceFileCanceled"); |
| 333 } | 332 } |
| 334 } | 333 } |
| 335 | 334 |
| 336 void TracingMessageHandler::OnLoadTraceFile(const ListValue* list) { | 335 void TracingMessageHandler::OnLoadTraceFile(const ListValue* list) { |
| 337 // Only allow a single dialog at a time. | 336 // Only allow a single dialog at a time. |
| 338 if (select_trace_file_dialog_.get()) | 337 if (select_trace_file_dialog_.get()) |
| 339 return; | 338 return; |
| 340 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; | 339 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; |
| 341 select_trace_file_dialog_ = SelectFileDialog::Create( | 340 select_trace_file_dialog_ = SelectFileDialog::Create(this); |
| 342 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | |
| 343 select_trace_file_dialog_->SelectFile( | 341 select_trace_file_dialog_->SelectFile( |
| 344 SelectFileDialog::SELECT_OPEN_FILE, | 342 SelectFileDialog::SELECT_OPEN_FILE, |
| 345 string16(), | 343 string16(), |
| 346 FilePath(), | 344 FilePath(), |
| 347 NULL, 0, FILE_PATH_LITERAL(""), | 345 NULL, 0, FILE_PATH_LITERAL(""), web_ui()->GetWebContents(), |
| 348 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); | 346 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); |
| 349 } | 347 } |
| 350 | 348 |
| 351 void TracingMessageHandler::LoadTraceFileComplete(std::string* file_contents) { | 349 void TracingMessageHandler::LoadTraceFileComplete(std::string* file_contents) { |
| 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 353 std::string javascript = "tracingController.onLoadTraceFileComplete(" | 351 std::string javascript = "tracingController.onLoadTraceFileComplete(" |
| 354 + *file_contents + ");"; | 352 + *file_contents + ");"; |
| 355 | 353 |
| 356 web_ui()->GetWebContents()->GetRenderViewHost()-> | 354 web_ui()->GetWebContents()->GetRenderViewHost()-> |
| 357 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(javascript)); | 355 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(javascript)); |
| 358 } | 356 } |
| 359 | 357 |
| 360 void TracingMessageHandler::OnSaveTraceFile(const ListValue* list) { | 358 void TracingMessageHandler::OnSaveTraceFile(const ListValue* list) { |
| 361 // Only allow a single dialog at a time. | 359 // Only allow a single dialog at a time. |
| 362 if (select_trace_file_dialog_.get()) | 360 if (select_trace_file_dialog_.get()) |
| 363 return; | 361 return; |
| 364 | 362 |
| 365 DCHECK(list->GetSize() == 1); | 363 DCHECK(list->GetSize() == 1); |
| 366 | 364 |
| 367 std::string* trace_data = new std::string(); | 365 std::string* trace_data = new std::string(); |
| 368 bool ok = list->GetString(0, trace_data); | 366 bool ok = list->GetString(0, trace_data); |
| 369 DCHECK(ok); | 367 DCHECK(ok); |
| 370 trace_data_to_save_.reset(trace_data); | 368 trace_data_to_save_.reset(trace_data); |
| 371 | 369 |
| 372 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE; | 370 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE; |
| 373 select_trace_file_dialog_ = SelectFileDialog::Create( | 371 select_trace_file_dialog_ = SelectFileDialog::Create(this); |
| 374 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | |
| 375 select_trace_file_dialog_->SelectFile( | 372 select_trace_file_dialog_->SelectFile( |
| 376 SelectFileDialog::SELECT_SAVEAS_FILE, | 373 SelectFileDialog::SELECT_SAVEAS_FILE, |
| 377 string16(), | 374 string16(), |
| 378 FilePath(), | 375 FilePath(), |
| 379 NULL, 0, FILE_PATH_LITERAL(""), | 376 NULL, 0, FILE_PATH_LITERAL(""), web_ui()->GetWebContents(), |
| 380 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); | 377 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); |
| 381 } | 378 } |
| 382 | 379 |
| 383 void TracingMessageHandler::SaveTraceFileComplete() { | 380 void TracingMessageHandler::SaveTraceFileComplete() { |
| 384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 385 web_ui()->CallJavascriptFunction("tracingController.onSaveTraceFileComplete"); | 382 web_ui()->CallJavascriptFunction("tracingController.onSaveTraceFileComplete"); |
| 386 } | 383 } |
| 387 | 384 |
| 388 void TracingMessageHandler::OnBeginTracing(const ListValue* args) { | 385 void TracingMessageHandler::OnBeginTracing(const ListValue* args) { |
| 389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 // | 489 // |
| 493 //////////////////////////////////////////////////////////////////////////////// | 490 //////////////////////////////////////////////////////////////////////////////// |
| 494 | 491 |
| 495 TracingUI::TracingUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 492 TracingUI::TracingUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 496 web_ui->AddMessageHandler(new TracingMessageHandler()); | 493 web_ui->AddMessageHandler(new TracingMessageHandler()); |
| 497 | 494 |
| 498 // Set up the chrome://tracing/ source. | 495 // Set up the chrome://tracing/ source. |
| 499 Profile* profile = Profile::FromWebUI(web_ui); | 496 Profile* profile = Profile::FromWebUI(web_ui); |
| 500 ChromeURLDataManager::AddDataSource(profile, CreateTracingHTMLSource()); | 497 ChromeURLDataManager::AddDataSource(profile, CreateTracingHTMLSource()); |
| 501 } | 498 } |
| OLD | NEW |