Chromium Code Reviews| 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["AddRaisedEventObserver"] = | |
| 2320 &TestingAutomationProvider::AddRaisedEventObserver; | |
| 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::AddRaisedEventObserver( | |
| 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 | |
| 6469 RaisedEventObserver* jsobserver = | |
|
Nirnimesh
2012/02/24 23:18:09
if the user fails to call RemoveEventObserver, doe
craigdh
2012/02/27 22:43:38
All un-removed observers are freed when the Testin
| |
| 6470 new RaisedEventObserver(automation_event_queue_, event_name); | |
| 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()); | |
| 6474 } | |
| 6475 | |
| 6476 void TestingAutomationProvider::RemoveEventObserver( | |
|
Nirnimesh
2012/02/24 23:18:09
this method name does not have 'Raised'.
craigdh
2012/02/27 22:43:38
It's not intended to, this method can remove any t
| |
| 6477 DictionaryValue* args, | |
| 6478 IPC::Message* reply_message) { | |
| 6479 int observer_id; | |
| 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); | |
|
Nirnimesh
2012/02/24 23:18:09
what if observer_id is invalid?
craigdh
2012/02/27 22:43:38
Then it does not remove anything. Do you think tha
Nirnimesh
2012/02/28 09:13:09
Yes, an error message would be nice.
| |
| 6486 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | |
| 6487 } | |
| 6488 | |
| 6489 void TestingAutomationProvider::ClearEvents( | |
|
Nirnimesh
2012/02/24 23:18:09
Shouldn't this imply ClearEventObservers as well?
craigdh
2012/02/27 22:43:38
I was imagining cases where it may be desirable to
Nirnimesh
2012/02/28 09:13:09
Unless you call ClearEventObservers as well, you c
| |
| 6490 DictionaryValue* args, | |
| 6491 IPC::Message* reply_message) { | |
| 6492 automation_event_queue_.Clear(); | |
| 6493 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | |
| 6494 } | |
| 6495 | |
| 6496 void TestingAutomationProvider::ClearEventObservers( | |
| 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::GetEvent( | |
| 6504 DictionaryValue* args, | |
| 6505 IPC::Message* reply_message) { | |
| 6506 int observer_id; | |
| 6507 bool blocking; | |
| 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); | |
| 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 |