| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/options/vpn_config_view.h" | 5 #include "chrome/browser/chromeos/options/vpn_config_view.h" |
| 6 | 6 |
| 7 #include "ash/system/chromeos/network/network_connect.h" |
| 7 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/cros/network_library.h" | |
| 11 #include "chrome/browser/chromeos/enrollment_dialog_view.h" | 11 #include "chrome/browser/chromeos/enrollment_dialog_view.h" |
| 12 #include "chrome/browser/chromeos/options/network_connect.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/common/net/x509_certificate_model.h" | 14 #include "chrome/common/net/x509_certificate_model.h" |
| 15 #include "chromeos/network/network_configuration_handler.h" |
| 16 #include "chromeos/network/network_event_log.h" |
| 17 #include "chromeos/network/network_state.h" |
| 18 #include "chromeos/network/network_state_handler.h" |
| 14 #include "chromeos/network/network_ui_data.h" | 19 #include "chromeos/network/network_ui_data.h" |
| 15 #include "chromeos/network/onc/onc_constants.h" | 20 #include "chromeos/network/onc/onc_constants.h" |
| 16 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
| 17 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 18 #include "grit/locale_settings.h" | 23 #include "grit/locale_settings.h" |
| 19 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 20 #include "ui/base/events/event.h" | 26 #include "ui/base/events/event.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/models/combobox_model.h" | 28 #include "ui/base/models/combobox_model.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 24 #include "ui/views/controls/button/checkbox.h" | 30 #include "ui/views/controls/button/checkbox.h" |
| 25 #include "ui/views/controls/combobox/combobox.h" | 31 #include "ui/views/controls/combobox/combobox.h" |
| 26 #include "ui/views/controls/label.h" | 32 #include "ui/views/controls/label.h" |
| 27 #include "ui/views/controls/textfield/textfield.h" | 33 #include "ui/views/controls/textfield/textfield.h" |
| 28 #include "ui/views/layout/grid_layout.h" | 34 #include "ui/views/layout/grid_layout.h" |
| 29 #include "ui/views/layout/layout_constants.h" | 35 #include "ui/views/layout/layout_constants.h" |
| 30 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 31 #include "ui/views/window/dialog_client_view.h" | 37 #include "ui/views/window/dialog_client_view.h" |
| 32 | 38 |
| 33 namespace { | 39 namespace { |
| 34 | 40 |
| 35 // Root CA certificates that are built into Chrome use this token name. | 41 // Root CA certificates that are built into Chrome use this token name. |
| 36 const char* const kRootCertificateTokenName = "Builtin Object Token"; | 42 const char* const kRootCertificateTokenName = "Builtin Object Token"; |
| 37 | 43 |
| 38 string16 ProviderTypeToString(chromeos::ProviderType type) { | 44 enum ProviderTypeIndex { |
| 39 switch (type) { | 45 PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK = 0, |
| 40 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_PSK: | 46 PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT = 1, |
| 47 PROVIDER_TYPE_INDEX_OPEN_VPN = 2, |
| 48 PROVIDER_TYPE_INDEX_MAX = 3, |
| 49 }; |
| 50 |
| 51 string16 ProviderTypeIndexToString(int index) { |
| 52 switch (index) { |
| 53 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK: |
| 41 return l10n_util::GetStringUTF16( | 54 return l10n_util::GetStringUTF16( |
| 42 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_PSK); | 55 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_PSK); |
| 43 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: | 56 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT: |
| 44 return l10n_util::GetStringUTF16( | 57 return l10n_util::GetStringUTF16( |
| 45 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_USER_CERT); | 58 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_USER_CERT); |
| 46 case chromeos::PROVIDER_TYPE_OPEN_VPN: | 59 case PROVIDER_TYPE_INDEX_OPEN_VPN: |
| 47 return l10n_util::GetStringUTF16( | 60 return l10n_util::GetStringUTF16( |
| 48 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_OPEN_VPN); | 61 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_OPEN_VPN); |
| 49 case chromeos::PROVIDER_TYPE_MAX: | |
| 50 break; | |
| 51 } | 62 } |
| 52 NOTREACHED(); | 63 NOTREACHED(); |
| 53 return string16(); | 64 return string16(); |
| 54 } | 65 } |
| 55 | 66 |
| 67 int ProviderTypeToIndex(const std::string& provider_type, |
| 68 const std::string& client_cert_id) { |
| 69 if (provider_type == flimflam::kProviderL2tpIpsec) { |
| 70 if (!client_cert_id.empty()) |
| 71 return PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT; |
| 72 else |
| 73 return PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK; |
| 74 } else { |
| 75 DCHECK(provider_type == flimflam::kProviderOpenVpn); |
| 76 return PROVIDER_TYPE_INDEX_OPEN_VPN; |
| 77 } |
| 78 } |
| 79 |
| 56 // Translates the provider type to the name of the respective ONC dictionary | 80 // Translates the provider type to the name of the respective ONC dictionary |
| 57 // containing configuration data for the type. | 81 // containing configuration data for the type. |
| 58 std::string ProviderTypeToONCDictKey(chromeos::ProviderType type) { | 82 std::string ProviderTypeIndexToONCDictKey(int provider_type_index) { |
| 59 switch (type) { | 83 switch (provider_type_index) { |
| 60 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_PSK: | 84 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK: |
| 61 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: | 85 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT: |
| 62 return chromeos::onc::vpn::kIPsec; | 86 return chromeos::onc::vpn::kIPsec; |
| 63 case chromeos::PROVIDER_TYPE_OPEN_VPN: | 87 case PROVIDER_TYPE_INDEX_OPEN_VPN: |
| 64 return chromeos::onc::vpn::kOpenVPN; | 88 return chromeos::onc::vpn::kOpenVPN; |
| 65 case chromeos::PROVIDER_TYPE_MAX: | |
| 66 break; | |
| 67 } | 89 } |
| 90 NOTREACHED() << "Unhandled provider type index " << provider_type_index; |
| 91 return std::string(); |
| 92 } |
| 68 | 93 |
| 69 NOTREACHED() << "Unhandled provider type " << type; | 94 std::string GetPemFromDictionary( |
| 70 return std::string(); | 95 const base::DictionaryValue* provider_properties, |
| 96 const std::string& key) { |
| 97 const base::ListValue* pems = NULL; |
| 98 if (!provider_properties->GetListWithoutPathExpansion(key, &pems)) |
| 99 return std::string(); |
| 100 std::string pem; |
| 101 pems->GetString(0, &pem); |
| 102 return pem; |
| 103 } |
| 104 |
| 105 void ShillError(const std::string& function, |
| 106 const std::string& error_name, |
| 107 scoped_ptr<base::DictionaryValue> error_data) { |
| 108 NET_LOG_ERROR("Shill Error from VpnConfigView: " + error_name, function); |
| 71 } | 109 } |
| 72 | 110 |
| 73 } // namespace | 111 } // namespace |
| 74 | 112 |
| 75 namespace chromeos { | 113 namespace chromeos { |
| 76 | 114 |
| 77 namespace internal { | 115 namespace internal { |
| 78 | 116 |
| 79 class ProviderTypeComboboxModel : public ui::ComboboxModel { | 117 class ProviderTypeComboboxModel : public ui::ComboboxModel { |
| 80 public: | 118 public: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 155 |
| 118 // ProviderTypeComboboxModel --------------------------------------------------- | 156 // ProviderTypeComboboxModel --------------------------------------------------- |
| 119 | 157 |
| 120 ProviderTypeComboboxModel::ProviderTypeComboboxModel() { | 158 ProviderTypeComboboxModel::ProviderTypeComboboxModel() { |
| 121 } | 159 } |
| 122 | 160 |
| 123 ProviderTypeComboboxModel::~ProviderTypeComboboxModel() { | 161 ProviderTypeComboboxModel::~ProviderTypeComboboxModel() { |
| 124 } | 162 } |
| 125 | 163 |
| 126 int ProviderTypeComboboxModel::GetItemCount() const { | 164 int ProviderTypeComboboxModel::GetItemCount() const { |
| 127 return PROVIDER_TYPE_MAX; | 165 return PROVIDER_TYPE_INDEX_MAX; |
| 128 } | 166 } |
| 129 | 167 |
| 130 string16 ProviderTypeComboboxModel::GetItemAt(int index) { | 168 string16 ProviderTypeComboboxModel::GetItemAt(int index) { |
| 131 ProviderType type = static_cast<ProviderType>(index); | 169 return ProviderTypeIndexToString(index); |
| 132 return ProviderTypeToString(type); | |
| 133 } | 170 } |
| 134 | 171 |
| 135 // VpnServerCACertComboboxModel ------------------------------------------------ | 172 // VpnServerCACertComboboxModel ------------------------------------------------ |
| 136 | 173 |
| 137 VpnServerCACertComboboxModel::VpnServerCACertComboboxModel() { | 174 VpnServerCACertComboboxModel::VpnServerCACertComboboxModel() { |
| 138 } | 175 } |
| 139 | 176 |
| 140 VpnServerCACertComboboxModel::~VpnServerCACertComboboxModel() { | 177 VpnServerCACertComboboxModel::~VpnServerCACertComboboxModel() { |
| 141 } | 178 } |
| 142 | 179 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 if (CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER) == 0) { | 223 if (CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER) == 0) { |
| 187 return l10n_util::GetStringUTF16( | 224 return l10n_util::GetStringUTF16( |
| 188 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED); | 225 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED); |
| 189 } | 226 } |
| 190 return CertLibrary::Get()->GetCertDisplayStringAt( | 227 return CertLibrary::Get()->GetCertDisplayStringAt( |
| 191 CertLibrary::CERT_TYPE_USER, index); | 228 CertLibrary::CERT_TYPE_USER, index); |
| 192 } | 229 } |
| 193 | 230 |
| 194 } // namespace internal | 231 } // namespace internal |
| 195 | 232 |
| 196 VPNConfigView::VPNConfigView(NetworkConfigView* parent, VirtualNetwork* vpn) | 233 VPNConfigView::VPNConfigView(NetworkConfigView* parent, |
| 197 : ChildNetworkConfigView(parent, vpn), | 234 const std::string& service_path) |
| 198 title_(0) { | 235 : ChildNetworkConfigView(parent, service_path), |
| 199 Init(vpn); | 236 service_text_modified_(false), |
| 200 } | 237 enable_psk_passphrase_(false), |
| 201 | 238 enable_user_cert_(false), |
| 202 VPNConfigView::VPNConfigView(NetworkConfigView* parent) | 239 enable_server_ca_cert_(false), |
| 203 : ChildNetworkConfigView(parent), | 240 enable_otp_(false), |
| 204 title_(0) { | 241 enable_group_name_(false), |
| 205 Init(NULL); | 242 title_(0), |
| 243 layout_(NULL), |
| 244 server_textfield_(NULL), |
| 245 service_text_(NULL), |
| 246 service_textfield_(NULL), |
| 247 provider_type_combobox_(NULL), |
| 248 provider_type_text_label_(NULL), |
| 249 psk_passphrase_label_(NULL), |
| 250 psk_passphrase_textfield_(NULL), |
| 251 user_cert_label_(NULL), |
| 252 user_cert_combobox_(NULL), |
| 253 server_ca_cert_label_(NULL), |
| 254 server_ca_cert_combobox_(NULL), |
| 255 username_textfield_(NULL), |
| 256 user_passphrase_textfield_(NULL), |
| 257 otp_label_(NULL), |
| 258 otp_textfield_(NULL), |
| 259 group_name_label_(NULL), |
| 260 group_name_textfield_(NULL), |
| 261 save_credentials_checkbox_(NULL), |
| 262 error_label_(NULL), |
| 263 provider_type_index_(PROVIDER_TYPE_INDEX_MAX), |
| 264 weak_ptr_factory_(this) { |
| 265 Init(); |
| 206 } | 266 } |
| 207 | 267 |
| 208 VPNConfigView::~VPNConfigView() { | 268 VPNConfigView::~VPNConfigView() { |
| 209 CertLibrary::Get()->RemoveObserver(this); | 269 CertLibrary::Get()->RemoveObserver(this); |
| 210 } | 270 } |
| 211 | 271 |
| 212 string16 VPNConfigView::GetTitle() const { | 272 string16 VPNConfigView::GetTitle() const { |
| 213 DCHECK_NE(title_, 0); | 273 DCHECK_NE(title_, 0); |
| 214 return l10n_util::GetStringUTF16(title_); | 274 return l10n_util::GetStringUTF16(title_); |
| 215 } | 275 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 236 // Username is always required. | 296 // Username is always required. |
| 237 if (GetUsername().empty()) | 297 if (GetUsername().empty()) |
| 238 return false; | 298 return false; |
| 239 | 299 |
| 240 // TODO(stevenjb): min kMinPassphraseLen length? | 300 // TODO(stevenjb): min kMinPassphraseLen length? |
| 241 if (service_path_.empty() && | 301 if (service_path_.empty() && |
| 242 (GetService().empty() || GetServer().empty())) | 302 (GetService().empty() || GetServer().empty())) |
| 243 return false; | 303 return false; |
| 244 | 304 |
| 245 // Block login if certs are required but user has none. | 305 // Block login if certs are required but user has none. |
| 246 if (UserCertRequired() && (!HaveUserCerts() || !IsUserCertValid())) | 306 bool cert_required = |
| 307 GetProviderTypeIndex() == PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT; |
| 308 if (cert_required && (!HaveUserCerts() || !IsUserCertValid())) |
| 247 return false; | 309 return false; |
| 248 | 310 |
| 249 return true; | 311 return true; |
| 250 } | 312 } |
| 251 | 313 |
| 252 void VPNConfigView::ContentsChanged(views::Textfield* sender, | 314 void VPNConfigView::ContentsChanged(views::Textfield* sender, |
| 253 const string16& new_contents) { | 315 const string16& new_contents) { |
| 254 if (sender == server_textfield_ && !service_text_modified_) { | 316 if (sender == server_textfield_ && !service_text_modified_) { |
| 255 // Set the service name to the server name up to '.', unless it has | 317 // Set the service name to the server name up to '.', unless it has |
| 256 // been explicitly set by the user. | 318 // been explicitly set by the user. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 276 parent_->GetDialogClientView()->AcceptWindow(); | 338 parent_->GetDialogClientView()->AcceptWindow(); |
| 277 } | 339 } |
| 278 return false; | 340 return false; |
| 279 } | 341 } |
| 280 | 342 |
| 281 void VPNConfigView::ButtonPressed(views::Button* sender, | 343 void VPNConfigView::ButtonPressed(views::Button* sender, |
| 282 const ui::Event& event) { | 344 const ui::Event& event) { |
| 283 } | 345 } |
| 284 | 346 |
| 285 void VPNConfigView::OnSelectedIndexChanged(views::Combobox* combobox) { | 347 void VPNConfigView::OnSelectedIndexChanged(views::Combobox* combobox) { |
| 286 if (combobox == provider_type_combobox_) { | 348 UpdateControls(); |
| 287 provider_type_ = static_cast<ProviderType>(combobox->selected_index()); | |
| 288 UpdateControls(); | |
| 289 } else if (combobox == user_cert_combobox_ || | |
| 290 combobox == server_ca_cert_combobox_) { | |
| 291 // Do nothing. | |
| 292 } else { | |
| 293 NOTREACHED(); | |
| 294 } | |
| 295 UpdateErrorLabel(); | 349 UpdateErrorLabel(); |
| 296 UpdateCanLogin(); | 350 UpdateCanLogin(); |
| 297 } | 351 } |
| 298 | 352 |
| 299 void VPNConfigView::OnCertificatesLoaded(bool initial_load) { | 353 void VPNConfigView::OnCertificatesLoaded(bool initial_load) { |
| 300 Refresh(); | 354 Refresh(); |
| 301 } | 355 } |
| 302 | 356 |
| 303 bool VPNConfigView::Login() { | 357 bool VPNConfigView::Login() { |
| 304 NetworkLibrary* cros = NetworkLibrary::Get(); | |
| 305 if (service_path_.empty()) { | 358 if (service_path_.empty()) { |
| 306 NetworkLibrary::VPNConfigData config_data; | 359 base::DictionaryValue properties; |
| 307 switch (provider_type_) { | 360 // Identifying properties |
| 308 case PROVIDER_TYPE_L2TP_IPSEC_PSK: | 361 properties.SetStringWithoutPathExpansion( |
| 309 config_data.psk = GetPSKPassphrase(); | 362 flimflam::kTypeProperty, flimflam::kTypeVPN); |
| 310 config_data.username = GetUsername(); | 363 properties.SetStringWithoutPathExpansion( |
| 311 config_data.user_passphrase = GetUserPassphrase(); | 364 flimflam::kNameProperty, GetService()); |
| 312 config_data.group_name = GetGroupName(); | 365 properties.SetStringWithoutPathExpansion( |
| 313 break; | 366 flimflam::kProviderHostProperty, GetServer()); |
| 314 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: { | 367 properties.SetStringWithoutPathExpansion( |
| 315 config_data.server_ca_cert_pem = GetServerCACertPEM(); | 368 flimflam::kProviderTypeProperty, GetProviderTypeString()); |
| 316 config_data.client_cert_pkcs11_id = GetUserCertID(); | 369 |
| 317 config_data.username = GetUsername(); | 370 SetConfigProperties(&properties); |
| 318 config_data.user_passphrase = GetUserPassphrase(); | 371 ash::network_connect::CreateConfigurationAndConnect( |
| 319 config_data.group_name = GetGroupName(); | 372 &properties, false /* not shared */); |
| 320 break; | 373 } else { |
| 321 } | 374 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> |
| 322 case PROVIDER_TYPE_OPEN_VPN: | 375 GetNetworkState(service_path_); |
| 323 config_data.server_ca_cert_pem = GetServerCACertPEM(); | 376 if (!vpn) { |
| 324 config_data.client_cert_pkcs11_id = GetUserCertID(); | 377 // Shill no longer knows about this network (edge case). |
| 325 config_data.username = GetUsername(); | 378 // TODO(stevenjb): Add notification for this. |
| 326 config_data.user_passphrase = GetUserPassphrase(); | 379 NET_LOG_ERROR("Network not found", service_path_); |
| 327 config_data.otp = GetOTP(); | 380 return true; // Close dialog |
| 328 break; | |
| 329 case PROVIDER_TYPE_MAX: | |
| 330 break; | |
| 331 } | 381 } |
| 332 config_data.save_credentials = GetSaveCredentials(); | 382 base::DictionaryValue properties; |
| 333 cros->ConnectToUnconfiguredVirtualNetwork( | 383 SetConfigProperties(&properties); |
| 334 GetService(), GetServer(), provider_type_, config_data); | 384 ash::network_connect::ConfigureNetworkAndConnect( |
| 335 } else { | 385 service_path_, properties, false /* not shared */); |
| 336 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); | |
| 337 if (!vpn) { | |
| 338 // TODO(stevenjb): Add notification for this. | |
| 339 LOG(WARNING) << "VPN no longer exists: " << service_path_; | |
| 340 return true; // Close dialog. | |
| 341 } | |
| 342 switch (provider_type_) { | |
| 343 case PROVIDER_TYPE_L2TP_IPSEC_PSK: | |
| 344 vpn->SetL2TPIPsecPSKCredentials(GetPSKPassphrase(), | |
| 345 GetUsername(), | |
| 346 GetUserPassphrase(), | |
| 347 GetGroupName()); | |
| 348 break; | |
| 349 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: { | |
| 350 vpn->SetL2TPIPsecCertCredentials(GetUserCertID(), | |
| 351 GetUsername(), | |
| 352 GetUserPassphrase(), | |
| 353 GetGroupName()); | |
| 354 break; | |
| 355 } | |
| 356 case PROVIDER_TYPE_OPEN_VPN: { | |
| 357 vpn->SetOpenVPNCredentials(GetUserCertID(), | |
| 358 GetUsername(), | |
| 359 GetUserPassphrase(), | |
| 360 GetOTP()); | |
| 361 break; | |
| 362 } | |
| 363 case PROVIDER_TYPE_MAX: | |
| 364 break; | |
| 365 } | |
| 366 vpn->SetEnrollmentDelegate( | |
| 367 CreateEnrollmentDelegate(GetWidget()->GetNativeWindow(), | |
| 368 vpn->name(), | |
| 369 ProfileManager::GetLastUsedProfile())); | |
| 370 vpn->SetSaveCredentials(GetSaveCredentials()); | |
| 371 cros->ConnectToVirtualNetwork(vpn); | |
| 372 } | 386 } |
| 373 // Connection failures are responsible for updating the UI, including | |
| 374 // reopening dialogs. | |
| 375 return true; // Close dialog. | 387 return true; // Close dialog. |
| 376 } | 388 } |
| 377 | 389 |
| 378 void VPNConfigView::Cancel() { | 390 void VPNConfigView::Cancel() { |
| 379 } | 391 } |
| 380 | 392 |
| 381 void VPNConfigView::InitFocus() { | 393 void VPNConfigView::InitFocus() { |
| 382 views::View* view_to_focus = GetInitiallyFocusedView(); | 394 views::View* view_to_focus = GetInitiallyFocusedView(); |
| 383 if (view_to_focus) | 395 if (view_to_focus) |
| 384 view_to_focus->RequestFocus(); | 396 view_to_focus->RequestFocus(); |
| 385 } | 397 } |
| 386 | 398 |
| 387 const std::string VPNConfigView::GetService() const { | 399 const std::string VPNConfigView::GetService() const { |
| 388 if (service_textfield_ != NULL) | 400 if (service_textfield_ != NULL) |
| 389 return GetTextFromField(service_textfield_, true); | 401 return GetTextFromField(service_textfield_, true); |
| 390 return service_path_; | 402 return service_path_; |
| 391 } | 403 } |
| 392 | 404 |
| 393 const std::string VPNConfigView::GetServer() const { | 405 const std::string VPNConfigView::GetServer() const { |
| 394 if (server_textfield_ != NULL) | 406 if (server_textfield_ != NULL) |
| 395 return GetTextFromField(server_textfield_, true); | 407 return GetTextFromField(server_textfield_, true); |
| 396 return server_hostname_; | 408 return std::string(); |
| 397 } | 409 } |
| 398 | 410 |
| 399 const std::string VPNConfigView::GetPSKPassphrase() const { | 411 const std::string VPNConfigView::GetPSKPassphrase() const { |
| 400 if (psk_passphrase_textfield_ && | 412 if (psk_passphrase_textfield_ && |
| 401 enable_psk_passphrase_ && | 413 enable_psk_passphrase_ && |
| 402 psk_passphrase_textfield_->visible()) | 414 psk_passphrase_textfield_->visible()) |
| 403 return GetPassphraseFromField(psk_passphrase_textfield_); | 415 return GetPassphraseFromField(psk_passphrase_textfield_); |
| 404 return std::string(); | 416 return std::string(); |
| 405 } | 417 } |
| 406 | 418 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 int index = user_cert_combobox_ ? user_cert_combobox_->selected_index() : 0; | 453 int index = user_cert_combobox_ ? user_cert_combobox_->selected_index() : 0; |
| 442 return CertLibrary::Get()->GetCertPkcs11IdAt( | 454 return CertLibrary::Get()->GetCertPkcs11IdAt( |
| 443 CertLibrary::CERT_TYPE_USER, index); | 455 CertLibrary::CERT_TYPE_USER, index); |
| 444 } | 456 } |
| 445 } | 457 } |
| 446 | 458 |
| 447 bool VPNConfigView::GetSaveCredentials() const { | 459 bool VPNConfigView::GetSaveCredentials() const { |
| 448 return save_credentials_checkbox_->checked(); | 460 return save_credentials_checkbox_->checked(); |
| 449 } | 461 } |
| 450 | 462 |
| 451 void VPNConfigView::Init(VirtualNetwork* vpn) { | 463 int VPNConfigView::GetProviderTypeIndex() const { |
| 452 if (vpn) { | 464 if (provider_type_combobox_) |
| 453 ProviderType type = vpn->provider_type(); | 465 return provider_type_combobox_->selected_index(); |
| 454 std::string type_dict_name = ProviderTypeToONCDictKey(type); | 466 return provider_type_index_; |
| 467 } |
| 455 | 468 |
| 456 if (type == PROVIDER_TYPE_L2TP_IPSEC_PSK) { | 469 std::string VPNConfigView::GetProviderTypeString() const { |
| 457 ParseVPNUIProperty(&ca_cert_ui_data_, vpn, type_dict_name, | 470 int index = GetProviderTypeIndex(); |
| 458 onc::ipsec::kServerCARef); | 471 switch (index) { |
| 459 ParseVPNUIProperty(&psk_passphrase_ui_data_, vpn, type_dict_name, | 472 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK: |
| 460 onc::ipsec::kPSK); | 473 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT: |
| 461 ParseVPNUIProperty(&group_name_ui_data_, vpn, type_dict_name, | 474 return flimflam::kProviderL2tpIpsec; |
| 462 onc::ipsec::kGroup); | 475 case PROVIDER_TYPE_INDEX_OPEN_VPN: |
| 463 } else { // OpenVPN | 476 return flimflam::kProviderOpenVpn; |
| 464 ParseVPNUIProperty(&ca_cert_ui_data_, vpn, type_dict_name, | 477 } |
| 465 onc::openvpn::kServerCARef); | 478 NOTREACHED(); |
| 466 } | 479 return std::string(); |
| 467 ParseVPNUIProperty(&user_cert_ui_data_, vpn, type_dict_name, | 480 } |
| 468 onc::vpn::kClientCertRef); | |
| 469 | 481 |
| 470 const std::string credentials_dict_name( | 482 void VPNConfigView::Init() { |
| 471 type == PROVIDER_TYPE_L2TP_IPSEC_PSK ? | 483 const NetworkState* vpn = NULL; |
| 472 onc::vpn::kL2TP : type_dict_name); | 484 if (!service_path_.empty()) { |
| 473 ParseVPNUIProperty(&username_ui_data_, vpn, credentials_dict_name, | 485 vpn = NetworkHandler::Get()->network_state_handler()-> |
| 474 onc::vpn::kUsername); | 486 GetNetworkState(service_path_); |
| 475 ParseVPNUIProperty(&user_passphrase_ui_data_, vpn, credentials_dict_name, | 487 DCHECK(vpn && vpn->type() == flimflam::kTypeVPN); |
| 476 onc::vpn::kPassword); | |
| 477 ParseVPNUIProperty(&save_credentials_ui_data_, vpn, credentials_dict_name, | |
| 478 onc::vpn::kSaveCredentials); | |
| 479 } | 488 } |
| 480 | 489 layout_ = views::GridLayout::CreatePanel(this); |
| 481 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | 490 SetLayoutManager(layout_); |
| 482 SetLayoutManager(layout); | |
| 483 | 491 |
| 484 // Observer any changes to the certificate list. | 492 // Observer any changes to the certificate list. |
| 485 CertLibrary::Get()->AddObserver(this); | 493 CertLibrary::Get()->AddObserver(this); |
| 486 | 494 |
| 487 const int column_view_set_id = 0; | 495 views::ColumnSet* column_set = layout_->AddColumnSet(0); |
| 488 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); | |
| 489 // Label. | 496 // Label. |
| 490 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | 497 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
| 491 views::GridLayout::USE_PREF, 0, 0); | 498 views::GridLayout::USE_PREF, 0, 0); |
| 492 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); | 499 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); |
| 493 // Textfield, combobox. | 500 // Textfield, combobox. |
| 494 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 501 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 495 views::GridLayout::USE_PREF, 0, | 502 views::GridLayout::USE_PREF, 0, |
| 496 ChildNetworkConfigView::kInputFieldMinWidth); | 503 ChildNetworkConfigView::kInputFieldMinWidth); |
| 497 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); | 504 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); |
| 498 // Policy indicator. | 505 // Policy indicator. |
| 499 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, | 506 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, |
| 500 views::GridLayout::USE_PREF, 0, 0); | 507 views::GridLayout::USE_PREF, 0, 0); |
| 501 | 508 |
| 502 // Initialize members. | 509 // Initialize members. |
| 503 service_text_modified_ = false; | 510 service_text_modified_ = false; |
| 504 if (vpn) { | |
| 505 provider_type_ = vpn->provider_type(); | |
| 506 // Sets enable_* based on the provider type which we use to control | |
| 507 // which controls to make visible. | |
| 508 UpdateControlsToEnable(); | |
| 509 } else { | |
| 510 // Set the default provider type. | |
| 511 provider_type_ = PROVIDER_TYPE_L2TP_IPSEC_PSK; | |
| 512 // Provider Type is user selectable, so enable all controls during init. | |
| 513 enable_psk_passphrase_ = true; | |
| 514 enable_user_cert_ = true; | |
| 515 enable_server_ca_cert_ = true; | |
| 516 enable_otp_ = true; | |
| 517 enable_group_name_ = true; | |
| 518 } | |
| 519 | |
| 520 // Initialize the title string ID used for the dialog. | |
| 521 title_ = vpn ? IDS_OPTIONS_SETTINGS_JOIN_VPN : IDS_OPTIONS_SETTINGS_ADD_VPN; | 511 title_ = vpn ? IDS_OPTIONS_SETTINGS_JOIN_VPN : IDS_OPTIONS_SETTINGS_ADD_VPN; |
| 522 | 512 |
| 513 // By default enable all controls. |
| 514 enable_psk_passphrase_ = true; |
| 515 enable_user_cert_ = true; |
| 516 enable_server_ca_cert_ = true; |
| 517 enable_otp_ = true; |
| 518 enable_group_name_ = true; |
| 519 |
| 523 // Server label and input. | 520 // Server label and input. |
| 524 // Only provide Server name when configuring a new VPN. | 521 // Only provide Server name when configuring a new VPN. |
| 525 if (!vpn) { | 522 if (service_path_.empty()) { |
| 526 layout->StartRow(0, column_view_set_id); | 523 layout_->StartRow(0, 0); |
| 527 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 524 layout_->AddView(new views::Label(l10n_util::GetStringUTF16( |
| 528 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVER_HOSTNAME))); | 525 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVER_HOSTNAME))); |
| 529 server_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 526 server_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
| 530 server_textfield_->SetController(this); | 527 server_textfield_->SetController(this); |
| 531 layout->AddView(server_textfield_); | 528 layout_->AddView(server_textfield_); |
| 532 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 529 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 533 } else { | 530 } else { |
| 534 server_textfield_ = NULL; | 531 server_textfield_ = NULL; |
| 535 } | 532 } |
| 536 | 533 |
| 537 // Service label and name or input. | 534 // Service label and name or input. |
| 538 layout->StartRow(0, column_view_set_id); | 535 layout_->StartRow(0, 0); |
| 539 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 536 layout_->AddView(new views::Label(l10n_util::GetStringUTF16( |
| 540 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVICE_NAME))); | 537 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVICE_NAME))); |
| 541 if (!vpn) { | 538 if (service_path_.empty()) { |
| 542 service_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 539 service_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
| 543 service_textfield_->SetController(this); | 540 service_textfield_->SetController(this); |
| 544 layout->AddView(service_textfield_); | 541 layout_->AddView(service_textfield_); |
| 545 service_text_ = NULL; | 542 service_text_ = NULL; |
| 546 } else { | 543 } else { |
| 547 service_text_ = new views::Label(ASCIIToUTF16(vpn->name())); | 544 service_text_ = new views::Label(); |
| 548 service_text_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 545 service_text_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 549 layout->AddView(service_text_); | 546 layout_->AddView(service_text_); |
| 550 service_textfield_ = NULL; | 547 service_textfield_ = NULL; |
| 551 } | 548 } |
| 552 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 549 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 553 | 550 |
| 554 // Provider type label and select. | 551 // Provider type label and select. |
| 555 layout->StartRow(0, column_view_set_id); | 552 layout_->StartRow(0, 0); |
| 556 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 553 layout_->AddView(new views::Label(l10n_util::GetStringUTF16( |
| 557 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE))); | 554 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE))); |
| 558 if (!vpn) { | 555 if (service_path_.empty()) { |
| 559 provider_type_combobox_model_.reset( | 556 provider_type_combobox_model_.reset( |
| 560 new internal::ProviderTypeComboboxModel); | 557 new internal::ProviderTypeComboboxModel); |
| 561 provider_type_combobox_ = new views::Combobox( | 558 provider_type_combobox_ = new views::Combobox( |
| 562 provider_type_combobox_model_.get()); | 559 provider_type_combobox_model_.get()); |
| 563 provider_type_combobox_->set_listener(this); | 560 provider_type_combobox_->set_listener(this); |
| 564 layout->AddView(provider_type_combobox_); | 561 layout_->AddView(provider_type_combobox_); |
| 565 provider_type_text_label_ = NULL; | 562 provider_type_text_label_ = NULL; |
| 566 } else { | 563 } else { |
| 567 provider_type_text_label_ = | 564 provider_type_text_label_ = new views::Label(); |
| 568 new views::Label(ProviderTypeToString(provider_type_)); | |
| 569 provider_type_text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 565 provider_type_text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 570 layout->AddView(provider_type_text_label_); | 566 layout_->AddView(provider_type_text_label_); |
| 571 provider_type_combobox_ = NULL; | 567 provider_type_combobox_ = NULL; |
| 572 } | 568 } |
| 573 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 569 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 574 | 570 |
| 575 // PSK passphrase label, input and visible button. | 571 // PSK passphrase label, input and visible button. |
| 576 if (enable_psk_passphrase_) { | 572 layout_->StartRow(0, 0); |
| 577 layout->StartRow(0, column_view_set_id); | 573 psk_passphrase_label_ = new views::Label(l10n_util::GetStringUTF16( |
| 578 psk_passphrase_label_ = new views::Label(l10n_util::GetStringUTF16( | 574 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PSK_PASSPHRASE)); |
| 579 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PSK_PASSPHRASE)); | 575 layout_->AddView(psk_passphrase_label_); |
| 580 layout->AddView(psk_passphrase_label_); | 576 psk_passphrase_textfield_ = new PassphraseTextfield(); |
| 581 bool has_psk_passphrase = vpn && !vpn->IsPSKPassphraseRequired(); | 577 psk_passphrase_textfield_->SetController(this); |
| 582 psk_passphrase_textfield_ = new PassphraseTextfield(has_psk_passphrase); | 578 layout_->AddView(psk_passphrase_textfield_); |
| 583 psk_passphrase_textfield_->SetController(this); | 579 layout_->AddView( |
| 584 layout->AddView(psk_passphrase_textfield_); | 580 new ControlledSettingIndicatorView(psk_passphrase_ui_data_)); |
| 585 layout->AddView( | 581 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 586 new ControlledSettingIndicatorView(psk_passphrase_ui_data_)); | |
| 587 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 588 } else { | |
| 589 psk_passphrase_label_ = NULL; | |
| 590 psk_passphrase_textfield_ = NULL; | |
| 591 } | |
| 592 | 582 |
| 593 // Server CA certificate | 583 // Server CA certificate |
| 594 // Only provide Server CA when configuring a new VPN. | 584 if (service_path_.empty()) { |
| 595 if (!vpn) { | 585 layout_->StartRow(0, 0); |
| 596 layout->StartRow(0, column_view_set_id); | 586 server_ca_cert_label_ = new views::Label(l10n_util::GetStringUTF16( |
| 597 server_ca_cert_label_ = | 587 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); |
| 598 new views::Label(l10n_util::GetStringUTF16( | 588 layout_->AddView(server_ca_cert_label_); |
| 599 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); | |
| 600 layout->AddView(server_ca_cert_label_); | |
| 601 server_ca_cert_combobox_model_.reset( | 589 server_ca_cert_combobox_model_.reset( |
| 602 new internal::VpnServerCACertComboboxModel()); | 590 new internal::VpnServerCACertComboboxModel()); |
| 603 server_ca_cert_combobox_ = new views::Combobox( | 591 server_ca_cert_combobox_ = new views::Combobox( |
| 604 server_ca_cert_combobox_model_.get()); | 592 server_ca_cert_combobox_model_.get()); |
| 605 layout->AddView(server_ca_cert_combobox_); | 593 layout_->AddView(server_ca_cert_combobox_); |
| 606 layout->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); | 594 layout_->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); |
| 607 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 595 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 608 } else { | 596 } else { |
| 609 server_ca_cert_label_ = NULL; | 597 server_ca_cert_label_ = NULL; |
| 610 server_ca_cert_combobox_ = NULL; | 598 server_ca_cert_combobox_ = NULL; |
| 611 } | 599 } |
| 612 | 600 |
| 613 // User certificate label and input. | 601 // User certificate label and input. |
| 614 if (enable_user_cert_) { | 602 layout_->StartRow(0, 0); |
| 615 layout->StartRow(0, column_view_set_id); | 603 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( |
| 616 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( | 604 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); |
| 617 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); | 605 layout_->AddView(user_cert_label_); |
| 618 layout->AddView(user_cert_label_); | 606 user_cert_combobox_model_.reset( |
| 619 user_cert_combobox_model_.reset( | 607 new internal::VpnUserCertComboboxModel()); |
| 620 new internal::VpnUserCertComboboxModel()); | 608 user_cert_combobox_ = new views::Combobox(user_cert_combobox_model_.get()); |
| 621 user_cert_combobox_ = new views::Combobox(user_cert_combobox_model_.get()); | 609 user_cert_combobox_->set_listener(this); |
| 622 user_cert_combobox_->set_listener(this); | 610 layout_->AddView(user_cert_combobox_); |
| 623 layout->AddView(user_cert_combobox_); | 611 layout_->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); |
| 624 layout->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); | 612 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 625 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 626 } else { | |
| 627 user_cert_label_ = NULL; | |
| 628 user_cert_combobox_ = NULL; | |
| 629 } | |
| 630 | 613 |
| 631 // Username label and input. | 614 // Username label and input. |
| 632 layout->StartRow(0, column_view_set_id); | 615 layout_->StartRow(0, 0); |
| 633 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 616 layout_->AddView(new views::Label(l10n_util::GetStringUTF16( |
| 634 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USERNAME))); | 617 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USERNAME))); |
| 635 username_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 618 username_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
| 636 username_textfield_->SetController(this); | 619 username_textfield_->SetController(this); |
| 637 username_textfield_->SetEnabled(username_ui_data_.IsEditable()); | 620 username_textfield_->SetEnabled(username_ui_data_.IsEditable()); |
| 638 if (vpn && !vpn->username().empty()) | 621 layout_->AddView(username_textfield_); |
| 639 username_textfield_->SetText(UTF8ToUTF16(vpn->username())); | 622 layout_->AddView(new ControlledSettingIndicatorView(username_ui_data_)); |
| 640 layout->AddView(username_textfield_); | 623 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 641 layout->AddView(new ControlledSettingIndicatorView(username_ui_data_)); | |
| 642 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 643 | 624 |
| 644 // User passphrase label, input and visble button. | 625 // User passphrase label, input and visble button. |
| 645 layout->StartRow(0, column_view_set_id); | 626 layout_->StartRow(0, 0); |
| 646 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 627 layout_->AddView(new views::Label(l10n_util::GetStringUTF16( |
| 647 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_PASSPHRASE))); | 628 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_PASSPHRASE))); |
| 648 bool has_user_passphrase = vpn && !vpn->IsUserPassphraseRequired(); | 629 user_passphrase_textfield_ = new PassphraseTextfield(); |
| 649 user_passphrase_textfield_ = new PassphraseTextfield(has_user_passphrase); | |
| 650 user_passphrase_textfield_->SetController(this); | 630 user_passphrase_textfield_->SetController(this); |
| 651 user_passphrase_textfield_->SetEnabled(user_passphrase_ui_data_.IsEditable()); | 631 user_passphrase_textfield_->SetEnabled(user_passphrase_ui_data_.IsEditable()); |
| 652 layout->AddView(user_passphrase_textfield_); | 632 layout_->AddView(user_passphrase_textfield_); |
| 653 layout->AddView(new ControlledSettingIndicatorView(user_passphrase_ui_data_)); | 633 layout_->AddView( |
| 654 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 634 new ControlledSettingIndicatorView(user_passphrase_ui_data_)); |
| 635 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 655 | 636 |
| 656 // OTP label and input. | 637 // OTP label and input. |
| 657 if (enable_otp_) { | 638 layout_->StartRow(0, 0); |
| 658 layout->StartRow(0, column_view_set_id); | 639 otp_label_ = new views::Label(l10n_util::GetStringUTF16( |
| 659 otp_label_ = new views::Label(l10n_util::GetStringUTF16( | 640 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_OTP)); |
| 660 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_OTP)); | 641 layout_->AddView(otp_label_); |
| 661 layout->AddView(otp_label_); | 642 otp_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
| 662 otp_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 643 otp_textfield_->SetController(this); |
| 663 otp_textfield_->SetController(this); | 644 layout_->AddView(otp_textfield_); |
| 664 layout->AddView(otp_textfield_); | 645 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 665 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 666 } else { | |
| 667 otp_label_ = NULL; | |
| 668 otp_textfield_ = NULL; | |
| 669 } | |
| 670 | 646 |
| 671 // Group Name label and input. | 647 // Group Name label and input. |
| 672 if (enable_group_name_) { | 648 layout_->StartRow(0, 0); |
| 673 layout->StartRow(0, column_view_set_id); | 649 group_name_label_ = new views::Label(l10n_util::GetStringUTF16( |
| 674 group_name_label_ = new views::Label(l10n_util::GetStringUTF16( | 650 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_GROUP_NAME)); |
| 675 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_GROUP_NAME)); | 651 layout_->AddView(group_name_label_); |
| 676 layout->AddView(group_name_label_); | 652 group_name_textfield_ = |
| 677 group_name_textfield_ = | 653 new views::Textfield(views::Textfield::STYLE_DEFAULT); |
| 678 new views::Textfield(views::Textfield::STYLE_DEFAULT); | 654 group_name_textfield_->SetController(this); |
| 679 group_name_textfield_->SetController(this); | 655 layout_->AddView(group_name_textfield_); |
| 680 if (vpn && !vpn->group_name().empty()) | 656 layout_->AddView(new ControlledSettingIndicatorView(group_name_ui_data_)); |
| 681 group_name_textfield_->SetText(UTF8ToUTF16(vpn->group_name())); | 657 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 682 layout->AddView(group_name_textfield_); | |
| 683 layout->AddView(new ControlledSettingIndicatorView(group_name_ui_data_)); | |
| 684 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 685 } else { | |
| 686 group_name_label_ = NULL; | |
| 687 group_name_textfield_ = NULL; | |
| 688 } | |
| 689 | 658 |
| 690 // Save credentials | 659 // Save credentials |
| 691 layout->StartRow(0, column_view_set_id); | 660 layout_->StartRow(0, 0); |
| 692 save_credentials_checkbox_ = new views::Checkbox( | 661 save_credentials_checkbox_ = new views::Checkbox( |
| 693 l10n_util::GetStringUTF16( | 662 l10n_util::GetStringUTF16( |
| 694 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS)); | 663 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS)); |
| 695 save_credentials_checkbox_->SetEnabled( | 664 save_credentials_checkbox_->SetEnabled( |
| 696 save_credentials_ui_data_.IsEditable()); | 665 save_credentials_ui_data_.IsEditable()); |
| 697 bool save_credentials = vpn ? vpn->save_credentials() : false; | 666 layout_->SkipColumns(1); |
| 698 save_credentials_checkbox_->SetChecked(save_credentials); | 667 layout_->AddView(save_credentials_checkbox_); |
| 699 layout->SkipColumns(1); | 668 layout_->AddView( |
| 700 layout->AddView(save_credentials_checkbox_); | |
| 701 layout->AddView( | |
| 702 new ControlledSettingIndicatorView(save_credentials_ui_data_)); | 669 new ControlledSettingIndicatorView(save_credentials_ui_data_)); |
| 703 | 670 |
| 704 // Error label. | 671 // Error label. |
| 705 layout->StartRow(0, column_view_set_id); | 672 layout_->StartRow(0, 0); |
| 706 layout->SkipColumns(1); | 673 layout_->SkipColumns(1); |
| 707 error_label_ = new views::Label(); | 674 error_label_ = new views::Label(); |
| 708 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 675 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 709 error_label_->SetEnabledColor(SK_ColorRED); | 676 error_label_->SetEnabledColor(SK_ColorRED); |
| 710 layout->AddView(error_label_); | 677 layout_->AddView(error_label_); |
| 711 | 678 |
| 712 // Set or hide the UI, update comboboxes and error labels. | 679 // Set or hide the UI, update comboboxes and error labels. |
| 713 Refresh(); | 680 Refresh(); |
| 681 |
| 682 if (vpn) { |
| 683 NetworkHandler::Get()->network_configuration_handler()->GetProperties( |
| 684 service_path_, |
| 685 base::Bind(&VPNConfigView::InitFromProperties, |
| 686 weak_ptr_factory_.GetWeakPtr()), |
| 687 base::Bind(&VPNConfigView::GetPropertiesError, |
| 688 weak_ptr_factory_.GetWeakPtr())); |
| 689 } |
| 690 } |
| 691 |
| 692 void VPNConfigView::InitFromProperties( |
| 693 const std::string& service_path, |
| 694 const base::DictionaryValue& service_properties) { |
| 695 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> |
| 696 GetNetworkState(service_path); |
| 697 if (!vpn) { |
| 698 NET_LOG_ERROR("Shill Error getting properties VpnConfigView", service_path); |
| 699 return; |
| 700 } |
| 701 |
| 702 std::string provider_type, server_hostname, username, group_name; |
| 703 bool psk_passphrase_required = false; |
| 704 const base::DictionaryValue* provider_properties; |
| 705 if (service_properties.GetDictionaryWithoutPathExpansion( |
| 706 flimflam::kProviderProperty, &provider_properties)) { |
| 707 provider_properties->GetStringWithoutPathExpansion( |
| 708 flimflam::kTypeProperty, &provider_type); |
| 709 provider_properties->GetStringWithoutPathExpansion( |
| 710 flimflam::kHostProperty, &server_hostname); |
| 711 } |
| 712 if (provider_type == flimflam::kProviderL2tpIpsec) { |
| 713 provider_properties->GetStringWithoutPathExpansion( |
| 714 flimflam::kL2tpIpsecClientCertIdProperty, &client_cert_id_); |
| 715 ca_cert_pem_ = GetPemFromDictionary( |
| 716 provider_properties, shill::kL2tpIpsecCaCertPemProperty); |
| 717 provider_properties->GetBooleanWithoutPathExpansion( |
| 718 flimflam::kL2tpIpsecPskRequiredProperty, &psk_passphrase_required); |
| 719 provider_properties->GetStringWithoutPathExpansion( |
| 720 flimflam::kL2tpIpsecUserProperty, &username); |
| 721 provider_properties->GetStringWithoutPathExpansion( |
| 722 shill::kL2tpIpsecTunnelGroupProperty, &group_name); |
| 723 } else if (provider_type == flimflam::kProviderOpenVpn) { |
| 724 provider_properties->GetStringWithoutPathExpansion( |
| 725 flimflam::kOpenVPNClientCertIdProperty, &client_cert_id_); |
| 726 ca_cert_pem_ = GetPemFromDictionary( |
| 727 provider_properties, shill::kOpenVPNCaCertPemProperty); |
| 728 provider_properties->GetStringWithoutPathExpansion( |
| 729 flimflam::kOpenVPNUserProperty, &username); |
| 730 } |
| 731 bool save_credentials = false; |
| 732 service_properties.GetBooleanWithoutPathExpansion( |
| 733 flimflam::kSaveCredentialsProperty, &save_credentials); |
| 734 |
| 735 provider_type_index_ = ProviderTypeToIndex(provider_type, client_cert_id_); |
| 736 |
| 737 if (service_text_) |
| 738 service_text_->SetText(ASCIIToUTF16(vpn->name())); |
| 739 if (provider_type_text_label_) |
| 740 provider_type_text_label_->SetText( |
| 741 ProviderTypeIndexToString(provider_type_index_)); |
| 742 |
| 743 if (server_textfield_ && !server_hostname.empty()) |
| 744 server_textfield_->SetText(UTF8ToUTF16(server_hostname)); |
| 745 if (username_textfield_ && !username.empty()) |
| 746 username_textfield_->SetText(UTF8ToUTF16(username)); |
| 747 if (group_name_textfield_ && !group_name.empty()) |
| 748 group_name_textfield_->SetText(UTF8ToUTF16(group_name)); |
| 749 if (psk_passphrase_textfield_) |
| 750 psk_passphrase_textfield_->SetShowFake(!psk_passphrase_required); |
| 751 if (save_credentials_checkbox_) |
| 752 save_credentials_checkbox_->SetChecked(save_credentials); |
| 753 |
| 754 Refresh(); |
| 755 } |
| 756 |
| 757 void VPNConfigView::ParseUIProperties(const NetworkState* vpn) { |
| 758 std::string type_dict_name = |
| 759 ProviderTypeIndexToONCDictKey(provider_type_index_); |
| 760 if (provider_type_index_ == PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK) { |
| 761 ParseVPNUIProperty(vpn, type_dict_name, onc::ipsec::kServerCARef, |
| 762 &ca_cert_ui_data_); |
| 763 ParseVPNUIProperty(vpn, type_dict_name, onc::ipsec::kPSK, |
| 764 &psk_passphrase_ui_data_); |
| 765 ParseVPNUIProperty(vpn, type_dict_name, onc::ipsec::kGroup, |
| 766 &group_name_ui_data_); |
| 767 } else if (provider_type_index_ == PROVIDER_TYPE_INDEX_OPEN_VPN) { |
| 768 ParseVPNUIProperty(vpn, type_dict_name, onc::openvpn::kServerCARef, |
| 769 &ca_cert_ui_data_); |
| 770 } |
| 771 ParseVPNUIProperty(vpn, type_dict_name, onc::vpn::kClientCertRef, |
| 772 &user_cert_ui_data_); |
| 773 |
| 774 const std::string credentials_dict_name( |
| 775 provider_type_index_ == PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK ? |
| 776 onc::vpn::kL2TP : type_dict_name); |
| 777 ParseVPNUIProperty(vpn, credentials_dict_name, onc::vpn::kUsername, |
| 778 &username_ui_data_); |
| 779 ParseVPNUIProperty(vpn, credentials_dict_name, onc::vpn::kPassword, |
| 780 &user_passphrase_ui_data_); |
| 781 ParseVPNUIProperty(vpn, credentials_dict_name, onc::vpn::kSaveCredentials, |
| 782 &save_credentials_ui_data_); |
| 783 } |
| 784 |
| 785 void VPNConfigView::GetPropertiesError( |
| 786 const std::string& error_name, |
| 787 scoped_ptr<base::DictionaryValue> error_data) { |
| 788 NET_LOG_ERROR("Shill Error from VpnConfigView: " + error_name, ""); |
| 789 } |
| 790 |
| 791 void VPNConfigView::SetConfigProperties( |
| 792 base::DictionaryValue* properties) { |
| 793 int provider_type_index = GetProviderTypeIndex(); |
| 794 std::string user_passphrase = GetUserPassphrase(); |
| 795 std::string user_name = GetUsername(); |
| 796 std::string group_name = GetGroupName(); |
| 797 switch (provider_type_index) { |
| 798 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK: { |
| 799 std::string psk_passphrase = GetPSKPassphrase(); |
| 800 if (!psk_passphrase.empty()) { |
| 801 properties->SetStringWithoutPathExpansion( |
| 802 flimflam::kL2tpIpsecPskProperty, GetPSKPassphrase()); |
| 803 } |
| 804 if (!group_name.empty()) { |
| 805 properties->SetStringWithoutPathExpansion( |
| 806 shill::kL2tpIpsecTunnelGroupProperty, group_name); |
| 807 } |
| 808 if (!user_name.empty()) { |
| 809 properties->SetStringWithoutPathExpansion( |
| 810 flimflam::kL2tpIpsecUserProperty, user_name); |
| 811 } |
| 812 if (!user_passphrase.empty()) { |
| 813 properties->SetStringWithoutPathExpansion( |
| 814 flimflam::kL2tpIpsecPasswordProperty, user_passphrase); |
| 815 } |
| 816 break; |
| 817 } |
| 818 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT: { |
| 819 std::string ca_cert_pem = GetServerCACertPEM(); |
| 820 if (!ca_cert_pem.empty()) { |
| 821 properties->SetStringWithoutPathExpansion( |
| 822 shill::kL2tpIpsecCaCertPemProperty, ca_cert_pem); |
| 823 } |
| 824 properties->SetStringWithoutPathExpansion( |
| 825 flimflam::kL2tpIpsecClientCertIdProperty, GetUserCertID()); |
| 826 if (!group_name.empty()) { |
| 827 properties->SetStringWithoutPathExpansion( |
| 828 shill::kL2tpIpsecTunnelGroupProperty, GetGroupName()); |
| 829 } |
| 830 if (!user_name.empty()) { |
| 831 properties->SetStringWithoutPathExpansion( |
| 832 flimflam::kL2tpIpsecUserProperty, user_name); |
| 833 } |
| 834 if (!user_passphrase.empty()) { |
| 835 properties->SetStringWithoutPathExpansion( |
| 836 flimflam::kL2tpIpsecPasswordProperty, user_passphrase); |
| 837 } |
| 838 break; |
| 839 } |
| 840 case PROVIDER_TYPE_INDEX_OPEN_VPN: { |
| 841 std::string ca_cert_pem = GetServerCACertPEM(); |
| 842 if (!ca_cert_pem.empty()) { |
| 843 base::ListValue* pem_list = new base::ListValue; |
| 844 pem_list->AppendString(GetServerCACertPEM()); |
| 845 properties->SetWithoutPathExpansion( |
| 846 shill::kOpenVPNCaCertPemProperty, pem_list); |
| 847 } |
| 848 properties->SetStringWithoutPathExpansion( |
| 849 flimflam::kOpenVPNClientCertIdProperty, GetUserCertID()); |
| 850 properties->SetStringWithoutPathExpansion( |
| 851 flimflam::kOpenVPNUserProperty, GetUsername()); |
| 852 if (!user_passphrase.empty()) { |
| 853 properties->SetStringWithoutPathExpansion( |
| 854 flimflam::kOpenVPNPasswordProperty, user_passphrase); |
| 855 } |
| 856 std::string otp = GetOTP(); |
| 857 if (!otp.empty()) { |
| 858 properties->SetStringWithoutPathExpansion( |
| 859 flimflam::kOpenVPNOTPProperty, otp); |
| 860 } |
| 861 break; |
| 862 } |
| 863 case PROVIDER_TYPE_INDEX_MAX: |
| 864 NOTREACHED(); |
| 865 break; |
| 866 } |
| 867 properties->SetBooleanWithoutPathExpansion( |
| 868 flimflam::kSaveCredentialsProperty, GetSaveCredentials()); |
| 714 } | 869 } |
| 715 | 870 |
| 716 void VPNConfigView::Refresh() { | 871 void VPNConfigView::Refresh() { |
| 717 NetworkLibrary* cros = NetworkLibrary::Get(); | |
| 718 | |
| 719 UpdateControls(); | 872 UpdateControls(); |
| 720 | 873 |
| 721 // Set certificate combo boxes. | 874 // Set certificate combo boxes. |
| 722 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); | |
| 723 if (server_ca_cert_combobox_) { | 875 if (server_ca_cert_combobox_) { |
| 724 server_ca_cert_combobox_->ModelChanged(); | 876 server_ca_cert_combobox_->ModelChanged(); |
| 725 if (enable_server_ca_cert_ && | 877 if (enable_server_ca_cert_ && !ca_cert_pem_.empty()) { |
| 726 (vpn && !vpn->ca_cert_pem().empty())) { | |
| 727 // Select the current server CA certificate in the combobox. | 878 // Select the current server CA certificate in the combobox. |
| 728 int cert_index = CertLibrary::Get()->GetCertIndexByPEM( | 879 int cert_index = CertLibrary::Get()->GetCertIndexByPEM( |
| 729 CertLibrary::CERT_TYPE_SERVER_CA, vpn->ca_cert_pem()); | 880 CertLibrary::CERT_TYPE_SERVER_CA, ca_cert_pem_); |
| 730 if (cert_index >= 0) { | 881 if (cert_index >= 0) { |
| 731 // Skip item for "Default" | 882 // Skip item for "Default" |
| 732 server_ca_cert_combobox_->SetSelectedIndex(1 + cert_index); | 883 server_ca_cert_combobox_->SetSelectedIndex(1 + cert_index); |
| 733 } else { | 884 } else { |
| 734 server_ca_cert_combobox_->SetSelectedIndex(0); | 885 server_ca_cert_combobox_->SetSelectedIndex(0); |
| 735 } | 886 } |
| 736 } else { | 887 } else { |
| 737 server_ca_cert_combobox_->SetSelectedIndex(0); | 888 server_ca_cert_combobox_->SetSelectedIndex(0); |
| 738 } | 889 } |
| 739 } | 890 } |
| 740 | 891 |
| 741 if (user_cert_combobox_) { | 892 if (user_cert_combobox_) { |
| 742 user_cert_combobox_->ModelChanged(); | 893 user_cert_combobox_->ModelChanged(); |
| 743 if (enable_user_cert_ && | 894 if (enable_user_cert_ && !client_cert_id_.empty()) { |
| 744 (vpn && !vpn->client_cert_id().empty())) { | |
| 745 int cert_index = CertLibrary::Get()->GetCertIndexByPkcs11Id( | 895 int cert_index = CertLibrary::Get()->GetCertIndexByPkcs11Id( |
| 746 CertLibrary::CERT_TYPE_USER, vpn->client_cert_id()); | 896 CertLibrary::CERT_TYPE_USER, client_cert_id_); |
| 747 if (cert_index >= 0) | 897 if (cert_index >= 0) |
| 748 user_cert_combobox_->SetSelectedIndex(cert_index); | 898 user_cert_combobox_->SetSelectedIndex(cert_index); |
| 749 else | 899 else |
| 750 user_cert_combobox_->SetSelectedIndex(0); | 900 user_cert_combobox_->SetSelectedIndex(0); |
| 751 } else { | 901 } else { |
| 752 user_cert_combobox_->SetSelectedIndex(0); | 902 user_cert_combobox_->SetSelectedIndex(0); |
| 753 } | 903 } |
| 754 } | 904 } |
| 755 | 905 |
| 756 UpdateErrorLabel(); | 906 UpdateErrorLabel(); |
| 757 } | 907 } |
| 758 | 908 |
| 759 void VPNConfigView::UpdateControlsToEnable() { | 909 void VPNConfigView::UpdateControlsToEnable() { |
| 760 // Set which controls are enabled. | |
| 761 enable_psk_passphrase_ = false; | 910 enable_psk_passphrase_ = false; |
| 762 enable_user_cert_ = false; | 911 enable_user_cert_ = false; |
| 763 enable_server_ca_cert_ = false; | 912 enable_server_ca_cert_ = false; |
| 764 enable_otp_ = false; | 913 enable_otp_ = false; |
| 765 enable_group_name_ = false; | 914 enable_group_name_ = false; |
| 766 switch (provider_type_) { | 915 int provider_type_index = GetProviderTypeIndex(); |
| 767 case PROVIDER_TYPE_L2TP_IPSEC_PSK: | 916 if (provider_type_index == PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK) { |
| 768 enable_psk_passphrase_ = true; | 917 enable_psk_passphrase_ = true; |
| 769 enable_group_name_ = true; | 918 enable_group_name_ = true; |
| 770 break; | 919 } else if (provider_type_index == PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT) { |
| 771 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: | 920 enable_server_ca_cert_ = true; |
| 772 enable_server_ca_cert_ = true; | 921 enable_user_cert_ = HaveUserCerts(); |
| 773 enable_user_cert_ = HaveUserCerts(); | 922 enable_group_name_ = true; |
| 774 enable_group_name_ = true; | 923 } else { // PROVIDER_TYPE_INDEX_OPEN_VPN (default) |
| 775 break; | 924 enable_server_ca_cert_ = true; |
| 776 case PROVIDER_TYPE_OPEN_VPN: | 925 enable_user_cert_ = HaveUserCerts(); |
| 777 enable_server_ca_cert_ = true; | 926 enable_otp_ = true; |
| 778 enable_user_cert_ = HaveUserCerts(); | |
| 779 enable_otp_ = true; | |
| 780 break; | |
| 781 default: | |
| 782 NOTREACHED(); | |
| 783 break; | |
| 784 } | 927 } |
| 785 } | 928 } |
| 786 | 929 |
| 787 void VPNConfigView::UpdateControls() { | 930 void VPNConfigView::UpdateControls() { |
| 788 UpdateControlsToEnable(); | 931 UpdateControlsToEnable(); |
| 789 | 932 |
| 790 if (psk_passphrase_label_) | 933 if (psk_passphrase_label_) |
| 791 psk_passphrase_label_->SetEnabled(enable_psk_passphrase_); | 934 psk_passphrase_label_->SetEnabled(enable_psk_passphrase_); |
| 792 if (psk_passphrase_textfield_) | 935 if (psk_passphrase_textfield_) |
| 793 psk_passphrase_textfield_->SetEnabled(enable_psk_passphrase_ && | 936 psk_passphrase_textfield_->SetEnabled(enable_psk_passphrase_ && |
| (...skipping 17 matching lines...) Expand all Loading... |
| 811 otp_textfield_->SetEnabled(enable_otp_); | 954 otp_textfield_->SetEnabled(enable_otp_); |
| 812 | 955 |
| 813 if (group_name_label_) | 956 if (group_name_label_) |
| 814 group_name_label_->SetEnabled(enable_group_name_); | 957 group_name_label_->SetEnabled(enable_group_name_); |
| 815 if (group_name_textfield_) | 958 if (group_name_textfield_) |
| 816 group_name_textfield_->SetEnabled(enable_group_name_ && | 959 group_name_textfield_->SetEnabled(enable_group_name_ && |
| 817 group_name_ui_data_.IsEditable()); | 960 group_name_ui_data_.IsEditable()); |
| 818 } | 961 } |
| 819 | 962 |
| 820 void VPNConfigView::UpdateErrorLabel() { | 963 void VPNConfigView::UpdateErrorLabel() { |
| 821 NetworkLibrary* cros = NetworkLibrary::Get(); | |
| 822 | |
| 823 // Error message. | 964 // Error message. |
| 824 std::string error_msg; | 965 string16 error_msg; |
| 825 if (UserCertRequired() && CertLibrary::Get()->CertificatesLoaded()) { | 966 bool cert_required = |
| 967 GetProviderTypeIndex() == PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT; |
| 968 if (cert_required && CertLibrary::Get()->CertificatesLoaded()) { |
| 826 if (!HaveUserCerts()) { | 969 if (!HaveUserCerts()) { |
| 827 error_msg = l10n_util::GetStringUTF8( | 970 error_msg = l10n_util::GetStringUTF16( |
| 828 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PLEASE_INSTALL_USER_CERT); | 971 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PLEASE_INSTALL_USER_CERT); |
| 829 } else if (!IsUserCertValid()) { | 972 } else if (!IsUserCertValid()) { |
| 830 error_msg = l10n_util::GetStringUTF8( | 973 error_msg = l10n_util::GetStringUTF16( |
| 831 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_REQUIRE_HARDWARE_BACKED); | 974 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_REQUIRE_HARDWARE_BACKED); |
| 832 } | 975 } |
| 833 } | 976 } |
| 834 if (error_msg.empty() && !service_path_.empty()) { | 977 if (error_msg.empty() && !service_path_.empty()) { |
| 835 // TODO(kuan): differentiate between bad psk and user passphrases. | 978 // TODO(kuan): differentiate between bad psk and user passphrases. |
| 836 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); | 979 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> |
| 837 if (vpn && vpn->failed()) { | 980 GetNetworkState(service_path_); |
| 838 if (vpn->error() == ERROR_BAD_PASSPHRASE) { | 981 if (vpn && vpn->connection_state() == flimflam::kStateFailure) |
| 839 error_msg = l10n_util::GetStringUTF8( | 982 error_msg = ash::network_connect::ErrorString(vpn->error()); |
| 840 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE); | |
| 841 } else { | |
| 842 error_msg = vpn->GetErrorString(); | |
| 843 } | |
| 844 } | |
| 845 } | 983 } |
| 846 if (!error_msg.empty()) { | 984 if (!error_msg.empty()) { |
| 847 error_label_->SetText(UTF8ToUTF16(error_msg)); | 985 error_label_->SetText(error_msg); |
| 848 error_label_->SetVisible(true); | 986 error_label_->SetVisible(true); |
| 849 } else { | 987 } else { |
| 850 error_label_->SetVisible(false); | 988 error_label_->SetVisible(false); |
| 851 } | 989 } |
| 852 } | 990 } |
| 853 | 991 |
| 854 void VPNConfigView::UpdateCanLogin() { | 992 void VPNConfigView::UpdateCanLogin() { |
| 855 parent_->GetDialogClientView()->UpdateDialogButtons(); | 993 parent_->GetDialogClientView()->UpdateDialogButtons(); |
| 856 } | 994 } |
| 857 | 995 |
| 858 bool VPNConfigView::UserCertRequired() const { | |
| 859 return provider_type_ == PROVIDER_TYPE_L2TP_IPSEC_USER_CERT; | |
| 860 } | |
| 861 | |
| 862 bool VPNConfigView::HaveUserCerts() const { | 996 bool VPNConfigView::HaveUserCerts() const { |
| 863 return CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER) > 0; | 997 return CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER) > 0; |
| 864 } | 998 } |
| 865 | 999 |
| 866 bool VPNConfigView::IsUserCertValid() const { | 1000 bool VPNConfigView::IsUserCertValid() const { |
| 867 if (!user_cert_combobox_ || !enable_user_cert_) | 1001 if (!user_cert_combobox_ || !enable_user_cert_) |
| 868 return false; | 1002 return false; |
| 869 int index = user_cert_combobox_->selected_index(); | 1003 int index = user_cert_combobox_->selected_index(); |
| 870 if (index < 0) | 1004 if (index < 0) |
| 871 return false; | 1005 return false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 889 return result; | 1023 return result; |
| 890 } | 1024 } |
| 891 | 1025 |
| 892 const std::string VPNConfigView::GetPassphraseFromField( | 1026 const std::string VPNConfigView::GetPassphraseFromField( |
| 893 PassphraseTextfield* textfield) const { | 1027 PassphraseTextfield* textfield) const { |
| 894 if (!textfield) | 1028 if (!textfield) |
| 895 return std::string(); | 1029 return std::string(); |
| 896 return textfield->GetPassphrase(); | 1030 return textfield->GetPassphrase(); |
| 897 } | 1031 } |
| 898 | 1032 |
| 899 void VPNConfigView::ParseVPNUIProperty(NetworkPropertyUIData* property_ui_data, | 1033 void VPNConfigView::ParseVPNUIProperty( |
| 900 Network* network, | 1034 const NetworkState* network, |
| 901 const std::string& dict_key, | 1035 const std::string& dict_key, |
| 902 const std::string& key) { | 1036 const std::string& key, |
| 1037 NetworkPropertyUIData* property_ui_data) { |
| 903 onc::ONCSource onc_source = onc::ONC_SOURCE_NONE; | 1038 onc::ONCSource onc_source = onc::ONC_SOURCE_NONE; |
| 904 const base::DictionaryValue* onc = | 1039 const base::DictionaryValue* onc = |
| 905 NetworkConfigView::FindPolicyForActiveUser(network, &onc_source); | 1040 network_connect::FindPolicyForActiveUser(network, &onc_source); |
| 906 | 1041 |
| 907 VLOG_IF(1, !onc) << "No ONC found for VPN network " << network->unique_id(); | 1042 VLOG_IF(1, !onc) << "No ONC found for VPN network " << network->guid(); |
| 908 property_ui_data->ParseOncProperty( | 1043 property_ui_data->ParseOncProperty( |
| 909 onc_source, | 1044 onc_source, |
| 910 onc, | 1045 onc, |
| 911 base::StringPrintf("%s.%s.%s", | 1046 base::StringPrintf("%s.%s.%s", |
| 912 onc::network_config::kVPN, | 1047 onc::network_config::kVPN, |
| 913 dict_key.c_str(), | 1048 dict_key.c_str(), |
| 914 key.c_str())); | 1049 key.c_str())); |
| 915 } | 1050 } |
| 916 | 1051 |
| 917 } // namespace chromeos | 1052 } // namespace chromeos |
| OLD | NEW |