Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / options / vpn_config_view.cc
index e0e65de..6efbef9 100644 (file)
 #include "chrome/browser/chromeos/net/onc_utils.h"
 #include "chrome/browser/profiles/profile_manager.h"
 #include "chrome/common/net/x509_certificate_model.h"
+#include "chrome/grit/chromium_strings.h"
+#include "chrome/grit/generated_resources.h"
+#include "chrome/grit/locale_settings.h"
+#include "chrome/grit/theme_resources.h"
 #include "chromeos/login/login_state.h"
 #include "chromeos/network/network_configuration_handler.h"
 #include "chromeos/network/network_event_log.h"
 #include "chromeos/network/network_state_handler.h"
 #include "chromeos/network/network_ui_data.h"
 #include "components/onc/onc_constants.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "grit/theme_resources.h"
 #include "third_party/cros_system_api/dbus/service_constants.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/base/models/combobox_model.h"
-#include "ui/base/resource/resource_bundle.h"
 #include "ui/events/event.h"
 #include "ui/views/controls/button/checkbox.h"
 #include "ui/views/controls/combobox/combobox.h"
@@ -453,13 +452,21 @@ const std::string VPNConfigView::GetServerCACertPEM() const {
   }
 }
 
-const std::string VPNConfigView::GetUserCertID() const {
+void VPNConfigView::SetUserCertProperties(
+    chromeos::client_cert::ConfigType client_cert_type,
+    base::DictionaryValue* properties) const {
   if (!HaveUserCerts()) {
-    return std::string();  // "None installed"
+    // No certificate selected or not required.
+    chromeos::client_cert::SetEmptyShillProperties(
+        chromeos::client_cert::CONFIG_TYPE_EAP, properties);
   } else {
     // Certificates are listed in the order they appear in the model.
     int index = user_cert_combobox_ ? user_cert_combobox_->selected_index() : 0;
-    return CertLibrary::Get()->GetUserCertPkcs11IdAt(index);
+    int slot_id = -1;
+    const std::string pkcs11_id =
+        CertLibrary::Get()->GetUserCertPkcs11IdAt(index, &slot_id);
+    chromeos::client_cert::SetShillProperties(
+        client_cert_type, slot_id, pkcs11_id, properties);
   }
 }
 
@@ -709,6 +716,7 @@ void VPNConfigView::InitFromProperties(
 
   std::string provider_type, server_hostname, username, group_name;
   bool psk_passphrase_required = false;
+  bool user_passphrase_required = true;
   const base::DictionaryValue* provider_properties;
   if (service_properties.GetDictionaryWithoutPathExpansion(
           shill::kProviderProperty, &provider_properties)) {
@@ -716,25 +724,27 @@ void VPNConfigView::InitFromProperties(
         shill::kTypeProperty, &provider_type);
     provider_properties->GetStringWithoutPathExpansion(
         shill::kHostProperty, &server_hostname);
-  }
-  if (provider_type == shill::kProviderL2tpIpsec) {
-    provider_properties->GetStringWithoutPathExpansion(
-        shill::kL2tpIpsecClientCertIdProperty, &client_cert_id_);
-    ca_cert_pem_ = GetPemFromDictionary(
-        provider_properties, shill::kL2tpIpsecCaCertPemProperty);
-    provider_properties->GetBooleanWithoutPathExpansion(
-        shill::kL2tpIpsecPskRequiredProperty, &psk_passphrase_required);
-    provider_properties->GetStringWithoutPathExpansion(
-        shill::kL2tpIpsecUserProperty, &username);
-    provider_properties->GetStringWithoutPathExpansion(
-        shill::kL2tpIpsecTunnelGroupProperty, &group_name);
-  } else if (provider_type == shill::kProviderOpenVpn) {
-    provider_properties->GetStringWithoutPathExpansion(
-        shill::kOpenVPNClientCertIdProperty, &client_cert_id_);
-    ca_cert_pem_ = GetPemFromDictionary(
-        provider_properties, shill::kOpenVPNCaCertPemProperty);
-    provider_properties->GetStringWithoutPathExpansion(
-        shill::kOpenVPNUserProperty, &username);
+    if (provider_type == shill::kProviderL2tpIpsec) {
+      provider_properties->GetStringWithoutPathExpansion(
+          shill::kL2tpIpsecClientCertIdProperty, &client_cert_id_);
+      ca_cert_pem_ = GetPemFromDictionary(
+          provider_properties, shill::kL2tpIpsecCaCertPemProperty);
+      provider_properties->GetBooleanWithoutPathExpansion(
+          shill::kL2tpIpsecPskRequiredProperty, &psk_passphrase_required);
+      provider_properties->GetStringWithoutPathExpansion(
+          shill::kL2tpIpsecUserProperty, &username);
+      provider_properties->GetStringWithoutPathExpansion(
+          shill::kL2tpIpsecTunnelGroupProperty, &group_name);
+    } else if (provider_type == shill::kProviderOpenVpn) {
+      provider_properties->GetStringWithoutPathExpansion(
+          shill::kOpenVPNClientCertIdProperty, &client_cert_id_);
+      ca_cert_pem_ = GetPemFromDictionary(
+          provider_properties, shill::kOpenVPNCaCertPemProperty);
+      provider_properties->GetStringWithoutPathExpansion(
+          shill::kOpenVPNUserProperty, &username);
+      provider_properties->GetBooleanWithoutPathExpansion(
+          shill::kPassphraseRequiredProperty, &user_passphrase_required);
+    }
   }
   bool save_credentials = false;
   service_properties.GetBooleanWithoutPathExpansion(
@@ -756,10 +766,13 @@ void VPNConfigView::InitFromProperties(
     group_name_textfield_->SetText(base::UTF8ToUTF16(group_name));
   if (psk_passphrase_textfield_)
     psk_passphrase_textfield_->SetShowFake(!psk_passphrase_required);
+  if (user_passphrase_textfield_)
+    user_passphrase_textfield_->SetShowFake(!user_passphrase_required);
   if (save_credentials_checkbox_)
     save_credentials_checkbox_->SetChecked(save_credentials);
 
   Refresh();
+  UpdateCanLogin();
 }
 
 void VPNConfigView::ParseUIProperties(const NetworkState* vpn) {
@@ -776,7 +789,7 @@ void VPNConfigView::ParseUIProperties(const NetworkState* vpn) {
     ParseVPNUIProperty(vpn, type_dict_name, ::onc::openvpn::kServerCARef,
                        &ca_cert_ui_data_);
   }
-  ParseVPNUIProperty(vpn, type_dict_name, ::onc::vpn::kClientCertRef,
+  ParseVPNUIProperty(vpn, type_dict_name, ::onc::client_cert::kClientCertRef,
                      &user_cert_ui_data_);
 
   const std::string credentials_dict_name(
@@ -831,8 +844,7 @@ void VPNConfigView::SetConfigProperties(
         properties->SetWithoutPathExpansion(
             shill::kL2tpIpsecCaCertPemProperty, pem_list);
       }
-      properties->SetStringWithoutPathExpansion(
-          shill::kL2tpIpsecClientCertIdProperty, GetUserCertID());
+      SetUserCertProperties(client_cert::CONFIG_TYPE_IPSEC, properties);
       if (!group_name.empty()) {
         properties->SetStringWithoutPathExpansion(
             shill::kL2tpIpsecTunnelGroupProperty, GetGroupName());
@@ -855,8 +867,7 @@ void VPNConfigView::SetConfigProperties(
         properties->SetWithoutPathExpansion(
             shill::kOpenVPNCaCertPemProperty, pem_list);
       }
-      properties->SetStringWithoutPathExpansion(
-          shill::kOpenVPNClientCertIdProperty, GetUserCertID());
+      SetUserCertProperties(client_cert::CONFIG_TYPE_OPENVPN, properties);
       properties->SetStringWithoutPathExpansion(
           shill::kOpenVPNUserProperty, GetUsername());
       if (!user_passphrase.empty()) {