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/automation/automation_provider.h" | 5 #include "chrome/browser/automation/automation_provider.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #include "chrome/common/chrome_paths.h" | 59 #include "chrome/common/chrome_paths.h" |
60 #include "chrome/common/chrome_switches.h" | 60 #include "chrome/common/chrome_switches.h" |
61 #include "chrome/common/chrome_version_info.h" | 61 #include "chrome/common/chrome_version_info.h" |
62 #include "chrome/common/pref_names.h" | 62 #include "chrome/common/pref_names.h" |
63 #include "chrome/common/render_messages.h" | 63 #include "chrome/common/render_messages.h" |
64 #include "chrome/common/url_constants.h" | 64 #include "chrome/common/url_constants.h" |
65 #include "content/public/browser/browser_thread.h" | 65 #include "content/public/browser/browser_thread.h" |
66 #include "content/public/browser/download_item.h" | 66 #include "content/public/browser/download_item.h" |
67 #include "content/public/browser/native_web_keyboard_event.h" | 67 #include "content/public/browser/native_web_keyboard_event.h" |
68 #include "content/public/browser/render_view_host.h" | 68 #include "content/public/browser/render_view_host.h" |
69 #include "content/public/browser/tracing_controller.h" | 69 #include "content/public/browser/trace_controller.h" |
70 #include "content/public/browser/web_contents.h" | 70 #include "content/public/browser/web_contents.h" |
71 #include "content/public/browser/web_contents_view.h" | 71 #include "content/public/browser/web_contents_view.h" |
72 #include "net/proxy/proxy_config_service_fixed.h" | 72 #include "net/proxy/proxy_config_service_fixed.h" |
73 #include "net/proxy/proxy_service.h" | 73 #include "net/proxy/proxy_service.h" |
74 #include "net/url_request/url_request_context.h" | 74 #include "net/url_request/url_request_context.h" |
75 #include "net/url_request/url_request_context_getter.h" | 75 #include "net/url_request/url_request_context_getter.h" |
76 #include "third_party/WebKit/public/web/WebFindOptions.h" | 76 #include "third_party/WebKit/public/web/WebFindOptions.h" |
77 | 77 |
78 #if defined(OS_CHROMEOS) | 78 #if defined(OS_CHROMEOS) |
79 #include "chromeos/chromeos_switches.h" | 79 #include "chromeos/chromeos_switches.h" |
80 #include "chromeos/login/login_state.h" | 80 #include "chromeos/login/login_state.h" |
81 #endif // defined(OS_CHROMEOS) | 81 #endif // defined(OS_CHROMEOS) |
82 | 82 |
83 using blink::WebFindOptions; | 83 using blink::WebFindOptions; |
84 using base::Time; | 84 using base::Time; |
85 using content::BrowserThread; | 85 using content::BrowserThread; |
86 using content::DownloadItem; | 86 using content::DownloadItem; |
87 using content::NavigationController; | 87 using content::NavigationController; |
88 using content::RenderViewHost; | 88 using content::RenderViewHost; |
89 using content::TracingController; | 89 using content::TraceController; |
90 using content::WebContents; | 90 using content::WebContents; |
91 | 91 |
92 namespace { | 92 namespace { |
93 | 93 |
94 void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) { | 94 void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) { |
95 DCHECK(pc); | 95 DCHECK(pc); |
96 bool no_proxy = false; | 96 bool no_proxy = false; |
97 if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) { | 97 if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) { |
98 // Make no changes to the ProxyConfig. | 98 // Make no changes to the ProxyConfig. |
99 return; | 99 return; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 void AutomationProvider::OnChannelConnected(int pid) { | 369 void AutomationProvider::OnChannelConnected(int pid) { |
370 is_connected_ = true; | 370 is_connected_ = true; |
371 | 371 |
372 // Send a hello message with our current automation protocol version. | 372 // Send a hello message with our current automation protocol version. |
373 VLOG(2) << "Testing channel connected, sending hello message"; | 373 VLOG(2) << "Testing channel connected, sending hello message"; |
374 channel_->Send(new AutomationMsg_Hello(GetProtocolVersion())); | 374 channel_->Send(new AutomationMsg_Hello(GetProtocolVersion())); |
375 | 375 |
376 SendInitialLoadMessage(); | 376 SendInitialLoadMessage(); |
377 } | 377 } |
378 | 378 |
| 379 void AutomationProvider::OnEndTracingComplete() { |
| 380 IPC::Message* reply_message = tracing_data_.reply_message.release(); |
| 381 if (reply_message) { |
| 382 AutomationMsg_EndTracing::WriteReplyParams( |
| 383 reply_message, tracing_data_.trace_output.size(), true); |
| 384 Send(reply_message); |
| 385 } |
| 386 } |
| 387 |
| 388 void AutomationProvider::OnTraceDataCollected( |
| 389 const scoped_refptr<base::RefCountedString>& trace_fragment) { |
| 390 tracing_data_.trace_output.push_back(trace_fragment->data()); |
| 391 } |
| 392 |
379 bool AutomationProvider::OnMessageReceived(const IPC::Message& message) { | 393 bool AutomationProvider::OnMessageReceived(const IPC::Message& message) { |
380 bool handled = true; | 394 bool handled = true; |
381 bool deserialize_success = true; | 395 bool deserialize_success = true; |
382 IPC_BEGIN_MESSAGE_MAP_EX(AutomationProvider, message, deserialize_success) | 396 IPC_BEGIN_MESSAGE_MAP_EX(AutomationProvider, message, deserialize_success) |
383 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) | 397 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) |
384 IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig) | 398 IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig) |
385 IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) | 399 IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) |
386 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) | 400 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) |
387 IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding) | 401 IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding) |
388 IPC_MESSAGE_HANDLER(AutomationMsg_SelectAll, SelectAll) | 402 IPC_MESSAGE_HANDLER(AutomationMsg_SelectAll, SelectAll) |
389 IPC_MESSAGE_HANDLER(AutomationMsg_Cut, Cut) | 403 IPC_MESSAGE_HANDLER(AutomationMsg_Cut, Cut) |
390 IPC_MESSAGE_HANDLER(AutomationMsg_Copy, Copy) | 404 IPC_MESSAGE_HANDLER(AutomationMsg_Copy, Copy) |
391 IPC_MESSAGE_HANDLER(AutomationMsg_Paste, Paste) | 405 IPC_MESSAGE_HANDLER(AutomationMsg_Paste, Paste) |
392 IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync) | 406 IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync) |
393 IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync) | 407 IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync) |
394 IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize) | 408 IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize) |
395 IPC_MESSAGE_HANDLER(AutomationMsg_SaveAsAsync, SaveAsAsync) | 409 IPC_MESSAGE_HANDLER(AutomationMsg_SaveAsAsync, SaveAsAsync) |
396 IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBrowsingData, RemoveBrowsingData) | 410 IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBrowsingData, RemoveBrowsingData) |
397 IPC_MESSAGE_HANDLER(AutomationMsg_JavaScriptStressTestControl, | 411 IPC_MESSAGE_HANDLER(AutomationMsg_JavaScriptStressTestControl, |
398 JavaScriptStressTestControl) | 412 JavaScriptStressTestControl) |
399 IPC_MESSAGE_HANDLER(AutomationMsg_BeginTracing, BeginTracing) | 413 IPC_MESSAGE_HANDLER(AutomationMsg_BeginTracing, BeginTracing) |
400 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EndTracing, EndTracing) | 414 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EndTracing, EndTracing) |
| 415 IPC_MESSAGE_HANDLER(AutomationMsg_GetTracingOutput, GetTracingOutput) |
401 #if defined(OS_WIN) | 416 #if defined(OS_WIN) |
402 // These are for use with external tabs. | 417 // These are for use with external tabs. |
403 IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab) | 418 IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab) |
404 IPC_MESSAGE_HANDLER(AutomationMsg_ProcessUnhandledAccelerator, | 419 IPC_MESSAGE_HANDLER(AutomationMsg_ProcessUnhandledAccelerator, |
405 ProcessUnhandledAccelerator) | 420 ProcessUnhandledAccelerator) |
406 IPC_MESSAGE_HANDLER(AutomationMsg_SetInitialFocus, SetInitialFocus) | 421 IPC_MESSAGE_HANDLER(AutomationMsg_SetInitialFocus, SetInitialFocus) |
407 IPC_MESSAGE_HANDLER(AutomationMsg_TabReposition, OnTabReposition) | 422 IPC_MESSAGE_HANDLER(AutomationMsg_TabReposition, OnTabReposition) |
408 IPC_MESSAGE_HANDLER(AutomationMsg_ForwardContextMenuCommandToChrome, | 423 IPC_MESSAGE_HANDLER(AutomationMsg_ForwardContextMenuCommandToChrome, |
409 OnForwardContextMenuCommandToChrome) | 424 OnForwardContextMenuCommandToChrome) |
410 IPC_MESSAGE_HANDLER(AutomationMsg_NavigateInExternalTab, | 425 IPC_MESSAGE_HANDLER(AutomationMsg_NavigateInExternalTab, |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 NOTREACHED(); | 715 NOTREACHED(); |
701 return; | 716 return; |
702 } | 717 } |
703 | 718 |
704 view->Send(new ChromeViewMsg_JavaScriptStressTestControl( | 719 view->Send(new ChromeViewMsg_JavaScriptStressTestControl( |
705 view->GetRoutingID(), cmd, param)); | 720 view->GetRoutingID(), cmd, param)); |
706 } | 721 } |
707 | 722 |
708 void AutomationProvider::BeginTracing(const std::string& category_patterns, | 723 void AutomationProvider::BeginTracing(const std::string& category_patterns, |
709 bool* success) { | 724 bool* success) { |
710 *success = TracingController::GetInstance()->EnableRecording( | 725 tracing_data_.trace_output.clear(); |
711 category_patterns, TracingController::DEFAULT_OPTIONS, | 726 *success = TraceController::GetInstance()->BeginTracing( |
712 TracingController::EnableRecordingDoneCallback()); | 727 this, |
| 728 category_patterns, |
| 729 base::debug::TraceLog::RECORD_UNTIL_FULL); |
713 } | 730 } |
714 | 731 |
715 void AutomationProvider::EndTracing(IPC::Message* reply_message) { | 732 void AutomationProvider::EndTracing(IPC::Message* reply_message) { |
716 base::FilePath path; | 733 bool success = false; |
717 if (!TracingController::GetInstance()->DisableRecording( | 734 if (!tracing_data_.reply_message.get()) |
718 path, base::Bind(&AutomationProvider::OnTraceDataCollected, this, | 735 success = TraceController::GetInstance()->EndTracingAsync(this); |
719 reply_message))) { | 736 if (success) { |
| 737 // Defer EndTracing reply until TraceController calls us back with all the |
| 738 // events. |
| 739 tracing_data_.reply_message.reset(reply_message); |
| 740 } else { |
720 // If failed to call EndTracingAsync, need to reply with failure now. | 741 // If failed to call EndTracingAsync, need to reply with failure now. |
721 AutomationMsg_EndTracing::WriteReplyParams(reply_message, path, false); | 742 AutomationMsg_EndTracing::WriteReplyParams(reply_message, size_t(0), false); |
722 Send(reply_message); | |
723 } | |
724 // Otherwise defer EndTracing reply until TraceController calls us back. | |
725 } | |
726 | |
727 void AutomationProvider::OnTraceDataCollected(IPC::Message* reply_message, | |
728 const base::FilePath& path) { | |
729 if (reply_message) { | |
730 AutomationMsg_EndTracing::WriteReplyParams(reply_message, path, true); | |
731 Send(reply_message); | 743 Send(reply_message); |
732 } | 744 } |
733 } | 745 } |
734 | 746 |
| 747 void AutomationProvider::GetTracingOutput(std::string* chunk, |
| 748 bool* success) { |
| 749 // The JSON data is sent back to the test in chunks, because IPC sends will |
| 750 // fail if they are too large. |
| 751 if (tracing_data_.trace_output.empty()) { |
| 752 *chunk = ""; |
| 753 *success = false; |
| 754 } else { |
| 755 *chunk = tracing_data_.trace_output.front(); |
| 756 tracing_data_.trace_output.pop_front(); |
| 757 *success = true; |
| 758 } |
| 759 } |
| 760 |
735 RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { | 761 RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { |
736 if (tab_tracker_->ContainsHandle(tab_handle)) { | 762 if (tab_tracker_->ContainsHandle(tab_handle)) { |
737 NavigationController* tab = tab_tracker_->GetResource(tab_handle); | 763 NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
738 if (!tab) { | 764 if (!tab) { |
739 NOTREACHED(); | 765 NOTREACHED(); |
740 return NULL; | 766 return NULL; |
741 } | 767 } |
742 | 768 |
743 WebContents* web_contents = tab->GetWebContents(); | 769 WebContents* web_contents = tab->GetWebContents(); |
744 if (!web_contents) { | 770 if (!web_contents) { |
745 NOTREACHED(); | 771 NOTREACHED(); |
746 return NULL; | 772 return NULL; |
747 } | 773 } |
748 | 774 |
749 RenderViewHost* view_host = web_contents->GetRenderViewHost(); | 775 RenderViewHost* view_host = web_contents->GetRenderViewHost(); |
750 return view_host; | 776 return view_host; |
751 } | 777 } |
752 | 778 |
753 return NULL; | 779 return NULL; |
754 } | 780 } |
755 | 781 |
756 void AutomationProvider::SaveAsAsync(int tab_handle) { | 782 void AutomationProvider::SaveAsAsync(int tab_handle) { |
757 NavigationController* tab = NULL; | 783 NavigationController* tab = NULL; |
758 WebContents* web_contents = GetWebContentsForHandle(tab_handle, &tab); | 784 WebContents* web_contents = GetWebContentsForHandle(tab_handle, &tab); |
759 if (web_contents) | 785 if (web_contents) |
760 web_contents->OnSavePage(); | 786 web_contents->OnSavePage(); |
761 } | 787 } |
OLD | NEW |