Chromium Code Reviews| Index: chrome/browser/automation/testing_automation_provider.cc |
| diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc |
| index b597482717b6cbf5726718c4228ef8df3be322c9..461c2fd342c96671ec244e28df4e24c307c0b557 100644 |
| --- a/chrome/browser/automation/testing_automation_provider.cc |
| +++ b/chrome/browser/automation/testing_automation_provider.cc |
| @@ -105,6 +105,7 @@ |
| #include "ui/base/events.h" |
| #include "ui/base/keycodes/keyboard_codes.h" |
| #include "ui/base/message_box_flags.h" |
| +#include "webkit/glue/webdropdata.h" |
| #include "webkit/plugins/npapi/plugin_list.h" |
| namespace { |
| @@ -1081,6 +1082,60 @@ void TestingAutomationProvider::WebkitMouseDoubleClick( |
| tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
| } |
| +void TestingAutomationProvider::DragAndDropFilePaths( |
| + DictionaryValue* args, IPC::Message* reply_message) { |
| + TabContents* tab_contents; |
| + std::string error; |
| + if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
| + AutomationJSONReply(this, reply_message).SendError(error); |
| + return; |
| + } |
| + |
| + int x, y; |
| + if (!args->GetInteger("x", &x) || !args->GetInteger("y", &y)) { |
| + AutomationJSONReply(this, reply_message) |
| + .SendError("(X,Y) coordinates missing or invalid"); |
| + return; |
| + } |
| + |
| + ListValue* paths = NULL; |
| + if (!args->GetList("paths", &paths)) { |
| + AutomationJSONReply(this, reply_message) |
| + .SendError("paths missing or invalid"); |
|
kkania
2011/06/01 16:16:41
'paths'
nodchip
2011/06/02 07:15:53
Done.
|
| + return; |
| + } |
| + |
| + // Emulate drag and drop to set the file paths to the file upload control. |
| + WebDropData drop_data; |
| + for (size_t path_index = 0; path_index < paths->GetSize(); ++path_index) { |
| + string16 path; |
| + if (!paths->GetString(path_index, &path)) { |
| + AutomationJSONReply(this, reply_message) |
| + .SendError("'paths' contains a non-string type"); |
| + return; |
| + } |
| + |
| + drop_data.filenames.push_back(path); |
| + } |
| + |
| + const gfx::Point client(x, y); |
| + // We don't set any values in screen variable because DragTarget*** ignore the |
| + // screen argument. |
| + const gfx::Point screen; |
| + |
| + int operations = 0; |
| + operations |= WebKit::WebDragOperationCopy; |
| + operations |= WebKit::WebDragOperationLink; |
| + operations |= WebKit::WebDragOperationMove; |
| + |
| + RenderViewHost* host = tab_contents->render_view_host(); |
| + host->DragTargetDragEnter( |
| + drop_data, client, screen, |
| + static_cast<WebKit::WebDragOperationsMask>(operations)); |
| + new DragTargetDropAckNotificationObserver(this, reply_message); |
| + host->DragTargetDrop(client, screen); |
| +} |
| + |
| void TestingAutomationProvider::GetTabCount(int handle, int* tab_count) { |
| *tab_count = -1; // -1 is the error code |
| @@ -2219,6 +2274,8 @@ void TestingAutomationProvider::SendJSONRequest(int handle, |
| &TestingAutomationProvider::WebkitMouseButtonDown; |
| handler_map["WebkitMouseDoubleClick"] = |
| &TestingAutomationProvider::WebkitMouseDoubleClick; |
| + handler_map["DragAndDropFilePaths"] = |
| + &TestingAutomationProvider::DragAndDropFilePaths; |
| handler_map["SendWebkitKeyEvent"] = |
| &TestingAutomationProvider::SendWebkitKeyEvent; |
| handler_map["SendOSLevelKeyEventToTab"] = |