#include "base/command_line.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part_chromeos.h"
+#include "chrome/browser/chromeos/net/network_portal_detector.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
-#include "chrome/browser/extensions/extension_function_registry.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/networking_private.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/onc/onc_signature.h"
#include "chromeos/network/onc/onc_translator.h"
+#include "chromeos/network/onc/onc_utils.h"
#include "chromeos/network/shill_property_util.h"
#include "components/onc/onc_constants.h"
+#include "extensions/browser/extension_function_registry.h"
namespace api = extensions::api::networking_private;
using chromeos::DBusThreadManager;
using chromeos::ManagedNetworkConfigurationHandler;
using chromeos::NetworkHandler;
+using chromeos::NetworkPortalDetector;
using chromeos::NetworkState;
using chromeos::NetworkStateHandler;
using chromeos::NetworkTypePattern;
~NetworkingPrivateGetPropertiesFunction() {
}
-bool NetworkingPrivateGetPropertiesFunction::RunImpl() {
+bool NetworkingPrivateGetPropertiesFunction::RunAsync() {
scoped_ptr<api::GetProperties::Params> params =
api::GetProperties::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
~NetworkingPrivateGetManagedPropertiesFunction() {
}
-bool NetworkingPrivateGetManagedPropertiesFunction::RunImpl() {
+bool NetworkingPrivateGetManagedPropertiesFunction::RunAsync() {
scoped_ptr<api::GetManagedProperties::Params> params =
api::GetManagedProperties::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
~NetworkingPrivateGetStateFunction() {
}
-bool NetworkingPrivateGetStateFunction::RunImpl() {
+bool NetworkingPrivateGetStateFunction::RunAsync() {
scoped_ptr<api::GetState::Params> params =
api::GetState::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
}
scoped_ptr<base::DictionaryValue> result_dict(new base::DictionaryValue);
- state->GetProperties(result_dict.get());
+ state->GetStateProperties(result_dict.get());
scoped_ptr<base::DictionaryValue> onc_network_part =
chromeos::onc::TranslateShillServiceToONCPart(*result_dict,
&chromeos::onc::kNetworkWithStateSignature);
~NetworkingPrivateSetPropertiesFunction() {
}
-bool NetworkingPrivateSetPropertiesFunction::RunImpl() {
+bool NetworkingPrivateSetPropertiesFunction::RunAsync() {
scoped_ptr<api::SetProperties::Params> params =
api::SetProperties::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
~NetworkingPrivateCreateNetworkFunction() {
}
-bool NetworkingPrivateCreateNetworkFunction::RunImpl() {
+bool NetworkingPrivateCreateNetworkFunction::RunAsync() {
scoped_ptr<api::CreateNetwork::Params> params =
api::CreateNetwork::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
~NetworkingPrivateGetVisibleNetworksFunction() {
}
-bool NetworkingPrivateGetVisibleNetworksFunction::RunImpl() {
+bool NetworkingPrivateGetVisibleNetworksFunction::RunAsync() {
scoped_ptr<api::GetVisibleNetworks::Params> params =
api::GetVisibleNetworks::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
- std::string type_filter =
- api::GetVisibleNetworks::Params::ToString(params->type);
+ NetworkTypePattern type = chromeos::onc::NetworkTypePatternFromOncType(
+ api::GetVisibleNetworks::Params::ToString(params->type));
NetworkStateHandler::NetworkStateList network_states;
- NetworkHandler::Get()->network_state_handler()->GetNetworkList(
- &network_states);
+ NetworkHandler::Get()->network_state_handler()->GetNetworkListByType(
+ type, &network_states);
base::ListValue* network_properties_list = new base::ListValue;
for (NetworkStateHandler::NetworkStateList::iterator it =
network_states.begin();
it != network_states.end(); ++it) {
- const std::string& service_path = (*it)->path();
base::DictionaryValue shill_dictionary;
- (*it)->GetProperties(&shill_dictionary);
+ (*it)->GetStateProperties(&shill_dictionary);
scoped_ptr<base::DictionaryValue> onc_network_part =
- chromeos::onc::TranslateShillServiceToONCPart(shill_dictionary,
- &chromeos::onc::kNetworkWithStateSignature);
-
- std::string onc_type;
- onc_network_part->GetStringWithoutPathExpansion(onc::network_config::kType,
- &onc_type);
- if (type_filter == onc::network_type::kAllTypes ||
- onc_type == type_filter) {
- onc_network_part->SetStringWithoutPathExpansion(
- onc::network_config::kGUID,
- service_path);
- network_properties_list->Append(onc_network_part.release());
- }
+ chromeos::onc::TranslateShillServiceToONCPart(
+ shill_dictionary, &chromeos::onc::kNetworkWithStateSignature);
+ // TODO(stevenjb): Fix this to always use GUID: crbug.com/284827
+ onc_network_part->SetStringWithoutPathExpansion(
+ onc::network_config::kGUID, (*it)->path());
+ network_properties_list->Append(onc_network_part.release());
}
SetResult(network_properties_list);
~NetworkingPrivateGetEnabledNetworkTypesFunction() {
}
-bool NetworkingPrivateGetEnabledNetworkTypesFunction::RunImpl() {
+bool NetworkingPrivateGetEnabledNetworkTypesFunction::RunSync() {
NetworkStateHandler* state_handler =
NetworkHandler::Get()->network_state_handler();
~NetworkingPrivateEnableNetworkTypeFunction() {
}
-bool NetworkingPrivateEnableNetworkTypeFunction::RunImpl() {
+bool NetworkingPrivateEnableNetworkTypeFunction::RunSync() {
scoped_ptr<api::EnableNetworkType::Params> params =
api::EnableNetworkType::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
~NetworkingPrivateDisableNetworkTypeFunction() {
}
-bool NetworkingPrivateDisableNetworkTypeFunction::RunImpl() {
+bool NetworkingPrivateDisableNetworkTypeFunction::RunSync() {
scoped_ptr<api::DisableNetworkType::Params> params =
api::DisableNetworkType::Params::Create(*args_);
NetworkStateHandler* state_handler =
~NetworkingPrivateRequestNetworkScanFunction() {
}
-bool NetworkingPrivateRequestNetworkScanFunction::RunImpl() {
+bool NetworkingPrivateRequestNetworkScanFunction::RunSync() {
NetworkHandler::Get()->network_state_handler()->RequestScan();
return true;
}
SendResponse(false);
}
-bool NetworkingPrivateStartConnectFunction::RunImpl() {
+bool NetworkingPrivateStartConnectFunction::RunAsync() {
scoped_ptr<api::StartConnect::Params> params =
api::StartConnect::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
SendResponse(false);
}
-bool NetworkingPrivateStartDisconnectFunction::RunImpl() {
+bool NetworkingPrivateStartDisconnectFunction::RunAsync() {
scoped_ptr<api::StartDisconnect::Params> params =
api::StartDisconnect::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
~NetworkingPrivateVerifyDestinationFunction() {
}
-bool NetworkingPrivateVerifyDestinationFunction::RunImpl() {
+bool NetworkingPrivateVerifyDestinationFunction::RunAsync() {
scoped_ptr<api::VerifyDestination::Params> params =
api::VerifyDestination::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
~NetworkingPrivateVerifyAndEncryptCredentialsFunction() {
}
-bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunImpl() {
+bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() {
scoped_ptr<api::VerifyAndEncryptCredentials::Params> params =
api::VerifyAndEncryptCredentials::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
~NetworkingPrivateVerifyAndEncryptDataFunction() {
}
-bool NetworkingPrivateVerifyAndEncryptDataFunction::RunImpl() {
+bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() {
scoped_ptr<api::VerifyAndEncryptData::Params> params =
api::VerifyAndEncryptData::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
~NetworkingPrivateSetWifiTDLSEnabledStateFunction() {
}
-bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunImpl() {
+bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() {
scoped_ptr<api::SetWifiTDLSEnabledState::Params> params =
api::SetWifiTDLSEnabledState::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
~NetworkingPrivateGetWifiTDLSStatusFunction() {
}
-bool NetworkingPrivateGetWifiTDLSStatusFunction::RunImpl() {
+bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() {
scoped_ptr<api::GetWifiTDLSStatus::Params> params =
api::GetWifiTDLSStatus::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
error_ = error_name;
SendResponse(false);
}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateGetCaptivePortalStatusFunction
+
+NetworkingPrivateGetCaptivePortalStatusFunction::
+ ~NetworkingPrivateGetCaptivePortalStatusFunction() {}
+
+bool NetworkingPrivateGetCaptivePortalStatusFunction::RunAsync() {
+ scoped_ptr<api::GetCaptivePortalStatus::Params> params =
+ api::GetCaptivePortalStatus::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ NetworkPortalDetector* detector = NetworkPortalDetector::Get();
+ if (!detector) {
+ error_ = "Error.NotReady";
+ return false;
+ }
+
+ NetworkPortalDetector::CaptivePortalState state =
+ detector->GetCaptivePortalState(params->network_path);
+
+ SetResult(new base::StringValue(
+ NetworkPortalDetector::CaptivePortalStatusString(state.status)));
+ SendResponse(true);
+ return true;
+}