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

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: Created 8 years, 5 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 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 handler_map_["ExecuteJavascriptInRenderView"] = 1690 handler_map_["ExecuteJavascriptInRenderView"] =
1691 &TestingAutomationProvider::ExecuteJavascriptInRenderView; 1691 &TestingAutomationProvider::ExecuteJavascriptInRenderView;
1692 handler_map_["GoForward"] = 1692 handler_map_["GoForward"] =
1693 &TestingAutomationProvider::GoForward; 1693 &TestingAutomationProvider::GoForward;
1694 handler_map_["GoBack"] = 1694 handler_map_["GoBack"] =
1695 &TestingAutomationProvider::GoBack; 1695 &TestingAutomationProvider::GoBack;
1696 handler_map_["Reload"] = 1696 handler_map_["Reload"] =
1697 &TestingAutomationProvider::ReloadJSON; 1697 &TestingAutomationProvider::ReloadJSON;
1698 handler_map_["CaptureEntirePage"] = 1698 handler_map_["CaptureEntirePage"] =
1699 &TestingAutomationProvider::CaptureEntirePageJSON; 1699 &TestingAutomationProvider::CaptureEntirePageJSON;
1700 handler_map_["SetDownloadShelfVisible"] =
1701 &TestingAutomationProvider::SetDownloadShelfVisibleJSON;
1702 handler_map_["IsDownloadShelfVisible"] =
1703 &TestingAutomationProvider::IsDownloadShelfVisibleJSON;
1704 handler_map_["GetDownloadDirectory"] =
1705 &TestingAutomationProvider::GetDownloadDirectoryJSON;
1700 handler_map_["GetCookies"] = 1706 handler_map_["GetCookies"] =
1701 &TestingAutomationProvider::GetCookiesJSON; 1707 &TestingAutomationProvider::GetCookiesJSON;
1702 handler_map_["DeleteCookie"] = 1708 handler_map_["DeleteCookie"] =
1703 &TestingAutomationProvider::DeleteCookieJSON; 1709 &TestingAutomationProvider::DeleteCookieJSON;
1704 handler_map_["SetCookie"] = 1710 handler_map_["SetCookie"] =
1705 &TestingAutomationProvider::SetCookieJSON; 1711 &TestingAutomationProvider::SetCookieJSON;
1712 handler_map_["GetTabCookies"] =
1713 &TestingAutomationProvider::GetTabCookiesJSON;
1714 handler_map_["DeleteTabCookie"] =
1715 &TestingAutomationProvider::DeleteTabCookieJSON;
1716 handler_map_["SetTabCookie"] =
1717 &TestingAutomationProvider::SetTabCookieJSON;
1706 handler_map_["GetTabIds"] = 1718 handler_map_["GetTabIds"] =
1707 &TestingAutomationProvider::GetTabIds; 1719 &TestingAutomationProvider::GetTabIds;
1708 handler_map_["GetViews"] = 1720 handler_map_["GetViews"] =
1709 &TestingAutomationProvider::GetViews; 1721 &TestingAutomationProvider::GetViews;
1710 handler_map_["IsTabIdValid"] = 1722 handler_map_["IsTabIdValid"] =
1711 &TestingAutomationProvider::IsTabIdValid; 1723 &TestingAutomationProvider::IsTabIdValid;
1712 handler_map_["DoesAutomationObjectExist"] = 1724 handler_map_["DoesAutomationObjectExist"] =
1713 &TestingAutomationProvider::DoesAutomationObjectExist; 1725 &TestingAutomationProvider::DoesAutomationObjectExist;
1714 handler_map_["CloseTab"] = 1726 handler_map_["CloseTab"] =
1715 &TestingAutomationProvider::CloseTabJSON; 1727 &TestingAutomationProvider::CloseTabJSON;
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2838 } else if (action == "cancel") { 2850 } else if (action == "cancel") {
2839 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2851 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2840 this, reply_message, false)); 2852 this, reply_message, false));
2841 selected_item->Cancel(true); 2853 selected_item->Cancel(true);
2842 } else { 2854 } else {
2843 AutomationJSONReply(this, reply_message) 2855 AutomationJSONReply(this, reply_message)
2844 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str())); 2856 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str()));
2845 } 2857 }
2846 } 2858 }
2847 2859
2860 void TestingAutomationProvider::SetDownloadShelfVisibleJSON(
2861 DictionaryValue* args,
2862 IPC::Message* reply_message) {
2863 AutomationJSONReply reply(this, reply_message);
2864 Browser* browser;
2865 std::string error_msg;
2866 bool is_visible;
2867 if (!GetBrowserFromJSONArgs(args, &browser, &error_msg)) {
2868 reply.SendError(error_msg);
2869 return;
2870 }
2871 if (!args->GetBoolean("is_visible", &is_visible)) {
2872 reply.SendError("'is_visible' missing or invalid.");
2873 return;
2874 }
2875 if (is_visible) {
2876 browser->window()->GetDownloadShelf()->Show();
2877 } else {
2878 browser->window()->GetDownloadShelf()->Close();
2879 }
2880 reply.SendSuccess(NULL);
2881 }
2882
2883 void TestingAutomationProvider::IsDownloadShelfVisibleJSON(
2884 DictionaryValue* args,
2885 IPC::Message* reply_message) {
2886 AutomationJSONReply reply(this, reply_message);
2887 Browser* browser;
2888 std::string error_msg;
2889 if (!GetBrowserFromJSONArgs(args, &browser, &error_msg)) {
2890 reply.SendError(error_msg);
2891 return;
2892 }
2893 DictionaryValue dict;
2894 dict.SetBoolean("is_visible", browser->window()->IsDownloadShelfVisible());
2895 reply.SendSuccess(&dict);
2896 }
2897
2898 void TestingAutomationProvider::GetDownloadDirectoryJSON(
2899 DictionaryValue* args,
2900 IPC::Message* reply_message) {
2901 AutomationJSONReply reply(this, reply_message);
2902 WebContents* web_contents;
2903 std::string error;
2904 if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
2905 reply.SendError(error);
2906 return;
2907 }
2908 DownloadManager* dlm =
2909 BrowserContext::GetDownloadManager(
2910 web_contents->GetController().GetBrowserContext());
2911 DictionaryValue dict;
2912 dict.SetString("path",
2913 DownloadPrefs::FromDownloadManager(dlm)->download_path().value());
2914 reply.SendSuccess(&dict);
2915 }
2916
2848 // Sample JSON input { "command": "LoadSearchEngineInfo" } 2917 // Sample JSON input { "command": "LoadSearchEngineInfo" }
2849 void TestingAutomationProvider::LoadSearchEngineInfo( 2918 void TestingAutomationProvider::LoadSearchEngineInfo(
2850 Browser* browser, 2919 Browser* browser,
2851 DictionaryValue* args, 2920 DictionaryValue* args,
2852 IPC::Message* reply_message) { 2921 IPC::Message* reply_message) {
2853 TemplateURLService* url_model = 2922 TemplateURLService* url_model =
2854 TemplateURLServiceFactory::GetForProfile(browser->profile()); 2923 TemplateURLServiceFactory::GetForProfile(browser->profile());
2855 if (url_model->loaded()) { 2924 if (url_model->loaded()) {
2856 AutomationJSONReply(this, reply_message).SendSuccess(NULL); 2925 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
2857 return; 2926 return;
(...skipping 3709 matching lines...) Expand 10 before | Expand all | Expand 10 after
6567 void TestingAutomationProvider::DeleteCookieJSON( 6636 void TestingAutomationProvider::DeleteCookieJSON(
6568 DictionaryValue* args, IPC::Message* reply_message) { 6637 DictionaryValue* args, IPC::Message* reply_message) {
6569 automation_util::DeleteCookieJSON(this, args, reply_message); 6638 automation_util::DeleteCookieJSON(this, args, reply_message);
6570 } 6639 }
6571 6640
6572 void TestingAutomationProvider::SetCookieJSON( 6641 void TestingAutomationProvider::SetCookieJSON(
6573 DictionaryValue* args, IPC::Message* reply_message) { 6642 DictionaryValue* args, IPC::Message* reply_message) {
6574 automation_util::SetCookieJSON(this, args, reply_message); 6643 automation_util::SetCookieJSON(this, args, reply_message);
6575 } 6644 }
6576 6645
6646 void TestingAutomationProvider::GetTabCookiesJSON(DictionaryValue* args,
6647 IPC::Message* reply_message) {
6648 AutomationJSONReply reply(this, reply_message);
6649 WebContents* web_contents;
6650 std::string value, error, url_string;
6651 int value_size = -1;
6652 if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
6653 reply.SendError(error);
6654 return;
6655 }
6656 if (!args->GetString("url", &url_string)) {
6657 reply.SendError("'url' missing or invalid.");
6658 return;
6659 }
6660 GURL url(url_string);
6661 if (!url.is_valid()) {
6662 reply.SendError("Invalid url.");
6663 return;
6664 }
6665 automation_util::GetCookies(url, web_contents, &value_size, &value);
6666 if (value_size == -1) {
6667 reply.SendError(
6668 StringPrintf("Unable to retrieve cookies for url=%s.",
6669 url_string.c_str()));
6670 return;
6671 }
6672 DictionaryValue dict;
6673 dict.SetString("cookies", value);
6674 reply.SendSuccess(&dict);
6675 }
6676
6677 void TestingAutomationProvider::DeleteTabCookieJSON(
6678 DictionaryValue* args,
6679 IPC::Message* reply_message) {
6680 AutomationJSONReply reply(this, reply_message);
6681 WebContents* web_contents;
6682 std::string cookie_name, error, url_string;
6683 bool success = false;
6684 if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
6685 reply.SendError(error);
6686 return;
6687 }
6688 if (!args->GetString("cookie_name", &cookie_name)) {
6689 reply.SendError("'cookie_name' missing or invalid.");
6690 return;
6691 }
6692 if (!args->GetString("url", &url_string)) {
6693 reply.SendError("'url' missing or invalid.");
6694 return;
6695 }
6696 GURL url(url_string);
6697 if (!url.is_valid()) {
6698 reply.SendError("Invalid url.");
6699 return;
6700 }
6701 automation_util::DeleteCookie(url, cookie_name, web_contents, &success);
6702 if (!success) {
6703 reply.SendError(
6704 StringPrintf("Failed to delete cookie with name=%s for url=%s.",
6705 cookie_name.c_str(), url_string.c_str()));
6706 return;
6707 }
6708 reply.SendSuccess(NULL);
6709 }
6710
6711 void TestingAutomationProvider::SetTabCookieJSON(DictionaryValue* args,
Nirnimesh 2012/07/20 02:19:46 What is setTabCookie for? I thought cookies were k
craigdh 2012/07/20 15:27:43 If you think of a better name, let me know. The na
craigdh 2012/07/20 18:49:59 How about 'SetCookieInTab'?
6712 IPC::Message* reply_message) {
6713 AutomationJSONReply reply(this, reply_message);
6714 WebContents* web_contents;
6715 std::string value, error, url_string;
6716 int response_value = -1;
6717 if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
6718 reply.SendError(error);
6719 return;
6720 }
6721 if (!args->GetString("value", &value)) {
6722 reply.SendError("'value' missing or invalid.");
6723 return;
6724 }
6725 if (!args->GetString("url", &url_string)) {
6726 reply.SendError("'url' missing or invalid.");
6727 return;
6728 }
6729 GURL url(url_string);
6730 if (!url.is_valid()) {
6731 reply.SendError("Invalid url.");
6732 return;
6733 }
6734 automation_util::SetCookie(url, value, web_contents, &response_value);
6735 if (response_value != 1) {
6736 reply.SendError(
6737 StringPrintf("Unable set cookie for url=%s.", url_string.c_str()));
6738 return;
6739 }
6740 reply.SendSuccess(NULL);
6741 }
6742
6577 void TestingAutomationProvider::GetTabIds( 6743 void TestingAutomationProvider::GetTabIds(
6578 DictionaryValue* args, IPC::Message* reply_message) { 6744 DictionaryValue* args, IPC::Message* reply_message) {
6579 ListValue* id_list = new ListValue(); 6745 ListValue* id_list = new ListValue();
6580 BrowserList::const_iterator iter = BrowserList::begin(); 6746 BrowserList::const_iterator iter = BrowserList::begin();
6581 for (; iter != BrowserList::end(); ++iter) { 6747 for (; iter != BrowserList::end(); ++iter) {
6582 Browser* browser = *iter; 6748 Browser* browser = *iter;
6583 for (int i = 0; i < browser->tab_count(); ++i) { 6749 for (int i = 0; i < browser->tab_count(); ++i) {
6584 int id = chrome::GetTabContentsAt(browser, i)->restore_tab_helper()-> 6750 int id = chrome::GetTabContentsAt(browser, i)->restore_tab_helper()->
6585 session_id().id(); 6751 session_id().id();
6586 id_list->Append(Value::CreateIntegerValue(id)); 6752 id_list->Append(Value::CreateIntegerValue(id));
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
6904 void TestingAutomationProvider::OnRemoveProvider() { 7070 void TestingAutomationProvider::OnRemoveProvider() {
6905 if (g_browser_process) 7071 if (g_browser_process)
6906 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 7072 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6907 } 7073 }
6908 7074
6909 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 7075 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
6910 WebContents* tab) { 7076 WebContents* tab) {
6911 if (chrome::GetActiveWebContents(browser) != tab) 7077 if (chrome::GetActiveWebContents(browser) != tab)
6912 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); 7078 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true);
6913 } 7079 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698