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

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

Issue 109013006: Update some uses of UTF conversions in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 12 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 const base::string16& frame_xpath, 1008 const base::string16& frame_xpath,
1009 const base::string16& script, 1009 const base::string16& script,
1010 IPC::Message* reply_message, 1010 IPC::Message* reply_message,
1011 RenderViewHost* render_view_host) { 1011 RenderViewHost* render_view_host) {
1012 // Set the routing id of this message with the controller. 1012 // Set the routing id of this message with the controller.
1013 // This routing id needs to be remembered for the reverse 1013 // This routing id needs to be remembered for the reverse
1014 // communication while sending back the response of 1014 // communication while sending back the response of
1015 // this javascript execution. 1015 // this javascript execution.
1016 render_view_host->ExecuteJavascriptInWebFrame( 1016 render_view_host->ExecuteJavascriptInWebFrame(
1017 frame_xpath, 1017 frame_xpath,
1018 UTF8ToUTF16("window.domAutomationController.setAutomationId(0);")); 1018 base::ASCIIToUTF16("window.domAutomationController.setAutomationId(0);"));
1019 render_view_host->ExecuteJavascriptInWebFrame( 1019 render_view_host->ExecuteJavascriptInWebFrame(
1020 frame_xpath, script); 1020 frame_xpath, script);
1021 } 1021 }
1022 1022
1023 void TestingAutomationProvider::ExecuteJavascript( 1023 void TestingAutomationProvider::ExecuteJavascript(
1024 int handle, 1024 int handle,
1025 const std::wstring& frame_xpath, 1025 const std::wstring& frame_xpath,
1026 const std::wstring& script, 1026 const std::wstring& script,
1027 IPC::Message* reply_message) { 1027 IPC::Message* reply_message) {
1028 WebContents* web_contents = GetWebContentsForHandle(handle, NULL); 1028 WebContents* web_contents = GetWebContentsForHandle(handle, NULL);
1029 if (!web_contents) { 1029 if (!web_contents) {
1030 AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string()); 1030 AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string());
1031 Send(reply_message); 1031 Send(reply_message);
1032 return; 1032 return;
1033 } 1033 }
1034 1034
1035 new DomOperationMessageSender(this, reply_message, false); 1035 new DomOperationMessageSender(this, reply_message, false);
1036 ExecuteJavascriptInRenderViewFrame(WideToUTF16Hack(frame_xpath), 1036 ExecuteJavascriptInRenderViewFrame(WideToUTF16Hack(frame_xpath),
1037 WideToUTF16Hack(script), reply_message, 1037 WideToUTF16Hack(script), reply_message,
1038 web_contents->GetRenderViewHost()); 1038 web_contents->GetRenderViewHost());
1039 } 1039 }
1040 1040
1041 // Sample json input: { "command": "OpenNewBrowserWindowWithNewProfile" } 1041 // Sample json input: { "command": "OpenNewBrowserWindowWithNewProfile" }
1042 // Sample output: {} 1042 // Sample output: {}
1043 void TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile( 1043 void TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile(
1044 base::DictionaryValue* args, IPC::Message* reply_message) { 1044 base::DictionaryValue* args, IPC::Message* reply_message) {
1045 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1045 ProfileManager* profile_manager = g_browser_process->profile_manager();
1046 new BrowserOpenedWithNewProfileNotificationObserver(this, reply_message); 1046 new BrowserOpenedWithNewProfileNotificationObserver(this, reply_message);
1047 profile_manager->CreateMultiProfileAsync( 1047 profile_manager->CreateMultiProfileAsync(
1048 base::string16(), base::string16(), ProfileManager::CreateCallback(), std: :string()); 1048 base::string16(), base::string16(),
1049 ProfileManager::CreateCallback(), std::string());
1049 } 1050 }
1050 1051
1051 // Sample json input: { "command": "GetMultiProfileInfo" } 1052 // Sample json input: { "command": "GetMultiProfileInfo" }
1052 // See GetMultiProfileInfo() in pyauto.py for sample output. 1053 // See GetMultiProfileInfo() in pyauto.py for sample output.
1053 void TestingAutomationProvider::GetMultiProfileInfo( 1054 void TestingAutomationProvider::GetMultiProfileInfo(
1054 base::DictionaryValue* args, IPC::Message* reply_message) { 1055 base::DictionaryValue* args, IPC::Message* reply_message) {
1055 scoped_ptr<base::DictionaryValue> return_value(new base::DictionaryValue); 1056 scoped_ptr<base::DictionaryValue> return_value(new base::DictionaryValue);
1056 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1057 ProfileManager* profile_manager = g_browser_process->profile_manager();
1057 const ProfileInfoCache& profile_info_cache = 1058 const ProfileInfoCache& profile_info_cache =
1058 profile_manager->GetProfileInfoCache(); 1059 profile_manager->GetProfileInfoCache();
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after
2679 IPC::Message* reply_message) { 2680 IPC::Message* reply_message) {
2680 TemplateURLService* url_model = 2681 TemplateURLService* url_model =
2681 TemplateURLServiceFactory::GetForProfile(browser->profile()); 2682 TemplateURLServiceFactory::GetForProfile(browser->profile());
2682 scoped_ptr<base::DictionaryValue> return_value(new base::DictionaryValue); 2683 scoped_ptr<base::DictionaryValue> return_value(new base::DictionaryValue);
2683 base::ListValue* search_engines = new base::ListValue; 2684 base::ListValue* search_engines = new base::ListValue;
2684 TemplateURLService::TemplateURLVector template_urls = 2685 TemplateURLService::TemplateURLVector template_urls =
2685 url_model->GetTemplateURLs(); 2686 url_model->GetTemplateURLs();
2686 for (TemplateURLService::TemplateURLVector::const_iterator it = 2687 for (TemplateURLService::TemplateURLVector::const_iterator it =
2687 template_urls.begin(); it != template_urls.end(); ++it) { 2688 template_urls.begin(); it != template_urls.end(); ++it) {
2688 base::DictionaryValue* search_engine = new base::DictionaryValue; 2689 base::DictionaryValue* search_engine = new base::DictionaryValue;
2689 search_engine->SetString("short_name", UTF16ToUTF8((*it)->short_name())); 2690 search_engine->SetString("short_name",
2690 search_engine->SetString("keyword", UTF16ToUTF8((*it)->keyword())); 2691 base::UTF16ToUTF8((*it)->short_name()));
2692 search_engine->SetString("keyword", base::UTF16ToUTF8((*it)->keyword()));
2691 search_engine->SetBoolean("in_default_list", (*it)->ShowInDefaultList()); 2693 search_engine->SetBoolean("in_default_list", (*it)->ShowInDefaultList());
2692 search_engine->SetBoolean("is_default", 2694 search_engine->SetBoolean("is_default",
2693 (*it) == url_model->GetDefaultSearchProvider()); 2695 (*it) == url_model->GetDefaultSearchProvider());
2694 search_engine->SetBoolean("is_valid", (*it)->url_ref().IsValid()); 2696 search_engine->SetBoolean("is_valid", (*it)->url_ref().IsValid());
2695 search_engine->SetBoolean("supports_replacement", 2697 search_engine->SetBoolean("supports_replacement",
2696 (*it)->url_ref().SupportsReplacement()); 2698 (*it)->url_ref().SupportsReplacement());
2697 search_engine->SetString("url", (*it)->url()); 2699 search_engine->SetString("url", (*it)->url());
2698 search_engine->SetString("host", (*it)->url_ref().GetHost()); 2700 search_engine->SetString("host", (*it)->url_ref().GetHost());
2699 search_engine->SetString("path", (*it)->url_ref().GetPath()); 2701 search_engine->SetString("path", (*it)->url_ref().GetPath());
2700 search_engine->SetString("display_url", 2702 search_engine->SetString("display_url",
2701 UTF16ToUTF8((*it)->url_ref().DisplayURL())); 2703 base::UTF16ToUTF8((*it)->url_ref().DisplayURL()));
2702 search_engines->Append(search_engine); 2704 search_engines->Append(search_engine);
2703 } 2705 }
2704 return_value->Set("search_engines", search_engines); 2706 return_value->Set("search_engines", search_engines);
2705 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); 2707 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
2706 } 2708 }
2707 2709
2708 // Refer to pyauto.py for sample JSON input. 2710 // Refer to pyauto.py for sample JSON input.
2709 void TestingAutomationProvider::AddOrEditSearchEngine( 2711 void TestingAutomationProvider::AddOrEditSearchEngine(
2710 Browser* browser, 2712 Browser* browser,
2711 base::DictionaryValue* args, 2713 base::DictionaryValue* args,
2712 IPC::Message* reply_message) { 2714 IPC::Message* reply_message) {
2713 TemplateURLService* url_model = 2715 TemplateURLService* url_model =
2714 TemplateURLServiceFactory::GetForProfile(browser->profile()); 2716 TemplateURLServiceFactory::GetForProfile(browser->profile());
2715 base::string16 new_title; 2717 base::string16 new_title;
2716 base::string16 new_keyword; 2718 base::string16 new_keyword;
2717 std::string new_url; 2719 std::string new_url;
2718 std::string keyword; 2720 std::string keyword;
2719 if (!args->GetString("new_title", &new_title) || 2721 if (!args->GetString("new_title", &new_title) ||
2720 !args->GetString("new_keyword", &new_keyword) || 2722 !args->GetString("new_keyword", &new_keyword) ||
2721 !args->GetString("new_url", &new_url)) { 2723 !args->GetString("new_url", &new_url)) {
2722 AutomationJSONReply(this, reply_message).SendError( 2724 AutomationJSONReply(this, reply_message).SendError(
2723 "One or more inputs invalid"); 2725 "One or more inputs invalid");
2724 return; 2726 return;
2725 } 2727 }
2726 std::string new_ref_url = TemplateURLRef::DisplayURLToURLRef( 2728 std::string new_ref_url = TemplateURLRef::DisplayURLToURLRef(
2727 UTF8ToUTF16(new_url)); 2729 base::UTF8ToUTF16(new_url));
2728 scoped_ptr<KeywordEditorController> controller( 2730 scoped_ptr<KeywordEditorController> controller(
2729 new KeywordEditorController(browser->profile())); 2731 new KeywordEditorController(browser->profile()));
2730 if (args->GetString("keyword", &keyword)) { 2732 if (args->GetString("keyword", &keyword)) {
2731 TemplateURL* template_url = 2733 TemplateURL* template_url =
2732 url_model->GetTemplateURLForKeyword(UTF8ToUTF16(keyword)); 2734 url_model->GetTemplateURLForKeyword(base::UTF8ToUTF16(keyword));
2733 if (template_url == NULL) { 2735 if (template_url == NULL) {
2734 AutomationJSONReply(this, reply_message).SendError( 2736 AutomationJSONReply(this, reply_message).SendError(
2735 "No match for keyword: " + keyword); 2737 "No match for keyword: " + keyword);
2736 return; 2738 return;
2737 } 2739 }
2738 url_model->AddObserver(new AutomationProviderSearchEngineObserver( 2740 url_model->AddObserver(new AutomationProviderSearchEngineObserver(
2739 this, browser->profile(), reply_message)); 2741 this, browser->profile(), reply_message));
2740 controller->ModifyTemplateURL(template_url, new_title, new_keyword, 2742 controller->ModifyTemplateURL(template_url, new_title, new_keyword,
2741 new_ref_url); 2743 new_ref_url);
2742 } else { 2744 } else {
(...skipping 13 matching lines...) Expand all
2756 TemplateURLServiceFactory::GetForProfile(browser->profile()); 2758 TemplateURLServiceFactory::GetForProfile(browser->profile());
2757 std::string keyword; 2759 std::string keyword;
2758 std::string action; 2760 std::string action;
2759 if (!args->GetString("keyword", &keyword) || 2761 if (!args->GetString("keyword", &keyword) ||
2760 !args->GetString("action", &action)) { 2762 !args->GetString("action", &action)) {
2761 AutomationJSONReply(this, reply_message).SendError( 2763 AutomationJSONReply(this, reply_message).SendError(
2762 "One or more inputs invalid"); 2764 "One or more inputs invalid");
2763 return; 2765 return;
2764 } 2766 }
2765 TemplateURL* template_url = 2767 TemplateURL* template_url =
2766 url_model->GetTemplateURLForKeyword(UTF8ToUTF16(keyword)); 2768 url_model->GetTemplateURLForKeyword(base::UTF8ToUTF16(keyword));
2767 if (template_url == NULL) { 2769 if (template_url == NULL) {
2768 AutomationJSONReply(this, reply_message).SendError( 2770 AutomationJSONReply(this, reply_message).SendError(
2769 "No match for keyword: " + keyword); 2771 "No match for keyword: " + keyword);
2770 return; 2772 return;
2771 } 2773 }
2772 if (action == "delete") { 2774 if (action == "delete") {
2773 url_model->AddObserver(new AutomationProviderSearchEngineObserver( 2775 url_model->AddObserver(new AutomationProviderSearchEngineObserver(
2774 this, browser->profile(), reply_message)); 2776 this, browser->profile(), reply_message));
2775 url_model->Remove(template_url); 2777 url_model->Remove(template_url);
2776 } else if (action == "default") { 2778 } else if (action == "default") {
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after
4207 void TestingAutomationProvider::GetAppModalDialogMessage( 4209 void TestingAutomationProvider::GetAppModalDialogMessage(
4208 base::DictionaryValue* args, IPC::Message* reply_message) { 4210 base::DictionaryValue* args, IPC::Message* reply_message) {
4209 AutomationJSONReply reply(this, reply_message); 4211 AutomationJSONReply reply(this, reply_message);
4210 std::string error_msg; 4212 std::string error_msg;
4211 JavaScriptAppModalDialog* dialog = GetActiveJavaScriptModalDialog(&error_msg); 4213 JavaScriptAppModalDialog* dialog = GetActiveJavaScriptModalDialog(&error_msg);
4212 if (!dialog) { 4214 if (!dialog) {
4213 reply.SendError(error_msg); 4215 reply.SendError(error_msg);
4214 return; 4216 return;
4215 } 4217 }
4216 base::DictionaryValue result_dict; 4218 base::DictionaryValue result_dict;
4217 result_dict.SetString("message", UTF16ToUTF8(dialog->message_text())); 4219 result_dict.SetString("message", base::UTF16ToUTF8(dialog->message_text()));
4218 reply.SendSuccess(&result_dict); 4220 reply.SendSuccess(&result_dict);
4219 } 4221 }
4220 4222
4221 void TestingAutomationProvider::AcceptOrDismissAppModalDialog( 4223 void TestingAutomationProvider::AcceptOrDismissAppModalDialog(
4222 base::DictionaryValue* args, IPC::Message* reply_message) { 4224 base::DictionaryValue* args, IPC::Message* reply_message) {
4223 AutomationJSONReply reply(this, reply_message); 4225 AutomationJSONReply reply(this, reply_message);
4224 bool accept; 4226 bool accept;
4225 if (!args->GetBoolean("accept", &accept)) { 4227 if (!args->GetBoolean("accept", &accept)) {
4226 reply.SendError("Missing or invalid 'accept'"); 4228 reply.SendError("Missing or invalid 'accept'");
4227 return; 4229 return;
4228 } 4230 }
4229 4231
4230 std::string error_msg; 4232 std::string error_msg;
4231 JavaScriptAppModalDialog* dialog = GetActiveJavaScriptModalDialog(&error_msg); 4233 JavaScriptAppModalDialog* dialog = GetActiveJavaScriptModalDialog(&error_msg);
4232 if (!dialog) { 4234 if (!dialog) {
4233 reply.SendError(error_msg); 4235 reply.SendError(error_msg);
4234 return; 4236 return;
4235 } 4237 }
4236 if (accept) { 4238 if (accept) {
4237 std::string prompt_text; 4239 std::string prompt_text;
4238 if (args->GetString("prompt_text", &prompt_text)) 4240 if (args->GetString("prompt_text", &prompt_text))
4239 dialog->SetOverridePromptText(UTF8ToUTF16(prompt_text)); 4241 dialog->SetOverridePromptText(base::UTF8ToUTF16(prompt_text));
4240 dialog->native_dialog()->AcceptAppModalDialog(); 4242 dialog->native_dialog()->AcceptAppModalDialog();
4241 } else { 4243 } else {
4242 dialog->native_dialog()->CancelAppModalDialog(); 4244 dialog->native_dialog()->CancelAppModalDialog();
4243 } 4245 }
4244 reply.SendSuccess(NULL); 4246 reply.SendSuccess(NULL);
4245 } 4247 }
4246 4248
4247 // Sample JSON input: { "command": "LaunchApp", 4249 // Sample JSON input: { "command": "LaunchApp",
4248 // "id": "ahfgeienlihckogmohjhadlkjgocpleb" } 4250 // "id": "ahfgeienlihckogmohjhadlkjgocpleb" }
4249 // Sample JSON output: {} 4251 // Sample JSON output: {}
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
5462 if (g_browser_process) 5464 if (g_browser_process)
5463 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 5465 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
5464 } 5466 }
5465 5467
5466 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 5468 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
5467 WebContents* tab) { 5469 WebContents* tab) {
5468 TabStripModel* tab_strip = browser->tab_strip_model(); 5470 TabStripModel* tab_strip = browser->tab_strip_model();
5469 if (tab_strip->GetActiveWebContents() != tab) 5471 if (tab_strip->GetActiveWebContents() != tab)
5470 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); 5472 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true);
5471 } 5473 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698