OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/chromeos/network_config_message_handler.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/values.h" |
| 13 #include "chromeos/network/managed_network_configuration_handler.h" |
| 14 #include "chromeos/network/network_state.h" |
| 15 #include "chromeos/network/network_state_handler.h" |
| 16 #include "chromeos/network/onc/onc_signature.h" |
| 17 #include "chromeos/network/onc/onc_translator.h" |
| 18 #include "chromeos/network/onc/onc_utils.h" |
| 19 #include "chromeos/network/shill_property_util.h" |
| 20 #include "components/onc/onc_constants.h" |
| 21 #include "content/public/browser/web_ui.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 23 |
| 24 namespace chromeos { |
| 25 |
| 26 NetworkConfigMessageHandler::NetworkConfigMessageHandler() { |
| 27 } |
| 28 |
| 29 NetworkConfigMessageHandler::~NetworkConfigMessageHandler() { |
| 30 } |
| 31 |
| 32 void NetworkConfigMessageHandler::RegisterMessages() { |
| 33 web_ui()->RegisterMessageCallback( |
| 34 "networkConfig.getVisibleNetworks", |
| 35 base::Bind(&NetworkConfigMessageHandler::GetVisibleNetworks, |
| 36 base::Unretained(this))); |
| 37 web_ui()->RegisterMessageCallback( |
| 38 "networkConfig.getProperties", |
| 39 base::Bind(&NetworkConfigMessageHandler::GetProperties, |
| 40 base::Unretained(this))); |
| 41 } |
| 42 |
| 43 void NetworkConfigMessageHandler::GetVisibleNetworks( |
| 44 const base::ListValue* arg_list) const { |
| 45 int callback_id; |
| 46 std::string type; |
| 47 if (!arg_list->GetInteger(0, &callback_id) || |
| 48 !arg_list->GetString(1, &type)) { |
| 49 NOTREACHED(); |
| 50 } |
| 51 base::ListValue return_arg_list; |
| 52 return_arg_list.AppendInteger(callback_id); |
| 53 |
| 54 NetworkTypePattern pattern = onc::NetworkTypePatternFromOncType(type); |
| 55 scoped_ptr<base::ListValue> network_properties_list = |
| 56 chromeos::onc::TranslateShillNetworkListToONC(pattern); |
| 57 return_arg_list.Append(network_properties_list.release()); |
| 58 InvokeCallback(return_arg_list); |
| 59 } |
| 60 |
| 61 void NetworkConfigMessageHandler::GetProperties( |
| 62 const base::ListValue* arg_list) const { |
| 63 int callback_id; |
| 64 std::string guid; |
| 65 if (!arg_list->GetInteger(0, &callback_id) || |
| 66 !arg_list->GetString(1, &guid)) { |
| 67 NOTREACHED(); |
| 68 } |
| 69 NetworkHandler::Get()->managed_network_configuration_handler()->GetProperties( |
| 70 guid, |
| 71 base::Bind(&NetworkConfigMessageHandler::GetPropertiesSuccess, |
| 72 base::Unretained(this), callback_id), |
| 73 base::Bind(&NetworkConfigMessageHandler::ErrorCallback, |
| 74 base::Unretained(this), callback_id)); |
| 75 } |
| 76 |
| 77 void NetworkConfigMessageHandler::GetPropertiesSuccess( |
| 78 int callback_id, |
| 79 const std::string& service_path, |
| 80 const base::DictionaryValue& dictionary) const { |
| 81 base::ListValue return_arg_list; |
| 82 return_arg_list.AppendInteger(callback_id); |
| 83 |
| 84 base::DictionaryValue* network_properties = dictionary.DeepCopy(); |
| 85 network_properties->SetStringWithoutPathExpansion( |
| 86 ::onc::network_config::kGUID, service_path); |
| 87 return_arg_list.Append(network_properties); |
| 88 InvokeCallback(return_arg_list); |
| 89 } |
| 90 |
| 91 void NetworkConfigMessageHandler::InvokeCallback( |
| 92 const base::ListValue& arg_list) const { |
| 93 web_ui()->CallJavascriptFunction( |
| 94 "networkConfig.chromeCallbackSuccess", arg_list); |
| 95 } |
| 96 |
| 97 void NetworkConfigMessageHandler::ErrorCallback( |
| 98 int callback_id, |
| 99 const std::string& error_name, |
| 100 scoped_ptr<base::DictionaryValue> error_data) const { |
| 101 LOG(ERROR) << "NetworkConfigMessageHandler Error: " << error_name; |
| 102 base::ListValue arg_list; |
| 103 arg_list.AppendInteger(callback_id); |
| 104 arg_list.AppendString(error_name); |
| 105 web_ui()->CallJavascriptFunction( |
| 106 "networkConfig.chromeCallbackError", arg_list); |
| 107 } |
| 108 |
| 109 } // namespace chromeos |
OLD | NEW |