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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 497 |
498 void TestingAutomationProvider::AppendTab(int handle, | 498 void TestingAutomationProvider::AppendTab(int handle, |
499 const GURL& url, | 499 const GURL& url, |
500 IPC::Message* reply_message) { | 500 IPC::Message* reply_message) { |
501 int append_tab_response = -1; // -1 is the error code | 501 int append_tab_response = -1; // -1 is the error code |
502 TabAppendedNotificationObserver* observer = NULL; | 502 TabAppendedNotificationObserver* observer = NULL; |
503 | 503 |
504 if (browser_tracker_->ContainsHandle(handle)) { | 504 if (browser_tracker_->ContainsHandle(handle)) { |
505 Browser* browser = browser_tracker_->GetResource(handle); | 505 Browser* browser = browser_tracker_->GetResource(handle); |
506 observer = new TabAppendedNotificationObserver(browser, this, | 506 observer = new TabAppendedNotificationObserver(browser, this, |
507 reply_message); | 507 reply_message, false); |
508 TabContents* contents = chrome::AddSelectedTabWithURL( | 508 TabContents* contents = |
509 browser, url, content::PAGE_TRANSITION_TYPED); | 509 chrome::AddSelectedTabWithURL(browser, url, |
| 510 content::PAGE_TRANSITION_TYPED); |
510 if (contents) { | 511 if (contents) { |
511 append_tab_response = GetIndexForNavigationController( | 512 append_tab_response = GetIndexForNavigationController( |
512 &contents->web_contents()->GetController(), browser); | 513 &contents->web_contents()->GetController(), browser); |
513 } | 514 } |
514 } | 515 } |
515 | 516 |
516 if (append_tab_response < 0) { | 517 if (append_tab_response < 0) { |
517 // Appending tab failed. Clean up and send failure response. | 518 // Appending tab failed. Clean up and send failure response. |
518 | 519 |
519 if (observer) | 520 if (observer) |
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 } | 1671 } |
1671 | 1672 |
1672 void TestingAutomationProvider::BuildJSONHandlerMaps() { | 1673 void TestingAutomationProvider::BuildJSONHandlerMaps() { |
1673 // Map json commands to their handlers. | 1674 // Map json commands to their handlers. |
1674 handler_map_["WaitForAllTabsToStopLoading"] = | 1675 handler_map_["WaitForAllTabsToStopLoading"] = |
1675 &TestingAutomationProvider::WaitForAllViewsToStopLoading; | 1676 &TestingAutomationProvider::WaitForAllViewsToStopLoading; |
1676 handler_map_["GetIndicesFromTab"] = | 1677 handler_map_["GetIndicesFromTab"] = |
1677 &TestingAutomationProvider::GetIndicesFromTab; | 1678 &TestingAutomationProvider::GetIndicesFromTab; |
1678 handler_map_["NavigateToURL"] = | 1679 handler_map_["NavigateToURL"] = |
1679 &TestingAutomationProvider::NavigateToURL; | 1680 &TestingAutomationProvider::NavigateToURL; |
| 1681 handler_map_["GetActiveTabIndex"] = |
| 1682 &TestingAutomationProvider::GetActiveTabIndexJSON; |
| 1683 handler_map_["AppendTab"] = |
| 1684 &TestingAutomationProvider::AppendTabJSON; |
1680 handler_map_["WaitUntilNavigationCompletes"] = | 1685 handler_map_["WaitUntilNavigationCompletes"] = |
1681 &TestingAutomationProvider::WaitUntilNavigationCompletes; | 1686 &TestingAutomationProvider::WaitUntilNavigationCompletes; |
1682 handler_map_["GetLocalStatePrefsInfo"] = | 1687 handler_map_["GetLocalStatePrefsInfo"] = |
1683 &TestingAutomationProvider::GetLocalStatePrefsInfo; | 1688 &TestingAutomationProvider::GetLocalStatePrefsInfo; |
1684 handler_map_["SetLocalStatePrefs"] = | 1689 handler_map_["SetLocalStatePrefs"] = |
1685 &TestingAutomationProvider::SetLocalStatePrefs; | 1690 &TestingAutomationProvider::SetLocalStatePrefs; |
1686 handler_map_["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; | 1691 handler_map_["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; |
1687 handler_map_["SetPrefs"] = &TestingAutomationProvider::SetPrefs; | 1692 handler_map_["SetPrefs"] = &TestingAutomationProvider::SetPrefs; |
1688 handler_map_["ExecuteJavascript"] = | 1693 handler_map_["ExecuteJavascript"] = |
1689 &TestingAutomationProvider::ExecuteJavascriptJSON; | 1694 &TestingAutomationProvider::ExecuteJavascriptJSON; |
(...skipping 4450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6140 navigation_count, false, true); | 6145 navigation_count, false, true); |
6141 OpenURLParams params( | 6146 OpenURLParams params( |
6142 GURL(url), content::Referrer(), CURRENT_TAB, | 6147 GURL(url), content::Referrer(), CURRENT_TAB, |
6143 content::PageTransitionFromInt( | 6148 content::PageTransitionFromInt( |
6144 content::PAGE_TRANSITION_TYPED | | 6149 content::PAGE_TRANSITION_TYPED | |
6145 content::PAGE_TRANSITION_FROM_ADDRESS_BAR), | 6150 content::PAGE_TRANSITION_FROM_ADDRESS_BAR), |
6146 false); | 6151 false); |
6147 browser->OpenURLFromTab(web_contents, params); | 6152 browser->OpenURLFromTab(web_contents, params); |
6148 } | 6153 } |
6149 | 6154 |
| 6155 void TestingAutomationProvider::GetActiveTabIndexJSON( |
| 6156 DictionaryValue* args, |
| 6157 IPC::Message* reply_message) { |
| 6158 AutomationJSONReply reply(this, reply_message); |
| 6159 Browser* browser; |
| 6160 std::string error_msg; |
| 6161 if (!GetBrowserFromJSONArgs(args, &browser, &error_msg)) { |
| 6162 reply.SendError(error_msg); |
| 6163 return; |
| 6164 } |
| 6165 int tab_index = browser->active_index(); |
| 6166 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 6167 return_value->SetInteger("tab_index", tab_index); |
| 6168 reply.SendSuccess(return_value.get()); |
| 6169 } |
| 6170 |
| 6171 void TestingAutomationProvider::AppendTabJSON(DictionaryValue* args, |
| 6172 IPC::Message* reply_message) { |
| 6173 TabAppendedNotificationObserver* observer = NULL; |
| 6174 int append_tab_response = -1; |
| 6175 Browser* browser; |
| 6176 std::string error_msg, url; |
| 6177 if (!GetBrowserFromJSONArgs(args, &browser, &error_msg)) { |
| 6178 AutomationJSONReply(this, reply_message).SendError(error_msg); |
| 6179 return; |
| 6180 } |
| 6181 if (!args->GetString("url", &url)) { |
| 6182 AutomationJSONReply(this, reply_message) |
| 6183 .SendError("'url' missing or invalid"); |
| 6184 return; |
| 6185 } |
| 6186 observer = new TabAppendedNotificationObserver(browser, this, reply_message, |
| 6187 true); |
| 6188 TabContents* contents = |
| 6189 chrome::AddSelectedTabWithURL(browser, GURL(url), |
| 6190 content::PAGE_TRANSITION_TYPED); |
| 6191 if (contents) { |
| 6192 append_tab_response = GetIndexForNavigationController( |
| 6193 &contents->web_contents()->GetController(), browser); |
| 6194 } |
| 6195 |
| 6196 if (!contents || append_tab_response < 0) { |
| 6197 if (observer) { |
| 6198 observer->ReleaseReply(); |
| 6199 delete observer; |
| 6200 } |
| 6201 AutomationJSONReply(this, reply_message).SendError("Failed to append tab."); |
| 6202 } |
| 6203 } |
| 6204 |
6150 void TestingAutomationProvider::WaitUntilNavigationCompletes( | 6205 void TestingAutomationProvider::WaitUntilNavigationCompletes( |
6151 DictionaryValue* args, | 6206 DictionaryValue* args, |
6152 IPC::Message* reply_message) { | 6207 IPC::Message* reply_message) { |
6153 if (SendErrorIfModalDialogActive(this, reply_message)) | 6208 if (SendErrorIfModalDialogActive(this, reply_message)) |
6154 return; | 6209 return; |
6155 | 6210 |
6156 std::string error; | 6211 std::string error; |
6157 Browser* browser; | 6212 Browser* browser; |
6158 WebContents* web_contents; | 6213 WebContents* web_contents; |
6159 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &web_contents, &error)) { | 6214 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &web_contents, &error)) { |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6767 void TestingAutomationProvider::OnRemoveProvider() { | 6822 void TestingAutomationProvider::OnRemoveProvider() { |
6768 if (g_browser_process) | 6823 if (g_browser_process) |
6769 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6824 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6770 } | 6825 } |
6771 | 6826 |
6772 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 6827 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
6773 WebContents* tab) { | 6828 WebContents* tab) { |
6774 if (chrome::GetActiveWebContents(browser) != tab) | 6829 if (chrome::GetActiveWebContents(browser) != tab) |
6775 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); | 6830 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); |
6776 } | 6831 } |
OLD | NEW |