| 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 2143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2154 } | 2154 } |
| 2155 | 2155 |
| 2156 // Map json commands to their handlers. | 2156 // Map json commands to their handlers. |
| 2157 std::map<std::string, JsonHandler> handler_map; | 2157 std::map<std::string, JsonHandler> handler_map; |
| 2158 handler_map["WaitForAllTabsToStopLoading"] = | 2158 handler_map["WaitForAllTabsToStopLoading"] = |
| 2159 &TestingAutomationProvider::WaitForAllViewsToStopLoading; | 2159 &TestingAutomationProvider::WaitForAllViewsToStopLoading; |
| 2160 handler_map["GetIndicesFromTab"] = | 2160 handler_map["GetIndicesFromTab"] = |
| 2161 &TestingAutomationProvider::GetIndicesFromTab; | 2161 &TestingAutomationProvider::GetIndicesFromTab; |
| 2162 handler_map["NavigateToURL"] = | 2162 handler_map["NavigateToURL"] = |
| 2163 &TestingAutomationProvider::NavigateToURL; | 2163 &TestingAutomationProvider::NavigateToURL; |
| 2164 handler_map["WaitUntilNavigationCompletes"] = |
| 2165 &TestingAutomationProvider::WaitUntilNavigationCompletes; |
| 2164 handler_map["GetLocalStatePrefsInfo"] = | 2166 handler_map["GetLocalStatePrefsInfo"] = |
| 2165 &TestingAutomationProvider::GetLocalStatePrefsInfo; | 2167 &TestingAutomationProvider::GetLocalStatePrefsInfo; |
| 2166 handler_map["SetLocalStatePrefs"] = | 2168 handler_map["SetLocalStatePrefs"] = |
| 2167 &TestingAutomationProvider::SetLocalStatePrefs; | 2169 &TestingAutomationProvider::SetLocalStatePrefs; |
| 2168 handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; | 2170 handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; |
| 2169 handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; | 2171 handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; |
| 2170 handler_map["ExecuteJavascript"] = | 2172 handler_map["ExecuteJavascript"] = |
| 2171 &TestingAutomationProvider::ExecuteJavascriptJSON; | 2173 &TestingAutomationProvider::ExecuteJavascriptJSON; |
| 2172 handler_map["AddDomEventObserver"] = | 2174 handler_map["AddDomEventObserver"] = |
| 2173 &TestingAutomationProvider::AddDomEventObserver; | 2175 &TestingAutomationProvider::AddDomEventObserver; |
| (...skipping 4158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6332 return; | 6334 return; |
| 6333 } | 6335 } |
| 6334 new NavigationNotificationObserver( | 6336 new NavigationNotificationObserver( |
| 6335 &web_contents->GetController(), this, reply_message, | 6337 &web_contents->GetController(), this, reply_message, |
| 6336 navigation_count, false, true); | 6338 navigation_count, false, true); |
| 6337 browser->OpenURLFromTab(web_contents, OpenURLParams( | 6339 browser->OpenURLFromTab(web_contents, OpenURLParams( |
| 6338 GURL(url), content::Referrer(), CURRENT_TAB, | 6340 GURL(url), content::Referrer(), CURRENT_TAB, |
| 6339 content::PAGE_TRANSITION_TYPED, false)); | 6341 content::PAGE_TRANSITION_TYPED, false)); |
| 6340 } | 6342 } |
| 6341 | 6343 |
| 6344 void TestingAutomationProvider::WaitUntilNavigationCompletes( |
| 6345 DictionaryValue* args, |
| 6346 IPC::Message* reply_message) { |
| 6347 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 6348 return; |
| 6349 |
| 6350 std::string error; |
| 6351 Browser* browser; |
| 6352 WebContents* web_contents; |
| 6353 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &web_contents, &error)) { |
| 6354 AutomationJSONReply(this, reply_message).SendError(error); |
| 6355 return; |
| 6356 } |
| 6357 NavigationNotificationObserver* observer = |
| 6358 new NavigationNotificationObserver(&web_contents->GetController(), this, |
| 6359 reply_message, 1, true, true); |
| 6360 if (!web_contents->IsLoading()) { |
| 6361 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 6362 delete observer; |
| 6363 return; |
| 6364 } |
| 6365 } |
| 6366 |
| 6342 void TestingAutomationProvider::ExecuteJavascriptJSON( | 6367 void TestingAutomationProvider::ExecuteJavascriptJSON( |
| 6343 DictionaryValue* args, | 6368 DictionaryValue* args, |
| 6344 IPC::Message* reply_message) { | 6369 IPC::Message* reply_message) { |
| 6345 if (SendErrorIfModalDialogActive(this, reply_message)) | 6370 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 6346 return; | 6371 return; |
| 6347 | 6372 |
| 6348 string16 frame_xpath, javascript; | 6373 string16 frame_xpath, javascript; |
| 6349 std::string error; | 6374 std::string error; |
| 6350 RenderViewHost* render_view; | 6375 RenderViewHost* render_view; |
| 6351 if (!GetRenderViewFromJSONArgs(args, profile(), &render_view, &error)) { | 6376 if (!GetRenderViewFromJSONArgs(args, profile(), &render_view, &error)) { |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6978 *browser_handle = browser_tracker_->Add(browser); | 7003 *browser_handle = browser_tracker_->Add(browser); |
| 6979 *success = true; | 7004 *success = true; |
| 6980 } | 7005 } |
| 6981 } | 7006 } |
| 6982 } | 7007 } |
| 6983 | 7008 |
| 6984 void TestingAutomationProvider::OnRemoveProvider() { | 7009 void TestingAutomationProvider::OnRemoveProvider() { |
| 6985 if (g_browser_process) | 7010 if (g_browser_process) |
| 6986 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 7011 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 6987 } | 7012 } |
| OLD | NEW |