OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 #include "content/browser/renderer_host/render_process_host.h" | 101 #include "content/browser/renderer_host/render_process_host.h" |
102 #include "content/browser/renderer_host/render_view_host.h" | 102 #include "content/browser/renderer_host/render_view_host.h" |
103 #include "content/browser/tab_contents/interstitial_page.h" | 103 #include "content/browser/tab_contents/interstitial_page.h" |
104 #include "content/common/common_param_traits.h" | 104 #include "content/common/common_param_traits.h" |
105 #include "content/common/notification_service.h" | 105 #include "content/common/notification_service.h" |
106 #include "net/base/cookie_store.h" | 106 #include "net/base/cookie_store.h" |
107 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 107 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
108 #include "ui/base/events.h" | 108 #include "ui/base/events.h" |
109 #include "ui/base/keycodes/keyboard_codes.h" | 109 #include "ui/base/keycodes/keyboard_codes.h" |
110 #include "ui/base/message_box_flags.h" | 110 #include "ui/base/message_box_flags.h" |
| 111 #include "webkit/glue/webdropdata.h" |
111 #include "webkit/plugins/npapi/plugin_list.h" | 112 #include "webkit/plugins/npapi/plugin_list.h" |
112 | 113 |
113 namespace { | 114 namespace { |
114 | 115 |
115 void SendMouseClick(int flags) { | 116 void SendMouseClick(int flags) { |
116 ui_controls::MouseButton button = ui_controls::LEFT; | 117 ui_controls::MouseButton button = ui_controls::LEFT; |
117 if ((flags & ui::EF_LEFT_BUTTON_DOWN) == | 118 if ((flags & ui::EF_LEFT_BUTTON_DOWN) == |
118 ui::EF_LEFT_BUTTON_DOWN) { | 119 ui::EF_LEFT_BUTTON_DOWN) { |
119 button = ui_controls::LEFT; | 120 button = ui_controls::LEFT; |
120 } else if ((flags & ui::EF_RIGHT_BUTTON_DOWN) == | 121 } else if ((flags & ui::EF_RIGHT_BUTTON_DOWN) == |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1066 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
1066 | 1067 |
1067 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 1068 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
1068 mouse_event.clickCount = 2; | 1069 mouse_event.clickCount = 2; |
1069 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1070 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
1070 | 1071 |
1071 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 1072 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
1072 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1073 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
1073 } | 1074 } |
1074 | 1075 |
| 1076 void TestingAutomationProvider::DragAndDropFilePaths( |
| 1077 DictionaryValue* args, IPC::Message* reply_message) { |
| 1078 TabContents* tab_contents; |
| 1079 std::string error; |
| 1080 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
| 1081 AutomationJSONReply(this, reply_message).SendError(error); |
| 1082 return; |
| 1083 } |
| 1084 |
| 1085 int x, y; |
| 1086 if (!args->GetInteger("x", &x) || !args->GetInteger("y", &y)) { |
| 1087 AutomationJSONReply(this, reply_message) |
| 1088 .SendError("(X,Y) coordinates missing or invalid"); |
| 1089 return; |
| 1090 } |
| 1091 |
| 1092 ListValue* paths = NULL; |
| 1093 if (!args->GetList("paths", &paths)) { |
| 1094 AutomationJSONReply(this, reply_message) |
| 1095 .SendError("'paths' missing or invalid"); |
| 1096 return; |
| 1097 } |
| 1098 |
| 1099 // Emulate drag and drop to set the file paths to the file upload control. |
| 1100 WebDropData drop_data; |
| 1101 for (size_t path_index = 0; path_index < paths->GetSize(); ++path_index) { |
| 1102 string16 path; |
| 1103 if (!paths->GetString(path_index, &path)) { |
| 1104 AutomationJSONReply(this, reply_message) |
| 1105 .SendError("'paths' contains a non-string type"); |
| 1106 return; |
| 1107 } |
| 1108 |
| 1109 drop_data.filenames.push_back(path); |
| 1110 } |
| 1111 |
| 1112 const gfx::Point client(x, y); |
| 1113 // We don't set any values in screen variable because DragTarget*** ignore the |
| 1114 // screen argument. |
| 1115 const gfx::Point screen; |
| 1116 |
| 1117 int operations = 0; |
| 1118 operations |= WebKit::WebDragOperationCopy; |
| 1119 operations |= WebKit::WebDragOperationLink; |
| 1120 operations |= WebKit::WebDragOperationMove; |
| 1121 |
| 1122 RenderViewHost* host = tab_contents->render_view_host(); |
| 1123 host->DragTargetDragEnter( |
| 1124 drop_data, client, screen, |
| 1125 static_cast<WebKit::WebDragOperationsMask>(operations)); |
| 1126 new DragTargetDropAckNotificationObserver(this, reply_message); |
| 1127 host->DragTargetDrop(client, screen); |
| 1128 } |
| 1129 |
1075 void TestingAutomationProvider::GetTabCount(int handle, int* tab_count) { | 1130 void TestingAutomationProvider::GetTabCount(int handle, int* tab_count) { |
1076 *tab_count = -1; // -1 is the error code | 1131 *tab_count = -1; // -1 is the error code |
1077 | 1132 |
1078 if (browser_tracker_->ContainsHandle(handle)) { | 1133 if (browser_tracker_->ContainsHandle(handle)) { |
1079 Browser* browser = browser_tracker_->GetResource(handle); | 1134 Browser* browser = browser_tracker_->GetResource(handle); |
1080 *tab_count = browser->tab_count(); | 1135 *tab_count = browser->tab_count(); |
1081 } | 1136 } |
1082 } | 1137 } |
1083 | 1138 |
1084 void TestingAutomationProvider::GetType(int handle, int* type_as_int) { | 1139 void TestingAutomationProvider::GetType(int handle, int* type_as_int) { |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2109 handler_map["WebkitMouseClick"] = | 2164 handler_map["WebkitMouseClick"] = |
2110 &TestingAutomationProvider::WebkitMouseClick; | 2165 &TestingAutomationProvider::WebkitMouseClick; |
2111 handler_map["WebkitMouseDrag"] = | 2166 handler_map["WebkitMouseDrag"] = |
2112 &TestingAutomationProvider::WebkitMouseDrag; | 2167 &TestingAutomationProvider::WebkitMouseDrag; |
2113 handler_map["WebkitMouseButtonUp"] = | 2168 handler_map["WebkitMouseButtonUp"] = |
2114 &TestingAutomationProvider::WebkitMouseButtonUp; | 2169 &TestingAutomationProvider::WebkitMouseButtonUp; |
2115 handler_map["WebkitMouseButtonDown"] = | 2170 handler_map["WebkitMouseButtonDown"] = |
2116 &TestingAutomationProvider::WebkitMouseButtonDown; | 2171 &TestingAutomationProvider::WebkitMouseButtonDown; |
2117 handler_map["WebkitMouseDoubleClick"] = | 2172 handler_map["WebkitMouseDoubleClick"] = |
2118 &TestingAutomationProvider::WebkitMouseDoubleClick; | 2173 &TestingAutomationProvider::WebkitMouseDoubleClick; |
| 2174 handler_map["DragAndDropFilePaths"] = |
| 2175 &TestingAutomationProvider::DragAndDropFilePaths; |
2119 handler_map["SendWebkitKeyEvent"] = | 2176 handler_map["SendWebkitKeyEvent"] = |
2120 &TestingAutomationProvider::SendWebkitKeyEvent; | 2177 &TestingAutomationProvider::SendWebkitKeyEvent; |
2121 handler_map["SendOSLevelKeyEventToTab"] = | 2178 handler_map["SendOSLevelKeyEventToTab"] = |
2122 &TestingAutomationProvider::SendOSLevelKeyEventToTab; | 2179 &TestingAutomationProvider::SendOSLevelKeyEventToTab; |
2123 handler_map["ActivateTab"] = | 2180 handler_map["ActivateTab"] = |
2124 &TestingAutomationProvider::ActivateTabJSON; | 2181 &TestingAutomationProvider::ActivateTabJSON; |
2125 handler_map["GetAppModalDialogMessage"] = | 2182 handler_map["GetAppModalDialogMessage"] = |
2126 &TestingAutomationProvider::GetAppModalDialogMessage; | 2183 &TestingAutomationProvider::GetAppModalDialogMessage; |
2127 handler_map["AcceptOrDismissAppModalDialog"] = | 2184 handler_map["AcceptOrDismissAppModalDialog"] = |
2128 &TestingAutomationProvider::AcceptOrDismissAppModalDialog; | 2185 &TestingAutomationProvider::AcceptOrDismissAppModalDialog; |
(...skipping 3859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5988 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); | 6045 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); |
5989 | 6046 |
5990 Send(reply_message_); | 6047 Send(reply_message_); |
5991 redirect_query_ = 0; | 6048 redirect_query_ = 0; |
5992 reply_message_ = NULL; | 6049 reply_message_ = NULL; |
5993 } | 6050 } |
5994 | 6051 |
5995 void TestingAutomationProvider::OnRemoveProvider() { | 6052 void TestingAutomationProvider::OnRemoveProvider() { |
5996 AutomationProviderList::GetInstance()->RemoveProvider(this); | 6053 AutomationProviderList::GetInstance()->RemoveProvider(this); |
5997 } | 6054 } |
OLD | NEW |