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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 | 493 |
494 void TestingAutomationProvider::AppendTab(int handle, | 494 void TestingAutomationProvider::AppendTab(int handle, |
495 const GURL& url, | 495 const GURL& url, |
496 IPC::Message* reply_message) { | 496 IPC::Message* reply_message) { |
497 int append_tab_response = -1; // -1 is the error code | 497 int append_tab_response = -1; // -1 is the error code |
498 TabAppendedNotificationObserver* observer = NULL; | 498 TabAppendedNotificationObserver* observer = NULL; |
499 | 499 |
500 if (browser_tracker_->ContainsHandle(handle)) { | 500 if (browser_tracker_->ContainsHandle(handle)) { |
501 Browser* browser = browser_tracker_->GetResource(handle); | 501 Browser* browser = browser_tracker_->GetResource(handle); |
502 observer = new TabAppendedNotificationObserver(browser, this, | 502 observer = new TabAppendedNotificationObserver(browser, this, |
503 reply_message); | 503 reply_message, false); |
504 TabContents* contents = | 504 TabContents* contents = |
505 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED); | 505 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED); |
506 if (contents) { | 506 if (contents) { |
507 append_tab_response = GetIndexForNavigationController( | 507 append_tab_response = GetIndexForNavigationController( |
508 &contents->web_contents()->GetController(), browser); | 508 &contents->web_contents()->GetController(), browser); |
509 } | 509 } |
510 } | 510 } |
511 | 511 |
512 if (append_tab_response < 0) { | 512 if (append_tab_response < 0) { |
513 // Appending tab failed. Clean up and send failure response. | 513 // Appending tab failed. Clean up and send failure response. |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1692 } | 1692 } |
1693 | 1693 |
1694 // Map json commands to their handlers. | 1694 // Map json commands to their handlers. |
1695 std::map<std::string, JsonHandler> handler_map; | 1695 std::map<std::string, JsonHandler> handler_map; |
1696 handler_map["WaitForAllTabsToStopLoading"] = | 1696 handler_map["WaitForAllTabsToStopLoading"] = |
1697 &TestingAutomationProvider::WaitForAllViewsToStopLoading; | 1697 &TestingAutomationProvider::WaitForAllViewsToStopLoading; |
1698 handler_map["GetIndicesFromTab"] = | 1698 handler_map["GetIndicesFromTab"] = |
1699 &TestingAutomationProvider::GetIndicesFromTab; | 1699 &TestingAutomationProvider::GetIndicesFromTab; |
1700 handler_map["NavigateToURL"] = | 1700 handler_map["NavigateToURL"] = |
1701 &TestingAutomationProvider::NavigateToURL; | 1701 &TestingAutomationProvider::NavigateToURL; |
| 1702 handler_map["GetActiveTabIndex"] = |
| 1703 &TestingAutomationProvider::GetActiveTabIndexJSON; |
| 1704 handler_map["AppendTab"] = |
| 1705 &TestingAutomationProvider::AppendTabJSON; |
1702 handler_map["WaitUntilNavigationCompletes"] = | 1706 handler_map["WaitUntilNavigationCompletes"] = |
1703 &TestingAutomationProvider::WaitUntilNavigationCompletes; | 1707 &TestingAutomationProvider::WaitUntilNavigationCompletes; |
1704 handler_map["GetLocalStatePrefsInfo"] = | 1708 handler_map["GetLocalStatePrefsInfo"] = |
1705 &TestingAutomationProvider::GetLocalStatePrefsInfo; | 1709 &TestingAutomationProvider::GetLocalStatePrefsInfo; |
1706 handler_map["SetLocalStatePrefs"] = | 1710 handler_map["SetLocalStatePrefs"] = |
1707 &TestingAutomationProvider::SetLocalStatePrefs; | 1711 &TestingAutomationProvider::SetLocalStatePrefs; |
1708 handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; | 1712 handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; |
1709 handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; | 1713 handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; |
1710 handler_map["ExecuteJavascript"] = | 1714 handler_map["ExecuteJavascript"] = |
1711 &TestingAutomationProvider::ExecuteJavascriptJSON; | 1715 &TestingAutomationProvider::ExecuteJavascriptJSON; |
(...skipping 4394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6106 navigation_count, false, true); | 6110 navigation_count, false, true); |
6107 OpenURLParams params( | 6111 OpenURLParams params( |
6108 GURL(url), content::Referrer(), CURRENT_TAB, | 6112 GURL(url), content::Referrer(), CURRENT_TAB, |
6109 content::PageTransitionFromInt( | 6113 content::PageTransitionFromInt( |
6110 content::PAGE_TRANSITION_TYPED | | 6114 content::PAGE_TRANSITION_TYPED | |
6111 content::PAGE_TRANSITION_FROM_ADDRESS_BAR), | 6115 content::PAGE_TRANSITION_FROM_ADDRESS_BAR), |
6112 false); | 6116 false); |
6113 browser->OpenURLFromTab(web_contents, params); | 6117 browser->OpenURLFromTab(web_contents, params); |
6114 } | 6118 } |
6115 | 6119 |
| 6120 void TestingAutomationProvider::GetActiveTabIndexJSON( |
| 6121 DictionaryValue* args, |
| 6122 IPC::Message* reply_message) { |
| 6123 AutomationJSONReply reply(this, reply_message); |
| 6124 Browser* browser; |
| 6125 std::string error_msg; |
| 6126 if (!GetBrowserFromJSONArgs(args, &browser, &error_msg)) { |
| 6127 reply.SendError(error_msg); |
| 6128 return; |
| 6129 } |
| 6130 int tab_index = browser->active_index(); |
| 6131 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 6132 return_value->SetInteger("tab_index", tab_index); |
| 6133 reply.SendSuccess(return_value.get()); |
| 6134 } |
| 6135 |
| 6136 void TestingAutomationProvider::AppendTabJSON(DictionaryValue* args, |
| 6137 IPC::Message* reply_message) { |
| 6138 TabAppendedNotificationObserver* observer = NULL; |
| 6139 int append_tab_response = -1; |
| 6140 Browser* browser; |
| 6141 std::string error_msg, url; |
| 6142 if (!GetBrowserFromJSONArgs(args, &browser, &error_msg)) { |
| 6143 AutomationJSONReply(this, reply_message).SendError(error_msg); |
| 6144 return; |
| 6145 } |
| 6146 if (!args->GetString("url", &url)) { |
| 6147 AutomationJSONReply(this, reply_message) |
| 6148 .SendError("'url' missing or invalid"); |
| 6149 return; |
| 6150 } |
| 6151 observer = new TabAppendedNotificationObserver(browser, this, reply_message, |
| 6152 true); |
| 6153 TabContents* contents = |
| 6154 browser->AddSelectedTabWithURL(GURL(url), content::PAGE_TRANSITION_TYPED); |
| 6155 if (contents) { |
| 6156 append_tab_response = GetIndexForNavigationController( |
| 6157 &contents->web_contents()->GetController(), browser); |
| 6158 } |
| 6159 |
| 6160 if (!contents || append_tab_response < 0) { |
| 6161 if (observer) { |
| 6162 observer->ReleaseReply(); |
| 6163 delete observer; |
| 6164 } |
| 6165 AutomationJSONReply(this, reply_message).SendError("Failed to append tab."); |
| 6166 } |
| 6167 } |
| 6168 |
6116 void TestingAutomationProvider::WaitUntilNavigationCompletes( | 6169 void TestingAutomationProvider::WaitUntilNavigationCompletes( |
6117 DictionaryValue* args, | 6170 DictionaryValue* args, |
6118 IPC::Message* reply_message) { | 6171 IPC::Message* reply_message) { |
6119 if (SendErrorIfModalDialogActive(this, reply_message)) | 6172 if (SendErrorIfModalDialogActive(this, reply_message)) |
6120 return; | 6173 return; |
6121 | 6174 |
6122 std::string error; | 6175 std::string error; |
6123 Browser* browser; | 6176 Browser* browser; |
6124 WebContents* web_contents; | 6177 WebContents* web_contents; |
6125 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &web_contents, &error)) { | 6178 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &web_contents, &error)) { |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6735 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6788 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6736 } | 6789 } |
6737 | 6790 |
6738 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 6791 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
6739 WebContents* tab) { | 6792 WebContents* tab) { |
6740 if (browser->GetActiveWebContents() != tab) { | 6793 if (browser->GetActiveWebContents() != tab) { |
6741 browser->ActivateTabAt(browser->GetIndexOfController( | 6794 browser->ActivateTabAt(browser->GetIndexOfController( |
6742 &tab->GetController()), true); | 6795 &tab->GetController()), true); |
6743 } | 6796 } |
6744 } | 6797 } |
OLD | NEW |