Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / networking_private / networking_private_api_chromeos.cc
index df4f145..685290e 100644 (file)
@@ -10,8 +10,8 @@
 #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;
@@ -77,7 +80,7 @@ NetworkingPrivateGetPropertiesFunction::
   ~NetworkingPrivateGetPropertiesFunction() {
 }
 
-bool NetworkingPrivateGetPropertiesFunction::RunImpl() {
+bool NetworkingPrivateGetPropertiesFunction::RunAsync() {
   scoped_ptr<api::GetProperties::Params> params =
       api::GetProperties::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -115,7 +118,7 @@ NetworkingPrivateGetManagedPropertiesFunction::
   ~NetworkingPrivateGetManagedPropertiesFunction() {
 }
 
-bool NetworkingPrivateGetManagedPropertiesFunction::RunImpl() {
+bool NetworkingPrivateGetManagedPropertiesFunction::RunAsync() {
   scoped_ptr<api::GetManagedProperties::Params> params =
       api::GetManagedProperties::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -157,7 +160,7 @@ NetworkingPrivateGetStateFunction::
   ~NetworkingPrivateGetStateFunction() {
 }
 
-bool NetworkingPrivateGetStateFunction::RunImpl() {
+bool NetworkingPrivateGetStateFunction::RunAsync() {
   scoped_ptr<api::GetState::Params> params =
       api::GetState::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -172,7 +175,7 @@ bool NetworkingPrivateGetStateFunction::RunImpl() {
   }
 
   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);
@@ -189,7 +192,7 @@ NetworkingPrivateSetPropertiesFunction::
 ~NetworkingPrivateSetPropertiesFunction() {
 }
 
-bool NetworkingPrivateSetPropertiesFunction::RunImpl() {
+bool NetworkingPrivateSetPropertiesFunction::RunAsync() {
   scoped_ptr<api::SetProperties::Params> params =
       api::SetProperties::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -225,7 +228,7 @@ NetworkingPrivateCreateNetworkFunction::
 ~NetworkingPrivateCreateNetworkFunction() {
 }
 
-bool NetworkingPrivateCreateNetworkFunction::RunImpl() {
+bool NetworkingPrivateCreateNetworkFunction::RunAsync() {
   scoped_ptr<api::CreateNetwork::Params> params =
       api::CreateNetwork::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -268,39 +271,31 @@ NetworkingPrivateGetVisibleNetworksFunction::
 ~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);
@@ -315,7 +310,7 @@ NetworkingPrivateGetEnabledNetworkTypesFunction::
 ~NetworkingPrivateGetEnabledNetworkTypesFunction() {
 }
 
-bool NetworkingPrivateGetEnabledNetworkTypesFunction::RunImpl() {
+bool NetworkingPrivateGetEnabledNetworkTypesFunction::RunSync() {
   NetworkStateHandler* state_handler =
       NetworkHandler::Get()->network_state_handler();
 
@@ -339,7 +334,7 @@ NetworkingPrivateEnableNetworkTypeFunction::
 ~NetworkingPrivateEnableNetworkTypeFunction() {
 }
 
-bool NetworkingPrivateEnableNetworkTypeFunction::RunImpl() {
+bool NetworkingPrivateEnableNetworkTypeFunction::RunSync() {
   scoped_ptr<api::EnableNetworkType::Params> params =
       api::EnableNetworkType::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -378,7 +373,7 @@ NetworkingPrivateDisableNetworkTypeFunction::
 ~NetworkingPrivateDisableNetworkTypeFunction() {
 }
 
-bool NetworkingPrivateDisableNetworkTypeFunction::RunImpl() {
+bool NetworkingPrivateDisableNetworkTypeFunction::RunSync() {
   scoped_ptr<api::DisableNetworkType::Params> params =
       api::DisableNetworkType::Params::Create(*args_);
   NetworkStateHandler* state_handler =
@@ -417,7 +412,7 @@ NetworkingPrivateRequestNetworkScanFunction::
 ~NetworkingPrivateRequestNetworkScanFunction() {
 }
 
-bool NetworkingPrivateRequestNetworkScanFunction::RunImpl() {
+bool NetworkingPrivateRequestNetworkScanFunction::RunSync() {
   NetworkHandler::Get()->network_state_handler()->RequestScan();
   return true;
 }
@@ -440,7 +435,7 @@ void NetworkingPrivateStartConnectFunction::ConnectionStartFailed(
   SendResponse(false);
 }
 
-bool NetworkingPrivateStartConnectFunction::RunImpl() {
+bool NetworkingPrivateStartConnectFunction::RunAsync() {
   scoped_ptr<api::StartConnect::Params> params =
       api::StartConnect::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -476,7 +471,7 @@ void NetworkingPrivateStartDisconnectFunction::DisconnectionStartFailed(
   SendResponse(false);
 }
 
-bool NetworkingPrivateStartDisconnectFunction::RunImpl() {
+bool NetworkingPrivateStartDisconnectFunction::RunAsync() {
   scoped_ptr<api::StartDisconnect::Params> params =
       api::StartDisconnect::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -499,7 +494,7 @@ NetworkingPrivateVerifyDestinationFunction::
   ~NetworkingPrivateVerifyDestinationFunction() {
 }
 
-bool NetworkingPrivateVerifyDestinationFunction::RunImpl() {
+bool NetworkingPrivateVerifyDestinationFunction::RunAsync() {
   scoped_ptr<api::VerifyDestination::Params> params =
       api::VerifyDestination::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -537,7 +532,7 @@ NetworkingPrivateVerifyAndEncryptCredentialsFunction::
   ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() {
 }
 
-bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunImpl() {
+bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() {
   scoped_ptr<api::VerifyAndEncryptCredentials::Params> params =
       api::VerifyAndEncryptCredentials::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -578,7 +573,7 @@ NetworkingPrivateVerifyAndEncryptDataFunction::
   ~NetworkingPrivateVerifyAndEncryptDataFunction() {
 }
 
-bool NetworkingPrivateVerifyAndEncryptDataFunction::RunImpl() {
+bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() {
   scoped_ptr<api::VerifyAndEncryptData::Params> params =
       api::VerifyAndEncryptData::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -618,7 +613,7 @@ NetworkingPrivateSetWifiTDLSEnabledStateFunction::
   ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() {
 }
 
-bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunImpl() {
+bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() {
   scoped_ptr<api::SetWifiTDLSEnabledState::Params> params =
       api::SetWifiTDLSEnabledState::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -658,7 +653,7 @@ NetworkingPrivateGetWifiTDLSStatusFunction::
   ~NetworkingPrivateGetWifiTDLSStatusFunction() {
 }
 
-bool NetworkingPrivateGetWifiTDLSStatusFunction::RunImpl() {
+bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() {
   scoped_ptr<api::GetWifiTDLSStatus::Params> params =
       api::GetWifiTDLSStatus::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params);
@@ -688,3 +683,29 @@ void NetworkingPrivateGetWifiTDLSStatusFunction::Failure(
   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;
+}