| 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/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 *status = true; | 627 *status = true; |
| 628 } | 628 } |
| 629 } | 629 } |
| 630 } | 630 } |
| 631 | 631 |
| 632 void TestingAutomationProvider::Reload(int handle, | 632 void TestingAutomationProvider::Reload(int handle, |
| 633 IPC::Message* reply_message) { | 633 IPC::Message* reply_message) { |
| 634 if (tab_tracker_->ContainsHandle(handle)) { | 634 if (tab_tracker_->ContainsHandle(handle)) { |
| 635 NavigationController* tab = tab_tracker_->GetResource(handle); | 635 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 636 Browser* browser = FindAndActivateTab(tab); | 636 Browser* browser = FindAndActivateTab(tab); |
| 637 if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) { | 637 if (chrome::IsCommandEnabled(browser, IDC_RELOAD)) { |
| 638 new NavigationNotificationObserver( | 638 new NavigationNotificationObserver( |
| 639 tab, this, reply_message, 1, false, false); | 639 tab, this, reply_message, 1, false, false); |
| 640 chrome::Reload(browser, CURRENT_TAB); | 640 chrome::ExecuteCommand(browser, IDC_RELOAD); |
| 641 return; | 641 return; |
| 642 } | 642 } |
| 643 } | 643 } |
| 644 | 644 |
| 645 AutomationMsg_Reload::WriteReplyParams( | 645 AutomationMsg_Reload::WriteReplyParams( |
| 646 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); | 646 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 647 Send(reply_message); | 647 Send(reply_message); |
| 648 } | 648 } |
| 649 | 649 |
| 650 void TestingAutomationProvider::GetBrowserWindowCount(int* window_count) { | 650 void TestingAutomationProvider::GetBrowserWindowCount(int* window_count) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 671 | 671 |
| 672 void TestingAutomationProvider::ExecuteBrowserCommandAsync(int handle, | 672 void TestingAutomationProvider::ExecuteBrowserCommandAsync(int handle, |
| 673 int command, | 673 int command, |
| 674 bool* success) { | 674 bool* success) { |
| 675 *success = false; | 675 *success = false; |
| 676 if (!browser_tracker_->ContainsHandle(handle)) { | 676 if (!browser_tracker_->ContainsHandle(handle)) { |
| 677 LOG(WARNING) << "Browser tracker does not contain handle: " << handle; | 677 LOG(WARNING) << "Browser tracker does not contain handle: " << handle; |
| 678 return; | 678 return; |
| 679 } | 679 } |
| 680 Browser* browser = browser_tracker_->GetResource(handle); | 680 Browser* browser = browser_tracker_->GetResource(handle); |
| 681 if (!browser->command_updater()->SupportsCommand(command)) { | 681 if (!chrome::SupportsCommand(browser, command)) { |
| 682 LOG(WARNING) << "Browser does not support command: " << command; | 682 LOG(WARNING) << "Browser does not support command: " << command; |
| 683 return; | 683 return; |
| 684 } | 684 } |
| 685 if (!browser->command_updater()->IsCommandEnabled(command)) { | 685 if (!chrome::IsCommandEnabled(browser, command)) { |
| 686 LOG(WARNING) << "Browser command not enabled: " << command; | 686 LOG(WARNING) << "Browser command not enabled: " << command; |
| 687 return; | 687 return; |
| 688 } | 688 } |
| 689 browser->ExecuteCommand(command); | 689 chrome::ExecuteCommand(browser, command); |
| 690 *success = true; | 690 *success = true; |
| 691 } | 691 } |
| 692 | 692 |
| 693 void TestingAutomationProvider::ExecuteBrowserCommand( | 693 void TestingAutomationProvider::ExecuteBrowserCommand( |
| 694 int handle, int command, IPC::Message* reply_message) { | 694 int handle, int command, IPC::Message* reply_message) { |
| 695 // List of commands which just finish synchronously and don't require | 695 // List of commands which just finish synchronously and don't require |
| 696 // setting up an observer. | 696 // setting up an observer. |
| 697 static const int kSynchronousCommands[] = { | 697 static const int kSynchronousCommands[] = { |
| 698 IDC_HOME, | 698 IDC_HOME, |
| 699 IDC_SELECT_NEXT_TAB, | 699 IDC_SELECT_NEXT_TAB, |
| 700 IDC_SELECT_PREVIOUS_TAB, | 700 IDC_SELECT_PREVIOUS_TAB, |
| 701 IDC_SHOW_BOOKMARK_MANAGER, | 701 IDC_SHOW_BOOKMARK_MANAGER, |
| 702 }; | 702 }; |
| 703 if (browser_tracker_->ContainsHandle(handle)) { | 703 if (browser_tracker_->ContainsHandle(handle)) { |
| 704 Browser* browser = browser_tracker_->GetResource(handle); | 704 Browser* browser = browser_tracker_->GetResource(handle); |
| 705 if (browser->command_updater()->SupportsCommand(command) && | 705 if (chrome::SupportsCommand(browser, command) && |
| 706 browser->command_updater()->IsCommandEnabled(command)) { | 706 chrome::IsCommandEnabled(browser, command)) { |
| 707 // First check if we can handle the command without using an observer. | 707 // First check if we can handle the command without using an observer. |
| 708 for (size_t i = 0; i < arraysize(kSynchronousCommands); i++) { | 708 for (size_t i = 0; i < arraysize(kSynchronousCommands); i++) { |
| 709 if (command == kSynchronousCommands[i]) { | 709 if (command == kSynchronousCommands[i]) { |
| 710 browser->ExecuteCommand(command); | 710 chrome::ExecuteCommand(browser, command); |
| 711 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, | 711 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, |
| 712 true); | 712 true); |
| 713 Send(reply_message); | 713 Send(reply_message); |
| 714 return; | 714 return; |
| 715 } | 715 } |
| 716 } | 716 } |
| 717 | 717 |
| 718 // Use an observer if we have one, otherwise fail. | 718 // Use an observer if we have one, otherwise fail. |
| 719 if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver( | 719 if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver( |
| 720 this, browser, command, reply_message)) { | 720 this, browser, command, reply_message)) { |
| 721 browser->ExecuteCommand(command); | 721 chrome::ExecuteCommand(browser, command); |
| 722 return; | 722 return; |
| 723 } | 723 } |
| 724 } | 724 } |
| 725 } | 725 } |
| 726 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false); | 726 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false); |
| 727 Send(reply_message); | 727 Send(reply_message); |
| 728 } | 728 } |
| 729 | 729 |
| 730 void TestingAutomationProvider::WindowSimulateMouseMove( | 730 void TestingAutomationProvider::WindowSimulateMouseMove( |
| 731 const IPC::Message& message, | 731 const IPC::Message& message, |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 *success = true; | 1362 *success = true; |
| 1363 } | 1363 } |
| 1364 } | 1364 } |
| 1365 | 1365 |
| 1366 void TestingAutomationProvider::IsMenuCommandEnabled(int browser_handle, | 1366 void TestingAutomationProvider::IsMenuCommandEnabled(int browser_handle, |
| 1367 int message_num, | 1367 int message_num, |
| 1368 bool* menu_item_enabled) { | 1368 bool* menu_item_enabled) { |
| 1369 *menu_item_enabled = false; | 1369 *menu_item_enabled = false; |
| 1370 if (browser_tracker_->ContainsHandle(browser_handle)) { | 1370 if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 1371 Browser* browser = browser_tracker_->GetResource(browser_handle); | 1371 Browser* browser = browser_tracker_->GetResource(browser_handle); |
| 1372 *menu_item_enabled = | 1372 *menu_item_enabled = chrome::IsCommandEnabled(browser, message_num); |
| 1373 browser->command_updater()->IsCommandEnabled(message_num); | |
| 1374 } | 1373 } |
| 1375 } | 1374 } |
| 1376 | 1375 |
| 1377 void TestingAutomationProvider::HandleOpenFindInPageRequest( | 1376 void TestingAutomationProvider::HandleOpenFindInPageRequest( |
| 1378 const IPC::Message& message, int handle) { | 1377 const IPC::Message& message, int handle) { |
| 1379 if (browser_tracker_->ContainsHandle(handle)) { | 1378 if (browser_tracker_->ContainsHandle(handle)) { |
| 1380 Browser* browser = browser_tracker_->GetResource(handle); | 1379 Browser* browser = browser_tracker_->GetResource(handle); |
| 1381 chrome::FindInPage(browser, false, false); | 1380 chrome::FindInPage(browser, false, false); |
| 1382 } | 1381 } |
| 1383 } | 1382 } |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1615 | 1614 |
| 1616 // Set up an observer (it will delete itself). | 1615 // Set up an observer (it will delete itself). |
| 1617 new BrowserCountChangeNotificationObserver(target_count, this, reply_message); | 1616 new BrowserCountChangeNotificationObserver(target_count, this, reply_message); |
| 1618 } | 1617 } |
| 1619 | 1618 |
| 1620 void TestingAutomationProvider::GoBackBlockUntilNavigationsComplete( | 1619 void TestingAutomationProvider::GoBackBlockUntilNavigationsComplete( |
| 1621 int handle, int number_of_navigations, IPC::Message* reply_message) { | 1620 int handle, int number_of_navigations, IPC::Message* reply_message) { |
| 1622 if (tab_tracker_->ContainsHandle(handle)) { | 1621 if (tab_tracker_->ContainsHandle(handle)) { |
| 1623 NavigationController* tab = tab_tracker_->GetResource(handle); | 1622 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1624 Browser* browser = FindAndActivateTab(tab); | 1623 Browser* browser = FindAndActivateTab(tab); |
| 1625 if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { | 1624 if (chrome::IsCommandEnabled(browser, IDC_BACK)) { |
| 1626 new NavigationNotificationObserver(tab, this, reply_message, | 1625 new NavigationNotificationObserver(tab, this, reply_message, |
| 1627 number_of_navigations, false, false); | 1626 number_of_navigations, false, false); |
| 1628 chrome::GoBack(browser, CURRENT_TAB); | 1627 chrome::ExecuteCommand(browser, IDC_BACK); |
| 1629 return; | 1628 return; |
| 1630 } | 1629 } |
| 1631 } | 1630 } |
| 1632 | 1631 |
| 1633 AutomationMsg_GoBackBlockUntilNavigationsComplete::WriteReplyParams( | 1632 AutomationMsg_GoBackBlockUntilNavigationsComplete::WriteReplyParams( |
| 1634 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); | 1633 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 1635 Send(reply_message); | 1634 Send(reply_message); |
| 1636 } | 1635 } |
| 1637 | 1636 |
| 1638 void TestingAutomationProvider::GoForwardBlockUntilNavigationsComplete( | 1637 void TestingAutomationProvider::GoForwardBlockUntilNavigationsComplete( |
| 1639 int handle, int number_of_navigations, IPC::Message* reply_message) { | 1638 int handle, int number_of_navigations, IPC::Message* reply_message) { |
| 1640 if (tab_tracker_->ContainsHandle(handle)) { | 1639 if (tab_tracker_->ContainsHandle(handle)) { |
| 1641 NavigationController* tab = tab_tracker_->GetResource(handle); | 1640 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1642 Browser* browser = FindAndActivateTab(tab); | 1641 Browser* browser = FindAndActivateTab(tab); |
| 1643 if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { | 1642 if (chrome::IsCommandEnabled(browser, IDC_FORWARD)) { |
| 1644 new NavigationNotificationObserver(tab, this, reply_message, | 1643 new NavigationNotificationObserver(tab, this, reply_message, |
| 1645 number_of_navigations, false, false); | 1644 number_of_navigations, false, false); |
| 1646 chrome::GoForward(browser, CURRENT_TAB); | 1645 chrome::ExecuteCommand(browser, IDC_FORWARD); |
| 1647 return; | 1646 return; |
| 1648 } | 1647 } |
| 1649 } | 1648 } |
| 1650 | 1649 |
| 1651 AutomationMsg_GoForwardBlockUntilNavigationsComplete::WriteReplyParams( | 1650 AutomationMsg_GoForwardBlockUntilNavigationsComplete::WriteReplyParams( |
| 1652 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); | 1651 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 1653 Send(reply_message); | 1652 Send(reply_message); |
| 1654 } | 1653 } |
| 1655 | 1654 |
| 1656 void TestingAutomationProvider::SetShelfVisibility(int handle, bool visible) { | 1655 void TestingAutomationProvider::SetShelfVisibility(int handle, bool visible) { |
| (...skipping 5078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6735 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6734 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 6736 } | 6735 } |
| 6737 | 6736 |
| 6738 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 6737 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
| 6739 WebContents* tab) { | 6738 WebContents* tab) { |
| 6740 if (browser->GetActiveWebContents() != tab) { | 6739 if (browser->GetActiveWebContents() != tab) { |
| 6741 browser->ActivateTabAt(browser->GetIndexOfController( | 6740 browser->ActivateTabAt(browser->GetIndexOfController( |
| 6742 &tab->GetController()), true); | 6741 &tab->GetController()), true); |
| 6743 } | 6742 } |
| 6744 } | 6743 } |
| OLD | NEW |