Chromium Code Reviews| 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 <string> | 8 #include <string> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 | 10 | 
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 | 163 | 
| 164 TabContents* GetTabContentsAt(int browser_index, int tab_index) { | 164 TabContents* GetTabContentsAt(int browser_index, int tab_index) { | 
| 165 if (tab_index < 0) | 165 if (tab_index < 0) | 
| 166 return NULL; | 166 return NULL; | 
| 167 Browser* browser = GetBrowserAt(browser_index); | 167 Browser* browser = GetBrowserAt(browser_index); | 
| 168 if (!browser || tab_index >= browser->tab_count()) | 168 if (!browser || tab_index >= browser->tab_count()) | 
| 169 return NULL; | 169 return NULL; | 
| 170 return browser->GetTabContentsAt(tab_index); | 170 return browser->GetTabContentsAt(tab_index); | 
| 171 } | 171 } | 
| 172 | 172 | 
| 173 bool GetBrowserFromJSONArgs( | |
| 
 
Paweł Hajdan Jr.
2011/03/05 11:44:56
Could you move those helpers to automation_provide
 
kkania
2011/03/07 04:31:51
Done.
 
 | |
| 174 DictionaryValue* args, | |
| 175 Browser** browser, | |
| 176 std::string* error) { | |
| 177 int browser_index = 0; | |
| 178 if (!args->GetInteger("windex", &browser_index)) { | |
| 179 *error = "'windex' missing or invalid"; | |
| 
 
Paweł Hajdan Jr.
2011/03/05 11:44:56
It seems that we should be appending to |error| ra
 
kkania
2011/03/07 04:31:51
The error is only set if the func returns false, i
 
 | |
| 180 return false; | |
| 181 } | |
| 182 *browser = GetBrowserAt(browser_index); | |
| 183 if (!*browser) { | |
| 184 *error = "Cannot locate browser from given index"; | |
| 185 return false; | |
| 186 } | |
| 187 return true; | |
| 188 } | |
| 189 | |
| 190 bool GetTabFromJSONArgs( | |
| 191 DictionaryValue* args, | |
| 192 TabContents** tab, | |
| 193 std::string* error) { | |
| 194 int browser_index = 0, tab_index = 0; | |
| 195 if (!args->GetInteger("windex", &browser_index)) { | |
| 196 *error = "'windex' missing or invalid"; | |
| 197 return false; | |
| 198 } | |
| 199 if (!args->GetInteger("tab_index", &tab_index)) { | |
| 200 *error = "'tab_index' missing or invalid"; | |
| 201 return false; | |
| 202 } | |
| 203 *tab = GetTabContentsAt(browser_index, tab_index); | |
| 204 if (!*tab) { | |
| 205 *error = "Cannot locate tab from given indices"; | |
| 206 return false; | |
| 207 } | |
| 208 return true; | |
| 209 } | |
| 210 | |
| 211 bool GetBrowserAndTabFromJSONArgs( | |
| 212 DictionaryValue* args, | |
| 213 Browser** browser, | |
| 214 TabContents** tab, | |
| 215 std::string* error) { | |
| 216 return GetBrowserFromJSONArgs(args, browser, error) && | |
| 217 GetTabFromJSONArgs(args, tab, error); | |
| 218 } | |
| 219 | |
| 173 } // namespace | 220 } // namespace | 
| 174 | 221 | 
| 175 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) | 222 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) | 
| 176 : AutomationProvider(profile), | 223 : AutomationProvider(profile), | 
| 177 #if defined(TOOLKIT_VIEWS) | 224 #if defined(TOOLKIT_VIEWS) | 
| 178 popup_menu_waiter_(NULL), | 225 popup_menu_waiter_(NULL), | 
| 179 #endif | 226 #endif | 
| 180 redirect_query_(0) { | 227 redirect_query_(0) { | 
| 181 BrowserList::AddObserver(this); | 228 BrowserList::AddObserver(this); | 
| 182 registrar_.Add(this, NotificationType::SESSION_END, | 229 registrar_.Add(this, NotificationType::SESSION_END, | 
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 ((flags & ui::EF_CONTROL_DOWN) == | 953 ((flags & ui::EF_CONTROL_DOWN) == | 
| 907 ui::EF_CONTROL_DOWN), | 954 ui::EF_CONTROL_DOWN), | 
| 908 ((flags & ui::EF_SHIFT_DOWN) == | 955 ((flags & ui::EF_SHIFT_DOWN) == | 
| 909 ui::EF_SHIFT_DOWN), | 956 ui::EF_SHIFT_DOWN), | 
| 910 ((flags & ui::EF_ALT_DOWN) == | 957 ((flags & ui::EF_ALT_DOWN) == | 
| 911 ui::EF_ALT_DOWN), | 958 ui::EF_ALT_DOWN), | 
| 912 ((flags & ui::EF_COMMAND_DOWN) == | 959 ((flags & ui::EF_COMMAND_DOWN) == | 
| 913 ui::EF_COMMAND_DOWN)); | 960 ui::EF_COMMAND_DOWN)); | 
| 914 } | 961 } | 
| 915 | 962 | 
| 916 void TestingAutomationProvider::WebkitMouseClick(Browser* browser, | 963 void TestingAutomationProvider::WebkitMouseClick(DictionaryValue* args, | 
| 917 DictionaryValue* args, | |
| 918 IPC::Message* reply_message) { | 964 IPC::Message* reply_message) { | 
| 965 TabContents* tab_contents; | |
| 966 std::string error; | |
| 967 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 968 AutomationJSONReply(this, reply_message).SendError(error); | |
| 969 return; | |
| 970 } | |
| 971 | |
| 919 WebKit::WebMouseEvent mouse_event; | 972 WebKit::WebMouseEvent mouse_event; | 
| 920 | |
| 921 if (!args->GetInteger("x", &mouse_event.x) || | 973 if (!args->GetInteger("x", &mouse_event.x) || | 
| 922 !args->GetInteger("y", &mouse_event.y)) { | 974 !args->GetInteger("y", &mouse_event.y)) { | 
| 923 AutomationJSONReply(this, reply_message) | 975 AutomationJSONReply(this, reply_message) | 
| 924 .SendError("(X,Y) coordinates missing or invalid"); | 976 .SendError("(X,Y) coordinates missing or invalid"); | 
| 925 return; | 977 return; | 
| 926 } | 978 } | 
| 927 | 979 | 
| 928 int button_flags; | 980 int button; | 
| 929 if (!args->GetInteger("button_flags", &button_flags)) { | 981 if (!args->GetInteger("button", &button)) { | 
| 930 AutomationJSONReply(this, reply_message) | 982 AutomationJSONReply(this, reply_message) | 
| 931 .SendError("Mouse button missing or invalid"); | 983 .SendError("Mouse button missing or invalid"); | 
| 932 return; | 984 return; | 
| 933 } | 985 } | 
| 934 | 986 if (button == automation::kLeftButton) { | 
| 935 if (button_flags == ui::EF_LEFT_BUTTON_DOWN) { | |
| 936 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 987 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 
| 937 } else if (button_flags == ui::EF_RIGHT_BUTTON_DOWN) { | 988 } else if (button == automation::kRightButton) { | 
| 938 mouse_event.button = WebKit::WebMouseEvent::ButtonRight; | 989 mouse_event.button = WebKit::WebMouseEvent::ButtonRight; | 
| 939 } else if (button_flags == ui::EF_MIDDLE_BUTTON_DOWN) { | 990 } else if (button == automation::kMiddleButton) { | 
| 940 mouse_event.button = WebKit::WebMouseEvent::ButtonMiddle; | 991 mouse_event.button = WebKit::WebMouseEvent::ButtonMiddle; | 
| 941 } else { | 992 } else { | 
| 942 AutomationJSONReply(this, reply_message) | 993 AutomationJSONReply(this, reply_message) | 
| 943 .SendError("Invalid button press requested"); | 994 .SendError("Invalid button press requested"); | 
| 944 return; | 995 return; | 
| 945 } | 996 } | 
| 946 | 997 | 
| 947 TabContents* tab_contents = browser->GetSelectedTabContents(); | |
| 948 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 998 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 
| 949 mouse_event.clickCount = 1; | 999 mouse_event.clickCount = 1; | 
| 950 | 1000 | 
| 951 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1001 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 
| 952 | 1002 | 
| 953 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 1003 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 
| 954 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type); | 1004 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type); | 
| 955 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1005 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 
| 956 } | 1006 } | 
| 957 | 1007 | 
| 958 void TestingAutomationProvider::WebkitMouseMove(Browser* browser, | 1008 void TestingAutomationProvider::WebkitMouseMove( | 
| 959 DictionaryValue* args, | 1009 DictionaryValue* args, IPC::Message* reply_message) { | 
| 960 IPC::Message* reply_message) { | 1010 TabContents* tab_contents; | 
| 1011 std::string error; | |
| 1012 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 1013 AutomationJSONReply(this, reply_message).SendError(error); | |
| 1014 return; | |
| 1015 } | |
| 1016 | |
| 961 WebKit::WebMouseEvent mouse_event; | 1017 WebKit::WebMouseEvent mouse_event; | 
| 962 | |
| 963 if (!args->GetInteger("x", &mouse_event.x) || | 1018 if (!args->GetInteger("x", &mouse_event.x) || | 
| 964 !args->GetInteger("y", &mouse_event.y)) { | 1019 !args->GetInteger("y", &mouse_event.y)) { | 
| 965 AutomationJSONReply(this, reply_message) | 1020 AutomationJSONReply(this, reply_message) | 
| 966 .SendError("(X,Y) coordinates missing or invalid"); | 1021 .SendError("(X,Y) coordinates missing or invalid"); | 
| 967 return; | 1022 return; | 
| 968 } | 1023 } | 
| 969 | 1024 | 
| 970 TabContents* tab_contents = browser->GetSelectedTabContents(); | |
| 971 mouse_event.type = WebKit::WebInputEvent::MouseMove; | 1025 mouse_event.type = WebKit::WebInputEvent::MouseMove; | 
| 972 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type); | 1026 new InputEventAckNotificationObserver(this, reply_message, mouse_event.type); | 
| 973 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1027 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 
| 974 } | 1028 } | 
| 975 | 1029 | 
| 976 void TestingAutomationProvider::WebkitMouseDrag(Browser* browser, | 1030 void TestingAutomationProvider::WebkitMouseDrag(DictionaryValue* args, | 
| 977 DictionaryValue* args, | |
| 978 IPC::Message* reply_message) { | 1031 IPC::Message* reply_message) { | 
| 1032 TabContents* tab_contents; | |
| 1033 std::string error; | |
| 1034 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 1035 AutomationJSONReply(this, reply_message).SendError(error); | |
| 1036 return; | |
| 1037 } | |
| 1038 | |
| 979 WebKit::WebMouseEvent mouse_event; | 1039 WebKit::WebMouseEvent mouse_event; | 
| 980 int start_x, start_y, end_x, end_y; | 1040 int start_x, start_y, end_x, end_y; | 
| 981 | |
| 982 if (!args->GetInteger("start_x", &start_x) || | 1041 if (!args->GetInteger("start_x", &start_x) || | 
| 983 !args->GetInteger("start_y", &start_y) || | 1042 !args->GetInteger("start_y", &start_y) || | 
| 984 !args->GetInteger("end_x", &end_x) || | 1043 !args->GetInteger("end_x", &end_x) || | 
| 985 !args->GetInteger("end_y", &end_y)) { | 1044 !args->GetInteger("end_y", &end_y)) { | 
| 986 AutomationJSONReply(this, reply_message) | 1045 AutomationJSONReply(this, reply_message) | 
| 987 .SendError("Invalid start/end positions"); | 1046 .SendError("Invalid start/end positions"); | 
| 988 return; | 1047 return; | 
| 989 } | 1048 } | 
| 990 | 1049 | 
| 991 mouse_event.type = WebKit::WebInputEvent::MouseMove; | 1050 mouse_event.type = WebKit::WebInputEvent::MouseMove; | 
| 992 TabContents* tab_contents = browser->GetSelectedTabContents(); | |
| 993 // Step 1- Move the mouse to the start position. | 1051 // Step 1- Move the mouse to the start position. | 
| 994 mouse_event.x = start_x; | 1052 mouse_event.x = start_x; | 
| 995 mouse_event.y = start_y; | 1053 mouse_event.y = start_y; | 
| 996 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1054 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 
| 997 | 1055 | 
| 998 // Step 2- Left click mouse down, the mouse button is fixed. | 1056 // Step 2- Left click mouse down, the mouse button is fixed. | 
| 999 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 1057 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 
| 1000 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 1058 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 
| 1001 mouse_event.clickCount = 1; | 1059 mouse_event.clickCount = 1; | 
| 1002 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1060 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 
| (...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2111 } | 2169 } | 
| 2112 | 2170 | 
| 2113 // Map json commands to their handlers. | 2171 // Map json commands to their handlers. | 
| 2114 std::map<std::string, JsonHandler> handler_map; | 2172 std::map<std::string, JsonHandler> handler_map; | 
| 2115 handler_map["WaitForAllTabsToStopLoading"] = | 2173 handler_map["WaitForAllTabsToStopLoading"] = | 
| 2116 &TestingAutomationProvider::WaitForAllTabsToStopLoading; | 2174 &TestingAutomationProvider::WaitForAllTabsToStopLoading; | 
| 2117 handler_map["GetIndicesFromTab"] = | 2175 handler_map["GetIndicesFromTab"] = | 
| 2118 &TestingAutomationProvider::GetIndicesFromTab; | 2176 &TestingAutomationProvider::GetIndicesFromTab; | 
| 2119 handler_map["NavigateToURL"] = | 2177 handler_map["NavigateToURL"] = | 
| 2120 &TestingAutomationProvider::NavigateToURL; | 2178 &TestingAutomationProvider::NavigateToURL; | 
| 2179 handler_map["ExecuteJavascript"] = | |
| 2180 &TestingAutomationProvider::ExecuteJavascriptJSON; | |
| 2181 handler_map["GoForward"] = | |
| 2182 &TestingAutomationProvider::GoForward; | |
| 2183 handler_map["GoBack"] = | |
| 2184 &TestingAutomationProvider::GoBack; | |
| 2185 handler_map["Reload"] = | |
| 2186 &TestingAutomationProvider::ReloadJSON; | |
| 2187 handler_map["GetTabURL"] = | |
| 2188 &TestingAutomationProvider::GetTabURLJSON; | |
| 2189 handler_map["GetTabTitle"] = | |
| 2190 &TestingAutomationProvider::GetTabTitleJSON; | |
| 2191 handler_map["GetCookies"] = | |
| 2192 &TestingAutomationProvider::GetCookiesJSON; | |
| 2193 handler_map["DeleteCookie"] = | |
| 2194 &TestingAutomationProvider::DeleteCookieJSON; | |
| 2195 handler_map["SetCookie"] = | |
| 2196 &TestingAutomationProvider::SetCookieJSON; | |
| 2197 handler_map["GetTabIds"] = | |
| 2198 &TestingAutomationProvider::GetTabIds; | |
| 2199 handler_map["IsTabIdValid"] = | |
| 2200 &TestingAutomationProvider::IsTabIdValid; | |
| 2201 handler_map["CloseTab"] = | |
| 2202 &TestingAutomationProvider::CloseTabJSON; | |
| 2203 handler_map["WebkitMouseMove"] = | |
| 2204 &TestingAutomationProvider::WebkitMouseMove; | |
| 2205 handler_map["WebkitMouseClick"] = | |
| 2206 &TestingAutomationProvider::WebkitMouseClick; | |
| 2207 handler_map["WebkitMouseDrag"] = | |
| 2208 &TestingAutomationProvider::WebkitMouseDrag; | |
| 2209 handler_map["SendWebkitKeyEvent"] = | |
| 2210 &TestingAutomationProvider::SendWebkitKeyEvent; | |
| 2211 handler_map["ActivateTab"] = | |
| 2212 &TestingAutomationProvider::ActivateTabJSON; | |
| 2121 #if defined(OS_CHROMEOS) | 2213 #if defined(OS_CHROMEOS) | 
| 2122 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; | 2214 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; | 
| 2123 handler_map["Login"] = &TestingAutomationProvider::Login; | 2215 handler_map["Login"] = &TestingAutomationProvider::Login; | 
| 2124 handler_map["Logout"] = &TestingAutomationProvider::Logout; | 2216 handler_map["Logout"] = &TestingAutomationProvider::Logout; | 
| 2125 handler_map["ScreenLock"] = &TestingAutomationProvider::ScreenLock; | 2217 handler_map["ScreenLock"] = &TestingAutomationProvider::ScreenLock; | 
| 2126 handler_map["ScreenUnlock"] = &TestingAutomationProvider::ScreenUnlock; | 2218 handler_map["ScreenUnlock"] = &TestingAutomationProvider::ScreenUnlock; | 
| 2127 #endif // defined(OS_CHROMEOS) | 2219 #endif // defined(OS_CHROMEOS) | 
| 2128 | 2220 | 
| 2129 std::map<std::string, BrowserJsonHandler> browser_handler_map; | 2221 std::map<std::string, BrowserJsonHandler> browser_handler_map; | 
| 2130 browser_handler_map["DisablePlugin"] = | 2222 browser_handler_map["DisablePlugin"] = | 
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2253 browser_handler_map["RemoveNTPMostVisitedThumbnail"] = | 2345 browser_handler_map["RemoveNTPMostVisitedThumbnail"] = | 
| 2254 &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail; | 2346 &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail; | 
| 2255 browser_handler_map["UnpinNTPMostVisitedThumbnail"] = | 2347 browser_handler_map["UnpinNTPMostVisitedThumbnail"] = | 
| 2256 &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail; | 2348 &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail; | 
| 2257 browser_handler_map["RestoreAllNTPMostVisitedThumbnails"] = | 2349 browser_handler_map["RestoreAllNTPMostVisitedThumbnails"] = | 
| 2258 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; | 2350 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; | 
| 2259 | 2351 | 
| 2260 browser_handler_map["KillRendererProcess"] = | 2352 browser_handler_map["KillRendererProcess"] = | 
| 2261 &TestingAutomationProvider::KillRendererProcess; | 2353 &TestingAutomationProvider::KillRendererProcess; | 
| 2262 | 2354 | 
| 2263 browser_handler_map["SendKeyEventToActiveTab"] = | |
| 2264 &TestingAutomationProvider::SendKeyEventToActiveTab; | |
| 2265 | |
| 2266 browser_handler_map["GetNTPThumbnailMode"] = | 2355 browser_handler_map["GetNTPThumbnailMode"] = | 
| 2267 &TestingAutomationProvider::GetNTPThumbnailMode; | 2356 &TestingAutomationProvider::GetNTPThumbnailMode; | 
| 2268 browser_handler_map["SetNTPThumbnailMode"] = | 2357 browser_handler_map["SetNTPThumbnailMode"] = | 
| 2269 &TestingAutomationProvider::SetNTPThumbnailMode; | 2358 &TestingAutomationProvider::SetNTPThumbnailMode; | 
| 2270 browser_handler_map["GetNTPMenuMode"] = | 2359 browser_handler_map["GetNTPMenuMode"] = | 
| 2271 &TestingAutomationProvider::GetNTPMenuMode; | 2360 &TestingAutomationProvider::GetNTPMenuMode; | 
| 2272 browser_handler_map["SetNTPMenuMode"] = | 2361 browser_handler_map["SetNTPMenuMode"] = | 
| 2273 &TestingAutomationProvider::SetNTPMenuMode; | 2362 &TestingAutomationProvider::SetNTPMenuMode; | 
| 2274 | 2363 | 
| 2275 browser_handler_map["WebkitMouseMove"] = | |
| 2276 &TestingAutomationProvider::WebkitMouseMove; | |
| 2277 browser_handler_map["WebkitMouseClick"] = | |
| 2278 &TestingAutomationProvider::WebkitMouseClick; | |
| 2279 browser_handler_map["WebkitMouseDrag"] = | |
| 2280 &TestingAutomationProvider::WebkitMouseDrag; | |
| 2281 | |
| 2282 if (handler_map.find(std::string(command)) != handler_map.end()) { | 2364 if (handler_map.find(std::string(command)) != handler_map.end()) { | 
| 2283 (this->*handler_map[command])(dict_value, reply_message); | 2365 (this->*handler_map[command])(dict_value, reply_message); | 
| 2284 } else if (browser_handler_map.find(std::string(command)) != | 2366 } else if (browser_handler_map.find(std::string(command)) != | 
| 2285 browser_handler_map.end()) { | 2367 browser_handler_map.end()) { | 
| 2286 Browser* browser = NULL; | 2368 Browser* browser = NULL; | 
| 2287 if (!browser_tracker_->ContainsHandle(handle) || | 2369 if (!browser_tracker_->ContainsHandle(handle) || | 
| 2288 !(browser = browser_tracker_->GetResource(handle))) { | 2370 !(browser = browser_tracker_->GetResource(handle))) { | 
| 2289 AutomationJSONReply(this, reply_message).SendError("No browser object."); | 2371 AutomationJSONReply(this, reply_message).SendError("No browser object."); | 
| 2290 return; | 2372 return; | 
| 2291 } | 2373 } | 
| (...skipping 2268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4560 if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { | 4642 if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { | 
| 4561 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( | 4643 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( | 
| 4562 "Failed to open process handle for pid %d", pid)); | 4644 "Failed to open process handle for pid %d", pid)); | 
| 4563 return; | 4645 return; | 
| 4564 } | 4646 } | 
| 4565 new RendererProcessClosedObserver(this, reply_message); | 4647 new RendererProcessClosedObserver(this, reply_message); | 
| 4566 base::KillProcess(process, 0, false); | 4648 base::KillProcess(process, 0, false); | 
| 4567 base::CloseProcessHandle(process); | 4649 base::CloseProcessHandle(process); | 
| 4568 } | 4650 } | 
| 4569 | 4651 | 
| 4570 void TestingAutomationProvider::SendKeyEventToActiveTab( | 4652 void TestingAutomationProvider::SendWebkitKeyEvent( | 
| 4571 Browser* browser, | |
| 4572 DictionaryValue* args, | 4653 DictionaryValue* args, | 
| 4573 IPC::Message* reply_message) { | 4654 IPC::Message* reply_message) { | 
| 4655 TabContents* tab_contents; | |
| 4656 std::string error; | |
| 4657 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 4658 AutomationJSONReply(this, reply_message).SendError(error); | |
| 4659 return; | |
| 4660 } | |
| 4661 | |
| 4574 int type, modifiers; | 4662 int type, modifiers; | 
| 4575 bool is_system_key; | 4663 bool is_system_key; | 
| 4576 string16 unmodified_text, text; | 4664 string16 unmodified_text, text; | 
| 4577 std::string key_identifier; | 4665 std::string key_identifier; | 
| 4578 NativeWebKeyboardEvent event; | 4666 NativeWebKeyboardEvent event; | 
| 4579 if (!args->GetInteger("type", &type)) { | 4667 if (!args->GetInteger("type", &type)) { | 
| 4580 AutomationJSONReply reply(this, reply_message); | 4668 AutomationJSONReply reply(this, reply_message); | 
| 4581 reply.SendError("'type' missing or invalid."); | 4669 reply.SendError("'type' missing or invalid."); | 
| 4582 return; | 4670 return; | 
| 4583 } | 4671 } | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4649 event.modifiers |= WebKit::WebInputEvent::ControlKey; | 4737 event.modifiers |= WebKit::WebInputEvent::ControlKey; | 
| 4650 if (modifiers & automation::kAltKeyMask) | 4738 if (modifiers & automation::kAltKeyMask) | 
| 4651 event.modifiers |= WebKit::WebInputEvent::AltKey; | 4739 event.modifiers |= WebKit::WebInputEvent::AltKey; | 
| 4652 if (modifiers & automation::kMetaKeyMask) | 4740 if (modifiers & automation::kMetaKeyMask) | 
| 4653 event.modifiers |= WebKit::WebInputEvent::MetaKey; | 4741 event.modifiers |= WebKit::WebInputEvent::MetaKey; | 
| 4654 | 4742 | 
| 4655 event.isSystemKey = is_system_key; | 4743 event.isSystemKey = is_system_key; | 
| 4656 event.timeStampSeconds = base::Time::Now().ToDoubleT(); | 4744 event.timeStampSeconds = base::Time::Now().ToDoubleT(); | 
| 4657 event.skip_in_browser = true; | 4745 event.skip_in_browser = true; | 
| 4658 new InputEventAckNotificationObserver(this, reply_message, event.type); | 4746 new InputEventAckNotificationObserver(this, reply_message, event.type); | 
| 4659 browser->GetSelectedTabContents()->render_view_host()-> | 4747 tab_contents->render_view_host()->ForwardKeyboardEvent(event); | 
| 4660 ForwardKeyboardEvent(event); | |
| 4661 } | 4748 } | 
| 4662 | 4749 | 
| 4663 // Sample JSON input: { "command": "GetNTPThumbnailMode" } | 4750 // Sample JSON input: { "command": "GetNTPThumbnailMode" } | 
| 4664 // For output, refer to GetNTPThumbnailMode() in | 4751 // For output, refer to GetNTPThumbnailMode() in | 
| 4665 // chrome/test/pyautolib/pyauto.py. | 4752 // chrome/test/pyautolib/pyauto.py. | 
| 4666 void TestingAutomationProvider::GetNTPThumbnailMode( | 4753 void TestingAutomationProvider::GetNTPThumbnailMode( | 
| 4667 Browser* browser, | 4754 Browser* browser, | 
| 4668 DictionaryValue* args, | 4755 DictionaryValue* args, | 
| 4669 IPC::Message* reply_message) { | 4756 IPC::Message* reply_message) { | 
| 4670 const int shown_sections = ShownSectionsHandler::GetShownSections( | 4757 const int shown_sections = ShownSectionsHandler::GetShownSections( | 
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4795 void TestingAutomationProvider::WaitForAllTabsToStopLoading( | 4882 void TestingAutomationProvider::WaitForAllTabsToStopLoading( | 
| 4796 DictionaryValue* args, | 4883 DictionaryValue* args, | 
| 4797 IPC::Message* reply_message) { | 4884 IPC::Message* reply_message) { | 
| 4798 new AllTabsStoppedLoadingObserver(this, reply_message); | 4885 new AllTabsStoppedLoadingObserver(this, reply_message); | 
| 4799 } | 4886 } | 
| 4800 | 4887 | 
| 4801 void TestingAutomationProvider::GetIndicesFromTab( | 4888 void TestingAutomationProvider::GetIndicesFromTab( | 
| 4802 DictionaryValue* args, | 4889 DictionaryValue* args, | 
| 4803 IPC::Message* reply_message) { | 4890 IPC::Message* reply_message) { | 
| 4804 AutomationJSONReply reply(this, reply_message); | 4891 AutomationJSONReply reply(this, reply_message); | 
| 4805 int tab_handle = 0; | 4892 int id_or_handle = 0; | 
| 4806 if (!args->GetInteger("tab_handle", &tab_handle) || | 4893 bool has_id = args->HasKey("tab_id"); | 
| 4807 !tab_tracker_->ContainsHandle(tab_handle)) { | 4894 bool has_handle = args->HasKey("tab_handle"); | 
| 4808 reply.SendError("'tab_handle' missing or invalid"); | 4895 if (!(has_id ^ has_handle)) { | 
| 
 
Paweł Hajdan Jr.
2011/03/05 11:44:56
Oh, that looks complicated. Why is it needed (the
 
kkania
2011/03/07 04:31:51
ok, i wrote it in simpler language
 
 | |
| 4896 reply.SendError("Either 'tab_id' or 'tab_handle' must be supplied"); | |
| 4809 return; | 4897 return; | 
| 4810 } | 4898 } | 
| 4811 NavigationController* controller = tab_tracker_->GetResource(tab_handle); | 4899 if (has_id && !args->GetInteger("tab_id", &id_or_handle)) { | 
| 4900 reply.SendError("'tab_id' is invalid"); | |
| 4901 } | |
| 4902 if (has_handle && (!args->GetInteger("tab_handle", &id_or_handle) || | |
| 4903 !tab_tracker_->ContainsHandle(id_or_handle))) { | |
| 4904 reply.SendError("'tab_handle' is invalid"); | |
| 4905 return; | |
| 4906 } | |
| 4907 int id = id_or_handle; | |
| 4908 if (has_handle) | |
| 4909 id = tab_tracker_->GetResource(id_or_handle)->session_id().id(); | |
| 4812 BrowserList::const_iterator iter = BrowserList::begin(); | 4910 BrowserList::const_iterator iter = BrowserList::begin(); | 
| 4813 int browser_index = 0; | 4911 int browser_index = 0; | 
| 4814 for (; iter != BrowserList::end(); ++iter, ++browser_index) { | 4912 for (; iter != BrowserList::end(); ++iter, ++browser_index) { | 
| 4815 Browser* browser = *iter; | 4913 Browser* browser = *iter; | 
| 4816 for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { | 4914 for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { | 
| 4817 if (browser->GetTabContentsAt(tab_index) == controller->tab_contents()) { | 4915 TabContents* tab = browser->GetTabContentsAt(tab_index); | 
| 4916 if (tab->controller().session_id().id() == id) { | |
| 4818 DictionaryValue dict; | 4917 DictionaryValue dict; | 
| 4819 dict.SetInteger("windex", browser_index); | 4918 dict.SetInteger("windex", browser_index); | 
| 4820 dict.SetInteger("tab_index", tab_index); | 4919 dict.SetInteger("tab_index", tab_index); | 
| 4821 reply.SendSuccess(&dict); | 4920 reply.SendSuccess(&dict); | 
| 4822 return; | 4921 return; | 
| 4823 } | 4922 } | 
| 4824 } | 4923 } | 
| 4825 } | 4924 } | 
| 4826 reply.SendError("Could not find tab among current browser windows"); | 4925 reply.SendError("Could not find tab among current browser windows"); | 
| 4827 } | 4926 } | 
| (...skipping 30 matching lines...) Expand all Loading... | |
| 4858 .SendError("Cannot locate tab or browser to navigate"); | 4957 .SendError("Cannot locate tab or browser to navigate"); | 
| 4859 return; | 4958 return; | 
| 4860 } | 4959 } | 
| 4861 new NavigationNotificationObserver( | 4960 new NavigationNotificationObserver( | 
| 4862 &tab_contents->controller(), this, reply_message, | 4961 &tab_contents->controller(), this, reply_message, | 
| 4863 navigation_count, false, true); | 4962 navigation_count, false, true); | 
| 4864 browser->OpenURLFromTab( | 4963 browser->OpenURLFromTab( | 
| 4865 tab_contents, GURL(url), GURL(), CURRENT_TAB, PageTransition::TYPED); | 4964 tab_contents, GURL(url), GURL(), CURRENT_TAB, PageTransition::TYPED); | 
| 4866 } | 4965 } | 
| 4867 | 4966 | 
| 4967 void TestingAutomationProvider::ExecuteJavascriptJSON( | |
| 4968 DictionaryValue* args, | |
| 4969 IPC::Message* reply_message) { | |
| 4970 int browser_index = 0, tab_index = 0; | |
| 4971 string16 frame_xpath, javascript; | |
| 4972 if (!args->GetInteger("windex", &browser_index)) { | |
| 4973 AutomationJSONReply(this, reply_message) | |
| 4974 .SendError("'windex' missing or invalid"); | |
| 4975 return; | |
| 4976 } | |
| 4977 if (!args->GetInteger("tab_index", &tab_index)) { | |
| 4978 AutomationJSONReply(this, reply_message) | |
| 4979 .SendError("'tab_index' missing or invalid"); | |
| 4980 return; | |
| 4981 } | |
| 4982 if (!args->GetString("frame_xpath", &frame_xpath)) { | |
| 4983 AutomationJSONReply(this, reply_message) | |
| 4984 .SendError("'frame_xpath' missing or invalid"); | |
| 4985 return; | |
| 4986 } | |
| 4987 if (!args->GetString("javascript", &javascript)) { | |
| 4988 AutomationJSONReply(this, reply_message) | |
| 4989 .SendError("'javascript' missing or invalid"); | |
| 4990 return; | |
| 4991 } | |
| 4992 Browser* browser = GetBrowserAt(browser_index); | |
| 4993 TabContents* tab_contents = GetTabContentsAt(browser_index, tab_index); | |
| 4994 if (!browser || !tab_contents) { | |
| 4995 AutomationJSONReply(this, reply_message) | |
| 4996 .SendError("Cannot locate tab or browser to navigate"); | |
| 4997 return; | |
| 4998 } | |
| 4999 | |
| 5000 // Set the routing id of this message with the controller. | |
| 5001 // This routing id needs to be remembered for the reverse | |
| 5002 // communication while sending back the response of | |
| 5003 // this javascript execution. | |
| 5004 std::string set_automation_id; | |
| 5005 base::SStringPrintf(&set_automation_id, | |
| 5006 "window.domAutomationController.setAutomationId(%d);", | |
| 5007 reply_message->routing_id()); | |
| 5008 | |
| 5009 new ExecuteJavascriptObserver(this, reply_message); | |
| 5010 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( | |
| 5011 frame_xpath, UTF8ToUTF16(set_automation_id)); | |
| 5012 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( | |
| 5013 frame_xpath, javascript); | |
| 5014 } | |
| 5015 | |
| 5016 void TestingAutomationProvider::GoForward( | |
| 5017 DictionaryValue* args, | |
| 5018 IPC::Message* reply_message) { | |
| 5019 TabContents* tab_contents; | |
| 5020 std::string error; | |
| 5021 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 5022 AutomationJSONReply(this, reply_message).SendError(error); | |
| 5023 return; | |
| 5024 } | |
| 5025 NavigationController& controller = tab_contents->controller(); | |
| 5026 if (!controller.CanGoForward()) { | |
| 5027 DictionaryValue dict; | |
| 5028 dict.SetBoolean("did_go_forward", false); | |
| 5029 AutomationJSONReply(this, reply_message).SendSuccess(&dict); | |
| 5030 return; | |
| 5031 } | |
| 5032 new NavigationNotificationObserver(&controller, this, reply_message, | |
| 5033 1, false, true); | |
| 5034 controller.GoForward(); | |
| 5035 } | |
| 5036 | |
| 5037 void TestingAutomationProvider::GoBack( | |
| 5038 DictionaryValue* args, | |
| 5039 IPC::Message* reply_message) { | |
| 5040 TabContents* tab_contents; | |
| 5041 std::string error; | |
| 5042 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 5043 AutomationJSONReply(this, reply_message).SendError(error); | |
| 5044 return; | |
| 5045 } | |
| 5046 NavigationController& controller = tab_contents->controller(); | |
| 5047 if (!controller.CanGoBack()) { | |
| 5048 DictionaryValue dict; | |
| 5049 dict.SetBoolean("did_go_back", false); | |
| 5050 AutomationJSONReply(this, reply_message).SendSuccess(&dict); | |
| 5051 return; | |
| 5052 } | |
| 5053 new NavigationNotificationObserver(&controller, this, reply_message, | |
| 5054 1, false, true); | |
| 5055 controller.GoBack(); | |
| 5056 } | |
| 5057 | |
| 5058 void TestingAutomationProvider::ReloadJSON( | |
| 5059 DictionaryValue* args, | |
| 5060 IPC::Message* reply_message) { | |
| 5061 TabContents* tab_contents; | |
| 5062 std::string error; | |
| 5063 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 5064 AutomationJSONReply(this, reply_message).SendError(error); | |
| 5065 return; | |
| 5066 } | |
| 5067 NavigationController& controller = tab_contents->controller(); | |
| 5068 new NavigationNotificationObserver(&controller, this, reply_message, | |
| 5069 1, false, true); | |
| 5070 controller.Reload(false); | |
| 5071 } | |
| 5072 | |
| 5073 void TestingAutomationProvider::GetTabURLJSON( | |
| 5074 DictionaryValue* args, | |
| 5075 IPC::Message* reply_message) { | |
| 5076 AutomationJSONReply reply(this, reply_message); | |
| 5077 TabContents* tab_contents; | |
| 5078 std::string error; | |
| 5079 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 5080 reply.SendError(error); | |
| 5081 return; | |
| 5082 } | |
| 5083 DictionaryValue dict; | |
| 5084 dict.SetString("url", tab_contents->GetURL().possibly_invalid_spec()); | |
| 5085 reply.SendSuccess(&dict); | |
| 5086 } | |
| 5087 | |
| 5088 void TestingAutomationProvider::GetTabTitleJSON( | |
| 5089 DictionaryValue* args, | |
| 5090 IPC::Message* reply_message) { | |
| 5091 AutomationJSONReply reply(this, reply_message); | |
| 5092 TabContents* tab_contents; | |
| 5093 std::string error; | |
| 5094 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 5095 reply.SendError(error); | |
| 5096 return; | |
| 5097 } | |
| 5098 DictionaryValue dict; | |
| 5099 dict.SetString("title", tab_contents->GetTitle()); | |
| 5100 reply.SendSuccess(&dict); | |
| 5101 } | |
| 5102 | |
| 5103 void TestingAutomationProvider::GetCookiesJSON( | |
| 
 
Paweł Hajdan Jr.
2011/03/05 11:44:56
I'm pretty sure this JSON cookie code duplicates s
 
kkania
2011/03/07 04:31:51
Yes, it does. Although really the only thing that
 
Paweł Hajdan Jr.
2011/03/07 21:03:39
The migration may be non-trivial, and I may have m
 
 | |
| 5104 DictionaryValue* args, IPC::Message* reply_message) { | |
| 5105 AutomationJSONReply reply(this, reply_message); | |
| 5106 Browser* browser; | |
| 5107 std::string error; | |
| 5108 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | |
| 5109 reply.SendError(error); | |
| 5110 return; | |
| 5111 } | |
| 5112 std::string url; | |
| 5113 if (!args->GetString("url", &url)) { | |
| 5114 AutomationJSONReply(this, reply_message) | |
| 5115 .SendError("'url' missing or invalid"); | |
| 5116 return; | |
| 5117 } | |
| 5118 | |
| 5119 // Since we are running on the UI thread don't call GetURLRequestContext(). | |
| 5120 scoped_refptr<URLRequestContextGetter> context_getter = | |
| 5121 browser->profile()->GetRequestContext(); | |
| 5122 | |
| 5123 std::string cookies; | |
| 5124 base::WaitableEvent event(true /* manual reset */, | |
| 5125 false /* not initially signaled */); | |
| 5126 Task* task = NewRunnableFunction( | |
| 5127 &GetCookiesOnIOThread, | |
| 5128 GURL(url), context_getter, &event, &cookies); | |
| 5129 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | |
| 5130 reply.SendError("Couldn't post task to get the cookies"); | |
| 5131 return; | |
| 5132 } | |
| 5133 event.Wait(); | |
| 5134 | |
| 5135 DictionaryValue dict; | |
| 5136 dict.SetString("cookies", cookies); | |
| 5137 reply.SendSuccess(&dict); | |
| 5138 } | |
| 5139 | |
| 5140 void TestingAutomationProvider::DeleteCookieJSON( | |
| 5141 DictionaryValue* args, IPC::Message* reply_message) { | |
| 5142 AutomationJSONReply reply(this, reply_message); | |
| 5143 Browser* browser; | |
| 5144 std::string error; | |
| 5145 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | |
| 5146 reply.SendError(error); | |
| 5147 return; | |
| 5148 } | |
| 5149 std::string url, name; | |
| 5150 if (!args->GetString("url", &url)) { | |
| 5151 AutomationJSONReply(this, reply_message) | |
| 5152 .SendError("'url' missing or invalid"); | |
| 5153 return; | |
| 5154 } | |
| 5155 if (!args->GetString("name", &name)) { | |
| 5156 AutomationJSONReply(this, reply_message) | |
| 5157 .SendError("'name' missing or invalid"); | |
| 5158 return; | |
| 5159 } | |
| 5160 | |
| 5161 // Since we are running on the UI thread don't call GetURLRequestContext(). | |
| 5162 scoped_refptr<URLRequestContextGetter> context_getter = | |
| 5163 browser->profile()->GetRequestContext(); | |
| 5164 | |
| 5165 base::WaitableEvent event(true /* manual reset */, | |
| 5166 false /* not initially signaled */); | |
| 5167 Task* task = NewRunnableFunction( | |
| 5168 &DeleteCookieOnIOThread, | |
| 5169 GURL(url), name, context_getter, &event); | |
| 5170 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | |
| 5171 reply.SendError("Couldn't post task to delete the cookie"); | |
| 5172 return; | |
| 5173 } | |
| 5174 event.Wait(); | |
| 5175 reply.SendSuccess(NULL); | |
| 5176 } | |
| 5177 | |
| 5178 void TestingAutomationProvider::SetCookieJSON( | |
| 5179 DictionaryValue* args, IPC::Message* reply_message) { | |
| 5180 AutomationJSONReply reply(this, reply_message); | |
| 5181 Browser* browser; | |
| 5182 std::string error; | |
| 5183 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | |
| 5184 reply.SendError(error); | |
| 5185 return; | |
| 5186 } | |
| 5187 std::string url, cookie; | |
| 5188 if (!args->GetString("url", &url)) { | |
| 5189 AutomationJSONReply(this, reply_message) | |
| 5190 .SendError("'url' missing or invalid"); | |
| 5191 return; | |
| 5192 } | |
| 5193 if (!args->GetString("cookie", &cookie)) { | |
| 5194 AutomationJSONReply(this, reply_message) | |
| 5195 .SendError("'cookie' missing or invalid"); | |
| 5196 return; | |
| 5197 } | |
| 5198 | |
| 5199 // Since we are running on the UI thread don't call GetURLRequestContext(). | |
| 5200 scoped_refptr<URLRequestContextGetter> context_getter = | |
| 5201 browser->profile()->GetRequestContext(); | |
| 5202 | |
| 5203 base::WaitableEvent event(true /* manual reset */, | |
| 5204 false /* not initially signaled */); | |
| 5205 bool success = false; | |
| 5206 Task* task = NewRunnableFunction( | |
| 5207 &SetCookieOnIOThread, | |
| 5208 GURL(url), cookie, context_getter, &event, &success); | |
| 5209 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | |
| 5210 reply.SendError("Couldn't post task to set the cookie"); | |
| 5211 return; | |
| 5212 } | |
| 5213 event.Wait(); | |
| 5214 | |
| 5215 if (!success) { | |
| 5216 reply.SendError("Could not set the cookie"); | |
| 5217 return; | |
| 5218 } | |
| 5219 reply.SendSuccess(NULL); | |
| 5220 } | |
| 5221 | |
| 5222 void TestingAutomationProvider::GetTabIds( | |
| 5223 DictionaryValue* args, IPC::Message* reply_message) { | |
| 5224 ListValue* id_list = new ListValue(); | |
| 5225 BrowserList::const_iterator iter = BrowserList::begin(); | |
| 5226 for (; iter != BrowserList::end(); ++iter) { | |
| 5227 Browser* browser = *iter; | |
| 5228 for (int i = 0; i < browser->tab_count(); ++i) { | |
| 5229 int id = browser->GetTabContentsAt(i)->controller().session_id().id(); | |
| 5230 id_list->Append(Value::CreateIntegerValue(id)); | |
| 5231 } | |
| 5232 } | |
| 5233 DictionaryValue dict; | |
| 5234 dict.Set("ids", id_list); | |
| 5235 AutomationJSONReply(this, reply_message).SendSuccess(&dict); | |
| 5236 } | |
| 5237 | |
| 5238 void TestingAutomationProvider::IsTabIdValid( | |
| 5239 DictionaryValue* args, IPC::Message* reply_message) { | |
| 5240 AutomationJSONReply reply(this, reply_message); | |
| 5241 int id; | |
| 5242 if (!args->GetInteger("id", &id)) { | |
| 5243 reply.SendError("'id' missing or invalid"); | |
| 5244 return; | |
| 5245 } | |
| 5246 bool is_valid = false; | |
| 5247 BrowserList::const_iterator iter = BrowserList::begin(); | |
| 5248 for (; iter != BrowserList::end(); ++iter) { | |
| 5249 Browser* browser = *iter; | |
| 5250 for (int i = 0; i < browser->tab_count(); ++i) { | |
| 5251 TabContents* tab = browser->GetTabContentsAt(i); | |
| 5252 if (tab->controller().session_id().id() == id) { | |
| 5253 is_valid = true; | |
| 5254 break; | |
| 5255 } | |
| 5256 } | |
| 5257 } | |
| 5258 DictionaryValue dict; | |
| 5259 dict.SetBoolean("is_valid", is_valid); | |
| 5260 reply.SendSuccess(&dict); | |
| 5261 } | |
| 5262 | |
| 5263 void TestingAutomationProvider::CloseTabJSON( | |
| 5264 DictionaryValue* args, IPC::Message* reply_message) { | |
| 5265 AutomationJSONReply reply(this, reply_message); | |
| 5266 Browser* browser; | |
| 5267 TabContents* tab_contents; | |
| 5268 std::string error; | |
| 5269 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab_contents, &error)) { | |
| 5270 reply.SendError(error); | |
| 5271 return; | |
| 5272 } | |
| 5273 browser->CloseTabContents(tab_contents); | |
| 5274 reply.SendSuccess(NULL); | |
| 5275 } | |
| 5276 | |
| 5277 void TestingAutomationProvider::ActivateTabJSON( | |
| 5278 DictionaryValue* args, | |
| 5279 IPC::Message* reply_message) { | |
| 5280 AutomationJSONReply reply(this, reply_message); | |
| 5281 Browser* browser; | |
| 5282 TabContents* tab_contents; | |
| 5283 std::string error; | |
| 5284 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab_contents, &error)) { | |
| 5285 reply.SendError(error); | |
| 5286 return; | |
| 5287 } | |
| 5288 browser->SelectTabContentsAt( | |
| 5289 browser->GetIndexOfController(&tab_contents->controller()), true); | |
| 5290 reply.SendSuccess(NULL); | |
| 5291 } | |
| 5292 | |
| 4868 void TestingAutomationProvider::WaitForTabCountToBecome( | 5293 void TestingAutomationProvider::WaitForTabCountToBecome( | 
| 4869 int browser_handle, | 5294 int browser_handle, | 
| 4870 int target_tab_count, | 5295 int target_tab_count, | 
| 4871 IPC::Message* reply_message) { | 5296 IPC::Message* reply_message) { | 
| 4872 if (!browser_tracker_->ContainsHandle(browser_handle)) { | 5297 if (!browser_tracker_->ContainsHandle(browser_handle)) { | 
| 4873 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message, | 5298 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message, | 
| 4874 false); | 5299 false); | 
| 4875 Send(reply_message); | 5300 Send(reply_message); | 
| 4876 return; | 5301 return; | 
| 4877 } | 5302 } | 
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5023 // If you change this, update Observer for NotificationType::SESSION_END | 5448 // If you change this, update Observer for NotificationType::SESSION_END | 
| 5024 // below. | 5449 // below. | 
| 5025 MessageLoop::current()->PostTask(FROM_HERE, | 5450 MessageLoop::current()->PostTask(FROM_HERE, | 
| 5026 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5451 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 
| 5027 } | 5452 } | 
| 5028 } | 5453 } | 
| 5029 | 5454 | 
| 5030 void TestingAutomationProvider::OnRemoveProvider() { | 5455 void TestingAutomationProvider::OnRemoveProvider() { | 
| 5031 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5456 AutomationProviderList::GetInstance()->RemoveProvider(this); | 
| 5032 } | 5457 } | 
| OLD | NEW |