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["AddDomRaisedEventObserver"] = |
| 2320 &TestingAutomationProvider::AddDomRaisedEventObserver; |
| 2321 handler_map["RemoveEventObserver"] = |
| 2322 &TestingAutomationProvider::RemoveEventObserver; |
| 2323 handler_map["GetNextEvent"] = |
| 2324 &TestingAutomationProvider::GetNextEvent; |
| 2325 handler_map["ClearEventQueue"] = |
| 2326 &TestingAutomationProvider::ClearEventQueue; |
2319 handler_map["ExecuteJavascriptInRenderView"] = | 2327 handler_map["ExecuteJavascriptInRenderView"] = |
2320 &TestingAutomationProvider::ExecuteJavascriptInRenderView; | 2328 &TestingAutomationProvider::ExecuteJavascriptInRenderView; |
2321 handler_map["GoForward"] = | 2329 handler_map["GoForward"] = |
2322 &TestingAutomationProvider::GoForward; | 2330 &TestingAutomationProvider::GoForward; |
2323 handler_map["GoBack"] = | 2331 handler_map["GoBack"] = |
2324 &TestingAutomationProvider::GoBack; | 2332 &TestingAutomationProvider::GoBack; |
2325 handler_map["Reload"] = | 2333 handler_map["Reload"] = |
2326 &TestingAutomationProvider::ReloadJSON; | 2334 &TestingAutomationProvider::ReloadJSON; |
2327 handler_map["CaptureEntirePage"] = | 2335 handler_map["CaptureEntirePage"] = |
2328 &TestingAutomationProvider::CaptureEntirePageJSON; | 2336 &TestingAutomationProvider::CaptureEntirePageJSON; |
(...skipping 4107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6436 AutomationJSONReply(this, reply_message).SendError( | 6444 AutomationJSONReply(this, reply_message).SendError( |
6437 "A RenderViewHost object was not found with the given view ID."); | 6445 "A RenderViewHost object was not found with the given view ID."); |
6438 return; | 6446 return; |
6439 } | 6447 } |
6440 | 6448 |
6441 new DomOperationMessageSender(this, reply_message, true); | 6449 new DomOperationMessageSender(this, reply_message, true); |
6442 ExecuteJavascriptInRenderViewFrame(frame_xpath, javascript, reply_message, | 6450 ExecuteJavascriptInRenderViewFrame(frame_xpath, javascript, reply_message, |
6443 rvh); | 6451 rvh); |
6444 } | 6452 } |
6445 | 6453 |
| 6454 void TestingAutomationProvider::AddDomRaisedEventObserver( |
| 6455 DictionaryValue* args, |
| 6456 IPC::Message* reply_message) { |
| 6457 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 6458 return; |
| 6459 |
| 6460 AutomationJSONReply reply(this, reply_message); |
| 6461 std::string event_name; |
| 6462 if (!args->GetString("event_name", &event_name)) { |
| 6463 reply.SendError("'event_name' missing or invalid"); |
| 6464 return; |
| 6465 } |
| 6466 |
| 6467 if (!automation_event_queue_.get()) |
| 6468 automation_event_queue_.reset(new AutomationEventQueue); |
| 6469 |
| 6470 int observer_id = automation_event_queue_->AddObserver( |
| 6471 new DomRaisedEventObserver(automation_event_queue_.get(), event_name)); |
| 6472 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 6473 return_value->SetInteger("observer_id", observer_id); |
| 6474 reply.SendSuccess(return_value.get()); |
| 6475 } |
| 6476 |
| 6477 void TestingAutomationProvider::RemoveEventObserver( |
| 6478 DictionaryValue* args, |
| 6479 IPC::Message* reply_message) { |
| 6480 AutomationJSONReply reply(this, reply_message); |
| 6481 int observer_id; |
| 6482 if (!args->GetInteger("observer_id", &observer_id) || |
| 6483 !automation_event_queue_.get()) { |
| 6484 reply.SendError("'observer_id' missing or invalid"); |
| 6485 return; |
| 6486 } |
| 6487 if (automation_event_queue_->RemoveObserver(observer_id)) { |
| 6488 reply.SendSuccess(NULL); |
| 6489 return; |
| 6490 } |
| 6491 reply.SendError("Invalid observer id."); |
| 6492 } |
| 6493 |
| 6494 void TestingAutomationProvider::ClearEventQueue( |
| 6495 DictionaryValue* args, |
| 6496 IPC::Message* reply_message) { |
| 6497 automation_event_queue_.reset(); |
| 6498 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 6499 } |
| 6500 |
| 6501 void TestingAutomationProvider::GetNextEvent( |
| 6502 DictionaryValue* args, |
| 6503 IPC::Message* reply_message) { |
| 6504 scoped_ptr<AutomationJSONReply> reply( |
| 6505 new AutomationJSONReply(this, reply_message)); |
| 6506 int observer_id; |
| 6507 bool blocking; |
| 6508 if (!args->GetInteger("observer_id", &observer_id)) { |
| 6509 reply->SendError("'observer_id' missing or invalid"); |
| 6510 return; |
| 6511 } |
| 6512 if (!args->GetBoolean("blocking", &blocking)) { |
| 6513 reply->SendError("'blocking' missing or invalid"); |
| 6514 return; |
| 6515 } |
| 6516 if (!automation_event_queue_.get()) { |
| 6517 reply->SendError( |
| 6518 "No observers are attached to the queue. Did you forget to add one?"); |
| 6519 return; |
| 6520 } |
| 6521 |
| 6522 // The reply will be freed once a matching event is added to the queue. |
| 6523 automation_event_queue_->GetNextEvent(reply.release(), observer_id, blocking); |
| 6524 } |
| 6525 |
6446 void TestingAutomationProvider::GoForward( | 6526 void TestingAutomationProvider::GoForward( |
6447 DictionaryValue* args, | 6527 DictionaryValue* args, |
6448 IPC::Message* reply_message) { | 6528 IPC::Message* reply_message) { |
6449 if (SendErrorIfModalDialogActive(this, reply_message)) | 6529 if (SendErrorIfModalDialogActive(this, reply_message)) |
6450 return; | 6530 return; |
6451 | 6531 |
6452 WebContents* web_contents; | 6532 WebContents* web_contents; |
6453 std::string error; | 6533 std::string error; |
6454 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { | 6534 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { |
6455 AutomationJSONReply(this, reply_message).SendError(error); | 6535 AutomationJSONReply(this, reply_message).SendError(error); |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6973 | 7053 |
6974 Send(reply_message_); | 7054 Send(reply_message_); |
6975 redirect_query_ = 0; | 7055 redirect_query_ = 0; |
6976 reply_message_ = NULL; | 7056 reply_message_ = NULL; |
6977 } | 7057 } |
6978 | 7058 |
6979 void TestingAutomationProvider::OnRemoveProvider() { | 7059 void TestingAutomationProvider::OnRemoveProvider() { |
6980 if (g_browser_process) | 7060 if (g_browser_process) |
6981 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 7061 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6982 } | 7062 } |
OLD | NEW |