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 int observer_id = automation_event_queue_.AddObserver( | |
6468 new DomRaisedEventObserver(automation_event_queue_, event_name)); | |
6469 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | |
6470 return_value->SetInteger("observer_id", observer_id); | |
6471 reply.SendSuccess(return_value.get()); | |
6472 } | |
6473 | |
6474 void TestingAutomationProvider::RemoveEventObserver( | |
6475 DictionaryValue* args, | |
6476 IPC::Message* reply_message) { | |
6477 AutomationJSONReply reply(this, reply_message); | |
6478 int observer_id; | |
6479 if (!args->GetInteger("observer_id", &observer_id)) { | |
6480 reply.SendError("'observer_id' missing or invalid"); | |
6481 return; | |
6482 } | |
6483 if (automation_event_queue_.RemoveObserver(observer_id)) { | |
6484 reply.SendSuccess(NULL); | |
6485 return; | |
6486 } | |
6487 reply.SendError("Invalid observer id."); | |
6488 } | |
6489 | |
6490 void TestingAutomationProvider::ClearEventQueue( | |
6491 DictionaryValue* args, | |
6492 IPC::Message* reply_message) { | |
6493 automation_event_queue_.Clear(); | |
6494 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | |
6495 } | |
6496 | |
6497 void TestingAutomationProvider::GetNextEvent( | |
6498 DictionaryValue* args, | |
6499 IPC::Message* reply_message) { | |
6500 scoped_ptr<AutomationJSONReply> reply( | |
Nirnimesh
2012/02/29 03:22:08
won't this get free'd when this method's scope end
craigdh
2012/02/29 22:53:43
This function doesn't normally respond to the auto
| |
6501 new AutomationJSONReply(this, reply_message)); | |
6502 int observer_id; | |
6503 bool blocking; | |
6504 if (!args->GetInteger("observer_id", &observer_id)) { | |
6505 reply->SendError("'observer_id' missing or invalid"); | |
6506 return; | |
6507 } | |
6508 if (!args->GetBoolean("blocking", &blocking)) { | |
6509 reply->SendError("'blocking' missing or invalid"); | |
6510 return; | |
6511 } | |
6512 | |
6513 automation_event_queue_.GetNextEvent(reply.release(), observer_id, blocking); | |
Nirnimesh
2012/02/29 03:22:08
When all cases of SendSuccess/SendError are not co
craigdh
2012/02/29 22:53:43
It's actually cleaner to hold on to this Automatio
| |
6514 } | |
6515 | |
6446 void TestingAutomationProvider::GoForward( | 6516 void TestingAutomationProvider::GoForward( |
6447 DictionaryValue* args, | 6517 DictionaryValue* args, |
6448 IPC::Message* reply_message) { | 6518 IPC::Message* reply_message) { |
6449 if (SendErrorIfModalDialogActive(this, reply_message)) | 6519 if (SendErrorIfModalDialogActive(this, reply_message)) |
6450 return; | 6520 return; |
6451 | 6521 |
6452 WebContents* web_contents; | 6522 WebContents* web_contents; |
6453 std::string error; | 6523 std::string error; |
6454 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { | 6524 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { |
6455 AutomationJSONReply(this, reply_message).SendError(error); | 6525 AutomationJSONReply(this, reply_message).SendError(error); |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6973 | 7043 |
6974 Send(reply_message_); | 7044 Send(reply_message_); |
6975 redirect_query_ = 0; | 7045 redirect_query_ = 0; |
6976 reply_message_ = NULL; | 7046 reply_message_ = NULL; |
6977 } | 7047 } |
6978 | 7048 |
6979 void TestingAutomationProvider::OnRemoveProvider() { | 7049 void TestingAutomationProvider::OnRemoveProvider() { |
6980 if (g_browser_process) | 7050 if (g_browser_process) |
6981 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 7051 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6982 } | 7052 } |
OLD | NEW |