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/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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 #endif // defined(OS_WIN) | 97 #endif // defined(OS_WIN) |
98 | 98 |
99 #if defined(OS_CHROMEOS) | 99 #if defined(OS_CHROMEOS) |
100 #include "chrome/browser/chromeos/login/user_manager.h" | 100 #include "chrome/browser/chromeos/login/user_manager.h" |
101 #endif // defined(OS_CHROMEOS) | 101 #endif // defined(OS_CHROMEOS) |
102 | 102 |
103 using WebKit::WebFindOptions; | 103 using WebKit::WebFindOptions; |
104 using base::Time; | 104 using base::Time; |
105 using content::BrowserThread; | 105 using content::BrowserThread; |
106 using content::DownloadItem; | 106 using content::DownloadItem; |
| 107 using content::NavigationController; |
107 using content::WebContents; | 108 using content::WebContents; |
108 | 109 |
109 namespace { | 110 namespace { |
110 | 111 |
111 void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) { | 112 void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) { |
112 DCHECK(pc); | 113 DCHECK(pc); |
113 bool no_proxy = false; | 114 bool no_proxy = false; |
114 if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) { | 115 if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) { |
115 // Make no changes to the ProxyConfig. | 116 // Make no changes to the ProxyConfig. |
116 return; | 117 return; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } | 285 } |
285 | 286 |
286 void AutomationProvider::OnLoginWebuiReady() { | 287 void AutomationProvider::OnLoginWebuiReady() { |
287 login_webui_ready_ = true; | 288 login_webui_ready_ = true; |
288 VLOG(2) << "OnLoginWebuiReady"; | 289 VLOG(2) << "OnLoginWebuiReady"; |
289 if (is_connected_ && initial_tab_loads_complete_ && | 290 if (is_connected_ && initial_tab_loads_complete_ && |
290 network_library_initialized_) | 291 network_library_initialized_) |
291 Send(new AutomationMsg_InitialLoadsComplete()); | 292 Send(new AutomationMsg_InitialLoadsComplete()); |
292 } | 293 } |
293 | 294 |
294 void AutomationProvider::AddLoginHandler(content::NavigationController* tab, | 295 void AutomationProvider::AddLoginHandler(NavigationController* tab, |
295 LoginHandler* handler) { | 296 LoginHandler* handler) { |
296 login_handler_map_[tab] = handler; | 297 login_handler_map_[tab] = handler; |
297 } | 298 } |
298 | 299 |
299 void AutomationProvider::RemoveLoginHandler(content::NavigationController* tab)
{ | 300 void AutomationProvider::RemoveLoginHandler(NavigationController* tab) { |
300 DCHECK(login_handler_map_[tab]); | 301 DCHECK(login_handler_map_[tab]); |
301 login_handler_map_.erase(tab); | 302 login_handler_map_.erase(tab); |
302 } | 303 } |
303 | 304 |
304 int AutomationProvider::GetIndexForNavigationController( | 305 int AutomationProvider::GetIndexForNavigationController( |
305 const content::NavigationController* controller, | 306 const NavigationController* controller, const Browser* parent) const { |
306 const Browser* parent) const { | |
307 DCHECK(parent); | 307 DCHECK(parent); |
308 return parent->GetIndexOfController(controller); | 308 return parent->GetIndexOfController(controller); |
309 } | 309 } |
310 | 310 |
311 int AutomationProvider::AddExtension(const Extension* extension) { | 311 int AutomationProvider::AddExtension(const Extension* extension) { |
312 DCHECK(extension); | 312 DCHECK(extension); |
313 return extension_tracker_->Add(extension); | 313 return extension_tracker_->Add(extension); |
314 } | 314 } |
315 | 315 |
316 // TODO(phajdan.jr): move to TestingAutomationProvider. | 316 // TODO(phajdan.jr): move to TestingAutomationProvider. |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 VLOG(1) << "AutomationProxy went away, shutting down app."; | 520 VLOG(1) << "AutomationProxy went away, shutting down app."; |
521 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 521 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
522 } | 522 } |
523 | 523 |
524 bool AutomationProvider::Send(IPC::Message* msg) { | 524 bool AutomationProvider::Send(IPC::Message* msg) { |
525 DCHECK(channel_.get()); | 525 DCHECK(channel_.get()); |
526 return channel_->Send(msg); | 526 return channel_->Send(msg); |
527 } | 527 } |
528 | 528 |
529 Browser* AutomationProvider::FindAndActivateTab( | 529 Browser* AutomationProvider::FindAndActivateTab( |
530 content::NavigationController* controller) { | 530 NavigationController* controller) { |
531 int tab_index; | 531 int tab_index; |
532 Browser* browser = Browser::GetBrowserForController(controller, &tab_index); | 532 Browser* browser = Browser::GetBrowserForController(controller, &tab_index); |
533 if (browser) | 533 if (browser) |
534 browser->ActivateTabAt(tab_index, true); | 534 browser->ActivateTabAt(tab_index, true); |
535 | 535 |
536 return browser; | 536 return browser; |
537 } | 537 } |
538 | 538 |
539 void AutomationProvider::HandleFindRequest( | 539 void AutomationProvider::HandleFindRequest( |
540 int handle, | 540 int handle, |
541 const AutomationMsg_Find_Params& params, | 541 const AutomationMsg_Find_Params& params, |
542 IPC::Message* reply_message) { | 542 IPC::Message* reply_message) { |
543 if (!tab_tracker_->ContainsHandle(handle)) { | 543 if (!tab_tracker_->ContainsHandle(handle)) { |
544 AutomationMsg_Find::WriteReplyParams(reply_message, -1, -1); | 544 AutomationMsg_Find::WriteReplyParams(reply_message, -1, -1); |
545 Send(reply_message); | 545 Send(reply_message); |
546 return; | 546 return; |
547 } | 547 } |
548 | 548 |
549 content::NavigationController* nav = tab_tracker_->GetResource(handle); | 549 NavigationController* nav = tab_tracker_->GetResource(handle); |
550 WebContents* web_contents = nav->GetWebContents(); | 550 WebContents* web_contents = nav->GetWebContents(); |
551 | 551 |
552 SendFindRequest(web_contents, | 552 SendFindRequest(web_contents, |
553 false, | 553 false, |
554 params.search_string, | 554 params.search_string, |
555 params.forward, | 555 params.forward, |
556 params.match_case, | 556 params.match_case, |
557 params.find_next, | 557 params.find_next, |
558 reply_message); | 558 reply_message); |
559 } | 559 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 profile_->GetRequestContext(); | 594 profile_->GetRequestContext(); |
595 DCHECK(context_getter); | 595 DCHECK(context_getter); |
596 | 596 |
597 BrowserThread::PostTask( | 597 BrowserThread::PostTask( |
598 BrowserThread::IO, FROM_HERE, | 598 BrowserThread::IO, FROM_HERE, |
599 base::Bind(SetProxyConfigCallback, make_scoped_refptr(context_getter), | 599 base::Bind(SetProxyConfigCallback, make_scoped_refptr(context_getter), |
600 new_proxy_config)); | 600 new_proxy_config)); |
601 } | 601 } |
602 | 602 |
603 WebContents* AutomationProvider::GetWebContentsForHandle( | 603 WebContents* AutomationProvider::GetWebContentsForHandle( |
604 int handle, content::NavigationController** tab) { | 604 int handle, NavigationController** tab) { |
605 if (tab_tracker_->ContainsHandle(handle)) { | 605 if (tab_tracker_->ContainsHandle(handle)) { |
606 content::NavigationController* nav_controller = | 606 NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
607 tab_tracker_->GetResource(handle); | |
608 if (tab) | 607 if (tab) |
609 *tab = nav_controller; | 608 *tab = nav_controller; |
610 return nav_controller->GetWebContents(); | 609 return nav_controller->GetWebContents(); |
611 } | 610 } |
612 return NULL; | 611 return NULL; |
613 } | 612 } |
614 | 613 |
615 // Gets the current used encoding name of the page in the specified tab. | 614 // Gets the current used encoding name of the page in the specified tab. |
616 void AutomationProvider::OverrideEncoding(int tab_handle, | 615 void AutomationProvider::OverrideEncoding(int tab_handle, |
617 const std::string& encoding_name, | 616 const std::string& encoding_name, |
618 bool* success) { | 617 bool* success) { |
619 *success = false; | 618 *success = false; |
620 if (tab_tracker_->ContainsHandle(tab_handle)) { | 619 if (tab_tracker_->ContainsHandle(tab_handle)) { |
621 content::NavigationController* nav = tab_tracker_->GetResource(tab_handle); | 620 NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
622 if (!nav) | 621 if (!nav) |
623 return; | 622 return; |
624 Browser* browser = FindAndActivateTab(nav); | 623 Browser* browser = FindAndActivateTab(nav); |
625 | 624 |
626 // If the browser has UI, simulate what a user would do. | 625 // If the browser has UI, simulate what a user would do. |
627 // Activate the tab and then click the encoding menu. | 626 // Activate the tab and then click the encoding menu. |
628 if (browser && | 627 if (browser && |
629 browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) { | 628 browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) { |
630 int selected_encoding_id = | 629 int selected_encoding_id = |
631 CharacterEncoding::GetCommandIdByCanonicalEncodingName(encoding_name); | 630 CharacterEncoding::GetCommandIdByCanonicalEncodingName(encoding_name); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 if (!view) { | 682 if (!view) { |
684 NOTREACHED(); | 683 NOTREACHED(); |
685 return; | 684 return; |
686 } | 685 } |
687 | 686 |
688 view->Paste(); | 687 view->Paste(); |
689 } | 688 } |
690 | 689 |
691 void AutomationProvider::ReloadAsync(int tab_handle) { | 690 void AutomationProvider::ReloadAsync(int tab_handle) { |
692 if (tab_tracker_->ContainsHandle(tab_handle)) { | 691 if (tab_tracker_->ContainsHandle(tab_handle)) { |
693 content::NavigationController* tab = tab_tracker_->GetResource(tab_handle); | 692 NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
694 if (!tab) { | 693 if (!tab) { |
695 NOTREACHED(); | 694 NOTREACHED(); |
696 return; | 695 return; |
697 } | 696 } |
698 | 697 |
699 const bool check_for_repost = true; | 698 const bool check_for_repost = true; |
700 tab->Reload(check_for_repost); | 699 tab->Reload(check_for_repost); |
701 } | 700 } |
702 } | 701 } |
703 | 702 |
(...skipping 15 matching lines...) Expand all Loading... |
719 static_cast<AutomationPageFontSize>(font_size); | 718 static_cast<AutomationPageFontSize>(font_size); |
720 | 719 |
721 if (automation_font_size < SMALLEST_FONT || | 720 if (automation_font_size < SMALLEST_FONT || |
722 automation_font_size > LARGEST_FONT) { | 721 automation_font_size > LARGEST_FONT) { |
723 DLOG(ERROR) << "Invalid font size specified : " | 722 DLOG(ERROR) << "Invalid font size specified : " |
724 << font_size; | 723 << font_size; |
725 return; | 724 return; |
726 } | 725 } |
727 | 726 |
728 if (tab_tracker_->ContainsHandle(tab_handle)) { | 727 if (tab_tracker_->ContainsHandle(tab_handle)) { |
729 content::NavigationController* tab = tab_tracker_->GetResource(tab_handle); | 728 NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
730 DCHECK(tab != NULL); | 729 DCHECK(tab != NULL); |
731 if (tab && tab->GetWebContents()) { | 730 if (tab && tab->GetWebContents()) { |
732 DCHECK(tab->GetWebContents()->GetBrowserContext() != NULL); | 731 DCHECK(tab->GetWebContents()->GetBrowserContext() != NULL); |
733 Profile* profile = Profile::FromBrowserContext( | 732 Profile* profile = Profile::FromBrowserContext( |
734 tab->GetWebContents()->GetBrowserContext()); | 733 tab->GetWebContents()->GetBrowserContext()); |
735 profile->GetPrefs()->SetInteger( | 734 profile->GetPrefs()->SetInteger( |
736 prefs::kWebKitGlobalDefaultFontSize, font_size); | 735 prefs::kWebKitGlobalDefaultFontSize, font_size); |
737 } | 736 } |
738 } | 737 } |
739 } | 738 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 *success = false; | 789 *success = false; |
791 } else { | 790 } else { |
792 *chunk = tracing_data_.trace_output.front(); | 791 *chunk = tracing_data_.trace_output.front(); |
793 tracing_data_.trace_output.pop_front(); | 792 tracing_data_.trace_output.pop_front(); |
794 *success = true; | 793 *success = true; |
795 } | 794 } |
796 } | 795 } |
797 | 796 |
798 RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { | 797 RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { |
799 if (tab_tracker_->ContainsHandle(tab_handle)) { | 798 if (tab_tracker_->ContainsHandle(tab_handle)) { |
800 content::NavigationController* tab = tab_tracker_->GetResource(tab_handle); | 799 NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
801 if (!tab) { | 800 if (!tab) { |
802 NOTREACHED(); | 801 NOTREACHED(); |
803 return NULL; | 802 return NULL; |
804 } | 803 } |
805 | 804 |
806 WebContents* web_contents = tab->GetWebContents(); | 805 WebContents* web_contents = tab->GetWebContents(); |
807 if (!web_contents) { | 806 if (!web_contents) { |
808 NOTREACHED(); | 807 NOTREACHED(); |
809 return NULL; | 808 return NULL; |
810 } | 809 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 } | 997 } |
999 break; | 998 break; |
1000 default: | 999 default: |
1001 LOG(WARNING) << "Trying to get undefined extension property"; | 1000 LOG(WARNING) << "Trying to get undefined extension property"; |
1002 break; | 1001 break; |
1003 } | 1002 } |
1004 } | 1003 } |
1005 } | 1004 } |
1006 | 1005 |
1007 void AutomationProvider::SaveAsAsync(int tab_handle) { | 1006 void AutomationProvider::SaveAsAsync(int tab_handle) { |
1008 content::NavigationController* tab = NULL; | 1007 NavigationController* tab = NULL; |
1009 WebContents* web_contents = GetWebContentsForHandle(tab_handle, &tab); | 1008 WebContents* web_contents = GetWebContentsForHandle(tab_handle, &tab); |
1010 if (web_contents) | 1009 if (web_contents) |
1011 web_contents->OnSavePage(); | 1010 web_contents->OnSavePage(); |
1012 } | 1011 } |
OLD | NEW |