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["GetQueuedEvent"] = | |
2324 &TestingAutomationProvider::GetQueuedEvent; | |
2325 handler_map["ClearQueuedEvents"] = | |
2326 &TestingAutomationProvider::ClearQueuedEvents; | |
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::AddDomRaisedEventObserver( | |
6457 DictionaryValue* args, | |
6458 IPC::Message* reply_message) { | |
6459 if (SendErrorIfModalDialogActive(this, reply_message)) | |
6460 return; | |
6461 | |
Nirnimesh
2012/02/28 09:13:09
Create an instance of AutomationJSONReply
craigdh
2012/02/28 22:42:56
Done.
| |
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"); | |
Nirnimesh
2012/02/28 09:13:09
then use it here
craigdh
2012/02/28 22:42:56
Done.
| |
6466 return; | |
6467 } | |
6468 | |
6469 DomRaisedEventObserver* jsobserver = | |
6470 new DomRaisedEventObserver(automation_event_queue_, event_name); | |
Nirnimesh
2012/02/28 09:13:09
Since automation_event_queue_ owns the new observe
craigdh
2012/02/28 22:42:56
Done.
| |
6471 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | |
6472 return_value->SetInteger("observer_id", jsobserver->GetId()); | |
6473 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | |
Nirnimesh
2012/02/28 09:13:09
and here
craigdh
2012/02/28 22:42:56
Done.
| |
6474 } | |
6475 | |
6476 void TestingAutomationProvider::RemoveEventObserver( | |
6477 DictionaryValue* args, | |
6478 IPC::Message* reply_message) { | |
6479 int observer_id; | |
Nirnimesh
2012/02/28 09:13:09
create AutomationJSONReply once, the use it in lin
craigdh
2012/02/28 22:42:56
Done.
| |
6480 if (!args->GetInteger("observer_id", &observer_id)) { | |
6481 AutomationJSONReply(this, reply_message) | |
6482 .SendError("'observer_id' missing or invalid"); | |
6483 return; | |
6484 } | |
6485 automation_event_queue_.RemoveObserver(observer_id); | |
6486 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | |
6487 } | |
6488 | |
6489 void TestingAutomationProvider::ClearQueuedEvents( | |
6490 DictionaryValue* args, | |
6491 IPC::Message* reply_message) { | |
6492 automation_event_queue_.Clear(); | |
Nirnimesh
2012/02/28 09:13:09
Does this really free up the observers?
craigdh
2012/02/28 22:42:56
I've now merged ClearEventObservers() into Clear()
| |
6493 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | |
6494 } | |
6495 | |
6496 void TestingAutomationProvider::ClearEventObservers( | |
Nirnimesh
2012/02/28 09:13:09
As a user, I don't understand how this differs fro
craigdh
2012/02/28 22:42:56
See previous.
| |
6497 DictionaryValue* args, | |
6498 IPC::Message* reply_message) { | |
6499 automation_event_queue_.ClearObservers(); | |
6500 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | |
6501 } | |
6502 | |
6503 void TestingAutomationProvider::GetQueuedEvent( | |
Nirnimesh
2012/02/28 09:13:09
rename to: GetNextEvent?
craigdh
2012/02/28 22:42:56
Done.
| |
6504 DictionaryValue* args, | |
6505 IPC::Message* reply_message) { | |
6506 int observer_id; | |
6507 bool blocking; | |
Nirnimesh
2012/02/28 09:13:09
define AutomationJSONReply here and use it below
craigdh
2012/02/28 22:42:56
Done.
| |
6508 if (!args->GetInteger("observer_id", &observer_id)) { | |
6509 AutomationJSONReply(this, reply_message) | |
6510 .SendError("'observer_id' missing or invalid"); | |
6511 return; | |
6512 } | |
6513 if (!args->GetBoolean("blocking", &blocking)) { | |
6514 AutomationJSONReply(this, reply_message) | |
6515 .SendError("'blocking' missing or invalid"); | |
6516 return; | |
6517 } | |
6518 | |
6519 automation_event_queue_.GetEvent(this, reply_message, observer_id, blocking); | |
Nirnimesh
2012/02/28 09:13:09
does this respond back to the client?
Why not fetc
craigdh
2012/02/28 22:42:56
Because if there is no matching event in the queue
| |
6520 } | |
6521 | |
6446 void TestingAutomationProvider::GoForward( | 6522 void TestingAutomationProvider::GoForward( |
6447 DictionaryValue* args, | 6523 DictionaryValue* args, |
6448 IPC::Message* reply_message) { | 6524 IPC::Message* reply_message) { |
6449 if (SendErrorIfModalDialogActive(this, reply_message)) | 6525 if (SendErrorIfModalDialogActive(this, reply_message)) |
6450 return; | 6526 return; |
6451 | 6527 |
6452 WebContents* web_contents; | 6528 WebContents* web_contents; |
6453 std::string error; | 6529 std::string error; |
6454 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { | 6530 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { |
6455 AutomationJSONReply(this, reply_message).SendError(error); | 6531 AutomationJSONReply(this, reply_message).SendError(error); |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6973 | 7049 |
6974 Send(reply_message_); | 7050 Send(reply_message_); |
6975 redirect_query_ = 0; | 7051 redirect_query_ = 0; |
6976 reply_message_ = NULL; | 7052 reply_message_ = NULL; |
6977 } | 7053 } |
6978 | 7054 |
6979 void TestingAutomationProvider::OnRemoveProvider() { | 7055 void TestingAutomationProvider::OnRemoveProvider() { |
6980 if (g_browser_process) | 7056 if (g_browser_process) |
6981 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 7057 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6982 } | 7058 } |
OLD | NEW |