Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1372)

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 10804038: Convert cookie and download automation commands to the JSON interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 IPC_BEGIN_MESSAGE_MAP_EX(TestingAutomationProvider, 366 IPC_BEGIN_MESSAGE_MAP_EX(TestingAutomationProvider,
367 message, 367 message,
368 deserialize_success) 368 deserialize_success)
369 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser) 369 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser)
370 IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab) 370 IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab)
371 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab) 371 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab)
372 IPC_MESSAGE_HANDLER(AutomationMsg_GetMachPortCount, GetMachPortCount) 372 IPC_MESSAGE_HANDLER(AutomationMsg_GetMachPortCount, GetMachPortCount)
373 IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex) 373 IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex)
374 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab) 374 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab)
375 IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies) 375 IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies)
376 IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie)
377 IPC_MESSAGE_HANDLER_DELAY_REPLY( 376 IPC_MESSAGE_HANDLER_DELAY_REPLY(
378 AutomationMsg_NavigateToURLBlockUntilNavigationsComplete, 377 AutomationMsg_NavigateToURLBlockUntilNavigationsComplete,
379 NavigateToURLBlockUntilNavigationsComplete) 378 NavigateToURLBlockUntilNavigationsComplete)
380 IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync) 379 IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync)
381 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload) 380 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload)
382 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount, GetBrowserWindowCount) 381 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount, GetBrowserWindowCount)
383 IPC_MESSAGE_HANDLER(AutomationMsg_NormalBrowserWindowCount, 382 IPC_MESSAGE_HANDLER(AutomationMsg_NormalBrowserWindowCount,
384 GetNormalBrowserWindowCount) 383 GetNormalBrowserWindowCount)
385 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindow, GetBrowserWindow) 384 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindow, GetBrowserWindow)
386 IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync, 385 IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync,
387 ExecuteBrowserCommandAsync) 386 ExecuteBrowserCommandAsync)
388 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand, 387 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand,
389 ExecuteBrowserCommand) 388 ExecuteBrowserCommand)
390 IPC_MESSAGE_HANDLER(AutomationMsg_TerminateSession, TerminateSession) 389 IPC_MESSAGE_HANDLER(AutomationMsg_TerminateSession, TerminateSession)
391 IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds) 390 IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds)
392 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) 391 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds)
393 IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove) 392 IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove)
394 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) 393 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress)
395 IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount) 394 IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount)
396 IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType) 395 IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType)
397 IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab) 396 IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab)
398 IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle) 397 IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle)
399 IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex) 398 IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex)
400 IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL) 399 IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL)
401 IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility, GetShelfVisibility)
402 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation, 400 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation,
403 ExecuteJavascript) 401 ExecuteJavascript)
404 IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory)
405 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType, 402 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType,
406 OpenNewBrowserWindowOfType) 403 OpenNewBrowserWindowOfType)
407 IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser) 404 IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser)
408 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored, 405 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored,
409 WaitForTabToBeRestored) 406 WaitForTabToBeRestored)
410 IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState, GetSecurityState) 407 IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState, GetSecurityState)
411 IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType, GetPageType) 408 IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType, GetPageType)
412 IPC_MESSAGE_HANDLER(AutomationMsg_GetMetricEventDuration, 409 IPC_MESSAGE_HANDLER(AutomationMsg_GetMetricEventDuration,
413 GetMetricEventDuration) 410 GetMetricEventDuration)
414 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage, 411 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage,
415 ActionOnSSLBlockingPage) 412 ActionOnSSLBlockingPage)
416 IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront) 413 IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront)
417 IPC_MESSAGE_HANDLER(AutomationMsg_IsMenuCommandEnabled,
418 IsMenuCommandEnabled)
419 IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage, 414 IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage,
420 HandleOpenFindInPageRequest) 415 HandleOpenFindInPageRequest)
421 IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibility, 416 IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibility,
422 GetFindWindowVisibility) 417 GetFindWindowVisibility)
423 IPC_MESSAGE_HANDLER(AutomationMsg_BookmarkBarVisibility, 418 IPC_MESSAGE_HANDLER(AutomationMsg_BookmarkBarVisibility,
424 GetBookmarkBarVisibility) 419 GetBookmarkBarVisibility)
425 IPC_MESSAGE_HANDLER(AutomationMsg_GetBookmarksAsJSON, 420 IPC_MESSAGE_HANDLER(AutomationMsg_GetBookmarksAsJSON,
426 GetBookmarksAsJSON) 421 GetBookmarksAsJSON)
427 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForBookmarkModelToLoad, 422 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForBookmarkModelToLoad,
428 WaitForBookmarkModelToLoad) 423 WaitForBookmarkModelToLoad)
(...skipping 11 matching lines...) Expand all
440 RemoveBookmark) 435 RemoveBookmark)
441 IPC_MESSAGE_HANDLER_DELAY_REPLY( 436 IPC_MESSAGE_HANDLER_DELAY_REPLY(
442 AutomationMsg_WaitForBrowserWindowCountToBecome, 437 AutomationMsg_WaitForBrowserWindowCountToBecome,
443 WaitForBrowserWindowCountToBecome) 438 WaitForBrowserWindowCountToBecome)
444 IPC_MESSAGE_HANDLER_DELAY_REPLY( 439 IPC_MESSAGE_HANDLER_DELAY_REPLY(
445 AutomationMsg_GoBackBlockUntilNavigationsComplete, 440 AutomationMsg_GoBackBlockUntilNavigationsComplete,
446 GoBackBlockUntilNavigationsComplete) 441 GoBackBlockUntilNavigationsComplete)
447 IPC_MESSAGE_HANDLER_DELAY_REPLY( 442 IPC_MESSAGE_HANDLER_DELAY_REPLY(
448 AutomationMsg_GoForwardBlockUntilNavigationsComplete, 443 AutomationMsg_GoForwardBlockUntilNavigationsComplete,
449 GoForwardBlockUntilNavigationsComplete) 444 GoForwardBlockUntilNavigationsComplete)
450 IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility)
451 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest, 445 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest,
452 SendJSONRequestWithBrowserIndex) 446 SendJSONRequestWithBrowserIndex)
453 IPC_MESSAGE_HANDLER_DELAY_REPLY( 447 IPC_MESSAGE_HANDLER_DELAY_REPLY(
454 AutomationMsg_SendJSONRequestWithBrowserHandle, 448 AutomationMsg_SendJSONRequestWithBrowserHandle,
455 SendJSONRequestWithBrowserHandle) 449 SendJSONRequestWithBrowserHandle)
456 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabCountToBecome, 450 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabCountToBecome,
457 WaitForTabCountToBecome) 451 WaitForTabCountToBecome)
458 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForInfoBarCount, 452 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForInfoBarCount,
459 WaitForInfoBarCount) 453 WaitForInfoBarCount)
460 IPC_MESSAGE_HANDLER(AutomationMsg_ResetToDefaultTheme, ResetToDefaultTheme) 454 IPC_MESSAGE_HANDLER(AutomationMsg_ResetToDefaultTheme, ResetToDefaultTheme)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 } 562 }
569 563
570 void TestingAutomationProvider::GetCookies(const GURL& url, int handle, 564 void TestingAutomationProvider::GetCookies(const GURL& url, int handle,
571 int* value_size, 565 int* value_size,
572 std::string* value) { 566 std::string* value) {
573 WebContents* contents = tab_tracker_->ContainsHandle(handle) ? 567 WebContents* contents = tab_tracker_->ContainsHandle(handle) ?
574 tab_tracker_->GetResource(handle)->GetWebContents() : NULL; 568 tab_tracker_->GetResource(handle)->GetWebContents() : NULL;
575 automation_util::GetCookies(url, contents, value_size, value); 569 automation_util::GetCookies(url, contents, value_size, value);
576 } 570 }
577 571
578 void TestingAutomationProvider::SetCookie(const GURL& url,
579 const std::string& value,
580 int handle,
581 int* response_value) {
582 WebContents* contents = tab_tracker_->ContainsHandle(handle) ?
583 tab_tracker_->GetResource(handle)->GetWebContents() : NULL;
584 automation_util::SetCookie(url, value, contents, response_value);
585 }
586
587 void TestingAutomationProvider::NavigateToURLBlockUntilNavigationsComplete( 572 void TestingAutomationProvider::NavigateToURLBlockUntilNavigationsComplete(
588 int handle, const GURL& url, int number_of_navigations, 573 int handle, const GURL& url, int number_of_navigations,
589 IPC::Message* reply_message) { 574 IPC::Message* reply_message) {
590 if (tab_tracker_->ContainsHandle(handle)) { 575 if (tab_tracker_->ContainsHandle(handle)) {
591 NavigationController* tab = tab_tracker_->GetResource(handle); 576 NavigationController* tab = tab_tracker_->GetResource(handle);
592 577
593 // Simulate what a user would do. Activate the tab and then navigate. 578 // Simulate what a user would do. Activate the tab and then navigate.
594 // We could allow navigating in a background tab in future. 579 // We could allow navigating in a background tab in future.
595 Browser* browser = FindAndActivateTab(tab); 580 Browser* browser = FindAndActivateTab(tab);
596 581
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 GURL* url) { 1078 GURL* url) {
1094 *success = false; 1079 *success = false;
1095 if (tab_tracker_->ContainsHandle(handle)) { 1080 if (tab_tracker_->ContainsHandle(handle)) {
1096 NavigationController* tab = tab_tracker_->GetResource(handle); 1081 NavigationController* tab = tab_tracker_->GetResource(handle);
1097 // Return what the user would see in the location bar. 1082 // Return what the user would see in the location bar.
1098 *url = tab->GetActiveEntry()->GetVirtualURL(); 1083 *url = tab->GetActiveEntry()->GetVirtualURL();
1099 *success = true; 1084 *success = true;
1100 } 1085 }
1101 } 1086 }
1102 1087
1103 void TestingAutomationProvider::GetShelfVisibility(int handle, bool* visible) {
1104 *visible = false;
1105
1106 if (browser_tracker_->ContainsHandle(handle)) {
1107 Browser* browser = browser_tracker_->GetResource(handle);
1108 if (browser) {
1109 *visible = browser->window()->IsDownloadShelfVisible();
1110 }
1111 }
1112 }
1113
1114 void TestingAutomationProvider::ExecuteJavascriptInRenderViewFrame( 1088 void TestingAutomationProvider::ExecuteJavascriptInRenderViewFrame(
1115 const string16& frame_xpath, 1089 const string16& frame_xpath,
1116 const string16& script, 1090 const string16& script,
1117 IPC::Message* reply_message, 1091 IPC::Message* reply_message,
1118 RenderViewHost* render_view_host) { 1092 RenderViewHost* render_view_host) {
1119 // Set the routing id of this message with the controller. 1093 // Set the routing id of this message with the controller.
1120 // This routing id needs to be remembered for the reverse 1094 // This routing id needs to be remembered for the reverse
1121 // communication while sending back the response of 1095 // communication while sending back the response of
1122 // this javascript execution. 1096 // this javascript execution.
1123 render_view_host->ExecuteJavascriptInWebFrame( 1097 render_view_host->ExecuteJavascriptInWebFrame(
(...skipping 14 matching lines...) Expand all
1138 Send(reply_message); 1112 Send(reply_message);
1139 return; 1113 return;
1140 } 1114 }
1141 1115
1142 new DomOperationMessageSender(this, reply_message, false); 1116 new DomOperationMessageSender(this, reply_message, false);
1143 ExecuteJavascriptInRenderViewFrame(WideToUTF16Hack(frame_xpath), 1117 ExecuteJavascriptInRenderViewFrame(WideToUTF16Hack(frame_xpath),
1144 WideToUTF16Hack(script), reply_message, 1118 WideToUTF16Hack(script), reply_message,
1145 web_contents->GetRenderViewHost()); 1119 web_contents->GetRenderViewHost());
1146 } 1120 }
1147 1121
1148 void TestingAutomationProvider::GetDownloadDirectory(
1149 int handle, FilePath* download_directory) {
1150 if (tab_tracker_->ContainsHandle(handle)) {
1151 NavigationController* tab = tab_tracker_->GetResource(handle);
1152 DownloadManager* dlm =
1153 BrowserContext::GetDownloadManager(tab->GetBrowserContext());
1154 *download_directory =
1155 DownloadPrefs::FromDownloadManager(dlm)->DownloadPath();
1156 }
1157 }
1158
1159 // Sample json input: { "command": "OpenNewBrowserWindowWithNewProfile" } 1122 // Sample json input: { "command": "OpenNewBrowserWindowWithNewProfile" }
1160 // Sample output: {} 1123 // Sample output: {}
1161 void TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile( 1124 void TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile(
1162 base::DictionaryValue* args, IPC::Message* reply_message) { 1125 base::DictionaryValue* args, IPC::Message* reply_message) {
1163 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1126 ProfileManager* profile_manager = g_browser_process->profile_manager();
1164 new BrowserOpenedWithNewProfileNotificationObserver(this, reply_message); 1127 new BrowserOpenedWithNewProfileNotificationObserver(this, reply_message);
1165 profile_manager->CreateMultiProfileAsync(string16(), string16()); 1128 profile_manager->CreateMultiProfileAsync(string16(), string16());
1166 } 1129 }
1167 1130
1168 // Sample json input: { "command": "GetMultiProfileInfo" } 1131 // Sample json input: { "command": "GetMultiProfileInfo" }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 void TestingAutomationProvider::BringBrowserToFront(int browser_handle, 1306 void TestingAutomationProvider::BringBrowserToFront(int browser_handle,
1344 bool* success) { 1307 bool* success) {
1345 *success = false; 1308 *success = false;
1346 if (browser_tracker_->ContainsHandle(browser_handle)) { 1309 if (browser_tracker_->ContainsHandle(browser_handle)) {
1347 Browser* browser = browser_tracker_->GetResource(browser_handle); 1310 Browser* browser = browser_tracker_->GetResource(browser_handle);
1348 browser->window()->Activate(); 1311 browser->window()->Activate();
1349 *success = true; 1312 *success = true;
1350 } 1313 }
1351 } 1314 }
1352 1315
1353 void TestingAutomationProvider::IsMenuCommandEnabled(int browser_handle,
1354 int message_num,
1355 bool* menu_item_enabled) {
1356 *menu_item_enabled = false;
1357 if (browser_tracker_->ContainsHandle(browser_handle)) {
1358 Browser* browser = browser_tracker_->GetResource(browser_handle);
1359 *menu_item_enabled = chrome::IsCommandEnabled(browser, message_num);
1360 }
1361 }
1362
1363 void TestingAutomationProvider::HandleOpenFindInPageRequest( 1316 void TestingAutomationProvider::HandleOpenFindInPageRequest(
1364 const IPC::Message& message, int handle) { 1317 const IPC::Message& message, int handle) {
1365 if (browser_tracker_->ContainsHandle(handle)) { 1318 if (browser_tracker_->ContainsHandle(handle)) {
1366 Browser* browser = browser_tracker_->GetResource(handle); 1319 Browser* browser = browser_tracker_->GetResource(handle);
1367 chrome::FindInPage(browser, false, false); 1320 chrome::FindInPage(browser, false, false);
1368 } 1321 }
1369 } 1322 }
1370 1323
1371 void TestingAutomationProvider::GetFindWindowVisibility(int handle, 1324 void TestingAutomationProvider::GetFindWindowVisibility(int handle,
1372 bool* visible) { 1325 bool* visible) {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 chrome::ExecuteCommand(browser, IDC_FORWARD); 1585 chrome::ExecuteCommand(browser, IDC_FORWARD);
1633 return; 1586 return;
1634 } 1587 }
1635 } 1588 }
1636 1589
1637 AutomationMsg_GoForwardBlockUntilNavigationsComplete::WriteReplyParams( 1590 AutomationMsg_GoForwardBlockUntilNavigationsComplete::WriteReplyParams(
1638 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); 1591 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
1639 Send(reply_message); 1592 Send(reply_message);
1640 } 1593 }
1641 1594
1642 void TestingAutomationProvider::SetShelfVisibility(int handle, bool visible) {
1643 if (browser_tracker_->ContainsHandle(handle)) {
1644 Browser* browser = browser_tracker_->GetResource(handle);
1645 if (browser) {
1646 if (visible)
1647 browser->window()->GetDownloadShelf()->Show();
1648 else
1649 browser->window()->GetDownloadShelf()->Close();
1650 }
1651 }
1652 }
1653
1654 void TestingAutomationProvider::BuildJSONHandlerMaps() { 1595 void TestingAutomationProvider::BuildJSONHandlerMaps() {
1655 // Map json commands to their handlers. 1596 // Map json commands to their handlers.
1656 handler_map_["ApplyAccelerator"] = 1597 handler_map_["ApplyAccelerator"] =
1657 &TestingAutomationProvider::ExecuteBrowserCommandAsyncJSON; 1598 &TestingAutomationProvider::ExecuteBrowserCommandAsyncJSON;
1658 handler_map_["RunCommand"] = 1599 handler_map_["RunCommand"] =
1659 &TestingAutomationProvider::ExecuteBrowserCommandJSON; 1600 &TestingAutomationProvider::ExecuteBrowserCommandJSON;
1660 handler_map_["IsMenuCommandEnabled"] = 1601 handler_map_["IsMenuCommandEnabled"] =
1661 &TestingAutomationProvider::IsMenuCommandEnabledJSON; 1602 &TestingAutomationProvider::IsMenuCommandEnabledJSON;
1662 handler_map_["ActivateTab"] = 1603 handler_map_["ActivateTab"] =
1663 &TestingAutomationProvider::ActivateTabJSON; 1604 &TestingAutomationProvider::ActivateTabJSON;
(...skipping 30 matching lines...) Expand all
1694 handler_map_["ExecuteJavascriptInRenderView"] = 1635 handler_map_["ExecuteJavascriptInRenderView"] =
1695 &TestingAutomationProvider::ExecuteJavascriptInRenderView; 1636 &TestingAutomationProvider::ExecuteJavascriptInRenderView;
1696 handler_map_["GoForward"] = 1637 handler_map_["GoForward"] =
1697 &TestingAutomationProvider::GoForward; 1638 &TestingAutomationProvider::GoForward;
1698 handler_map_["GoBack"] = 1639 handler_map_["GoBack"] =
1699 &TestingAutomationProvider::GoBack; 1640 &TestingAutomationProvider::GoBack;
1700 handler_map_["Reload"] = 1641 handler_map_["Reload"] =
1701 &TestingAutomationProvider::ReloadJSON; 1642 &TestingAutomationProvider::ReloadJSON;
1702 handler_map_["CaptureEntirePage"] = 1643 handler_map_["CaptureEntirePage"] =
1703 &TestingAutomationProvider::CaptureEntirePageJSON; 1644 &TestingAutomationProvider::CaptureEntirePageJSON;
1645 handler_map_["SetDownloadShelfVisible"] =
1646 &TestingAutomationProvider::SetDownloadShelfVisibleJSON;
1647 handler_map_["IsDownloadShelfVisible"] =
1648 &TestingAutomationProvider::IsDownloadShelfVisibleJSON;
1649 handler_map_["GetDownloadDirectory"] =
1650 &TestingAutomationProvider::GetDownloadDirectoryJSON;
1704 handler_map_["GetCookies"] = 1651 handler_map_["GetCookies"] =
1705 &TestingAutomationProvider::GetCookiesJSON; 1652 &TestingAutomationProvider::GetCookiesJSON;
1706 handler_map_["DeleteCookie"] = 1653 handler_map_["DeleteCookie"] =
1707 &TestingAutomationProvider::DeleteCookieJSON; 1654 &TestingAutomationProvider::DeleteCookieJSON;
1708 handler_map_["SetCookie"] = 1655 handler_map_["SetCookie"] =
1709 &TestingAutomationProvider::SetCookieJSON; 1656 &TestingAutomationProvider::SetCookieJSON;
1657 handler_map_["GetCookiesInBrowserContext"] =
1658 &TestingAutomationProvider::GetCookiesInBrowserContext;
1659 handler_map_["DeleteCookieInBrowserContext"] =
1660 &TestingAutomationProvider::DeleteCookieInBrowserContext;
1661 handler_map_["SetCookieInBrowserContext"] =
1662 &TestingAutomationProvider::SetCookieInBrowserContext;
1710 handler_map_["GetTabIds"] = 1663 handler_map_["GetTabIds"] =
1711 &TestingAutomationProvider::GetTabIds; 1664 &TestingAutomationProvider::GetTabIds;
1712 handler_map_["GetViews"] = 1665 handler_map_["GetViews"] =
1713 &TestingAutomationProvider::GetViews; 1666 &TestingAutomationProvider::GetViews;
1714 handler_map_["IsTabIdValid"] = 1667 handler_map_["IsTabIdValid"] =
1715 &TestingAutomationProvider::IsTabIdValid; 1668 &TestingAutomationProvider::IsTabIdValid;
1716 handler_map_["DoesAutomationObjectExist"] = 1669 handler_map_["DoesAutomationObjectExist"] =
1717 &TestingAutomationProvider::DoesAutomationObjectExist; 1670 &TestingAutomationProvider::DoesAutomationObjectExist;
1718 handler_map_["CloseTab"] = 1671 handler_map_["CloseTab"] =
1719 &TestingAutomationProvider::CloseTabJSON; 1672 &TestingAutomationProvider::CloseTabJSON;
(...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2860 } else if (action == "cancel") { 2813 } else if (action == "cancel") {
2861 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2814 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2862 this, reply_message, false)); 2815 this, reply_message, false));
2863 selected_item->Cancel(true); 2816 selected_item->Cancel(true);
2864 } else { 2817 } else {
2865 AutomationJSONReply(this, reply_message) 2818 AutomationJSONReply(this, reply_message)
2866 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str())); 2819 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str()));
2867 } 2820 }
2868 } 2821 }
2869 2822
2823 void TestingAutomationProvider::SetDownloadShelfVisibleJSON(
2824 DictionaryValue* args,
2825 IPC::Message* reply_message) {
2826 AutomationJSONReply reply(this, reply_message);
2827 Browser* browser;
2828 std::string error_msg;
2829 bool is_visible;
2830 if (!GetBrowserFromJSONArgs(args, &browser, &error_msg)) {
2831 reply.SendError(error_msg);
2832 return;
2833 }
2834 if (!args->GetBoolean("is_visible", &is_visible)) {
2835 reply.SendError("'is_visible' missing or invalid.");
2836 return;
2837 }
2838 if (is_visible) {
2839 browser->window()->GetDownloadShelf()->Show();
2840 } else {
2841 browser->window()->GetDownloadShelf()->Close();
2842 }
2843 reply.SendSuccess(NULL);
2844 }
2845
2846 void TestingAutomationProvider::IsDownloadShelfVisibleJSON(
2847 DictionaryValue* args,
2848 IPC::Message* reply_message) {
2849 AutomationJSONReply reply(this, reply_message);
2850 Browser* browser;
2851 std::string error_msg;
2852 if (!GetBrowserFromJSONArgs(args, &browser, &error_msg)) {
2853 reply.SendError(error_msg);
2854 return;
2855 }
2856 DictionaryValue dict;
2857 dict.SetBoolean("is_visible", browser->window()->IsDownloadShelfVisible());
2858 reply.SendSuccess(&dict);
2859 }
2860
2861 void TestingAutomationProvider::GetDownloadDirectoryJSON(
2862 DictionaryValue* args,
2863 IPC::Message* reply_message) {
2864 AutomationJSONReply reply(this, reply_message);
2865 WebContents* web_contents;
2866 std::string error;
2867 if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
2868 reply.SendError(error);
2869 return;
2870 }
2871 DownloadManager* dlm =
2872 BrowserContext::GetDownloadManager(
2873 web_contents->GetController().GetBrowserContext());
2874 DictionaryValue dict;
2875 dict.SetString("path",
2876 DownloadPrefs::FromDownloadManager(dlm)->DownloadPath().value());
2877 reply.SendSuccess(&dict);
2878 }
2879
2870 // Sample JSON input { "command": "LoadSearchEngineInfo" } 2880 // Sample JSON input { "command": "LoadSearchEngineInfo" }
2871 void TestingAutomationProvider::LoadSearchEngineInfo( 2881 void TestingAutomationProvider::LoadSearchEngineInfo(
2872 Browser* browser, 2882 Browser* browser,
2873 DictionaryValue* args, 2883 DictionaryValue* args,
2874 IPC::Message* reply_message) { 2884 IPC::Message* reply_message) {
2875 TemplateURLService* url_model = 2885 TemplateURLService* url_model =
2876 TemplateURLServiceFactory::GetForProfile(browser->profile()); 2886 TemplateURLServiceFactory::GetForProfile(browser->profile());
2877 if (url_model->loaded()) { 2887 if (url_model->loaded()) {
2878 AutomationJSONReply(this, reply_message).SendSuccess(NULL); 2888 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
2879 return; 2889 return;
(...skipping 3742 matching lines...) Expand 10 before | Expand all | Expand 10 after
6622 void TestingAutomationProvider::DeleteCookieJSON( 6632 void TestingAutomationProvider::DeleteCookieJSON(
6623 DictionaryValue* args, IPC::Message* reply_message) { 6633 DictionaryValue* args, IPC::Message* reply_message) {
6624 automation_util::DeleteCookieJSON(this, args, reply_message); 6634 automation_util::DeleteCookieJSON(this, args, reply_message);
6625 } 6635 }
6626 6636
6627 void TestingAutomationProvider::SetCookieJSON( 6637 void TestingAutomationProvider::SetCookieJSON(
6628 DictionaryValue* args, IPC::Message* reply_message) { 6638 DictionaryValue* args, IPC::Message* reply_message) {
6629 automation_util::SetCookieJSON(this, args, reply_message); 6639 automation_util::SetCookieJSON(this, args, reply_message);
6630 } 6640 }
6631 6641
6642 void TestingAutomationProvider::GetCookiesInBrowserContext(
6643 DictionaryValue* args,
6644 IPC::Message* reply_message) {
6645 AutomationJSONReply reply(this, reply_message);
6646 WebContents* web_contents;
6647 std::string value, url_string;
6648 int windex, value_size;
6649 if (!args->GetInteger("windex", &windex)) {
6650 reply.SendError("'windex' missing or invalid.");
6651 return;
6652 }
6653 web_contents = automation_util::GetWebContentsAt(windex, 0);
6654 if (!web_contents) {
6655 reply.SendError("'windex' does not refer to a browser window.");
6656 return;
6657 }
6658 if (!args->GetString("url", &url_string)) {
6659 reply.SendError("'url' missing or invalid.");
6660 return;
6661 }
6662 GURL url(url_string);
6663 if (!url.is_valid()) {
6664 reply.SendError("Invalid url.");
6665 return;
6666 }
6667 automation_util::GetCookies(url, web_contents, &value_size, &value);
6668 if (value_size == -1) {
6669 reply.SendError(
6670 StringPrintf("Unable to retrieve cookies for url=%s.",
6671 url_string.c_str()));
6672 return;
6673 }
6674 DictionaryValue dict;
6675 dict.SetString("cookies", value);
6676 reply.SendSuccess(&dict);
6677 }
6678
6679 void TestingAutomationProvider::DeleteCookieInBrowserContext(
6680 DictionaryValue* args,
6681 IPC::Message* reply_message) {
6682 AutomationJSONReply reply(this, reply_message);
6683 WebContents* web_contents;
6684 std::string cookie_name, error, url_string;
6685 int windex;
6686 bool success = false;
6687 if (!args->GetInteger("windex", &windex)) {
6688 reply.SendError("'windex' missing or invalid.");
6689 return;
6690 }
6691 web_contents = automation_util::GetWebContentsAt(windex, 0);
6692 if (!web_contents) {
6693 reply.SendError("'windex' does not refer to a browser window.");
6694 return;
6695 }
6696 if (!args->GetString("cookie_name", &cookie_name)) {
6697 reply.SendError("'cookie_name' missing or invalid.");
6698 return;
6699 }
6700 if (!args->GetString("url", &url_string)) {
6701 reply.SendError("'url' missing or invalid.");
6702 return;
6703 }
6704 GURL url(url_string);
6705 if (!url.is_valid()) {
6706 reply.SendError("Invalid url.");
6707 return;
6708 }
6709 automation_util::DeleteCookie(url, cookie_name, web_contents, &success);
6710 if (!success) {
6711 reply.SendError(
6712 StringPrintf("Failed to delete cookie with name=%s for url=%s.",
6713 cookie_name.c_str(), url_string.c_str()));
6714 return;
6715 }
6716 reply.SendSuccess(NULL);
6717 }
6718
6719 void TestingAutomationProvider::SetCookieInBrowserContext(
6720 DictionaryValue* args,
6721 IPC::Message* reply_message) {
6722 AutomationJSONReply reply(this, reply_message);
6723 WebContents* web_contents;
6724 std::string value, error, url_string;
6725 int windex, response_value = -1;
6726 if (!args->GetInteger("windex", &windex)) {
6727 reply.SendError("'windex' missing or invalid.");
6728 return;
6729 }
6730 web_contents = automation_util::GetWebContentsAt(windex, 0);
6731 if (!web_contents) {
6732 reply.SendError("'windex' does not refer to a browser window.");
6733 return;
6734 }
6735 if (!args->GetString("value", &value)) {
6736 reply.SendError("'value' missing or invalid.");
6737 return;
6738 }
6739 if (!args->GetString("url", &url_string)) {
6740 reply.SendError("'url' missing or invalid.");
6741 return;
6742 }
6743 GURL url(url_string);
6744 if (!url.is_valid()) {
6745 reply.SendError("Invalid url.");
6746 return;
6747 }
6748 automation_util::SetCookie(url, value, web_contents, &response_value);
6749 if (response_value != 1) {
6750 reply.SendError(
6751 StringPrintf("Unable set cookie for url=%s.", url_string.c_str()));
6752 return;
6753 }
6754 reply.SendSuccess(NULL);
6755 }
6756
6632 void TestingAutomationProvider::GetTabIds( 6757 void TestingAutomationProvider::GetTabIds(
6633 DictionaryValue* args, IPC::Message* reply_message) { 6758 DictionaryValue* args, IPC::Message* reply_message) {
6634 ListValue* id_list = new ListValue(); 6759 ListValue* id_list = new ListValue();
6635 BrowserList::const_iterator iter = BrowserList::begin(); 6760 BrowserList::const_iterator iter = BrowserList::begin();
6636 for (; iter != BrowserList::end(); ++iter) { 6761 for (; iter != BrowserList::end(); ++iter) {
6637 Browser* browser = *iter; 6762 Browser* browser = *iter;
6638 for (int i = 0; i < browser->tab_count(); ++i) { 6763 for (int i = 0; i < browser->tab_count(); ++i) {
6639 int id = chrome::GetTabContentsAt(browser, i)->restore_tab_helper()-> 6764 int id = chrome::GetTabContentsAt(browser, i)->restore_tab_helper()->
6640 session_id().id(); 6765 session_id().id();
6641 id_list->Append(Value::CreateIntegerValue(id)); 6766 id_list->Append(Value::CreateIntegerValue(id));
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
6959 void TestingAutomationProvider::OnRemoveProvider() { 7084 void TestingAutomationProvider::OnRemoveProvider() {
6960 if (g_browser_process) 7085 if (g_browser_process)
6961 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 7086 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6962 } 7087 }
6963 7088
6964 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 7089 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
6965 WebContents* tab) { 7090 WebContents* tab) {
6966 if (chrome::GetActiveWebContents(browser) != tab) 7091 if (chrome::GetActiveWebContents(browser) != tab)
6967 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); 7092 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true);
6968 } 7093 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.h ('k') | chrome/common/automation_messages_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698