| 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 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 ui::EF_ALT_DOWN), | 927 ui::EF_ALT_DOWN), |
| 928 ((flags & ui::EF_COMMAND_DOWN) == | 928 ((flags & ui::EF_COMMAND_DOWN) == |
| 929 ui::EF_COMMAND_DOWN)); | 929 ui::EF_COMMAND_DOWN)); |
| 930 } | 930 } |
| 931 | 931 |
| 932 void TestingAutomationProvider::WebkitMouseClick(DictionaryValue* args, | 932 void TestingAutomationProvider::WebkitMouseClick(DictionaryValue* args, |
| 933 IPC::Message* reply_message) { | 933 IPC::Message* reply_message) { |
| 934 if (SendErrorIfModalDialogActive(this, reply_message)) | 934 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 935 return; | 935 return; |
| 936 | 936 |
| 937 TabContents* tab_contents; | 937 RenderViewHost* view; |
| 938 std::string error; | 938 std::string error; |
| 939 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 939 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
| 940 AutomationJSONReply(this, reply_message).SendError(error); | 940 AutomationJSONReply(this, reply_message).SendError(error); |
| 941 return; | 941 return; |
| 942 } | 942 } |
| 943 | 943 |
| 944 WebKit::WebMouseEvent mouse_event; | 944 WebKit::WebMouseEvent mouse_event; |
| 945 if (!args->GetInteger("x", &mouse_event.x) || | 945 if (!args->GetInteger("x", &mouse_event.x) || |
| 946 !args->GetInteger("y", &mouse_event.y)) { | 946 !args->GetInteger("y", &mouse_event.y)) { |
| 947 AutomationJSONReply(this, reply_message) | 947 AutomationJSONReply(this, reply_message) |
| 948 .SendError("(X,Y) coordinates missing or invalid"); | 948 .SendError("(X,Y) coordinates missing or invalid"); |
| 949 return; | 949 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 963 mouse_event.button = WebKit::WebMouseEvent::ButtonMiddle; | 963 mouse_event.button = WebKit::WebMouseEvent::ButtonMiddle; |
| 964 } else { | 964 } else { |
| 965 AutomationJSONReply(this, reply_message) | 965 AutomationJSONReply(this, reply_message) |
| 966 .SendError("Invalid button press requested"); | 966 .SendError("Invalid button press requested"); |
| 967 return; | 967 return; |
| 968 } | 968 } |
| 969 | 969 |
| 970 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 970 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
| 971 mouse_event.clickCount = 1; | 971 mouse_event.clickCount = 1; |
| 972 | 972 |
| 973 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 973 view->ForwardMouseEvent(mouse_event); |
| 974 | 974 |
| 975 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 975 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 976 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, | 976 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
| 977 1); | 977 1); |
| 978 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 978 view->ForwardMouseEvent(mouse_event); |
| 979 } | 979 } |
| 980 | 980 |
| 981 void TestingAutomationProvider::WebkitMouseMove( | 981 void TestingAutomationProvider::WebkitMouseMove( |
| 982 DictionaryValue* args, IPC::Message* reply_message) { | 982 DictionaryValue* args, IPC::Message* reply_message) { |
| 983 if (SendErrorIfModalDialogActive(this, reply_message)) | 983 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 984 return; | 984 return; |
| 985 | 985 |
| 986 TabContents* tab_contents; | 986 RenderViewHost* view; |
| 987 std::string error; | 987 std::string error; |
| 988 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 988 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
| 989 AutomationJSONReply(this, reply_message).SendError(error); | 989 AutomationJSONReply(this, reply_message).SendError(error); |
| 990 return; | 990 return; |
| 991 } | 991 } |
| 992 | 992 |
| 993 WebKit::WebMouseEvent mouse_event; | 993 WebKit::WebMouseEvent mouse_event; |
| 994 if (!args->GetInteger("x", &mouse_event.x) || | 994 if (!args->GetInteger("x", &mouse_event.x) || |
| 995 !args->GetInteger("y", &mouse_event.y)) { | 995 !args->GetInteger("y", &mouse_event.y)) { |
| 996 AutomationJSONReply(this, reply_message) | 996 AutomationJSONReply(this, reply_message) |
| 997 .SendError("(X,Y) coordinates missing or invalid"); | 997 .SendError("(X,Y) coordinates missing or invalid"); |
| 998 return; | 998 return; |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 mouse_event.type = WebKit::WebInputEvent::MouseMove; | 1001 mouse_event.type = WebKit::WebInputEvent::MouseMove; |
| 1002 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, | 1002 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
| 1003 1); | 1003 1); |
| 1004 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1004 view->ForwardMouseEvent(mouse_event); |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 void TestingAutomationProvider::WebkitMouseDrag(DictionaryValue* args, | 1007 void TestingAutomationProvider::WebkitMouseDrag(DictionaryValue* args, |
| 1008 IPC::Message* reply_message) { | 1008 IPC::Message* reply_message) { |
| 1009 if (SendErrorIfModalDialogActive(this, reply_message)) | 1009 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 1010 return; | 1010 return; |
| 1011 | 1011 |
| 1012 TabContents* tab_contents; | 1012 RenderViewHost* view; |
| 1013 std::string error; | 1013 std::string error; |
| 1014 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 1014 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
| 1015 AutomationJSONReply(this, reply_message).SendError(error); | 1015 AutomationJSONReply(this, reply_message).SendError(error); |
| 1016 return; | 1016 return; |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 WebKit::WebMouseEvent mouse_event; | 1019 WebKit::WebMouseEvent mouse_event; |
| 1020 int start_x, start_y, end_x, end_y; | 1020 int start_x, start_y, end_x, end_y; |
| 1021 if (!args->GetInteger("start_x", &start_x) || | 1021 if (!args->GetInteger("start_x", &start_x) || |
| 1022 !args->GetInteger("start_y", &start_y) || | 1022 !args->GetInteger("start_y", &start_y) || |
| 1023 !args->GetInteger("end_x", &end_x) || | 1023 !args->GetInteger("end_x", &end_x) || |
| 1024 !args->GetInteger("end_y", &end_y)) { | 1024 !args->GetInteger("end_y", &end_y)) { |
| 1025 AutomationJSONReply(this, reply_message) | 1025 AutomationJSONReply(this, reply_message) |
| 1026 .SendError("Invalid start/end positions"); | 1026 .SendError("Invalid start/end positions"); |
| 1027 return; | 1027 return; |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 mouse_event.type = WebKit::WebInputEvent::MouseMove; | 1030 mouse_event.type = WebKit::WebInputEvent::MouseMove; |
| 1031 // Step 1- Move the mouse to the start position. | 1031 // Step 1- Move the mouse to the start position. |
| 1032 mouse_event.x = start_x; | 1032 mouse_event.x = start_x; |
| 1033 mouse_event.y = start_y; | 1033 mouse_event.y = start_y; |
| 1034 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1034 view->ForwardMouseEvent(mouse_event); |
| 1035 | 1035 |
| 1036 // Step 2- Left click mouse down, the mouse button is fixed. | 1036 // Step 2- Left click mouse down, the mouse button is fixed. |
| 1037 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 1037 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
| 1038 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 1038 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
| 1039 mouse_event.clickCount = 1; | 1039 mouse_event.clickCount = 1; |
| 1040 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1040 view->ForwardMouseEvent(mouse_event); |
| 1041 | 1041 |
| 1042 // Step 3 - Move the mouse to the end position. | 1042 // Step 3 - Move the mouse to the end position. |
| 1043 // TODO(JMikhail): See if we should simulate the by not making such | |
| 1044 // a drastic jump by placing incrmental stops along the way. | |
| 1045 mouse_event.type = WebKit::WebInputEvent::MouseMove; | 1043 mouse_event.type = WebKit::WebInputEvent::MouseMove; |
| 1046 mouse_event.x = end_x; | 1044 mouse_event.x = end_x; |
| 1047 mouse_event.y = end_y; | 1045 mouse_event.y = end_y; |
| 1048 mouse_event.clickCount = 0; | 1046 mouse_event.clickCount = 0; |
| 1049 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1047 view->ForwardMouseEvent(mouse_event); |
| 1050 | 1048 |
| 1051 // Step 4 - Release the left mouse button. | 1049 // Step 4 - Release the left mouse button. |
| 1052 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 1050 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 1053 mouse_event.clickCount = 1; | 1051 mouse_event.clickCount = 1; |
| 1054 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, | 1052 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
| 1055 1); | 1053 1); |
| 1056 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1054 view->ForwardMouseEvent(mouse_event); |
| 1057 } | 1055 } |
| 1058 | 1056 |
| 1059 void TestingAutomationProvider::WebkitMouseButtonDown( | 1057 void TestingAutomationProvider::WebkitMouseButtonDown( |
| 1060 DictionaryValue* args, IPC::Message* reply_message) { | 1058 DictionaryValue* args, IPC::Message* reply_message) { |
| 1061 if (SendErrorIfModalDialogActive(this, reply_message)) | 1059 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 1062 return; | 1060 return; |
| 1063 | 1061 |
| 1064 TabContents* tab_contents; | 1062 RenderViewHost* view; |
| 1065 std::string error; | 1063 std::string error; |
| 1066 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 1064 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
| 1067 AutomationJSONReply(this, reply_message).SendError(error); | 1065 AutomationJSONReply(this, reply_message).SendError(error); |
| 1068 return; | 1066 return; |
| 1069 } | 1067 } |
| 1070 | 1068 |
| 1071 WebKit::WebMouseEvent mouse_event; | 1069 WebKit::WebMouseEvent mouse_event; |
| 1072 if (!args->GetInteger("x", &mouse_event.x) || | 1070 if (!args->GetInteger("x", &mouse_event.x) || |
| 1073 !args->GetInteger("y", &mouse_event.y)) { | 1071 !args->GetInteger("y", &mouse_event.y)) { |
| 1074 AutomationJSONReply(this, reply_message) | 1072 AutomationJSONReply(this, reply_message) |
| 1075 .SendError("(X,Y) coordinates missing or invalid"); | 1073 .SendError("(X,Y) coordinates missing or invalid"); |
| 1076 return; | 1074 return; |
| 1077 } | 1075 } |
| 1078 | 1076 |
| 1079 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 1077 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
| 1080 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 1078 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
| 1081 mouse_event.clickCount = 1; | 1079 mouse_event.clickCount = 1; |
| 1082 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, | 1080 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
| 1083 1); | 1081 1); |
| 1084 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1082 view->ForwardMouseEvent(mouse_event); |
| 1085 } | 1083 } |
| 1086 | 1084 |
| 1087 void TestingAutomationProvider::WebkitMouseButtonUp( | 1085 void TestingAutomationProvider::WebkitMouseButtonUp( |
| 1088 DictionaryValue* args, IPC::Message* reply_message) { | 1086 DictionaryValue* args, IPC::Message* reply_message) { |
| 1089 if (SendErrorIfModalDialogActive(this, reply_message)) | 1087 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 1090 return; | 1088 return; |
| 1091 | 1089 |
| 1092 TabContents* tab_contents; | 1090 RenderViewHost* view; |
| 1093 std::string error; | 1091 std::string error; |
| 1094 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 1092 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
| 1095 AutomationJSONReply(this, reply_message).SendError(error); | 1093 AutomationJSONReply(this, reply_message).SendError(error); |
| 1096 return; | 1094 return; |
| 1097 } | 1095 } |
| 1098 | 1096 |
| 1099 WebKit::WebMouseEvent mouse_event; | 1097 WebKit::WebMouseEvent mouse_event; |
| 1100 if (!args->GetInteger("x", &mouse_event.x) || | 1098 if (!args->GetInteger("x", &mouse_event.x) || |
| 1101 !args->GetInteger("y", &mouse_event.y)) { | 1099 !args->GetInteger("y", &mouse_event.y)) { |
| 1102 AutomationJSONReply(this, reply_message) | 1100 AutomationJSONReply(this, reply_message) |
| 1103 .SendError("(X,Y) coordinates missing or invalid"); | 1101 .SendError("(X,Y) coordinates missing or invalid"); |
| 1104 return; | 1102 return; |
| 1105 } | 1103 } |
| 1106 | 1104 |
| 1107 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 1105 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 1108 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 1106 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
| 1109 mouse_event.clickCount = 1; | 1107 mouse_event.clickCount = 1; |
| 1110 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, | 1108 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
| 1111 1); | 1109 1); |
| 1112 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1110 view->ForwardMouseEvent(mouse_event); |
| 1113 } | 1111 } |
| 1114 | 1112 |
| 1115 void TestingAutomationProvider::WebkitMouseDoubleClick( | 1113 void TestingAutomationProvider::WebkitMouseDoubleClick( |
| 1116 DictionaryValue* args, IPC::Message* reply_message) { | 1114 DictionaryValue* args, IPC::Message* reply_message) { |
| 1117 if (SendErrorIfModalDialogActive(this, reply_message)) | 1115 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 1118 return; | 1116 return; |
| 1119 | 1117 |
| 1120 TabContents* tab_contents; | 1118 RenderViewHost* view; |
| 1121 std::string error; | 1119 std::string error; |
| 1122 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 1120 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
| 1123 AutomationJSONReply(this, reply_message).SendError(error); | 1121 AutomationJSONReply(this, reply_message).SendError(error); |
| 1124 return; | 1122 return; |
| 1125 } | 1123 } |
| 1126 | 1124 |
| 1127 WebKit::WebMouseEvent mouse_event; | 1125 WebKit::WebMouseEvent mouse_event; |
| 1128 if (!args->GetInteger("x", &mouse_event.x) || | 1126 if (!args->GetInteger("x", &mouse_event.x) || |
| 1129 !args->GetInteger("y", &mouse_event.y)) { | 1127 !args->GetInteger("y", &mouse_event.y)) { |
| 1130 AutomationJSONReply(this, reply_message) | 1128 AutomationJSONReply(this, reply_message) |
| 1131 .SendError("(X,Y) coordinates missing or invalid"); | 1129 .SendError("(X,Y) coordinates missing or invalid"); |
| 1132 return; | 1130 return; |
| 1133 } | 1131 } |
| 1134 | 1132 |
| 1135 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 1133 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
| 1136 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 1134 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
| 1137 mouse_event.clickCount = 1; | 1135 mouse_event.clickCount = 1; |
| 1138 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1136 view->ForwardMouseEvent(mouse_event); |
| 1139 | 1137 |
| 1140 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 1138 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 1141 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, | 1139 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
| 1142 2); | 1140 2); |
| 1143 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1141 view->ForwardMouseEvent(mouse_event); |
| 1144 | 1142 |
| 1145 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 1143 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
| 1146 mouse_event.clickCount = 2; | 1144 mouse_event.clickCount = 2; |
| 1147 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1145 view->ForwardMouseEvent(mouse_event); |
| 1148 | 1146 |
| 1149 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 1147 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 1150 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1148 view->ForwardMouseEvent(mouse_event); |
| 1151 } | 1149 } |
| 1152 | 1150 |
| 1153 void TestingAutomationProvider::DragAndDropFilePaths( | 1151 void TestingAutomationProvider::DragAndDropFilePaths( |
| 1154 DictionaryValue* args, IPC::Message* reply_message) { | 1152 DictionaryValue* args, IPC::Message* reply_message) { |
| 1155 if (SendErrorIfModalDialogActive(this, reply_message)) | 1153 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 1156 return; | 1154 return; |
| 1157 | 1155 |
| 1158 TabContents* tab_contents; | 1156 RenderViewHost* view; |
| 1159 std::string error; | 1157 std::string error; |
| 1160 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 1158 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
| 1161 AutomationJSONReply(this, reply_message).SendError(error); | 1159 AutomationJSONReply(this, reply_message).SendError(error); |
| 1162 return; | 1160 return; |
| 1163 } | 1161 } |
| 1164 | 1162 |
| 1165 int x, y; | 1163 int x, y; |
| 1166 if (!args->GetInteger("x", &x) || !args->GetInteger("y", &y)) { | 1164 if (!args->GetInteger("x", &x) || !args->GetInteger("y", &y)) { |
| 1167 AutomationJSONReply(this, reply_message) | 1165 AutomationJSONReply(this, reply_message) |
| 1168 .SendError("(X,Y) coordinates missing or invalid"); | 1166 .SendError("(X,Y) coordinates missing or invalid"); |
| 1169 return; | 1167 return; |
| 1170 } | 1168 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1192 const gfx::Point client(x, y); | 1190 const gfx::Point client(x, y); |
| 1193 // We don't set any values in screen variable because DragTarget*** ignore the | 1191 // We don't set any values in screen variable because DragTarget*** ignore the |
| 1194 // screen argument. | 1192 // screen argument. |
| 1195 const gfx::Point screen; | 1193 const gfx::Point screen; |
| 1196 | 1194 |
| 1197 int operations = 0; | 1195 int operations = 0; |
| 1198 operations |= WebKit::WebDragOperationCopy; | 1196 operations |= WebKit::WebDragOperationCopy; |
| 1199 operations |= WebKit::WebDragOperationLink; | 1197 operations |= WebKit::WebDragOperationLink; |
| 1200 operations |= WebKit::WebDragOperationMove; | 1198 operations |= WebKit::WebDragOperationMove; |
| 1201 | 1199 |
| 1202 RenderViewHost* host = tab_contents->render_view_host(); | 1200 view->DragTargetDragEnter( |
| 1203 host->DragTargetDragEnter( | |
| 1204 drop_data, client, screen, | 1201 drop_data, client, screen, |
| 1205 static_cast<WebKit::WebDragOperationsMask>(operations)); | 1202 static_cast<WebKit::WebDragOperationsMask>(operations)); |
| 1206 new DragTargetDropAckNotificationObserver(this, reply_message); | 1203 new DragTargetDropAckNotificationObserver(this, reply_message); |
| 1207 host->DragTargetDrop(client, screen); | 1204 view->DragTargetDrop(client, screen); |
| 1208 } | 1205 } |
| 1209 | 1206 |
| 1210 void TestingAutomationProvider::GetTabCount(int handle, int* tab_count) { | 1207 void TestingAutomationProvider::GetTabCount(int handle, int* tab_count) { |
| 1211 *tab_count = -1; // -1 is the error code | 1208 *tab_count = -1; // -1 is the error code |
| 1212 | 1209 |
| 1213 if (browser_tracker_->ContainsHandle(handle)) { | 1210 if (browser_tracker_->ContainsHandle(handle)) { |
| 1214 Browser* browser = browser_tracker_->GetResource(handle); | 1211 Browser* browser = browser_tracker_->GetResource(handle); |
| 1215 *tab_count = browser->tab_count(); | 1212 *tab_count = browser->tab_count(); |
| 1216 } | 1213 } |
| 1217 } | 1214 } |
| (...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2258 handler_map["ExecuteJavascript"] = | 2255 handler_map["ExecuteJavascript"] = |
| 2259 &TestingAutomationProvider::ExecuteJavascriptJSON; | 2256 &TestingAutomationProvider::ExecuteJavascriptJSON; |
| 2260 handler_map["ExecuteJavascriptInRenderView"] = | 2257 handler_map["ExecuteJavascriptInRenderView"] = |
| 2261 &TestingAutomationProvider::ExecuteJavascriptInRenderView; | 2258 &TestingAutomationProvider::ExecuteJavascriptInRenderView; |
| 2262 handler_map["GoForward"] = | 2259 handler_map["GoForward"] = |
| 2263 &TestingAutomationProvider::GoForward; | 2260 &TestingAutomationProvider::GoForward; |
| 2264 handler_map["GoBack"] = | 2261 handler_map["GoBack"] = |
| 2265 &TestingAutomationProvider::GoBack; | 2262 &TestingAutomationProvider::GoBack; |
| 2266 handler_map["Reload"] = | 2263 handler_map["Reload"] = |
| 2267 &TestingAutomationProvider::ReloadJSON; | 2264 &TestingAutomationProvider::ReloadJSON; |
| 2268 handler_map["GetTabURL"] = | |
| 2269 &TestingAutomationProvider::GetTabURLJSON; | |
| 2270 handler_map["GetTabTitle"] = | |
| 2271 &TestingAutomationProvider::GetTabTitleJSON; | |
| 2272 handler_map["CaptureEntirePage"] = | 2265 handler_map["CaptureEntirePage"] = |
| 2273 &TestingAutomationProvider::CaptureEntirePageJSON; | 2266 &TestingAutomationProvider::CaptureEntirePageJSON; |
| 2274 handler_map["GetCookies"] = | 2267 handler_map["GetCookies"] = |
| 2275 &TestingAutomationProvider::GetCookiesJSON; | 2268 &TestingAutomationProvider::GetCookiesJSON; |
| 2276 handler_map["DeleteCookie"] = | 2269 handler_map["DeleteCookie"] = |
| 2277 &TestingAutomationProvider::DeleteCookieJSON; | 2270 &TestingAutomationProvider::DeleteCookieJSON; |
| 2278 handler_map["SetCookie"] = | 2271 handler_map["SetCookie"] = |
| 2279 &TestingAutomationProvider::SetCookieJSON; | 2272 &TestingAutomationProvider::SetCookieJSON; |
| 2280 handler_map["GetTabIds"] = | 2273 handler_map["GetTabIds"] = |
| 2281 &TestingAutomationProvider::GetTabIds; | 2274 &TestingAutomationProvider::GetTabIds; |
| 2275 handler_map["GetViews"] = |
| 2276 &TestingAutomationProvider::GetViews; |
| 2282 handler_map["IsTabIdValid"] = | 2277 handler_map["IsTabIdValid"] = |
| 2283 &TestingAutomationProvider::IsTabIdValid; | 2278 &TestingAutomationProvider::IsTabIdValid; |
| 2279 handler_map["DoesViewExist"] = |
| 2280 &TestingAutomationProvider::DoesViewExist; |
| 2284 handler_map["CloseTab"] = | 2281 handler_map["CloseTab"] = |
| 2285 &TestingAutomationProvider::CloseTabJSON; | 2282 &TestingAutomationProvider::CloseTabJSON; |
| 2286 handler_map["WebkitMouseMove"] = | 2283 handler_map["WebkitMouseMove"] = |
| 2287 &TestingAutomationProvider::WebkitMouseMove; | 2284 &TestingAutomationProvider::WebkitMouseMove; |
| 2288 handler_map["WebkitMouseClick"] = | 2285 handler_map["WebkitMouseClick"] = |
| 2289 &TestingAutomationProvider::WebkitMouseClick; | 2286 &TestingAutomationProvider::WebkitMouseClick; |
| 2290 handler_map["WebkitMouseDrag"] = | 2287 handler_map["WebkitMouseDrag"] = |
| 2291 &TestingAutomationProvider::WebkitMouseDrag; | 2288 &TestingAutomationProvider::WebkitMouseDrag; |
| 2292 handler_map["WebkitMouseButtonUp"] = | 2289 handler_map["WebkitMouseButtonUp"] = |
| 2293 &TestingAutomationProvider::WebkitMouseButtonUp; | 2290 &TestingAutomationProvider::WebkitMouseButtonUp; |
| (...skipping 3208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5502 NativeWebKeyboardEvent event; | 5499 NativeWebKeyboardEvent event; |
| 5503 // In the event of an error, BuildWebKeyEventFromArgs handles telling what | 5500 // In the event of an error, BuildWebKeyEventFromArgs handles telling what |
| 5504 // went wrong and sending the reply message; if it fails, we just have to | 5501 // went wrong and sending the reply message; if it fails, we just have to |
| 5505 // stop here. | 5502 // stop here. |
| 5506 std::string error; | 5503 std::string error; |
| 5507 if (!BuildWebKeyEventFromArgs(args, &error, &event)) { | 5504 if (!BuildWebKeyEventFromArgs(args, &error, &event)) { |
| 5508 AutomationJSONReply(this, reply_message).SendError(error); | 5505 AutomationJSONReply(this, reply_message).SendError(error); |
| 5509 return; | 5506 return; |
| 5510 } | 5507 } |
| 5511 | 5508 |
| 5512 TabContents* tab_contents; | 5509 RenderViewHost* view; |
| 5513 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 5510 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
| 5514 AutomationJSONReply(this, reply_message).SendError(error); | 5511 AutomationJSONReply(this, reply_message).SendError(error); |
| 5515 return; | 5512 return; |
| 5516 } | 5513 } |
| 5517 new InputEventAckNotificationObserver(this, reply_message, event.type, 1); | 5514 new InputEventAckNotificationObserver(this, reply_message, event.type, 1); |
| 5518 tab_contents->render_view_host()->ForwardKeyboardEvent(event); | 5515 view->ForwardKeyboardEvent(event); |
| 5519 } | 5516 } |
| 5520 | 5517 |
| 5521 void TestingAutomationProvider::SendOSLevelKeyEventToTab( | 5518 void TestingAutomationProvider::SendOSLevelKeyEventToTab( |
| 5522 DictionaryValue* args, | 5519 DictionaryValue* args, |
| 5523 IPC::Message* reply_message) { | 5520 IPC::Message* reply_message) { |
| 5524 if (SendErrorIfModalDialogActive(this, reply_message)) | 5521 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 5525 return; | 5522 return; |
| 5526 | 5523 |
| 5527 int modifiers, keycode; | 5524 int modifiers, keycode; |
| 5528 if (!args->GetInteger("keyCode", &keycode)) { | 5525 if (!args->GetInteger("keyCode", &keycode)) { |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5926 } | 5923 } |
| 5927 | 5924 |
| 5928 void TestingAutomationProvider::ExecuteJavascriptJSON( | 5925 void TestingAutomationProvider::ExecuteJavascriptJSON( |
| 5929 DictionaryValue* args, | 5926 DictionaryValue* args, |
| 5930 IPC::Message* reply_message) { | 5927 IPC::Message* reply_message) { |
| 5931 if (SendErrorIfModalDialogActive(this, reply_message)) | 5928 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 5932 return; | 5929 return; |
| 5933 | 5930 |
| 5934 string16 frame_xpath, javascript; | 5931 string16 frame_xpath, javascript; |
| 5935 std::string error; | 5932 std::string error; |
| 5936 TabContents* tab_contents; | 5933 RenderViewHost* render_view; |
| 5937 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 5934 if (!GetRenderViewFromJSONArgs(args, profile(), &render_view, &error)) { |
| 5938 AutomationJSONReply(this, reply_message).SendError(error); | 5935 AutomationJSONReply(this, reply_message).SendError(error); |
| 5939 return; | 5936 return; |
| 5940 } | 5937 } |
| 5941 if (!args->GetString("frame_xpath", &frame_xpath)) { | 5938 if (!args->GetString("frame_xpath", &frame_xpath)) { |
| 5942 AutomationJSONReply(this, reply_message) | 5939 AutomationJSONReply(this, reply_message) |
| 5943 .SendError("'frame_xpath' missing or invalid"); | 5940 .SendError("'frame_xpath' missing or invalid"); |
| 5944 return; | 5941 return; |
| 5945 } | 5942 } |
| 5946 if (!args->GetString("javascript", &javascript)) { | 5943 if (!args->GetString("javascript", &javascript)) { |
| 5947 AutomationJSONReply(this, reply_message) | 5944 AutomationJSONReply(this, reply_message) |
| 5948 .SendError("'javascript' missing or invalid"); | 5945 .SendError("'javascript' missing or invalid"); |
| 5949 return; | 5946 return; |
| 5950 } | 5947 } |
| 5951 | 5948 |
| 5952 new DomOperationMessageSender(this, reply_message, true); | 5949 new DomOperationMessageSender(this, reply_message, true); |
| 5953 ExecuteJavascriptInRenderViewFrame(frame_xpath, javascript, reply_message, | 5950 ExecuteJavascriptInRenderViewFrame(frame_xpath, javascript, reply_message, |
| 5954 tab_contents->render_view_host()); | 5951 render_view); |
| 5955 } | 5952 } |
| 5956 | 5953 |
| 5957 void TestingAutomationProvider::ExecuteJavascriptInRenderView( | 5954 void TestingAutomationProvider::ExecuteJavascriptInRenderView( |
| 5958 DictionaryValue* args, | 5955 DictionaryValue* args, |
| 5959 IPC::Message* reply_message) { | 5956 IPC::Message* reply_message) { |
| 5960 string16 frame_xpath, javascript, extension_id, url_text; | 5957 string16 frame_xpath, javascript, extension_id, url_text; |
| 5961 std::string error; | 5958 std::string error; |
| 5962 int render_process_id, render_view_id; | 5959 int render_process_id, render_view_id; |
| 5963 if (!args->GetString("frame_xpath", &frame_xpath)) { | 5960 if (!args->GetString("frame_xpath", &frame_xpath)) { |
| 5964 AutomationJSONReply(this, reply_message) | 5961 AutomationJSONReply(this, reply_message) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6053 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 6050 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
| 6054 AutomationJSONReply(this, reply_message).SendError(error); | 6051 AutomationJSONReply(this, reply_message).SendError(error); |
| 6055 return; | 6052 return; |
| 6056 } | 6053 } |
| 6057 NavigationController& controller = tab_contents->controller(); | 6054 NavigationController& controller = tab_contents->controller(); |
| 6058 new NavigationNotificationObserver(&controller, this, reply_message, | 6055 new NavigationNotificationObserver(&controller, this, reply_message, |
| 6059 1, false, true); | 6056 1, false, true); |
| 6060 controller.Reload(false); | 6057 controller.Reload(false); |
| 6061 } | 6058 } |
| 6062 | 6059 |
| 6063 void TestingAutomationProvider::GetTabURLJSON( | |
| 6064 DictionaryValue* args, | |
| 6065 IPC::Message* reply_message) { | |
| 6066 AutomationJSONReply reply(this, reply_message); | |
| 6067 TabContents* tab_contents; | |
| 6068 std::string error; | |
| 6069 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 6070 reply.SendError(error); | |
| 6071 return; | |
| 6072 } | |
| 6073 DictionaryValue dict; | |
| 6074 dict.SetString("url", tab_contents->GetURL().possibly_invalid_spec()); | |
| 6075 reply.SendSuccess(&dict); | |
| 6076 } | |
| 6077 | |
| 6078 void TestingAutomationProvider::GetTabTitleJSON( | |
| 6079 DictionaryValue* args, | |
| 6080 IPC::Message* reply_message) { | |
| 6081 AutomationJSONReply reply(this, reply_message); | |
| 6082 TabContents* tab_contents; | |
| 6083 std::string error; | |
| 6084 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 6085 reply.SendError(error); | |
| 6086 return; | |
| 6087 } | |
| 6088 DictionaryValue dict; | |
| 6089 dict.SetString("title", tab_contents->GetTitle()); | |
| 6090 reply.SendSuccess(&dict); | |
| 6091 } | |
| 6092 | |
| 6093 void TestingAutomationProvider::CaptureEntirePageJSON( | 6060 void TestingAutomationProvider::CaptureEntirePageJSON( |
| 6094 DictionaryValue* args, | 6061 DictionaryValue* args, |
| 6095 IPC::Message* reply_message) { | 6062 IPC::Message* reply_message) { |
| 6096 if (SendErrorIfModalDialogActive(this, reply_message)) | 6063 if (SendErrorIfModalDialogActive(this, reply_message)) |
| 6097 return; | 6064 return; |
| 6098 | 6065 |
| 6099 TabContents* tab_contents; | 6066 TabContents* tab_contents; |
| 6100 std::string error; | 6067 std::string error; |
| 6101 | 6068 |
| 6102 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 6069 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6150 int id = browser->GetTabContentsWrapperAt(i)->restore_tab_helper()-> | 6117 int id = browser->GetTabContentsWrapperAt(i)->restore_tab_helper()-> |
| 6151 session_id().id(); | 6118 session_id().id(); |
| 6152 id_list->Append(Value::CreateIntegerValue(id)); | 6119 id_list->Append(Value::CreateIntegerValue(id)); |
| 6153 } | 6120 } |
| 6154 } | 6121 } |
| 6155 DictionaryValue dict; | 6122 DictionaryValue dict; |
| 6156 dict.Set("ids", id_list); | 6123 dict.Set("ids", id_list); |
| 6157 AutomationJSONReply(this, reply_message).SendSuccess(&dict); | 6124 AutomationJSONReply(this, reply_message).SendSuccess(&dict); |
| 6158 } | 6125 } |
| 6159 | 6126 |
| 6127 void TestingAutomationProvider::GetViews( |
| 6128 DictionaryValue* args, IPC::Message* reply_message) { |
| 6129 ListValue* view_list = new ListValue(); |
| 6130 BrowserList::const_iterator browser_iter = BrowserList::begin(); |
| 6131 for (; browser_iter != BrowserList::end(); ++browser_iter) { |
| 6132 Browser* browser = *browser_iter; |
| 6133 for (int i = 0; i < browser->tab_count(); ++i) { |
| 6134 DictionaryValue* dict = new DictionaryValue(); |
| 6135 AutomationId id = automation_util::GetIdForTab( |
| 6136 browser->GetTabContentsWrapperAt(i)); |
| 6137 dict->Set("view_id", id.ToValue()); |
| 6138 view_list->Append(dict); |
| 6139 } |
| 6140 } |
| 6141 |
| 6142 ExtensionProcessManager* extension_mgr = |
| 6143 profile()->GetExtensionProcessManager(); |
| 6144 ExtensionProcessManager::const_iterator iter; |
| 6145 for (iter = extension_mgr->begin(); iter != extension_mgr->end(); |
| 6146 ++iter) { |
| 6147 ExtensionHost* host = *iter; |
| 6148 if (host->extension_host_type() != chrome::VIEW_TYPE_EXTENSION_POPUP) |
| 6149 continue; |
| 6150 DictionaryValue* dict = new DictionaryValue(); |
| 6151 AutomationId id = automation_util::GetIdForExtensionPopup( |
| 6152 host->extension()); |
| 6153 dict->Set("view_id", id.ToValue()); |
| 6154 dict->SetString("extension_id", host->extension()->id()); |
| 6155 view_list->Append(dict); |
| 6156 } |
| 6157 DictionaryValue dict; |
| 6158 dict.Set("views", view_list); |
| 6159 AutomationJSONReply(this, reply_message).SendSuccess(&dict); |
| 6160 } |
| 6161 |
| 6160 void TestingAutomationProvider::IsTabIdValid( | 6162 void TestingAutomationProvider::IsTabIdValid( |
| 6161 DictionaryValue* args, IPC::Message* reply_message) { | 6163 DictionaryValue* args, IPC::Message* reply_message) { |
| 6162 AutomationJSONReply reply(this, reply_message); | 6164 AutomationJSONReply reply(this, reply_message); |
| 6163 int id; | 6165 int id; |
| 6164 if (!args->GetInteger("id", &id)) { | 6166 if (!args->GetInteger("id", &id)) { |
| 6165 reply.SendError("'id' missing or invalid"); | 6167 reply.SendError("'id' missing or invalid"); |
| 6166 return; | 6168 return; |
| 6167 } | 6169 } |
| 6168 bool is_valid = false; | 6170 bool is_valid = false; |
| 6169 BrowserList::const_iterator iter = BrowserList::begin(); | 6171 BrowserList::const_iterator iter = BrowserList::begin(); |
| 6170 for (; iter != BrowserList::end(); ++iter) { | 6172 for (; iter != BrowserList::end(); ++iter) { |
| 6171 Browser* browser = *iter; | 6173 Browser* browser = *iter; |
| 6172 for (int i = 0; i < browser->tab_count(); ++i) { | 6174 for (int i = 0; i < browser->tab_count(); ++i) { |
| 6173 TabContentsWrapper* tab = browser->GetTabContentsWrapperAt(i); | 6175 TabContentsWrapper* tab = browser->GetTabContentsWrapperAt(i); |
| 6174 if (tab->restore_tab_helper()->session_id().id() == id) { | 6176 if (tab->restore_tab_helper()->session_id().id() == id) { |
| 6175 is_valid = true; | 6177 is_valid = true; |
| 6176 break; | 6178 break; |
| 6177 } | 6179 } |
| 6178 } | 6180 } |
| 6179 } | 6181 } |
| 6180 DictionaryValue dict; | 6182 DictionaryValue dict; |
| 6181 dict.SetBoolean("is_valid", is_valid); | 6183 dict.SetBoolean("is_valid", is_valid); |
| 6182 reply.SendSuccess(&dict); | 6184 reply.SendSuccess(&dict); |
| 6183 } | 6185 } |
| 6184 | 6186 |
| 6187 void TestingAutomationProvider::DoesViewExist( |
| 6188 DictionaryValue* args, IPC::Message* reply_message) { |
| 6189 AutomationJSONReply reply(this, reply_message); |
| 6190 AutomationId id; |
| 6191 std::string error_msg; |
| 6192 if (!GetAutomationIdFromJSONArgs(args, &id, &error_msg)) { |
| 6193 reply.SendError(error_msg); |
| 6194 return; |
| 6195 } |
| 6196 DictionaryValue dict; |
| 6197 dict.SetBoolean( |
| 6198 "does_exist", |
| 6199 automation_util::DoesObjectWithIdExist(id, profile())); |
| 6200 reply.SendSuccess(&dict); |
| 6201 } |
| 6202 |
| 6185 void TestingAutomationProvider::CloseTabJSON( | 6203 void TestingAutomationProvider::CloseTabJSON( |
| 6186 DictionaryValue* args, IPC::Message* reply_message) { | 6204 DictionaryValue* args, IPC::Message* reply_message) { |
| 6187 AutomationJSONReply reply(this, reply_message); | 6205 AutomationJSONReply reply(this, reply_message); |
| 6188 Browser* browser; | 6206 Browser* browser; |
| 6189 TabContents* tab_contents; | 6207 TabContents* tab_contents; |
| 6190 std::string error; | 6208 std::string error; |
| 6191 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab_contents, &error)) { | 6209 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab_contents, &error)) { |
| 6192 reply.SendError(error); | 6210 reply.SendError(error); |
| 6193 return; | 6211 return; |
| 6194 } | 6212 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6430 | 6448 |
| 6431 Send(reply_message_); | 6449 Send(reply_message_); |
| 6432 redirect_query_ = 0; | 6450 redirect_query_ = 0; |
| 6433 reply_message_ = NULL; | 6451 reply_message_ = NULL; |
| 6434 } | 6452 } |
| 6435 | 6453 |
| 6436 void TestingAutomationProvider::OnRemoveProvider() { | 6454 void TestingAutomationProvider::OnRemoveProvider() { |
| 6437 if (g_browser_process) | 6455 if (g_browser_process) |
| 6438 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6456 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 6439 } | 6457 } |
| OLD | NEW |