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