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 "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/automation/automation_provider_json.h" | 8 #include "chrome/browser/automation/automation_provider_json.h" |
9 #include "chrome/browser/automation/automation_provider_observers.h" | 9 #include "chrome/browser/automation/automation_provider_observers.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
11 #include "chrome/browser/chromeos/cros/network_library.h" | 11 #include "chrome/browser/chromeos/cros/network_library.h" |
12 #include "chrome/browser/chromeos/cros/power_library.h" | 12 #include "chrome/browser/chromeos/cros/power_library.h" |
13 #include "chrome/browser/chromeos/cros/screen_lock_library.h" | 13 #include "chrome/browser/chromeos/cros/screen_lock_library.h" |
14 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 14 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
15 #include "chrome/browser/chromeos/login/screen_locker.h" | 15 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 16 #include "chrome/browser/chromeos/proxy_cros_settings_provider.h" |
16 | 17 |
17 using chromeos::CrosLibrary; | 18 using chromeos::CrosLibrary; |
18 using chromeos::NetworkLibrary; | 19 using chromeos::NetworkLibrary; |
19 using chromeos::UserManager; | 20 using chromeos::UserManager; |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 DictionaryValue* GetNetworkInfoDict(const chromeos::Network* network) { | 24 DictionaryValue* GetNetworkInfoDict(const chromeos::Network* network) { |
24 DictionaryValue* item = new DictionaryValue; | 25 DictionaryValue* item = new DictionaryValue; |
25 item->SetString("name", network->name()); | 26 item->SetString("name", network->name()); |
26 item->SetString("device_path", network->device_path()); | 27 item->SetString("device_path", network->device_path()); |
27 item->SetString("ip_address", network->ip_address()); | 28 item->SetString("ip_address", network->ip_address()); |
28 item->SetString("status", network->GetStateString()); | 29 item->SetString("status", network->GetStateString()); |
29 return item; | 30 return item; |
30 } | 31 } |
31 | 32 |
| 33 Value* GetProxySetting(const std::string& setting_name) { |
| 34 chromeos::ProxyCrosSettingsProvider settings_provider; |
| 35 std::string setting_path = "cros.session.proxy."; |
| 36 setting_path.append(setting_name); |
| 37 |
| 38 if (setting_name == "ignorelist") { |
| 39 Value* value; |
| 40 if (settings_provider.Get(setting_path, &value)) |
| 41 return value; |
| 42 } else { |
| 43 Value* setting; |
| 44 if (settings_provider.Get(setting_path, &setting)) { |
| 45 DictionaryValue* setting_dict = static_cast<DictionaryValue*>(setting); |
| 46 Value* value; |
| 47 bool found = setting_dict->Remove("value", &value); |
| 48 delete setting; |
| 49 if (found) |
| 50 return value; |
| 51 } |
| 52 } |
| 53 return NULL; |
| 54 } |
| 55 |
32 } // namespace | 56 } // namespace |
33 | 57 |
34 void TestingAutomationProvider::GetLoginInfo(DictionaryValue* args, | 58 void TestingAutomationProvider::GetLoginInfo(DictionaryValue* args, |
35 IPC::Message* reply_message) { | 59 IPC::Message* reply_message) { |
36 AutomationJSONReply reply(this, reply_message); | 60 AutomationJSONReply reply(this, reply_message); |
37 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 61 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
38 | 62 |
39 const UserManager* user_manager = UserManager::Get(); | 63 const UserManager* user_manager = UserManager::Get(); |
40 if (!user_manager) | 64 if (!user_manager) |
41 reply.SendError("No user manager!"); | 65 reply.SendError("No user manager!"); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 return; | 279 return; |
256 } | 280 } |
257 | 281 |
258 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); | 282 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); |
259 network_library->RequestNetworkScan(); | 283 network_library->RequestNetworkScan(); |
260 | 284 |
261 // Set up an observer (it will delete itself). | 285 // Set up an observer (it will delete itself). |
262 new NetworkScanObserver(this, reply_message); | 286 new NetworkScanObserver(this, reply_message); |
263 } | 287 } |
264 | 288 |
| 289 void TestingAutomationProvider::GetProxySettings(DictionaryValue* args, |
| 290 IPC::Message* reply_message) { |
| 291 const char* settings[] = { "pacurl", "singlehttp", "singlehttpport", |
| 292 "httpurl", "httpport", "httpsurl", "httpsport", |
| 293 "type", "single", "ftpurl", "ftpport", |
| 294 "socks", "socksport", "ignorelist" }; |
| 295 |
| 296 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 297 chromeos::ProxyCrosSettingsProvider settings_provider; |
| 298 |
| 299 for (size_t i = 0; i < arraysize(settings); ++i) { |
| 300 Value* setting = GetProxySetting(settings[i]); |
| 301 if (setting) |
| 302 return_value->Set(settings[i], setting); |
| 303 } |
| 304 |
| 305 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
| 306 } |
| 307 |
| 308 void TestingAutomationProvider::SetProxySettings(DictionaryValue* args, |
| 309 IPC::Message* reply_message) { |
| 310 AutomationJSONReply reply(this, reply_message); |
| 311 std::string key; |
| 312 Value* value; |
| 313 if (!args->GetString("key", &key) || !args->Get("value", &value)) { |
| 314 reply.SendError("Invalid or missing args."); |
| 315 return; |
| 316 } |
| 317 |
| 318 std::string setting_path = "cros.session.proxy."; |
| 319 setting_path.append(key); |
| 320 |
| 321 // ProxyCrosSettingsProvider will own the Value* passed to Set(). |
| 322 chromeos::ProxyCrosSettingsProvider().Set(setting_path, value->DeepCopy()); |
| 323 reply.SendSuccess(NULL); |
| 324 } |
| 325 |
265 void TestingAutomationProvider::ConnectToWifiNetwork( | 326 void TestingAutomationProvider::ConnectToWifiNetwork( |
266 DictionaryValue* args, IPC::Message* reply_message) { | 327 DictionaryValue* args, IPC::Message* reply_message) { |
267 AutomationJSONReply reply(this, reply_message); | 328 AutomationJSONReply reply(this, reply_message); |
268 std::string service_path, password, identity, certpath; | 329 std::string service_path, password, identity, certpath; |
269 if (!args->GetString("service_path", &service_path) || | 330 if (!args->GetString("service_path", &service_path) || |
270 !args->GetString("password", &password) || | 331 !args->GetString("password", &password) || |
271 !args->GetString("identity", &identity) || | 332 !args->GetString("identity", &identity) || |
272 !args->GetString("certpath", &certpath)) { | 333 !args->GetString("certpath", &certpath)) { |
273 reply.SendError("Invalid or missing args."); | 334 reply.SendError("Invalid or missing args."); |
274 return; | 335 return; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); | 372 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); |
312 const chromeos::WifiNetwork* wifi = network_library->wifi_network(); | 373 const chromeos::WifiNetwork* wifi = network_library->wifi_network(); |
313 if (!wifi) { | 374 if (!wifi) { |
314 reply.SendError("Not connected to any wifi network."); | 375 reply.SendError("Not connected to any wifi network."); |
315 return; | 376 return; |
316 } | 377 } |
317 | 378 |
318 network_library->DisconnectFromWirelessNetwork(wifi); | 379 network_library->DisconnectFromWirelessNetwork(wifi); |
319 reply.SendSuccess(NULL); | 380 reply.SendSuccess(NULL); |
320 } | 381 } |
OLD | NEW |