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 <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 2293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2304 | 2304 |
2305 browser_handler_map["LoadSearchEngineInfo"] = | 2305 browser_handler_map["LoadSearchEngineInfo"] = |
2306 &TestingAutomationProvider::LoadSearchEngineInfo; | 2306 &TestingAutomationProvider::LoadSearchEngineInfo; |
2307 browser_handler_map["GetSearchEngineInfo"] = | 2307 browser_handler_map["GetSearchEngineInfo"] = |
2308 &TestingAutomationProvider::GetSearchEngineInfo; | 2308 &TestingAutomationProvider::GetSearchEngineInfo; |
2309 browser_handler_map["AddOrEditSearchEngine"] = | 2309 browser_handler_map["AddOrEditSearchEngine"] = |
2310 &TestingAutomationProvider::AddOrEditSearchEngine; | 2310 &TestingAutomationProvider::AddOrEditSearchEngine; |
2311 browser_handler_map["PerformActionOnSearchEngine"] = | 2311 browser_handler_map["PerformActionOnSearchEngine"] = |
2312 &TestingAutomationProvider::PerformActionOnSearchEngine; | 2312 &TestingAutomationProvider::PerformActionOnSearchEngine; |
2313 | 2313 |
| 2314 browser_handler_map["GetLocalStatePrefsInfo"] = |
| 2315 &TestingAutomationProvider::GetLocalStatePrefsInfo; |
| 2316 browser_handler_map["SetLocalState"] = |
| 2317 &TestingAutomationProvider::SetLocalState; |
2314 browser_handler_map["GetPrefsInfo"] = | 2318 browser_handler_map["GetPrefsInfo"] = |
2315 &TestingAutomationProvider::GetPrefsInfo; | 2319 &TestingAutomationProvider::GetPrefsInfo; |
2316 browser_handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; | 2320 browser_handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; |
2317 | 2321 |
2318 browser_handler_map["SetWindowDimensions"] = | 2322 browser_handler_map["SetWindowDimensions"] = |
2319 &TestingAutomationProvider::SetWindowDimensions; | 2323 &TestingAutomationProvider::SetWindowDimensions; |
2320 | 2324 |
2321 browser_handler_map["GetDownloadsInfo"] = | 2325 browser_handler_map["GetDownloadsInfo"] = |
2322 &TestingAutomationProvider::GetDownloadsInfo; | 2326 &TestingAutomationProvider::GetDownloadsInfo; |
2323 browser_handler_map["WaitForAllDownloadsToComplete"] = | 2327 browser_handler_map["WaitForAllDownloadsToComplete"] = |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3121 } else if (action == "default") { | 3125 } else if (action == "default") { |
3122 url_model->AddObserver(new AutomationProviderSearchEngineObserver( | 3126 url_model->AddObserver(new AutomationProviderSearchEngineObserver( |
3123 this, reply_message)); | 3127 this, reply_message)); |
3124 url_model->SetDefaultSearchProvider(template_url); | 3128 url_model->SetDefaultSearchProvider(template_url); |
3125 } else { | 3129 } else { |
3126 AutomationJSONReply(this, reply_message) | 3130 AutomationJSONReply(this, reply_message) |
3127 .SendError(StringPrintf("Invalid action: %s", action.c_str())); | 3131 .SendError(StringPrintf("Invalid action: %s", action.c_str())); |
3128 } | 3132 } |
3129 } | 3133 } |
3130 | 3134 |
| 3135 // Sample json input: { "command": "GetLocalStatePrefsInfo" } |
| 3136 // Refer chrome/test/pyautolib/prefs_info.py for sample json output. |
| 3137 void TestingAutomationProvider::GetLocalStatePrefsInfo( |
| 3138 Browser* browser, |
| 3139 DictionaryValue* args, |
| 3140 IPC::Message* reply_message) { |
| 3141 DictionaryValue* items = g_browser_process->local_state()-> |
| 3142 GetPreferenceValues(); |
| 3143 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 3144 return_value->Set("prefs", items); // return_value owns items. |
| 3145 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
| 3146 } |
| 3147 |
| 3148 // Sample json input: { "command": "SetLocalState", "path": path, |
| 3149 // "value": value } |
| 3150 void TestingAutomationProvider::SetLocalState(Browser* browser, |
| 3151 DictionaryValue* args, |
| 3152 IPC::Message* reply_message) { |
| 3153 std::string path; |
| 3154 Value* val; |
| 3155 AutomationJSONReply reply(this, reply_message); |
| 3156 if (args->GetString("path", &path) && args->Get("value", &val)) { |
| 3157 PrefService* pref_service = g_browser_process->local_state(); |
| 3158 const PrefService::Preference* pref = |
| 3159 pref_service->FindPreference(path.c_str()); |
| 3160 if (!pref) { // Not a registered pref. |
| 3161 reply.SendError("pref not registered."); |
| 3162 return; |
| 3163 } else if (pref->IsManaged()) { // Do not attempt to change a managed pref. |
| 3164 reply.SendError("pref is managed. cannot be changed."); |
| 3165 return; |
| 3166 } else { // Set the pref. |
| 3167 pref_service->Set(path.c_str(), *val); |
| 3168 } |
| 3169 } else { |
| 3170 reply.SendError("no pref path or value given."); |
| 3171 return; |
| 3172 } |
| 3173 |
| 3174 reply.SendSuccess(NULL); |
| 3175 } |
| 3176 |
3131 // Sample json input: { "command": "GetPrefsInfo" } | 3177 // Sample json input: { "command": "GetPrefsInfo" } |
3132 // Refer chrome/test/pyautolib/prefs_info.py for sample json output. | 3178 // Refer chrome/test/pyautolib/prefs_info.py for sample json output. |
3133 void TestingAutomationProvider::GetPrefsInfo(Browser* browser, | 3179 void TestingAutomationProvider::GetPrefsInfo(Browser* browser, |
3134 DictionaryValue* args, | 3180 DictionaryValue* args, |
3135 IPC::Message* reply_message) { | 3181 IPC::Message* reply_message) { |
3136 DictionaryValue* items = profile_->GetPrefs()->GetPreferenceValues(); | 3182 DictionaryValue* items = profile_->GetPrefs()->GetPreferenceValues(); |
3137 | 3183 |
3138 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 3184 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
3139 return_value->Set("prefs", items); // return_value owns items. | 3185 return_value->Set("prefs", items); // return_value owns items. |
3140 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 3186 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
(...skipping 2751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5892 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); | 5938 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); |
5893 | 5939 |
5894 Send(reply_message_); | 5940 Send(reply_message_); |
5895 redirect_query_ = 0; | 5941 redirect_query_ = 0; |
5896 reply_message_ = NULL; | 5942 reply_message_ = NULL; |
5897 } | 5943 } |
5898 | 5944 |
5899 void TestingAutomationProvider::OnRemoveProvider() { | 5945 void TestingAutomationProvider::OnRemoveProvider() { |
5900 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5946 AutomationProviderList::GetInstance()->RemoveProvider(this); |
5901 } | 5947 } |
OLD | NEW |