diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-30 12:56:58 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-30 12:56:58 +0000 |
commit | affb70ac2793ef088c0b5eb466cc107de024f173 (patch) | |
tree | e0180ca04a520c42d8bb4406c864cf0a82273b84 | |
parent | ac237576a47cbaf3dad11dc4ed5bf82edc817360 (diff) | |
download | chromium_src-affb70ac2793ef088c0b5eb466cc107de024f173.zip chromium_src-affb70ac2793ef088c0b5eb466cc107de024f173.tar.gz chromium_src-affb70ac2793ef088c0b5eb466cc107de024f173.tar.bz2 |
Fix WiFi & VPN connection dialogs when controls a disabled through policy.
Previously, the UI would make decision based on the enabled() state of
controls, indicating that the control is not relevant for the currently
chosen configuration. This doesn't work for policy-configured networks,
since the control might just be locked down, in which case it is
relevant, but disabled.
BUG=chromium-os:23124
TEST=Configure ONC networks through policy, observe that the connection dialogs show the configured values even though disabled.
Review URL: https://chromiumcodereview.appspot.com/9296009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119664 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/options/vpn_config_view.cc | 8 | ||||
-rw-r--r-- | chrome/browser/chromeos/options/wifi_config_view.cc | 144 | ||||
-rw-r--r-- | chrome/browser/chromeos/options/wifi_config_view.h | 14 |
3 files changed, 98 insertions, 68 deletions
diff --git a/chrome/browser/chromeos/options/vpn_config_view.cc b/chrome/browser/chromeos/options/vpn_config_view.cc index b131821..9ade022 100644 --- a/chrome/browser/chromeos/options/vpn_config_view.cc +++ b/chrome/browser/chromeos/options/vpn_config_view.cc @@ -323,7 +323,7 @@ const std::string VPNConfigView::GetServer() const { const std::string VPNConfigView::GetPSKPassphrase() const { if (psk_passphrase_textfield_ && - psk_passphrase_textfield_->enabled() && + enable_psk_passphrase_ && psk_passphrase_textfield_->visible()) return GetTextFromField(psk_passphrase_textfield_, false); return std::string(); @@ -619,7 +619,7 @@ void VPNConfigView::Refresh() { VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); if (server_ca_cert_combobox_) { server_ca_cert_combobox_->ModelChanged(); - if (server_ca_cert_combobox_->enabled() && + if (enable_server_ca_cert_ && (vpn && !vpn->ca_cert_nss().empty())) { // Select the current server CA certificate in the combobox. int cert_index = cert_library_->GetCACertificates().FindCertByNickname( @@ -637,7 +637,7 @@ void VPNConfigView::Refresh() { if (user_cert_combobox_) { user_cert_combobox_->ModelChanged(); - if (user_cert_combobox_->enabled() && + if (enable_user_cert_ && (vpn && !vpn->client_cert_id().empty())) { int cert_index = cert_library_->GetUserCertificates().FindCertByPkcs11Id( vpn->client_cert_id()); @@ -761,7 +761,7 @@ bool VPNConfigView::HaveUserCerts() const { } bool VPNConfigView::IsUserCertValid() const { - if (!user_cert_combobox_ || !user_cert_combobox_->enabled()) + if (!user_cert_combobox_ || !enable_user_cert_) return false; int selected = user_cert_combobox_->selected_item(); if (selected < 0) diff --git a/chrome/browser/chromeos/options/wifi_config_view.cc b/chrome/browser/chromeos/options/wifi_config_view.cc index b122667..27be94d 100644 --- a/chrome/browser/chromeos/options/wifi_config_view.cc +++ b/chrome/browser/chromeos/options/wifi_config_view.cc @@ -316,13 +316,12 @@ bool WifiConfigView::CanLogin() { // If the network requires a passphrase, make sure it is the right length. if (passphrase_textfield_ != NULL - && passphrase_textfield_->enabled() + && PassphraseActive() && passphrase_textfield_->text().length() < kMinWirelessPasswordLen) return false; // If we're using EAP, we must have a method. if (eap_method_combobox_ - && eap_method_combobox_->enabled() && eap_method_combobox_->selected_item() == EAP_METHOD_INDEX_NONE) return false; @@ -336,13 +335,7 @@ bool WifiConfigView::CanLogin() { bool WifiConfigView::UserCertRequired() const { if (!cert_library_) return false; // return false until cert_library_ is initialized. - // Only EAP-TLS requires a user certificate. - if (eap_method_combobox_ && - eap_method_combobox_->enabled() && - eap_method_combobox_->selected_item() == EAP_METHOD_INDEX_TLS) { - return true; - } - return false; + return UserCertActive(); } bool WifiConfigView::HaveUserCerts() const { @@ -350,7 +343,7 @@ bool WifiConfigView::HaveUserCerts() const { } bool WifiConfigView::IsUserCertValid() const { - if (!user_cert_combobox_ || !user_cert_combobox_->enabled()) + if (!UserCertActive()) return false; int selected = user_cert_combobox_->selected_item(); if (selected < 0) @@ -362,33 +355,71 @@ bool WifiConfigView::IsUserCertValid() const { return true; } +bool WifiConfigView::Phase2AuthActive() const { + if (phase_2_auth_combobox_) + return phase_2_auth_combobox_->model()->GetItemCount() > 1; + + return false; +} + +bool WifiConfigView::PassphraseActive() const { + if (eap_method_combobox_) { + // No password for EAP-TLS. + int selected = eap_method_combobox_->selected_item(); + return (selected != EAP_METHOD_INDEX_NONE && + selected != EAP_METHOD_INDEX_TLS); + } else if (security_combobox_) { + return security_combobox_->selected_item() != SECURITY_INDEX_NONE; + } + + return false; +} + +bool WifiConfigView::UserCertActive() const { + // User certs only for EAP-TLS. + if (eap_method_combobox_) + return eap_method_combobox_->selected_item() == EAP_METHOD_INDEX_TLS; + + return false; +} + +bool WifiConfigView::CaCertActive() const { + // No server CA certs for LEAP. + if (eap_method_combobox_) { + int selected = eap_method_combobox_->selected_item(); + return (selected != EAP_METHOD_INDEX_NONE && + selected != EAP_METHOD_INDEX_LEAP); + } + + return false; +} + void WifiConfigView::UpdateDialogButtons() { parent_->GetDialogClientView()->UpdateDialogButtons(); } void WifiConfigView::RefreshEapFields() { DCHECK(cert_library_); - int selected = eap_method_combobox_->selected_item(); // If EAP method changes, the phase 2 auth choices may have changed also. phase_2_auth_combobox_->ModelChanged(); phase_2_auth_combobox_->SetSelectedItem(0); - phase_2_auth_combobox_->SetEnabled( - phase_2_auth_combobox_->model()->GetItemCount() > 1 && - phase_2_auth_ui_data_.editable()); - phase_2_auth_label_->SetEnabled(phase_2_auth_combobox_->enabled()); - - // No password for EAP-TLS - passphrase_textfield_->SetEnabled(selected != EAP_METHOD_INDEX_NONE && - selected != EAP_METHOD_INDEX_TLS && + bool phase_2_auth_enabled = Phase2AuthActive(); + phase_2_auth_combobox_->SetEnabled(phase_2_auth_enabled && + phase_2_auth_ui_data_.editable()); + phase_2_auth_label_->SetEnabled(phase_2_auth_enabled); + + // Passphrase. + bool passphrase_enabled = PassphraseActive(); + passphrase_textfield_->SetEnabled(passphrase_enabled && passphrase_ui_data_.editable()); - passphrase_label_->SetEnabled(passphrase_textfield_->enabled()); - if (!passphrase_textfield_->enabled()) + passphrase_label_->SetEnabled(passphrase_enabled); + if (!passphrase_enabled) passphrase_textfield_->SetText(string16()); - // User certs only for EAP-TLS + // User cert. bool certs_loading = cert_library_->CertificatesLoading(); - bool user_cert_enabled = (selected == EAP_METHOD_INDEX_TLS); + bool user_cert_enabled = UserCertActive(); user_cert_label_->SetEnabled(user_cert_enabled); bool have_user_certs = !certs_loading && HaveUserCerts(); user_cert_combobox_->SetEnabled(user_cert_enabled && @@ -397,9 +428,8 @@ void WifiConfigView::RefreshEapFields() { user_cert_combobox_->ModelChanged(); user_cert_combobox_->SetSelectedItem(0); - // No server CA certs for LEAP - bool ca_cert_enabled = - (selected != EAP_METHOD_INDEX_NONE && selected != EAP_METHOD_INDEX_LEAP); + // Server CA. + bool ca_cert_enabled = CaCertActive(); server_ca_cert_label_->SetEnabled(ca_cert_enabled); server_ca_cert_combobox_->SetEnabled(ca_cert_enabled && !certs_loading && @@ -408,12 +438,11 @@ void WifiConfigView::RefreshEapFields() { server_ca_cert_combobox_->SetSelectedItem(0); // No anonymous identity if no phase 2 auth. + bool identity_anonymous_enabled = phase_2_auth_enabled; identity_anonymous_textfield_->SetEnabled( - phase_2_auth_combobox_->enabled() && - identity_anonymous_ui_data_.editable()); - identity_anonymous_label_->SetEnabled( - identity_anonymous_textfield_->enabled()); - if (!identity_anonymous_textfield_->enabled()) + identity_anonymous_enabled && identity_anonymous_ui_data_.editable()); + identity_anonymous_label_->SetEnabled(identity_anonymous_enabled); + if (!identity_anonymous_enabled) identity_anonymous_textfield_->SetText(string16()); RefreshShareCheckbox(); @@ -524,16 +553,12 @@ void WifiConfigView::ItemChanged(views::Combobox* combo_box, if (new_index == prev_index) return; if (combo_box == security_combobox_) { - // If changed to no security, then disable combobox and clear it. - // Otherwise, enable it. Also, update can login. - if (new_index == SECURITY_INDEX_NONE) { - passphrase_label_->SetEnabled(false); - passphrase_textfield_->SetEnabled(false); + bool passphrase_enabled = PassphraseActive(); + passphrase_label_->SetEnabled(passphrase_enabled); + passphrase_textfield_->SetEnabled(passphrase_enabled && + passphrase_ui_data_.editable()); + if (!passphrase_enabled) passphrase_textfield_->SetText(string16()); - } else { - passphrase_label_->SetEnabled(true); - passphrase_textfield_->SetEnabled(true); - } RefreshShareCheckbox(); } else if (combo_box == user_cert_combobox_) { RefreshShareCheckbox(); @@ -909,10 +934,8 @@ void WifiConfigView::Init(WifiNetwork* wifi, bool show_8021x) { if (wifi && !wifi->GetPassphrase().empty()) passphrase_textfield_->SetText(UTF8ToUTF16(wifi->GetPassphrase())); // Disable passphrase input initially for other network. - if (!wifi) { - passphrase_label_->SetEnabled(false); - passphrase_textfield_->SetEnabled(false); - } + passphrase_label_->SetEnabled(wifi != NULL); + passphrase_textfield_->SetEnabled(wifi && passphrase_ui_data_.editable()); passphrase_textfield_->SetAccessibleName(l10n_util::GetStringUTF16( label_text_id)); layout->AddView(passphrase_textfield_); @@ -1027,8 +1050,8 @@ void WifiConfigView::Init(WifiNetwork* wifi, bool show_8021x) { } RefreshEapFields(); - // Phase 2 authentication - if (phase_2_auth_combobox_->enabled()) { + // Phase 2 authentication and anonymous identity. + if (Phase2AuthActive()) { EAPPhase2Auth eap_phase_2_auth = (wifi ? wifi->eap_phase_2_auth() : EAP_PHASE_2_AUTH_AUTO); switch (eap_phase_2_auth) { @@ -1050,10 +1073,15 @@ void WifiConfigView::Init(WifiNetwork* wifi, bool show_8021x) { default: break; } + + const std::string& eap_anonymous_identity = + (wifi ? wifi->GetEapAnonymousIdentity() : std::string()); + identity_anonymous_textfield_->SetText( + UTF8ToUTF16(eap_anonymous_identity)); } // Server CA certificate - if (server_ca_cert_combobox_->enabled()) { + if (CaCertActive()) { const std::string& nss_nickname = (wifi ? wifi->eap_server_ca_cert_nss_nickname() : std::string()); if (nss_nickname.empty()) { @@ -1077,7 +1105,7 @@ void WifiConfigView::Init(WifiNetwork* wifi, bool show_8021x) { } // User certificate - if (user_cert_combobox_->enabled()) { + if (UserCertActive()) { const std::string& pkcs11_id = (wifi ? wifi->eap_client_cert_pkcs11_id() : std::string()); if (!pkcs11_id.empty()) { @@ -1089,23 +1117,13 @@ void WifiConfigView::Init(WifiNetwork* wifi, bool show_8021x) { } } - // Identity - if (identity_textfield_->enabled()) { - const std::string& eap_identity = - (wifi ? wifi->GetEapIdentity() : std::string()); - identity_textfield_->SetText(UTF8ToUTF16(eap_identity)); - } - - // Anonymous identity - if (identity_anonymous_textfield_->enabled()) { - const std::string& eap_anonymous_identity = - (wifi ? wifi->GetEapAnonymousIdentity() : std::string()); - identity_anonymous_textfield_->SetText( - UTF8ToUTF16(eap_anonymous_identity)); - } + // Identity is always active. + const std::string& eap_identity = + (wifi ? wifi->GetEapIdentity() : std::string()); + identity_textfield_->SetText(UTF8ToUTF16(eap_identity)); // Passphrase - if (passphrase_textfield_->enabled()) { + if (PassphraseActive()) { const std::string& eap_passphrase = (wifi ? wifi->eap_passphrase() : std::string()); passphrase_textfield_->SetText(UTF8ToUTF16(eap_passphrase)); diff --git a/chrome/browser/chromeos/options/wifi_config_view.h b/chrome/browser/chromeos/options/wifi_config_view.h index cff3a13..1460a10 100644 --- a/chrome/browser/chromeos/options/wifi_config_view.h +++ b/chrome/browser/chromeos/options/wifi_config_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -95,6 +95,18 @@ class WifiConfigView : public ChildNetworkConfigView, // Returns true if there is a selected user certificate and it is valid. bool IsUserCertValid() const; + // Returns true if the phase 2 auth is relevant. + bool Phase2AuthActive() const; + + // Returns whether the current configuration requires a passphrase. + bool PassphraseActive() const; + + // Returns true if a user cert should be selected. + bool UserCertActive() const; + + // Returns true if a CA cert selection should be allowed. + bool CaCertActive() const; + // Updates state of the Login button. void UpdateDialogButtons(); |