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 2298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2309 handler_map["NavigateToURL"] = | 2309 handler_map["NavigateToURL"] = |
2310 &TestingAutomationProvider::NavigateToURL; | 2310 &TestingAutomationProvider::NavigateToURL; |
2311 handler_map["GetLocalStatePrefsInfo"] = | 2311 handler_map["GetLocalStatePrefsInfo"] = |
2312 &TestingAutomationProvider::GetLocalStatePrefsInfo; | 2312 &TestingAutomationProvider::GetLocalStatePrefsInfo; |
2313 handler_map["SetLocalStatePrefs"] = | 2313 handler_map["SetLocalStatePrefs"] = |
2314 &TestingAutomationProvider::SetLocalStatePrefs; | 2314 &TestingAutomationProvider::SetLocalStatePrefs; |
2315 handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; | 2315 handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; |
2316 handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; | 2316 handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; |
2317 handler_map["ExecuteJavascript"] = | 2317 handler_map["ExecuteJavascript"] = |
2318 &TestingAutomationProvider::ExecuteJavascriptJSON; | 2318 &TestingAutomationProvider::ExecuteJavascriptJSON; |
| 2319 handler_map["ObserveRaisedEvents"] = |
| 2320 &TestingAutomationProvider::ObserveRaisedEvents; |
| 2321 handler_map["GetEvent"] = |
| 2322 &TestingAutomationProvider::GetEvent; |
| 2323 handler_map["RemoveEventObserver"] = |
| 2324 &TestingAutomationProvider::RemoveEventObserver; |
| 2325 handler_map["ClearEvents"] = |
| 2326 &TestingAutomationProvider::ClearEvents; |
| 2327 handler_map["ClearEventObservers"] = |
| 2328 &TestingAutomationProvider::ClearEventObservers; |
2319 handler_map["ExecuteJavascriptInRenderView"] = | 2329 handler_map["ExecuteJavascriptInRenderView"] = |
2320 &TestingAutomationProvider::ExecuteJavascriptInRenderView; | 2330 &TestingAutomationProvider::ExecuteJavascriptInRenderView; |
2321 handler_map["GoForward"] = | 2331 handler_map["GoForward"] = |
2322 &TestingAutomationProvider::GoForward; | 2332 &TestingAutomationProvider::GoForward; |
2323 handler_map["GoBack"] = | 2333 handler_map["GoBack"] = |
2324 &TestingAutomationProvider::GoBack; | 2334 &TestingAutomationProvider::GoBack; |
2325 handler_map["Reload"] = | 2335 handler_map["Reload"] = |
2326 &TestingAutomationProvider::ReloadJSON; | 2336 &TestingAutomationProvider::ReloadJSON; |
2327 handler_map["CaptureEntirePage"] = | 2337 handler_map["CaptureEntirePage"] = |
2328 &TestingAutomationProvider::CaptureEntirePageJSON; | 2338 &TestingAutomationProvider::CaptureEntirePageJSON; |
(...skipping 4107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6436 AutomationJSONReply(this, reply_message).SendError( | 6446 AutomationJSONReply(this, reply_message).SendError( |
6437 "A RenderViewHost object was not found with the given view ID."); | 6447 "A RenderViewHost object was not found with the given view ID."); |
6438 return; | 6448 return; |
6439 } | 6449 } |
6440 | 6450 |
6441 new DomOperationMessageSender(this, reply_message, true); | 6451 new DomOperationMessageSender(this, reply_message, true); |
6442 ExecuteJavascriptInRenderViewFrame(frame_xpath, javascript, reply_message, | 6452 ExecuteJavascriptInRenderViewFrame(frame_xpath, javascript, reply_message, |
6443 rvh); | 6453 rvh); |
6444 } | 6454 } |
6445 | 6455 |
| 6456 void TestingAutomationProvider::ObserveRaisedEvents( |
| 6457 DictionaryValue* args, |
| 6458 IPC::Message* reply_message) { |
| 6459 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 6460 return; |
| 6461 |
| 6462 std::string event_name; |
| 6463 if (!args->GetString("event_name", &event_name)) { |
| 6464 AutomationJSONReply(this, reply_message) |
| 6465 .SendError("'event_name' missing or invalid"); |
| 6466 return; |
| 6467 } |
| 6468 std::string error; |
| 6469 RenderViewHost* render_view; |
| 6470 if (!GetRenderViewFromJSONArgs(args, profile(), &render_view, &error)) { |
| 6471 AutomationJSONReply(this, reply_message).SendError( |
| 6472 Error(automation::kInvalidId, error)); |
| 6473 return; |
| 6474 } |
| 6475 string16 frame_xpath; |
| 6476 if (!args->GetString("frame_xpath", &frame_xpath)) { |
| 6477 AutomationJSONReply(this, reply_message) |
| 6478 .SendError("'frame_xpath' missing or invalid"); |
| 6479 return; |
| 6480 } |
| 6481 std::string set_automation_id; |
| 6482 base::SStringPrintf(&set_automation_id, |
| 6483 "window.domAutomationController.setAutomationId(%d);", |
| 6484 reply_message->routing_id()); |
| 6485 render_view->ExecuteJavascriptInWebFrame( |
| 6486 frame_xpath, UTF8ToUTF16(set_automation_id)); |
| 6487 |
| 6488 RaisedEventObserver* jsobserver = |
| 6489 new RaisedEventObserver(automation_event_queue_, event_name); |
| 6490 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 6491 return_value->SetInteger("observer_id", jsobserver->GetId()); |
| 6492 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
| 6493 } |
| 6494 |
| 6495 void TestingAutomationProvider::RemoveEventObserver( |
| 6496 DictionaryValue* args, |
| 6497 IPC::Message* reply_message) { |
| 6498 int observer_id; |
| 6499 if (!args->GetInteger("observer_id", &observer_id)) { |
| 6500 AutomationJSONReply(this, reply_message) |
| 6501 .SendError("'observer_id' missing or invalid"); |
| 6502 return; |
| 6503 } |
| 6504 automation_event_queue_.RemoveObserver(observer_id); |
| 6505 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 6506 } |
| 6507 |
| 6508 void TestingAutomationProvider::ClearEvents( |
| 6509 DictionaryValue* args, |
| 6510 IPC::Message* reply_message) { |
| 6511 automation_event_queue_.Clear(); |
| 6512 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 6513 } |
| 6514 |
| 6515 void TestingAutomationProvider::ClearEventObservers( |
| 6516 DictionaryValue* args, |
| 6517 IPC::Message* reply_message) { |
| 6518 automation_event_queue_.ClearObservers(); |
| 6519 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 6520 } |
| 6521 |
| 6522 void TestingAutomationProvider::GetEvent( |
| 6523 DictionaryValue* args, |
| 6524 IPC::Message* reply_message) { |
| 6525 int observer_id; |
| 6526 bool blocking; |
| 6527 if (!args->GetInteger("observer_id", &observer_id)) { |
| 6528 AutomationJSONReply(this, reply_message) |
| 6529 .SendError("'observer_id' missing or invalid"); |
| 6530 return; |
| 6531 } |
| 6532 if (!args->GetBoolean("blocking", &blocking)) { |
| 6533 AutomationJSONReply(this, reply_message) |
| 6534 .SendError("'blocking' missing or invalid"); |
| 6535 return; |
| 6536 } |
| 6537 |
| 6538 automation_event_queue_.GetEvent(this, reply_message, observer_id, blocking); |
| 6539 } |
| 6540 |
6446 void TestingAutomationProvider::GoForward( | 6541 void TestingAutomationProvider::GoForward( |
6447 DictionaryValue* args, | 6542 DictionaryValue* args, |
6448 IPC::Message* reply_message) { | 6543 IPC::Message* reply_message) { |
6449 if (SendErrorIfModalDialogActive(this, reply_message)) | 6544 if (SendErrorIfModalDialogActive(this, reply_message)) |
6450 return; | 6545 return; |
6451 | 6546 |
6452 WebContents* web_contents; | 6547 WebContents* web_contents; |
6453 std::string error; | 6548 std::string error; |
6454 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { | 6549 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { |
6455 AutomationJSONReply(this, reply_message).SendError(error); | 6550 AutomationJSONReply(this, reply_message).SendError(error); |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6973 | 7068 |
6974 Send(reply_message_); | 7069 Send(reply_message_); |
6975 redirect_query_ = 0; | 7070 redirect_query_ = 0; |
6976 reply_message_ = NULL; | 7071 reply_message_ = NULL; |
6977 } | 7072 } |
6978 | 7073 |
6979 void TestingAutomationProvider::OnRemoveProvider() { | 7074 void TestingAutomationProvider::OnRemoveProvider() { |
6980 if (g_browser_process) | 7075 if (g_browser_process) |
6981 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 7076 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6982 } | 7077 } |
OLD | NEW |