| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 144   } | 144   } | 
| 145 | 145 | 
| 146   virtual std::string GetHTMLContents() { return contents_; } | 146   virtual std::string GetHTMLContents() { return contents_; } | 
| 147 | 147 | 
| 148  private: | 148  private: | 
| 149   const std::string contents_; | 149   const std::string contents_; | 
| 150 | 150 | 
| 151   DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); | 151   DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); | 
| 152 }; | 152 }; | 
| 153 | 153 | 
| 154 Browser* GetBrowserAt(int index) { |  | 
| 155   if (index < 0) |  | 
| 156     return NULL; |  | 
| 157   BrowserList::const_iterator iter = BrowserList::begin(); |  | 
| 158   for (; (iter != BrowserList::end()) && (index > 0); ++iter, --index) {} |  | 
| 159   if (iter == BrowserList::end()) |  | 
| 160     return NULL; |  | 
| 161   return *iter; |  | 
| 162 } |  | 
| 163 |  | 
| 164 TabContents* GetTabContentsAt(int browser_index, int tab_index) { |  | 
| 165   if (tab_index < 0) |  | 
| 166     return NULL; |  | 
| 167   Browser* browser = GetBrowserAt(browser_index); |  | 
| 168   if (!browser || tab_index >= browser->tab_count()) |  | 
| 169     return NULL; |  | 
| 170   return browser->GetTabContentsAt(tab_index); |  | 
| 171 } |  | 
| 172 |  | 
| 173 }  // namespace | 154 }  // namespace | 
| 174 | 155 | 
| 175 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) | 156 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) | 
| 176     : AutomationProvider(profile), | 157     : AutomationProvider(profile), | 
| 177 #if defined(TOOLKIT_VIEWS) | 158 #if defined(TOOLKIT_VIEWS) | 
| 178       popup_menu_waiter_(NULL), | 159       popup_menu_waiter_(NULL), | 
| 179 #endif | 160 #endif | 
| 180       redirect_query_(0) { | 161       redirect_query_(0) { | 
| 181   BrowserList::AddObserver(this); | 162   BrowserList::AddObserver(this); | 
| 182   registrar_.Add(this, NotificationType::SESSION_END, | 163   registrar_.Add(this, NotificationType::SESSION_END, | 
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 768   *window_count = static_cast<int>(BrowserList::size()); | 749   *window_count = static_cast<int>(BrowserList::size()); | 
| 769 } | 750 } | 
| 770 | 751 | 
| 771 void TestingAutomationProvider::GetNormalBrowserWindowCount(int* window_count) { | 752 void TestingAutomationProvider::GetNormalBrowserWindowCount(int* window_count) { | 
| 772   *window_count = static_cast<int>( | 753   *window_count = static_cast<int>( | 
| 773       BrowserList::GetBrowserCountForType(profile_, Browser::TYPE_NORMAL)); | 754       BrowserList::GetBrowserCountForType(profile_, Browser::TYPE_NORMAL)); | 
| 774 } | 755 } | 
| 775 | 756 | 
| 776 void TestingAutomationProvider::GetBrowserWindow(int index, int* handle) { | 757 void TestingAutomationProvider::GetBrowserWindow(int index, int* handle) { | 
| 777   *handle = 0; | 758   *handle = 0; | 
| 778   Browser* browser = GetBrowserAt(index); | 759   if (index >= 0 && index < static_cast<int>(BrowserList::size())) | 
| 779   if (browser) | 760     *handle = browser_tracker_->Add(*(BrowserList::begin() + index)); | 
| 780     *handle = browser_tracker_->Add(browser); |  | 
| 781 } | 761 } | 
| 782 | 762 | 
| 783 void TestingAutomationProvider::FindNormalBrowserWindow(int* handle) { | 763 void TestingAutomationProvider::FindNormalBrowserWindow(int* handle) { | 
| 784   *handle = 0; | 764   *handle = 0; | 
| 785   Browser* browser = BrowserList::FindBrowserWithType(profile_, | 765   Browser* browser = BrowserList::FindBrowserWithType(profile_, | 
| 786                                                       Browser::TYPE_NORMAL, | 766                                                       Browser::TYPE_NORMAL, | 
| 787                                                       false); | 767                                                       false); | 
| 788   if (browser) | 768   if (browser) | 
| 789     *handle = browser_tracker_->Add(browser); | 769     *handle = browser_tracker_->Add(browser); | 
| 790 } | 770 } | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 906                             ((flags & ui::EF_CONTROL_DOWN) == | 886                             ((flags & ui::EF_CONTROL_DOWN) == | 
| 907                              ui::EF_CONTROL_DOWN), | 887                              ui::EF_CONTROL_DOWN), | 
| 908                             ((flags & ui::EF_SHIFT_DOWN) == | 888                             ((flags & ui::EF_SHIFT_DOWN) == | 
| 909                              ui::EF_SHIFT_DOWN), | 889                              ui::EF_SHIFT_DOWN), | 
| 910                             ((flags & ui::EF_ALT_DOWN) == | 890                             ((flags & ui::EF_ALT_DOWN) == | 
| 911                              ui::EF_ALT_DOWN), | 891                              ui::EF_ALT_DOWN), | 
| 912                             ((flags & ui::EF_COMMAND_DOWN) == | 892                             ((flags & ui::EF_COMMAND_DOWN) == | 
| 913                              ui::EF_COMMAND_DOWN)); | 893                              ui::EF_COMMAND_DOWN)); | 
| 914 } | 894 } | 
| 915 | 895 | 
| 916 void TestingAutomationProvider::WebkitMouseClick(Browser* browser, | 896 void TestingAutomationProvider::WebkitMouseClick(DictionaryValue* args, | 
| 917                                                  DictionaryValue* args, |  | 
| 918                                                  IPC::Message* reply_message) { | 897                                                  IPC::Message* reply_message) { | 
|  | 898   TabContents* tab_contents; | 
|  | 899   std::string error; | 
|  | 900   if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 
|  | 901     AutomationJSONReply(this, reply_message).SendError(error); | 
|  | 902     return; | 
|  | 903   } | 
|  | 904 | 
| 919   WebKit::WebMouseEvent mouse_event; | 905   WebKit::WebMouseEvent mouse_event; | 
| 920 |  | 
| 921   if (!args->GetInteger("x", &mouse_event.x) || | 906   if (!args->GetInteger("x", &mouse_event.x) || | 
| 922       !args->GetInteger("y", &mouse_event.y)) { | 907       !args->GetInteger("y", &mouse_event.y)) { | 
| 923     AutomationJSONReply(this, reply_message) | 908     AutomationJSONReply(this, reply_message) | 
| 924         .SendError("(X,Y) coordinates missing or invalid"); | 909         .SendError("(X,Y) coordinates missing or invalid"); | 
| 925     return; | 910     return; | 
| 926   } | 911   } | 
| 927 | 912 | 
| 928   int button_flags; | 913   int button; | 
| 929   if (!args->GetInteger("button_flags", &button_flags)) { | 914   if (!args->GetInteger("button", &button)) { | 
| 930     AutomationJSONReply(this, reply_message) | 915     AutomationJSONReply(this, reply_message) | 
| 931         .SendError("Mouse button missing or invalid"); | 916         .SendError("Mouse button missing or invalid"); | 
| 932     return; | 917     return; | 
| 933   } | 918   } | 
| 934 | 919   if (button == automation::kLeftButton) { | 
| 935   if (button_flags == ui::EF_LEFT_BUTTON_DOWN) { |  | 
| 936     mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 920     mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 
| 937   } else if (button_flags == ui::EF_RIGHT_BUTTON_DOWN) { | 921   } else if (button == automation::kRightButton) { | 
| 938     mouse_event.button = WebKit::WebMouseEvent::ButtonRight; | 922     mouse_event.button = WebKit::WebMouseEvent::ButtonRight; | 
| 939   } else if (button_flags == ui::EF_MIDDLE_BUTTON_DOWN) { | 923   } else if (button == automation::kMiddleButton) { | 
| 940     mouse_event.button = WebKit::WebMouseEvent::ButtonMiddle; | 924     mouse_event.button = WebKit::WebMouseEvent::ButtonMiddle; | 
| 941   } else { | 925   } else { | 
| 942     AutomationJSONReply(this, reply_message) | 926     AutomationJSONReply(this, reply_message) | 
| 943         .SendError("Invalid button press requested"); | 927         .SendError("Invalid button press requested"); | 
| 944     return; | 928     return; | 
| 945   } | 929   } | 
| 946 | 930 | 
| 947   TabContents* tab_contents = browser->GetSelectedTabContents(); |  | 
| 948   mouse_event.type = WebKit::WebInputEvent::MouseDown; | 931   mouse_event.type = WebKit::WebInputEvent::MouseDown; | 
| 949   mouse_event.clickCount = 1; | 932   mouse_event.clickCount = 1; | 
| 950 | 933 | 
| 951   tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 934   tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 
| 952 | 935 | 
| 953   mouse_event.type = WebKit::WebInputEvent::MouseUp; | 936   mouse_event.type = WebKit::WebInputEvent::MouseUp; | 
| 954   new InputEventAckNotificationObserver(this, reply_message, mouse_event.type); | 937   new InputEventAckNotificationObserver(this, reply_message, mouse_event.type); | 
| 955   tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 938   tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 
| 956 } | 939 } | 
| 957 | 940 | 
| 958 void TestingAutomationProvider::WebkitMouseMove(Browser* browser, | 941 void TestingAutomationProvider::WebkitMouseMove( | 
| 959                                                 DictionaryValue* args, | 942     DictionaryValue* args, IPC::Message* reply_message) { | 
| 960                                                 IPC::Message* reply_message) { | 943   TabContents* tab_contents; | 
|  | 944   std::string error; | 
|  | 945   if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 
|  | 946     AutomationJSONReply(this, reply_message).SendError(error); | 
|  | 947     return; | 
|  | 948   } | 
|  | 949 | 
| 961   WebKit::WebMouseEvent mouse_event; | 950   WebKit::WebMouseEvent mouse_event; | 
| 962 |  | 
| 963   if (!args->GetInteger("x", &mouse_event.x) || | 951   if (!args->GetInteger("x", &mouse_event.x) || | 
| 964       !args->GetInteger("y", &mouse_event.y)) { | 952       !args->GetInteger("y", &mouse_event.y)) { | 
| 965     AutomationJSONReply(this, reply_message) | 953     AutomationJSONReply(this, reply_message) | 
| 966         .SendError("(X,Y) coordinates missing or invalid"); | 954         .SendError("(X,Y) coordinates missing or invalid"); | 
| 967     return; | 955     return; | 
| 968   } | 956   } | 
| 969 | 957 | 
| 970   TabContents* tab_contents = browser->GetSelectedTabContents(); |  | 
| 971   mouse_event.type = WebKit::WebInputEvent::MouseMove; | 958   mouse_event.type = WebKit::WebInputEvent::MouseMove; | 
| 972   new InputEventAckNotificationObserver(this, reply_message, mouse_event.type); | 959   new InputEventAckNotificationObserver(this, reply_message, mouse_event.type); | 
| 973   tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 960   tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 
| 974 } | 961 } | 
| 975 | 962 | 
| 976 void TestingAutomationProvider::WebkitMouseDrag(Browser* browser, | 963 void TestingAutomationProvider::WebkitMouseDrag(DictionaryValue* args, | 
| 977                                                 DictionaryValue* args, |  | 
| 978                                                 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 | 
| 979   WebKit::WebMouseEvent mouse_event; | 972   WebKit::WebMouseEvent mouse_event; | 
| 980   int start_x, start_y, end_x, end_y; | 973   int start_x, start_y, end_x, end_y; | 
| 981 |  | 
| 982   if (!args->GetInteger("start_x", &start_x) || | 974   if (!args->GetInteger("start_x", &start_x) || | 
| 983       !args->GetInteger("start_y", &start_y) || | 975       !args->GetInteger("start_y", &start_y) || | 
| 984       !args->GetInteger("end_x", &end_x) || | 976       !args->GetInteger("end_x", &end_x) || | 
| 985       !args->GetInteger("end_y", &end_y)) { | 977       !args->GetInteger("end_y", &end_y)) { | 
| 986     AutomationJSONReply(this, reply_message) | 978     AutomationJSONReply(this, reply_message) | 
| 987         .SendError("Invalid start/end positions"); | 979         .SendError("Invalid start/end positions"); | 
| 988     return; | 980     return; | 
| 989   } | 981   } | 
| 990 | 982 | 
| 991   mouse_event.type = WebKit::WebInputEvent::MouseMove; | 983   mouse_event.type = WebKit::WebInputEvent::MouseMove; | 
| 992   TabContents* tab_contents = browser->GetSelectedTabContents(); |  | 
| 993   // Step 1- Move the mouse to the start position. | 984   // Step 1- Move the mouse to the start position. | 
| 994   mouse_event.x = start_x; | 985   mouse_event.x = start_x; | 
| 995   mouse_event.y = start_y; | 986   mouse_event.y = start_y; | 
| 996   tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 987   tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 
| 997 | 988 | 
| 998   // Step 2- Left click mouse down, the mouse button is fixed. | 989   // Step 2- Left click mouse down, the mouse button is fixed. | 
| 999   mouse_event.type = WebKit::WebInputEvent::MouseDown; | 990   mouse_event.type = WebKit::WebInputEvent::MouseDown; | 
| 1000   mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 991   mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 
| 1001   mouse_event.clickCount = 1; | 992   mouse_event.clickCount = 1; | 
| 1002   tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 993   tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 
| (...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2111   } | 2102   } | 
| 2112 | 2103 | 
| 2113   // Map json commands to their handlers. | 2104   // Map json commands to their handlers. | 
| 2114   std::map<std::string, JsonHandler> handler_map; | 2105   std::map<std::string, JsonHandler> handler_map; | 
| 2115   handler_map["WaitForAllTabsToStopLoading"] = | 2106   handler_map["WaitForAllTabsToStopLoading"] = | 
| 2116       &TestingAutomationProvider::WaitForAllTabsToStopLoading; | 2107       &TestingAutomationProvider::WaitForAllTabsToStopLoading; | 
| 2117   handler_map["GetIndicesFromTab"] = | 2108   handler_map["GetIndicesFromTab"] = | 
| 2118       &TestingAutomationProvider::GetIndicesFromTab; | 2109       &TestingAutomationProvider::GetIndicesFromTab; | 
| 2119   handler_map["NavigateToURL"] = | 2110   handler_map["NavigateToURL"] = | 
| 2120       &TestingAutomationProvider::NavigateToURL; | 2111       &TestingAutomationProvider::NavigateToURL; | 
|  | 2112   handler_map["ExecuteJavascript"] = | 
|  | 2113       &TestingAutomationProvider::ExecuteJavascriptJSON; | 
|  | 2114   handler_map["GoForward"] = | 
|  | 2115       &TestingAutomationProvider::GoForward; | 
|  | 2116   handler_map["GoBack"] = | 
|  | 2117       &TestingAutomationProvider::GoBack; | 
|  | 2118   handler_map["Reload"] = | 
|  | 2119       &TestingAutomationProvider::ReloadJSON; | 
|  | 2120   handler_map["GetTabURL"] = | 
|  | 2121       &TestingAutomationProvider::GetTabURLJSON; | 
|  | 2122   handler_map["GetTabTitle"] = | 
|  | 2123       &TestingAutomationProvider::GetTabTitleJSON; | 
|  | 2124   handler_map["GetCookies"] = | 
|  | 2125       &TestingAutomationProvider::GetCookiesJSON; | 
|  | 2126   handler_map["DeleteCookie"] = | 
|  | 2127       &TestingAutomationProvider::DeleteCookieJSON; | 
|  | 2128   handler_map["SetCookie"] = | 
|  | 2129       &TestingAutomationProvider::SetCookieJSON; | 
|  | 2130   handler_map["GetTabIds"] = | 
|  | 2131       &TestingAutomationProvider::GetTabIds; | 
|  | 2132   handler_map["IsTabIdValid"] = | 
|  | 2133       &TestingAutomationProvider::IsTabIdValid; | 
|  | 2134   handler_map["CloseTab"] = | 
|  | 2135       &TestingAutomationProvider::CloseTabJSON; | 
|  | 2136   handler_map["WebkitMouseMove"] = | 
|  | 2137       &TestingAutomationProvider::WebkitMouseMove; | 
|  | 2138   handler_map["WebkitMouseClick"] = | 
|  | 2139       &TestingAutomationProvider::WebkitMouseClick; | 
|  | 2140   handler_map["WebkitMouseDrag"] = | 
|  | 2141       &TestingAutomationProvider::WebkitMouseDrag; | 
|  | 2142   handler_map["SendWebkitKeyEvent"] = | 
|  | 2143       &TestingAutomationProvider::SendWebkitKeyEvent; | 
|  | 2144   handler_map["ActivateTab"] = | 
|  | 2145       &TestingAutomationProvider::ActivateTabJSON; | 
| 2121 #if defined(OS_CHROMEOS) | 2146 #if defined(OS_CHROMEOS) | 
| 2122   handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; | 2147   handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; | 
| 2123   handler_map["Login"] = &TestingAutomationProvider::Login; | 2148   handler_map["Login"] = &TestingAutomationProvider::Login; | 
| 2124   handler_map["Logout"] = &TestingAutomationProvider::Logout; | 2149   handler_map["Logout"] = &TestingAutomationProvider::Logout; | 
| 2125   handler_map["ScreenLock"] = &TestingAutomationProvider::ScreenLock; | 2150   handler_map["ScreenLock"] = &TestingAutomationProvider::ScreenLock; | 
| 2126   handler_map["ScreenUnlock"] = &TestingAutomationProvider::ScreenUnlock; | 2151   handler_map["ScreenUnlock"] = &TestingAutomationProvider::ScreenUnlock; | 
| 2127 #endif  // defined(OS_CHROMEOS) | 2152 #endif  // defined(OS_CHROMEOS) | 
| 2128 | 2153 | 
| 2129   std::map<std::string, BrowserJsonHandler> browser_handler_map; | 2154   std::map<std::string, BrowserJsonHandler> browser_handler_map; | 
| 2130   browser_handler_map["DisablePlugin"] = | 2155   browser_handler_map["DisablePlugin"] = | 
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2253   browser_handler_map["RemoveNTPMostVisitedThumbnail"] = | 2278   browser_handler_map["RemoveNTPMostVisitedThumbnail"] = | 
| 2254       &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail; | 2279       &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail; | 
| 2255   browser_handler_map["UnpinNTPMostVisitedThumbnail"] = | 2280   browser_handler_map["UnpinNTPMostVisitedThumbnail"] = | 
| 2256       &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail; | 2281       &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail; | 
| 2257   browser_handler_map["RestoreAllNTPMostVisitedThumbnails"] = | 2282   browser_handler_map["RestoreAllNTPMostVisitedThumbnails"] = | 
| 2258       &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; | 2283       &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; | 
| 2259 | 2284 | 
| 2260   browser_handler_map["KillRendererProcess"] = | 2285   browser_handler_map["KillRendererProcess"] = | 
| 2261       &TestingAutomationProvider::KillRendererProcess; | 2286       &TestingAutomationProvider::KillRendererProcess; | 
| 2262 | 2287 | 
| 2263   browser_handler_map["SendKeyEventToActiveTab"] = |  | 
| 2264       &TestingAutomationProvider::SendKeyEventToActiveTab; |  | 
| 2265 |  | 
| 2266   browser_handler_map["GetNTPThumbnailMode"] = | 2288   browser_handler_map["GetNTPThumbnailMode"] = | 
| 2267       &TestingAutomationProvider::GetNTPThumbnailMode; | 2289       &TestingAutomationProvider::GetNTPThumbnailMode; | 
| 2268   browser_handler_map["SetNTPThumbnailMode"] = | 2290   browser_handler_map["SetNTPThumbnailMode"] = | 
| 2269       &TestingAutomationProvider::SetNTPThumbnailMode; | 2291       &TestingAutomationProvider::SetNTPThumbnailMode; | 
| 2270   browser_handler_map["GetNTPMenuMode"] = | 2292   browser_handler_map["GetNTPMenuMode"] = | 
| 2271       &TestingAutomationProvider::GetNTPMenuMode; | 2293       &TestingAutomationProvider::GetNTPMenuMode; | 
| 2272   browser_handler_map["SetNTPMenuMode"] = | 2294   browser_handler_map["SetNTPMenuMode"] = | 
| 2273       &TestingAutomationProvider::SetNTPMenuMode; | 2295       &TestingAutomationProvider::SetNTPMenuMode; | 
| 2274 | 2296 | 
| 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()) { | 2297   if (handler_map.find(std::string(command)) != handler_map.end()) { | 
| 2283     (this->*handler_map[command])(dict_value, reply_message); | 2298     (this->*handler_map[command])(dict_value, reply_message); | 
| 2284   } else if (browser_handler_map.find(std::string(command)) != | 2299   } else if (browser_handler_map.find(std::string(command)) != | 
| 2285              browser_handler_map.end()) { | 2300              browser_handler_map.end()) { | 
| 2286     Browser* browser = NULL; | 2301     Browser* browser = NULL; | 
| 2287     if (!browser_tracker_->ContainsHandle(handle) || | 2302     if (!browser_tracker_->ContainsHandle(handle) || | 
| 2288         !(browser = browser_tracker_->GetResource(handle))) { | 2303         !(browser = browser_tracker_->GetResource(handle))) { | 
| 2289       AutomationJSONReply(this, reply_message).SendError("No browser object."); | 2304       AutomationJSONReply(this, reply_message).SendError("No browser object."); | 
| 2290       return; | 2305       return; | 
| 2291     } | 2306     } | 
| (...skipping 2268 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4560   if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { | 4575   if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { | 
| 4561     AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( | 4576     AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( | 
| 4562         "Failed to open process handle for pid %d", pid)); | 4577         "Failed to open process handle for pid %d", pid)); | 
| 4563     return; | 4578     return; | 
| 4564   } | 4579   } | 
| 4565   new RendererProcessClosedObserver(this, reply_message); | 4580   new RendererProcessClosedObserver(this, reply_message); | 
| 4566   base::KillProcess(process, 0, false); | 4581   base::KillProcess(process, 0, false); | 
| 4567   base::CloseProcessHandle(process); | 4582   base::CloseProcessHandle(process); | 
| 4568 } | 4583 } | 
| 4569 | 4584 | 
| 4570 void TestingAutomationProvider::SendKeyEventToActiveTab( | 4585 void TestingAutomationProvider::SendWebkitKeyEvent( | 
| 4571     Browser* browser, |  | 
| 4572     DictionaryValue* args, | 4586     DictionaryValue* args, | 
| 4573     IPC::Message* reply_message) { | 4587     IPC::Message* reply_message) { | 
|  | 4588   TabContents* tab_contents; | 
|  | 4589   std::string error; | 
|  | 4590   if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 
|  | 4591     AutomationJSONReply(this, reply_message).SendError(error); | 
|  | 4592     return; | 
|  | 4593   } | 
|  | 4594 | 
| 4574   int type, modifiers; | 4595   int type, modifiers; | 
| 4575   bool is_system_key; | 4596   bool is_system_key; | 
| 4576   string16 unmodified_text, text; | 4597   string16 unmodified_text, text; | 
| 4577   std::string key_identifier; | 4598   std::string key_identifier; | 
| 4578   NativeWebKeyboardEvent event; | 4599   NativeWebKeyboardEvent event; | 
| 4579   if (!args->GetInteger("type", &type)) { | 4600   if (!args->GetInteger("type", &type)) { | 
| 4580     AutomationJSONReply reply(this, reply_message); | 4601     AutomationJSONReply reply(this, reply_message); | 
| 4581     reply.SendError("'type' missing or invalid."); | 4602     reply.SendError("'type' missing or invalid."); | 
| 4582     return; | 4603     return; | 
| 4583   } | 4604   } | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4649     event.modifiers |= WebKit::WebInputEvent::ControlKey; | 4670     event.modifiers |= WebKit::WebInputEvent::ControlKey; | 
| 4650   if (modifiers & automation::kAltKeyMask) | 4671   if (modifiers & automation::kAltKeyMask) | 
| 4651     event.modifiers |= WebKit::WebInputEvent::AltKey; | 4672     event.modifiers |= WebKit::WebInputEvent::AltKey; | 
| 4652   if (modifiers & automation::kMetaKeyMask) | 4673   if (modifiers & automation::kMetaKeyMask) | 
| 4653     event.modifiers |= WebKit::WebInputEvent::MetaKey; | 4674     event.modifiers |= WebKit::WebInputEvent::MetaKey; | 
| 4654 | 4675 | 
| 4655   event.isSystemKey = is_system_key; | 4676   event.isSystemKey = is_system_key; | 
| 4656   event.timeStampSeconds = base::Time::Now().ToDoubleT(); | 4677   event.timeStampSeconds = base::Time::Now().ToDoubleT(); | 
| 4657   event.skip_in_browser = true; | 4678   event.skip_in_browser = true; | 
| 4658   new InputEventAckNotificationObserver(this, reply_message, event.type); | 4679   new InputEventAckNotificationObserver(this, reply_message, event.type); | 
| 4659   browser->GetSelectedTabContents()->render_view_host()-> | 4680   tab_contents->render_view_host()->ForwardKeyboardEvent(event); | 
| 4660     ForwardKeyboardEvent(event); |  | 
| 4661 } | 4681 } | 
| 4662 | 4682 | 
| 4663 // Sample JSON input: { "command": "GetNTPThumbnailMode" } | 4683 // Sample JSON input: { "command": "GetNTPThumbnailMode" } | 
| 4664 // For output, refer to GetNTPThumbnailMode() in | 4684 // For output, refer to GetNTPThumbnailMode() in | 
| 4665 // chrome/test/pyautolib/pyauto.py. | 4685 // chrome/test/pyautolib/pyauto.py. | 
| 4666 void TestingAutomationProvider::GetNTPThumbnailMode( | 4686 void TestingAutomationProvider::GetNTPThumbnailMode( | 
| 4667     Browser* browser, | 4687     Browser* browser, | 
| 4668     DictionaryValue* args, | 4688     DictionaryValue* args, | 
| 4669     IPC::Message* reply_message) { | 4689     IPC::Message* reply_message) { | 
| 4670   const int shown_sections = ShownSectionsHandler::GetShownSections( | 4690   const int shown_sections = ShownSectionsHandler::GetShownSections( | 
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4795 void TestingAutomationProvider::WaitForAllTabsToStopLoading( | 4815 void TestingAutomationProvider::WaitForAllTabsToStopLoading( | 
| 4796     DictionaryValue* args, | 4816     DictionaryValue* args, | 
| 4797     IPC::Message* reply_message) { | 4817     IPC::Message* reply_message) { | 
| 4798   new AllTabsStoppedLoadingObserver(this, reply_message); | 4818   new AllTabsStoppedLoadingObserver(this, reply_message); | 
| 4799 } | 4819 } | 
| 4800 | 4820 | 
| 4801 void TestingAutomationProvider::GetIndicesFromTab( | 4821 void TestingAutomationProvider::GetIndicesFromTab( | 
| 4802     DictionaryValue* args, | 4822     DictionaryValue* args, | 
| 4803     IPC::Message* reply_message) { | 4823     IPC::Message* reply_message) { | 
| 4804   AutomationJSONReply reply(this, reply_message); | 4824   AutomationJSONReply reply(this, reply_message); | 
| 4805   int tab_handle = 0; | 4825   int id_or_handle = 0; | 
| 4806   if (!args->GetInteger("tab_handle", &tab_handle) || | 4826   bool has_id = args->HasKey("tab_id"); | 
| 4807       !tab_tracker_->ContainsHandle(tab_handle)) { | 4827   bool has_handle = args->HasKey("tab_handle"); | 
| 4808     reply.SendError("'tab_handle' missing or invalid"); | 4828   if (has_id && has_handle) { | 
|  | 4829     reply.SendError( | 
|  | 4830         "Both 'tab_id' and 'tab_handle' were specified. Only one is allowed"); | 
|  | 4831     return; | 
|  | 4832   } else if (!has_id && !has_handle) { | 
|  | 4833     reply.SendError("Either 'tab_id' or 'tab_handle' must be specified"); | 
| 4809     return; | 4834     return; | 
| 4810   } | 4835   } | 
| 4811   NavigationController* controller = tab_tracker_->GetResource(tab_handle); | 4836   if (has_id && !args->GetInteger("tab_id", &id_or_handle)) { | 
|  | 4837     reply.SendError("'tab_id' is invalid"); | 
|  | 4838     return; | 
|  | 4839   } | 
|  | 4840   if (has_handle && (!args->GetInteger("tab_handle", &id_or_handle) || | 
|  | 4841                      !tab_tracker_->ContainsHandle(id_or_handle))) { | 
|  | 4842     reply.SendError("'tab_handle' is invalid"); | 
|  | 4843     return; | 
|  | 4844   } | 
|  | 4845   int id = id_or_handle; | 
|  | 4846   if (has_handle) | 
|  | 4847     id = tab_tracker_->GetResource(id_or_handle)->session_id().id(); | 
| 4812   BrowserList::const_iterator iter = BrowserList::begin(); | 4848   BrowserList::const_iterator iter = BrowserList::begin(); | 
| 4813   int browser_index = 0; | 4849   int browser_index = 0; | 
| 4814   for (; iter != BrowserList::end(); ++iter, ++browser_index) { | 4850   for (; iter != BrowserList::end(); ++iter, ++browser_index) { | 
| 4815     Browser* browser = *iter; | 4851     Browser* browser = *iter; | 
| 4816     for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { | 4852     for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { | 
| 4817       if (browser->GetTabContentsAt(tab_index) == controller->tab_contents()) { | 4853       TabContents* tab = browser->GetTabContentsAt(tab_index); | 
|  | 4854       if (tab->controller().session_id().id() == id) { | 
| 4818         DictionaryValue dict; | 4855         DictionaryValue dict; | 
| 4819         dict.SetInteger("windex", browser_index); | 4856         dict.SetInteger("windex", browser_index); | 
| 4820         dict.SetInteger("tab_index", tab_index); | 4857         dict.SetInteger("tab_index", tab_index); | 
| 4821         reply.SendSuccess(&dict); | 4858         reply.SendSuccess(&dict); | 
| 4822         return; | 4859         return; | 
| 4823       } | 4860       } | 
| 4824     } | 4861     } | 
| 4825   } | 4862   } | 
| 4826   reply.SendError("Could not find tab among current browser windows"); | 4863   reply.SendError("Could not find tab among current browser windows"); | 
| 4827 } | 4864 } | 
| 4828 | 4865 | 
| 4829 void TestingAutomationProvider::NavigateToURL( | 4866 void TestingAutomationProvider::NavigateToURL( | 
| 4830     DictionaryValue* args, | 4867     DictionaryValue* args, | 
| 4831     IPC::Message* reply_message) { | 4868     IPC::Message* reply_message) { | 
| 4832   int browser_index = 0, tab_index = 0, navigation_count = 0; | 4869   int navigation_count; | 
| 4833   std::string url; | 4870   std::string url, error; | 
| 4834   if (!args->GetInteger("windex", &browser_index)) { | 4871   Browser* browser; | 
| 4835     AutomationJSONReply(this, reply_message) | 4872   TabContents* tab_contents; | 
| 4836         .SendError("'windex' missing or invalid"); | 4873   if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab_contents, &error)) { | 
| 4837     return; | 4874     AutomationJSONReply(this, reply_message).SendError(error); | 
| 4838   } |  | 
| 4839   if (!args->GetInteger("tab_index", &tab_index)) { |  | 
| 4840     AutomationJSONReply(this, reply_message) |  | 
| 4841         .SendError("'tab_index' missing or invalid"); |  | 
| 4842     return; | 4875     return; | 
| 4843   } | 4876   } | 
| 4844   if (!args->GetString("url", &url)) { | 4877   if (!args->GetString("url", &url)) { | 
| 4845     AutomationJSONReply(this, reply_message) | 4878     AutomationJSONReply(this, reply_message) | 
| 4846         .SendError("'url' missing or invalid"); | 4879         .SendError("'url' missing or invalid"); | 
| 4847     return; | 4880     return; | 
| 4848   } | 4881   } | 
| 4849   if (!args->GetInteger("navigation_count", &navigation_count)) { | 4882   if (!args->GetInteger("navigation_count", &navigation_count)) { | 
| 4850     AutomationJSONReply(this, reply_message) | 4883     AutomationJSONReply(this, reply_message) | 
| 4851         .SendError("'navigation_count' missing or invalid"); | 4884         .SendError("'navigation_count' missing or invalid"); | 
| 4852     return; | 4885     return; | 
| 4853   } | 4886   } | 
| 4854   Browser* browser = GetBrowserAt(browser_index); |  | 
| 4855   TabContents* tab_contents = GetTabContentsAt(browser_index, tab_index); |  | 
| 4856   if (!browser || !tab_contents) { |  | 
| 4857     AutomationJSONReply(this, reply_message) |  | 
| 4858         .SendError("Cannot locate tab or browser to navigate"); |  | 
| 4859     return; |  | 
| 4860   } |  | 
| 4861   new NavigationNotificationObserver( | 4887   new NavigationNotificationObserver( | 
| 4862       &tab_contents->controller(), this, reply_message, | 4888       &tab_contents->controller(), this, reply_message, | 
| 4863       navigation_count, false, true); | 4889       navigation_count, false, true); | 
| 4864   browser->OpenURLFromTab( | 4890   browser->OpenURLFromTab( | 
| 4865       tab_contents, GURL(url), GURL(), CURRENT_TAB, PageTransition::TYPED); | 4891       tab_contents, GURL(url), GURL(), CURRENT_TAB, PageTransition::TYPED); | 
| 4866 } | 4892 } | 
| 4867 | 4893 | 
|  | 4894 void TestingAutomationProvider::ExecuteJavascriptJSON( | 
|  | 4895     DictionaryValue* args, | 
|  | 4896     IPC::Message* reply_message) { | 
|  | 4897   string16 frame_xpath, javascript; | 
|  | 4898   std::string error; | 
|  | 4899   TabContents* tab_contents; | 
|  | 4900   if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 
|  | 4901     AutomationJSONReply(this, reply_message).SendError(error); | 
|  | 4902     return; | 
|  | 4903   } | 
|  | 4904   if (!args->GetString("frame_xpath", &frame_xpath)) { | 
|  | 4905     AutomationJSONReply(this, reply_message) | 
|  | 4906         .SendError("'frame_xpath' missing or invalid"); | 
|  | 4907     return; | 
|  | 4908   } | 
|  | 4909   if (!args->GetString("javascript", &javascript)) { | 
|  | 4910     AutomationJSONReply(this, reply_message) | 
|  | 4911         .SendError("'javascript' missing or invalid"); | 
|  | 4912     return; | 
|  | 4913   } | 
|  | 4914 | 
|  | 4915   // Set the routing id of this message with the controller. | 
|  | 4916   // This routing id needs to be remembered for the reverse | 
|  | 4917   // communication while sending back the response of | 
|  | 4918   // this javascript execution. | 
|  | 4919   std::string set_automation_id; | 
|  | 4920   base::SStringPrintf(&set_automation_id, | 
|  | 4921                       "window.domAutomationController.setAutomationId(%d);", | 
|  | 4922                       reply_message->routing_id()); | 
|  | 4923 | 
|  | 4924   new ExecuteJavascriptObserver(this, reply_message); | 
|  | 4925   tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( | 
|  | 4926       frame_xpath, UTF8ToUTF16(set_automation_id)); | 
|  | 4927   tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( | 
|  | 4928       frame_xpath, javascript); | 
|  | 4929 } | 
|  | 4930 | 
|  | 4931 void TestingAutomationProvider::GoForward( | 
|  | 4932     DictionaryValue* args, | 
|  | 4933     IPC::Message* reply_message) { | 
|  | 4934   TabContents* tab_contents; | 
|  | 4935   std::string error; | 
|  | 4936   if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 
|  | 4937     AutomationJSONReply(this, reply_message).SendError(error); | 
|  | 4938     return; | 
|  | 4939   } | 
|  | 4940   NavigationController& controller = tab_contents->controller(); | 
|  | 4941   if (!controller.CanGoForward()) { | 
|  | 4942     DictionaryValue dict; | 
|  | 4943     dict.SetBoolean("did_go_forward", false); | 
|  | 4944     AutomationJSONReply(this, reply_message).SendSuccess(&dict); | 
|  | 4945     return; | 
|  | 4946   } | 
|  | 4947   new NavigationNotificationObserver(&controller, this, reply_message, | 
|  | 4948                                      1, false, true); | 
|  | 4949   controller.GoForward(); | 
|  | 4950 } | 
|  | 4951 | 
|  | 4952 void TestingAutomationProvider::GoBack( | 
|  | 4953     DictionaryValue* args, | 
|  | 4954     IPC::Message* reply_message) { | 
|  | 4955   TabContents* tab_contents; | 
|  | 4956   std::string error; | 
|  | 4957   if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 
|  | 4958     AutomationJSONReply(this, reply_message).SendError(error); | 
|  | 4959     return; | 
|  | 4960   } | 
|  | 4961   NavigationController& controller = tab_contents->controller(); | 
|  | 4962   if (!controller.CanGoBack()) { | 
|  | 4963     DictionaryValue dict; | 
|  | 4964     dict.SetBoolean("did_go_back", false); | 
|  | 4965     AutomationJSONReply(this, reply_message).SendSuccess(&dict); | 
|  | 4966     return; | 
|  | 4967   } | 
|  | 4968   new NavigationNotificationObserver(&controller, this, reply_message, | 
|  | 4969                                      1, false, true); | 
|  | 4970   controller.GoBack(); | 
|  | 4971 } | 
|  | 4972 | 
|  | 4973 void TestingAutomationProvider::ReloadJSON( | 
|  | 4974     DictionaryValue* args, | 
|  | 4975     IPC::Message* reply_message) { | 
|  | 4976   TabContents* tab_contents; | 
|  | 4977   std::string error; | 
|  | 4978   if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 
|  | 4979     AutomationJSONReply(this, reply_message).SendError(error); | 
|  | 4980     return; | 
|  | 4981   } | 
|  | 4982   NavigationController& controller = tab_contents->controller(); | 
|  | 4983   new NavigationNotificationObserver(&controller, this, reply_message, | 
|  | 4984                                      1, false, true); | 
|  | 4985   controller.Reload(false); | 
|  | 4986 } | 
|  | 4987 | 
|  | 4988 void TestingAutomationProvider::GetTabURLJSON( | 
|  | 4989     DictionaryValue* args, | 
|  | 4990     IPC::Message* reply_message) { | 
|  | 4991   AutomationJSONReply reply(this, reply_message); | 
|  | 4992   TabContents* tab_contents; | 
|  | 4993   std::string error; | 
|  | 4994   if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 
|  | 4995     reply.SendError(error); | 
|  | 4996     return; | 
|  | 4997   } | 
|  | 4998   DictionaryValue dict; | 
|  | 4999   dict.SetString("url", tab_contents->GetURL().possibly_invalid_spec()); | 
|  | 5000   reply.SendSuccess(&dict); | 
|  | 5001 } | 
|  | 5002 | 
|  | 5003 void TestingAutomationProvider::GetTabTitleJSON( | 
|  | 5004     DictionaryValue* args, | 
|  | 5005     IPC::Message* reply_message) { | 
|  | 5006   AutomationJSONReply reply(this, reply_message); | 
|  | 5007   TabContents* tab_contents; | 
|  | 5008   std::string error; | 
|  | 5009   if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 
|  | 5010     reply.SendError(error); | 
|  | 5011     return; | 
|  | 5012   } | 
|  | 5013   DictionaryValue dict; | 
|  | 5014   dict.SetString("title", tab_contents->GetTitle()); | 
|  | 5015   reply.SendSuccess(&dict); | 
|  | 5016 } | 
|  | 5017 | 
|  | 5018 void TestingAutomationProvider::GetCookiesJSON( | 
|  | 5019     DictionaryValue* args, IPC::Message* reply_message) { | 
|  | 5020   AutomationJSONReply reply(this, reply_message); | 
|  | 5021   Browser* browser; | 
|  | 5022   std::string error; | 
|  | 5023   if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | 
|  | 5024     reply.SendError(error); | 
|  | 5025     return; | 
|  | 5026   } | 
|  | 5027   std::string url; | 
|  | 5028   if (!args->GetString("url", &url)) { | 
|  | 5029     reply.SendError("'url' missing or invalid"); | 
|  | 5030     return; | 
|  | 5031   } | 
|  | 5032 | 
|  | 5033   // Since we are running on the UI thread don't call GetURLRequestContext(). | 
|  | 5034   scoped_refptr<URLRequestContextGetter> context_getter = | 
|  | 5035       browser->profile()->GetRequestContext(); | 
|  | 5036 | 
|  | 5037   std::string cookies; | 
|  | 5038   base::WaitableEvent event(true /* manual reset */, | 
|  | 5039                             false /* not initially signaled */); | 
|  | 5040   Task* task = NewRunnableFunction( | 
|  | 5041       &GetCookiesOnIOThread, | 
|  | 5042       GURL(url), context_getter, &event, &cookies); | 
|  | 5043   if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | 
|  | 5044     reply.SendError("Couldn't post task to get the cookies"); | 
|  | 5045     return; | 
|  | 5046   } | 
|  | 5047   event.Wait(); | 
|  | 5048 | 
|  | 5049   DictionaryValue dict; | 
|  | 5050   dict.SetString("cookies", cookies); | 
|  | 5051   reply.SendSuccess(&dict); | 
|  | 5052 } | 
|  | 5053 | 
|  | 5054 void TestingAutomationProvider::DeleteCookieJSON( | 
|  | 5055     DictionaryValue* args, IPC::Message* reply_message) { | 
|  | 5056   AutomationJSONReply reply(this, reply_message); | 
|  | 5057   Browser* browser; | 
|  | 5058   std::string error; | 
|  | 5059   if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | 
|  | 5060     reply.SendError(error); | 
|  | 5061     return; | 
|  | 5062   } | 
|  | 5063   std::string url, name; | 
|  | 5064   if (!args->GetString("url", &url)) { | 
|  | 5065     reply.SendError("'url' missing or invalid"); | 
|  | 5066     return; | 
|  | 5067   } | 
|  | 5068   if (!args->GetString("name", &name)) { | 
|  | 5069     reply.SendError("'name' missing or invalid"); | 
|  | 5070     return; | 
|  | 5071   } | 
|  | 5072 | 
|  | 5073   // Since we are running on the UI thread don't call GetURLRequestContext(). | 
|  | 5074   scoped_refptr<URLRequestContextGetter> context_getter = | 
|  | 5075       browser->profile()->GetRequestContext(); | 
|  | 5076 | 
|  | 5077   base::WaitableEvent event(true /* manual reset */, | 
|  | 5078                             false /* not initially signaled */); | 
|  | 5079   Task* task = NewRunnableFunction( | 
|  | 5080       &DeleteCookieOnIOThread, | 
|  | 5081       GURL(url), name, context_getter, &event); | 
|  | 5082   if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | 
|  | 5083     reply.SendError("Couldn't post task to delete the cookie"); | 
|  | 5084     return; | 
|  | 5085   } | 
|  | 5086   event.Wait(); | 
|  | 5087   reply.SendSuccess(NULL); | 
|  | 5088 } | 
|  | 5089 | 
|  | 5090 void TestingAutomationProvider::SetCookieJSON( | 
|  | 5091     DictionaryValue* args, IPC::Message* reply_message) { | 
|  | 5092   AutomationJSONReply reply(this, reply_message); | 
|  | 5093   Browser* browser; | 
|  | 5094   std::string error; | 
|  | 5095   if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | 
|  | 5096     reply.SendError(error); | 
|  | 5097     return; | 
|  | 5098   } | 
|  | 5099   std::string url, cookie; | 
|  | 5100   if (!args->GetString("url", &url)) { | 
|  | 5101     reply.SendError("'url' missing or invalid"); | 
|  | 5102     return; | 
|  | 5103   } | 
|  | 5104   if (!args->GetString("cookie", &cookie)) { | 
|  | 5105     reply.SendError("'cookie' missing or invalid"); | 
|  | 5106     return; | 
|  | 5107   } | 
|  | 5108 | 
|  | 5109   // Since we are running on the UI thread don't call GetURLRequestContext(). | 
|  | 5110   scoped_refptr<URLRequestContextGetter> context_getter = | 
|  | 5111       browser->profile()->GetRequestContext(); | 
|  | 5112 | 
|  | 5113   base::WaitableEvent event(true /* manual reset */, | 
|  | 5114                             false /* not initially signaled */); | 
|  | 5115   bool success = false; | 
|  | 5116   Task* task = NewRunnableFunction( | 
|  | 5117       &SetCookieOnIOThread, | 
|  | 5118       GURL(url), cookie, context_getter, &event, &success); | 
|  | 5119   if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | 
|  | 5120     reply.SendError("Couldn't post task to set the cookie"); | 
|  | 5121     return; | 
|  | 5122   } | 
|  | 5123   event.Wait(); | 
|  | 5124 | 
|  | 5125   if (!success) { | 
|  | 5126     reply.SendError("Could not set the cookie"); | 
|  | 5127     return; | 
|  | 5128   } | 
|  | 5129   reply.SendSuccess(NULL); | 
|  | 5130 } | 
|  | 5131 | 
|  | 5132 void TestingAutomationProvider::GetTabIds( | 
|  | 5133     DictionaryValue* args, IPC::Message* reply_message) { | 
|  | 5134   ListValue* id_list = new ListValue(); | 
|  | 5135   BrowserList::const_iterator iter = BrowserList::begin(); | 
|  | 5136   for (; iter != BrowserList::end(); ++iter) { | 
|  | 5137     Browser* browser = *iter; | 
|  | 5138     for (int i = 0; i < browser->tab_count(); ++i) { | 
|  | 5139       int id = browser->GetTabContentsAt(i)->controller().session_id().id(); | 
|  | 5140       id_list->Append(Value::CreateIntegerValue(id)); | 
|  | 5141     } | 
|  | 5142   } | 
|  | 5143   DictionaryValue dict; | 
|  | 5144   dict.Set("ids", id_list); | 
|  | 5145   AutomationJSONReply(this, reply_message).SendSuccess(&dict); | 
|  | 5146 } | 
|  | 5147 | 
|  | 5148 void TestingAutomationProvider::IsTabIdValid( | 
|  | 5149     DictionaryValue* args, IPC::Message* reply_message) { | 
|  | 5150   AutomationJSONReply reply(this, reply_message); | 
|  | 5151   int id; | 
|  | 5152   if (!args->GetInteger("id", &id)) { | 
|  | 5153     reply.SendError("'id' missing or invalid"); | 
|  | 5154     return; | 
|  | 5155   } | 
|  | 5156   bool is_valid = false; | 
|  | 5157   BrowserList::const_iterator iter = BrowserList::begin(); | 
|  | 5158   for (; iter != BrowserList::end(); ++iter) { | 
|  | 5159     Browser* browser = *iter; | 
|  | 5160     for (int i = 0; i < browser->tab_count(); ++i) { | 
|  | 5161       TabContents* tab = browser->GetTabContentsAt(i); | 
|  | 5162       if (tab->controller().session_id().id() == id) { | 
|  | 5163         is_valid = true; | 
|  | 5164         break; | 
|  | 5165       } | 
|  | 5166     } | 
|  | 5167   } | 
|  | 5168   DictionaryValue dict; | 
|  | 5169   dict.SetBoolean("is_valid", is_valid); | 
|  | 5170   reply.SendSuccess(&dict); | 
|  | 5171 } | 
|  | 5172 | 
|  | 5173 void TestingAutomationProvider::CloseTabJSON( | 
|  | 5174     DictionaryValue* args, IPC::Message* reply_message) { | 
|  | 5175   AutomationJSONReply reply(this, reply_message); | 
|  | 5176   Browser* browser; | 
|  | 5177   TabContents* tab_contents; | 
|  | 5178   std::string error; | 
|  | 5179   if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab_contents, &error)) { | 
|  | 5180     reply.SendError(error); | 
|  | 5181     return; | 
|  | 5182   } | 
|  | 5183   browser->CloseTabContents(tab_contents); | 
|  | 5184   reply.SendSuccess(NULL); | 
|  | 5185 } | 
|  | 5186 | 
|  | 5187 void TestingAutomationProvider::ActivateTabJSON( | 
|  | 5188     DictionaryValue* args, | 
|  | 5189     IPC::Message* reply_message) { | 
|  | 5190   AutomationJSONReply reply(this, reply_message); | 
|  | 5191   Browser* browser; | 
|  | 5192   TabContents* tab_contents; | 
|  | 5193   std::string error; | 
|  | 5194   if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab_contents, &error)) { | 
|  | 5195     reply.SendError(error); | 
|  | 5196     return; | 
|  | 5197   } | 
|  | 5198   browser->SelectTabContentsAt( | 
|  | 5199       browser->GetIndexOfController(&tab_contents->controller()), true); | 
|  | 5200   reply.SendSuccess(NULL); | 
|  | 5201 } | 
|  | 5202 | 
| 4868 void TestingAutomationProvider::WaitForTabCountToBecome( | 5203 void TestingAutomationProvider::WaitForTabCountToBecome( | 
| 4869     int browser_handle, | 5204     int browser_handle, | 
| 4870     int target_tab_count, | 5205     int target_tab_count, | 
| 4871     IPC::Message* reply_message) { | 5206     IPC::Message* reply_message) { | 
| 4872   if (!browser_tracker_->ContainsHandle(browser_handle)) { | 5207   if (!browser_tracker_->ContainsHandle(browser_handle)) { | 
| 4873     AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message, | 5208     AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message, | 
| 4874                                                             false); | 5209                                                             false); | 
| 4875     Send(reply_message); | 5210     Send(reply_message); | 
| 4876     return; | 5211     return; | 
| 4877   } | 5212   } | 
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 5023     // If you change this, update Observer for NotificationType::SESSION_END | 5358     // If you change this, update Observer for NotificationType::SESSION_END | 
| 5024     // below. | 5359     // below. | 
| 5025     MessageLoop::current()->PostTask(FROM_HERE, | 5360     MessageLoop::current()->PostTask(FROM_HERE, | 
| 5026         NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5361         NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 
| 5027   } | 5362   } | 
| 5028 } | 5363 } | 
| 5029 | 5364 | 
| 5030 void TestingAutomationProvider::OnRemoveProvider() { | 5365 void TestingAutomationProvider::OnRemoveProvider() { | 
| 5031   AutomationProviderList::GetInstance()->RemoveProvider(this); | 5366   AutomationProviderList::GetInstance()->RemoveProvider(this); | 
| 5032 } | 5367 } | 
| OLD | NEW | 
|---|