| Index: chrome/browser/extensions/api/networking_private/networking_private_api_nonchromeos.cc
|
| diff --git a/chrome/browser/extensions/api/networking_private/networking_private_api_nonchromeos.cc b/chrome/browser/extensions/api/networking_private/networking_private_api_nonchromeos.cc
|
| index 167d853cbf914169eb912054a2053691ad0d14fd..0e9bbcbb226d90a728e1ba250673cf5208ffa7c8 100644
|
| --- a/chrome/browser/extensions/api/networking_private/networking_private_api_nonchromeos.cc
|
| +++ b/chrome/browser/extensions/api/networking_private/networking_private_api_nonchromeos.cc
|
| @@ -9,13 +9,15 @@
|
| #include "base/callback.h"
|
| #include "base/command_line.h"
|
| #include "base/json/json_reader.h"
|
| +#include "base/strings/stringprintf.h"
|
| #include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/extensions/api/networking_private/networking_private_process_client.h"
|
| #include "chrome/browser/extensions/event_router.h"
|
| #include "chrome/browser/extensions/extension_function_registry.h"
|
| #include "chrome/browser/extensions/extension_system.h"
|
| -#include "chrome/browser/profiles/profile.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/extensions/api/networking_private.h"
|
| +#include "components/onc/onc_constants.h"
|
|
|
| using extensions::EventRouter;
|
| using extensions::ExtensionSystem;
|
| @@ -24,15 +26,6 @@ namespace api = extensions::api::networking_private;
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // NetworkingPrivateGetPropertiesFunction
|
|
|
| -
|
| -const char kNetworkingPrivateProperties[] = "NetworkingPrivateProperties";
|
| -
|
| -struct NetworkingPrivatePropertiesData : base::SupportsUserData::Data {
|
| - explicit NetworkingPrivatePropertiesData(const base::DictionaryValue* prop) :
|
| - properties_(prop->DeepCopy()) { }
|
| - scoped_ptr<base::DictionaryValue> properties_;
|
| -};
|
| -
|
| NetworkingPrivateGetPropertiesFunction::
|
| ~NetworkingPrivateGetPropertiesFunction() {
|
| }
|
| @@ -42,38 +35,32 @@ bool NetworkingPrivateGetPropertiesFunction::RunImpl() {
|
| api::GetProperties::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
|
|
| - // If there are properties set by SetProperties function, use those.
|
| - NetworkingPrivatePropertiesData* stored_properties =
|
| - static_cast<NetworkingPrivatePropertiesData*> (
|
| - profile()->GetUserData(kNetworkingPrivateProperties));
|
| - if (stored_properties != NULL) {
|
| - SetResult(stored_properties->properties_.release());
|
| - SendResponse(true);
|
| - return true;
|
| - }
|
| + scoped_refptr<NetworkingPrivateProcessClient> process_client(
|
| + NetworkingPrivateProcessClient::GetProcessClientForProfile(profile_));
|
|
|
| - const std::string network_properties =
|
| - "{\"ConnectionState\":\"NotConnected\","
|
| - "\"GUID\":\"stub_wifi2\","
|
| - "\"Name\":\"wifi2_PSK\","
|
| - "\"Type\":\"WiFi\","
|
| - "\"WiFi\":{"
|
| - "\"Frequency\":5000,"
|
| - "\"FrequencyList\":[2400,5000],"
|
| - "\"SSID\":\"wifi2_PSK\","
|
| - "\"Security\":\"WPA-PSK\","
|
| - "\"SignalStrength\":80}}";
|
| -
|
| - if (params->network_guid == "nonexistent_path") {
|
| - error_ = "Error.DBusFailed";
|
| - SendResponse(false);
|
| - } else {
|
| - SetResult(base::JSONReader::Read(network_properties));
|
| - SendResponse(true);
|
| - }
|
| + process_client->GetProperties(
|
| + params->network_guid, // service path
|
| + base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess,
|
| + this),
|
| + base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed,
|
| + this));
|
| return true;
|
| }
|
|
|
| +void NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess(
|
| + const std::string& service_path,
|
| + const base::DictionaryValue& dictionary) {
|
| + SetResult(dictionary.DeepCopy());
|
| + SendResponse(true);
|
| +}
|
| +
|
| +void NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed(
|
| + const std::string& error_name,
|
| + scoped_ptr<base::DictionaryValue> error_data) {
|
| + error_ = error_name;
|
| + SendResponse(false);
|
| +}
|
| +
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // NetworkingPrivateGetManagedPropertiesFunction
|
|
|
| @@ -184,13 +171,28 @@ bool NetworkingPrivateSetPropertiesFunction::RunImpl() {
|
| scoped_ptr<base::DictionaryValue> properties_dict(
|
| params->properties.ToValue());
|
|
|
| - // Store properties_dict in profile to return from GetProperties.
|
| - profile()->SetUserData(kNetworkingPrivateProperties,
|
| - new NetworkingPrivatePropertiesData(properties_dict.get()));
|
| - SendResponse(true);
|
| + scoped_refptr<NetworkingPrivateProcessClient> process_client(
|
| + NetworkingPrivateProcessClient::GetProcessClientForProfile(profile_));
|
| +
|
| + process_client->SetProperties(
|
| + params->network_guid, // service path
|
| + *properties_dict,
|
| + base::Bind(&NetworkingPrivateSetPropertiesFunction::ResultCallback, this),
|
| + base::Bind(&NetworkingPrivateSetPropertiesFunction::ErrorCallback, this));
|
| return true;
|
| }
|
|
|
| +void NetworkingPrivateSetPropertiesFunction::ErrorCallback(
|
| + const std::string& error_name,
|
| + const scoped_ptr<base::DictionaryValue> error_data) {
|
| + error_ = error_name;
|
| + SendResponse(false);
|
| +}
|
| +
|
| +void NetworkingPrivateSetPropertiesFunction::ResultCallback() {
|
| + SendResponse(true);
|
| +}
|
| +
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // NetworkingPrivateCreateNetworkFunction
|
|
|
| @@ -203,14 +205,6 @@ bool NetworkingPrivateCreateNetworkFunction::RunImpl() {
|
| api::CreateNetwork::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
|
|
| - // Store properties_dict in profile to return from GetProperties.
|
| - scoped_ptr<base::DictionaryValue> properties_dict(
|
| - params->properties.ToValue());
|
| - properties_dict->SetString("GUID", "fake_guid");
|
| - profile()->SetUserData(
|
| - kNetworkingPrivateProperties,
|
| - new NetworkingPrivatePropertiesData(properties_dict.get()));
|
| -
|
| results_ = api::CreateNetwork::Results::Create("fake_guid");
|
| SendResponse(true);
|
| return true;
|
| @@ -227,66 +221,47 @@ bool NetworkingPrivateGetVisibleNetworksFunction::RunImpl() {
|
| scoped_ptr<api::GetVisibleNetworks::Params> params =
|
| api::GetVisibleNetworks::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| - const std::string networks_json =
|
| - "[{"
|
| - " \"ConnectionState\": \"Connected\","
|
| - " \"GUID\": \"stub_ethernet\","
|
| - " \"Name\": \"eth0\","
|
| - " \"Type\": \"Ethernet\","
|
| - " \"Ethernet\": {"
|
| - " \"Authentication\": \"None\""
|
| - " }"
|
| - " },"
|
| - " {"
|
| - " \"ConnectionState\": \"Connected\","
|
| - " \"GUID\": \"stub_wifi1\","
|
| - " \"Name\": \"wifi1\","
|
| - " \"Type\": \"WiFi\","
|
| - " \"WiFi\": {"
|
| - " \"Security\": \"WEP-PSK\","
|
| - " \"SignalStrength\": 0"
|
| - " }"
|
| - " },"
|
| - " {"
|
| - " \"ConnectionState\": \"Connected\","
|
| - " \"GUID\": \"stub_vpn1\","
|
| - " \"Name\": \"vpn1\","
|
| - " \"Type\": \"VPN\""
|
| - " },"
|
| - " {"
|
| - " \"ConnectionState\": \"NotConnected\","
|
| - " \"GUID\": \"stub_wifi2\","
|
| - " \"Name\": \"wifi2_PSK\","
|
| - " \"Type\": \"WiFi\","
|
| - " \"WiFi\": {"
|
| - " \"Security\": \"WPA-PSK\","
|
| - " \"SignalStrength\": 80"
|
| - " }"
|
| - " },"
|
| - " {"
|
| - " \"Cellular\": {"
|
| - " \"ActivateOverNonCellularNetwork\": false,"
|
| - " \"ActivationState\": \"not-activated\","
|
| - " \"NetworkTechnology\": \"GSM\","
|
| - " \"RoamingState\": \"home\""
|
| - " },"
|
| - " \"ConnectionState\": \"NotConnected\","
|
| - " \"GUID\": \"stub_cellular1\","
|
| - " \"Name\": \"cellular1\","
|
| - " \"Type\": \"Cellular\""
|
| - " }]";
|
| - ListValue* visible_networks =
|
| - static_cast<ListValue*>(base::JSONReader::Read(networks_json));
|
| - // If caller only needs WiFi networks, then remove all other networks.
|
| - if (params->type == api::GetVisibleNetworks::Params::TYPE_WIFI) {
|
| - visible_networks->Remove(4, NULL);
|
| - visible_networks->Remove(2, NULL);
|
| - visible_networks->Remove(0, NULL);
|
| +
|
| + scoped_refptr<NetworkingPrivateProcessClient> process_client(
|
| + NetworkingPrivateProcessClient::GetProcessClientForProfile(profile_));
|
| +
|
| + process_client->GetVisibleNetworks(base::Bind(
|
| + &NetworkingPrivateGetVisibleNetworksFunction::ResultCallback, this));
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void NetworkingPrivateGetVisibleNetworksFunction::ResultCallback(
|
| + const base::ListValue& network_list) {
|
| + scoped_ptr<api::GetVisibleNetworks::Params> params =
|
| + api::GetVisibleNetworks::Params::Create(*args_);
|
| + ListValue* result = new ListValue();
|
| + std::string params_type =
|
| + api::GetVisibleNetworks::Params::ToString(params->type);
|
| + bool request_all =
|
| + params->type == api::GetVisibleNetworks::Params::TYPE_ALL;
|
| +
|
| + // Copy networks of requested type;
|
| + for (base::ListValue::const_iterator it = network_list.begin();
|
| + it != network_list.end();
|
| + ++it) {
|
| + const base::Value* network_value = *it;
|
| + const DictionaryValue* network_dict = NULL;
|
| + if (!network_value->GetAsDictionary(&network_dict)) {
|
| + LOG(ERROR) << "Value is not a dictionary";
|
| + continue;
|
| + }
|
| + if (!request_all) {
|
| + std::string network_type;
|
| + network_dict->GetString(onc::network_config::kType, &network_type);
|
| + if (network_type != params_type)
|
| + continue;
|
| + }
|
| + result->Append(network_value->DeepCopy());
|
| }
|
|
|
| - SetResult(visible_networks);
|
| + SetResult(result);
|
| SendResponse(true);
|
| - return true;
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -297,20 +272,9 @@ NetworkingPrivateRequestNetworkScanFunction::
|
| }
|
|
|
| bool NetworkingPrivateRequestNetworkScanFunction::RunImpl() {
|
| - // Generate onNetworkListChanged event.
|
| - std::vector<std::string> changes;
|
| - changes.push_back("stub_ethernet");
|
| - changes.push_back("stub_wifi1");
|
| - changes.push_back("stub_vpn1");
|
| - changes.push_back("stub_wifi2");
|
| - changes.push_back("stub_cellular1");
|
| -
|
| - EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router();
|
| - scoped_ptr<base::ListValue> args(api::OnNetworkListChanged::Create(changes));
|
| - scoped_ptr<extensions::Event> extension_event(new extensions::Event(
|
| - api::OnNetworkListChanged::kEventName, args.Pass()));
|
| - event_router->BroadcastEvent(extension_event.Pass());
|
| -
|
| + scoped_refptr<NetworkingPrivateProcessClient> process_client(
|
| + NetworkingPrivateProcessClient::GetProcessClientForProfile(profile_));
|
| + process_client->RequestNetworkScan();
|
| return true;
|
| }
|
|
|
| @@ -325,52 +289,28 @@ bool NetworkingPrivateStartConnectFunction::RunImpl() {
|
| scoped_ptr<api::StartConnect::Params> params =
|
| api::StartConnect::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| - if (params->network_guid == "nonexistent_path") {
|
| - error_ = "configure-failed";
|
| - SendResponse(false);
|
| - } else {
|
| - SendResponse(true);
|
| - // Set Properties to reflect connected state
|
| - const std::string network_properties =
|
| - "{\"ConnectionState\":\"Connected\","
|
| - "\"GUID\":\"stub_wifi2\","
|
| - "\"Name\":\"wifi2_PSK\","
|
| - "\"Type\":\"WiFi\","
|
| - "\"WiFi\":{"
|
| - "\"SSID\":\"stub_wifi2\","
|
| - "\"Security\":\"WPA-PSK\","
|
| - "\"SignalStrength\":80}}";
|
| -
|
| - // Store network_properties in profile to return from GetProperties.
|
| - profile()->SetUserData(kNetworkingPrivateProperties,
|
| - new NetworkingPrivatePropertiesData(
|
| - static_cast<DictionaryValue*>(
|
| - base::JSONReader::Read(network_properties))));
|
| -
|
| - // Broadcast NetworksChanged Event that network is connected
|
| - EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router();
|
| - scoped_ptr<base::ListValue> args(api::OnNetworksChanged::Create(
|
| - std::vector<std::string>(1, params->network_guid)));
|
| - scoped_ptr<extensions::Event> netchanged_event(
|
| - new extensions::Event(api::OnNetworksChanged::kEventName, args.Pass()));
|
| - event_router->BroadcastEvent(netchanged_event.Pass());
|
| -
|
| - // Generate NetworkListChanged event.
|
| - std::vector<std::string> list;
|
| - list.push_back("stub_ethernet");
|
| - list.push_back("stub_wifi2");
|
| - list.push_back("stub_vpn1");
|
| - list.push_back("stub_wifi1");
|
| - list.push_back("stub_cellular1");
|
| -
|
| - scoped_ptr<base::ListValue> arg2(api::OnNetworkListChanged::Create(list));
|
| - scoped_ptr<extensions::Event> netlist_event(new extensions::Event(
|
| - api::OnNetworkListChanged::kEventName, arg2.Pass()));
|
| - event_router->BroadcastEvent(netlist_event.Pass());
|
| - }
|
| + scoped_refptr<NetworkingPrivateProcessClient> process_client(
|
| + NetworkingPrivateProcessClient::GetProcessClientForProfile(profile_));
|
| + process_client->StartConnect(
|
| + params->network_guid, // service path
|
| + base::Bind(&NetworkingPrivateStartConnectFunction::ConnectionStartSuccess,
|
| + this),
|
| + base::Bind(&NetworkingPrivateStartConnectFunction::ConnectionStartFailed,
|
| + this));
|
| return true;
|
| }
|
|
|
| +void NetworkingPrivateStartConnectFunction::ConnectionStartSuccess() {
|
| + SendResponse(true);
|
| +}
|
| +
|
| +void NetworkingPrivateStartConnectFunction::ConnectionStartFailed(
|
| + const std::string& error_name,
|
| + const scoped_ptr<base::DictionaryValue> error_data) {
|
| + error_ = error_name;
|
| + SendResponse(false);
|
| +}
|
| +
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // NetworkingPrivateStartDisconnectFunction
|
|
|
| @@ -382,35 +322,45 @@ bool NetworkingPrivateStartDisconnectFunction::RunImpl() {
|
| scoped_ptr<api::StartDisconnect::Params> params =
|
| api::StartDisconnect::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| - if (params->network_guid == "nonexistent_path") {
|
| - error_ = "not-found";
|
| - SendResponse(false);
|
| - } else {
|
| - SendResponse(true);
|
| -
|
| - // Send Event that network is disconnected. Listener will use GetProperties.
|
| - EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router();
|
| - scoped_ptr<base::ListValue> args(api::OnNetworksChanged::Create(
|
| - std::vector<std::string>(1, params->network_guid)));
|
| - scoped_ptr<extensions::Event> extension_event(
|
| - new extensions::Event(api::OnNetworksChanged::kEventName, args.Pass()));
|
| - event_router->BroadcastEvent(extension_event.Pass());
|
| - }
|
| + scoped_refptr<NetworkingPrivateProcessClient> process_client(
|
| + NetworkingPrivateProcessClient::GetProcessClientForProfile(profile_));
|
| + process_client->StartDisconnect(
|
| + params->network_guid, // service path
|
| + base::Bind(
|
| + &NetworkingPrivateStartDisconnectFunction::DisconnectionStartSuccess,
|
| + this),
|
| + base::Bind(
|
| + &NetworkingPrivateStartDisconnectFunction::DisconnectionStartFailed,
|
| + this));
|
| return true;
|
| }
|
|
|
| +void NetworkingPrivateStartDisconnectFunction::DisconnectionStartSuccess() {
|
| + SendResponse(true);
|
| +}
|
| +
|
| +void NetworkingPrivateStartDisconnectFunction::DisconnectionStartFailed(
|
| + const std::string& error_name,
|
| + const scoped_ptr<base::DictionaryValue> error_data) {
|
| + error_ = error_name;
|
| + SendResponse(false);
|
| +}
|
| +
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // NetworkingPrivateVerifyDestinationFunction
|
|
|
| NetworkingPrivateVerifyDestinationFunction::
|
| - ~NetworkingPrivateVerifyDestinationFunction() {
|
| -}
|
| + ~NetworkingPrivateVerifyDestinationFunction() {}
|
|
|
| bool NetworkingPrivateVerifyDestinationFunction::RunImpl() {
|
| scoped_ptr<api::VerifyDestination::Params> params =
|
| api::VerifyDestination::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| - SetResult(new base::FundamentalValue(true));
|
| + scoped_refptr<NetworkingPrivateProcessClient> process_client(
|
| + NetworkingPrivateProcessClient::GetProcessClientForProfile(profile_));
|
| +
|
| + bool verified = process_client->VerifyDestination(params->properties);
|
| + SetResult(new base::FundamentalValue(verified));
|
| SendResponse(true);
|
| return true;
|
| }
|
| @@ -442,7 +392,17 @@ bool NetworkingPrivateVerifyAndEncryptDataFunction::RunImpl() {
|
| scoped_ptr<api::VerifyAndEncryptData::Params> params =
|
| api::VerifyAndEncryptData::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| - SetResult(new base::StringValue("encrypted_data"));
|
| + scoped_refptr<NetworkingPrivateProcessClient> process_client(
|
| + NetworkingPrivateProcessClient::GetProcessClientForProfile(profile_));
|
| +
|
| + std::string encoded_data;
|
| + if (!process_client->VerifyAndEncryptData(
|
| + params->properties, params->data, &encoded_data)) {
|
| + error_ = "VerifyDestinationError";
|
| + return false;
|
| + }
|
| +
|
| + SetResult(new base::StringValue(encoded_data));
|
| SendResponse(true);
|
| return true;
|
| }
|
|
|