Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/wifi_config_view.h" | 5 #include "chrome/browser/chromeos/options/wifi_config_view.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | 9 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" | 10 #include "chrome/browser/chromeos/login/user_manager.h" |
| 11 #include "chrome/browser/chromeos/options/network_config_view.h" | 11 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 12 #include "grit/chromium_strings.h" | 12 #include "grit/chromium_strings.h" |
| 13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 14 #include "grit/locale_settings.h" | 14 #include "grit/locale_settings.h" |
| 15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "views/controls/button/image_button.h" | 18 #include "views/controls/button/image_button.h" |
| 19 #include "views/controls/button/native_button.h" | 19 #include "views/controls/button/native_button.h" |
| 20 #include "views/controls/label.h" | 20 #include "views/controls/label.h" |
| 21 #include "views/layout/grid_layout.h" | 21 #include "views/layout/grid_layout.h" |
| 22 #include "views/layout/layout_constants.h" | 22 #include "views/layout/layout_constants.h" |
| 23 #include "views/window/window.h" | 23 #include "views/window/window.h" |
| 24 | 24 |
| 25 namespace chromeos { | 25 namespace chromeos { |
| 26 | 26 |
| 27 namespace { | |
| 28 | |
| 27 // The width of the password field. | 29 // The width of the password field. |
| 28 const int kPasswordWidth = 150; | 30 const int kPasswordWidth = 150; |
| 29 | 31 |
| 30 enum SecurityComboboxIndex { | 32 enum SecurityComboboxIndex { |
| 31 INDEX_NONE = 0, | 33 SECURITY_INDEX_NONE = 0, |
| 32 INDEX_WEP = 1, | 34 SECURITY_INDEX_WEP = 1, |
| 33 INDEX_WPA = 2, | 35 SECURITY_INDEX_WPA = 2, |
| 34 INDEX_RSN = 3, | 36 SECURITY_INDEX_RSN = 3, |
| 35 INDEX_COUNT = 4 | 37 SECURITY_INDEX_COUNT = 4 |
| 36 }; | 38 }; |
| 37 | 39 |
| 38 int WifiConfigView::SecurityComboboxModel::GetItemCount() { | 40 class SecurityComboboxModel : public ui::ComboboxModel { |
| 39 return INDEX_COUNT; | 41 public: |
| 40 } | 42 SecurityComboboxModel() {} |
| 43 virtual ~SecurityComboboxModel() {} | |
| 44 virtual int GetItemCount() { | |
| 45 return SECURITY_INDEX_COUNT; | |
| 46 } | |
| 47 virtual string16 GetItemAt(int index) { | |
| 48 if (index == SECURITY_INDEX_NONE) | |
| 49 return l10n_util::GetStringUTF16( | |
| 50 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_NONE); | |
| 51 else if (index == SECURITY_INDEX_WEP) | |
| 52 return l10n_util::GetStringUTF16( | |
| 53 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_WEP); | |
| 54 else if (index == SECURITY_INDEX_WPA) | |
| 55 return l10n_util::GetStringUTF16( | |
| 56 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_WPA); | |
| 57 else if (index == SECURITY_INDEX_RSN) | |
| 58 return l10n_util::GetStringUTF16( | |
| 59 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_RSN); | |
| 60 NOTREACHED(); | |
| 61 return string16(); | |
| 62 } | |
| 63 private: | |
| 64 DISALLOW_COPY_AND_ASSIGN(SecurityComboboxModel); | |
| 65 }; | |
| 41 | 66 |
| 42 string16 WifiConfigView::SecurityComboboxModel::GetItemAt(int index) { | 67 enum EAPMethodComboboxIndex { |
| 43 if (index == INDEX_NONE) | 68 EAP_METHOD_INDEX_NONE = 0, |
| 44 return l10n_util::GetStringUTF16( | 69 EAP_METHOD_INDEX_PEAP = 1, |
| 45 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_NONE); | 70 EAP_METHOD_INDEX_TLS = 2, |
| 46 else if (index == INDEX_WEP) | 71 EAP_METHOD_INDEX_TTLS = 3, |
| 47 return l10n_util::GetStringUTF16( | 72 EAP_METHOD_INDEX_LEAP = 4, |
| 48 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_WEP); | 73 EAP_METHOD_INDEX_COUNT = 5 |
| 49 else if (index == INDEX_WPA) | 74 }; |
| 50 return l10n_util::GetStringUTF16( | 75 |
| 51 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_WPA); | 76 class EAPMethodComboboxModel : public ui::ComboboxModel { |
| 52 else if (index == INDEX_RSN) | 77 public: |
| 53 return l10n_util::GetStringUTF16( | 78 EAPMethodComboboxModel() {} |
| 54 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_RSN); | 79 virtual ~EAPMethodComboboxModel() {} |
| 55 NOTREACHED(); | 80 virtual int GetItemCount() { |
| 56 return string16(); | 81 return EAP_METHOD_INDEX_COUNT; |
| 57 } | 82 } |
| 83 virtual string16 GetItemAt(int index) { | |
| 84 if (index == EAP_METHOD_INDEX_NONE) | |
| 85 return l10n_util::GetStringUTF16( | |
| 86 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD_NONE); | |
| 87 else if (index == EAP_METHOD_INDEX_PEAP) | |
| 88 return l10n_util::GetStringUTF16( | |
| 89 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD_PEAP); | |
| 90 else if (index == EAP_METHOD_INDEX_TLS) | |
| 91 return l10n_util::GetStringUTF16( | |
| 92 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD_TLS); | |
| 93 else if (index == EAP_METHOD_INDEX_TTLS) | |
| 94 return l10n_util::GetStringUTF16( | |
| 95 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD_TTLS); | |
| 96 else if (index == EAP_METHOD_INDEX_LEAP) | |
| 97 return l10n_util::GetStringUTF16( | |
| 98 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD_LEAP); | |
| 99 NOTREACHED(); | |
| 100 return string16(); | |
| 101 } | |
| 102 private: | |
| 103 DISALLOW_COPY_AND_ASSIGN(EAPMethodComboboxModel); | |
| 104 }; | |
| 105 | |
| 106 enum Phase2AuthComboboxIndex { | |
| 107 PHASE_2_AUTH_INDEX_AUTO = 0, // LEAP, EAP-TLS have only this auth. | |
| 108 PHASE_2_AUTH_INDEX_MD5 = 1, | |
| 109 PHASE_2_AUTH_INDEX_MSCHAPV2 = 2, // PEAP has up to this auth. | |
| 110 PHASE_2_AUTH_INDEX_MSCHAP = 3, | |
| 111 PHASE_2_AUTH_INDEX_PAP = 4, | |
| 112 PHASE_2_AUTH_INDEX_CHAP = 5, // EAP-TTLS has up to this auth. | |
| 113 PHASE_2_AUTH_INDEX_COUNT = 6 | |
| 114 }; | |
| 115 | |
| 116 class Phase2AuthComboboxModel : public ui::ComboboxModel { | |
| 117 public: | |
| 118 explicit Phase2AuthComboboxModel(views::Combobox* eap_method_combobox) | |
| 119 : eap_method_combobox_(eap_method_combobox) {} | |
| 120 virtual ~Phase2AuthComboboxModel() {} | |
| 121 virtual int GetItemCount() { | |
| 122 switch (eap_method_combobox_->selected_item()) { | |
| 123 case EAP_METHOD_INDEX_NONE: | |
| 124 case EAP_METHOD_INDEX_TLS: | |
| 125 case EAP_METHOD_INDEX_LEAP: | |
| 126 return PHASE_2_AUTH_INDEX_AUTO + 1; | |
| 127 case EAP_METHOD_INDEX_PEAP: | |
| 128 return PHASE_2_AUTH_INDEX_MSCHAPV2 + 1; | |
| 129 case EAP_METHOD_INDEX_TTLS: | |
| 130 return PHASE_2_AUTH_INDEX_CHAP + 1; | |
| 131 } | |
| 132 NOTREACHED(); | |
| 133 return 0; | |
| 134 } | |
| 135 virtual string16 GetItemAt(int index) { | |
| 136 if (index == PHASE_2_AUTH_INDEX_AUTO) | |
| 137 return l10n_util::GetStringUTF16( | |
| 138 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_AUTO); | |
| 139 else if (index == PHASE_2_AUTH_INDEX_MD5) | |
| 140 return l10n_util::GetStringUTF16( | |
| 141 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_MD5); | |
| 142 else if (index == PHASE_2_AUTH_INDEX_MSCHAPV2) | |
| 143 return l10n_util::GetStringUTF16( | |
| 144 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_MSCHAPV2); | |
| 145 else if (index == PHASE_2_AUTH_INDEX_MSCHAP) | |
| 146 return l10n_util::GetStringUTF16( | |
| 147 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_MSCHAP); | |
| 148 else if (index == PHASE_2_AUTH_INDEX_PAP) | |
| 149 return l10n_util::GetStringUTF16( | |
| 150 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_PAP); | |
| 151 else if (index == PHASE_2_AUTH_INDEX_CHAP) | |
| 152 return l10n_util::GetStringUTF16( | |
| 153 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_CHAP); | |
| 154 NOTREACHED(); | |
| 155 return string16(); | |
| 156 } | |
| 157 private: | |
| 158 views::Combobox* eap_method_combobox_; | |
| 159 DISALLOW_COPY_AND_ASSIGN(Phase2AuthComboboxModel); | |
| 160 }; | |
| 161 | |
| 162 } // namespace | |
| 58 | 163 |
| 59 WifiConfigView::WifiConfigView(NetworkConfigView* parent, | 164 WifiConfigView::WifiConfigView(NetworkConfigView* parent, |
| 60 const WifiNetwork* wifi) | 165 const WifiNetwork* wifi) |
| 61 : parent_(parent), | 166 : parent_(parent), |
| 62 can_login_(false), | 167 is_8021x_(false), |
| 63 wifi_(new WifiNetwork(*wifi)), | 168 wifi_(new WifiNetwork(*wifi)), |
| 64 ssid_textfield_(NULL), | 169 ssid_textfield_(NULL), |
| 170 eap_method_combobox_(NULL), | |
| 171 phase_2_auth_combobox_(NULL), | |
| 65 identity_textfield_(NULL), | 172 identity_textfield_(NULL), |
| 173 identity_anonymous_textfield_(NULL), | |
| 66 certificate_browse_button_(NULL), | 174 certificate_browse_button_(NULL), |
| 67 certificate_path_(), | 175 certificate_path_(), |
| 68 security_combobox_(NULL), | 176 security_combobox_(NULL), |
| 69 passphrase_textfield_(NULL), | 177 passphrase_textfield_(NULL), |
| 70 passphrase_visible_button_(NULL), | 178 passphrase_visible_button_(NULL), |
| 71 error_label_(NULL) { | 179 error_label_(NULL) { |
| 72 Init(); | 180 Init(); |
| 73 } | 181 } |
| 74 | 182 |
| 75 WifiConfigView::WifiConfigView(NetworkConfigView* parent) | 183 WifiConfigView::WifiConfigView(NetworkConfigView* parent) |
| 76 : parent_(parent), | 184 : parent_(parent), |
| 77 can_login_(false), | 185 is_8021x_(false), |
| 78 ssid_textfield_(NULL), | 186 ssid_textfield_(NULL), |
| 187 eap_method_combobox_(NULL), | |
| 188 phase_2_auth_combobox_(NULL), | |
| 79 identity_textfield_(NULL), | 189 identity_textfield_(NULL), |
| 190 identity_anonymous_textfield_(NULL), | |
| 80 certificate_browse_button_(NULL), | 191 certificate_browse_button_(NULL), |
| 81 certificate_path_(), | 192 certificate_path_(), |
| 82 security_combobox_(NULL), | 193 security_combobox_(NULL), |
| 83 passphrase_textfield_(NULL), | 194 passphrase_textfield_(NULL), |
| 84 passphrase_visible_button_(NULL), | 195 passphrase_visible_button_(NULL), |
| 85 error_label_(NULL) { | 196 error_label_(NULL) { |
| 86 Init(); | 197 Init(); |
| 87 } | 198 } |
| 88 | 199 |
| 89 WifiConfigView::~WifiConfigView() { | 200 WifiConfigView::~WifiConfigView() { |
| 90 } | 201 } |
| 91 | 202 |
| 92 void WifiConfigView::UpdateCanLogin(void) { | 203 bool WifiConfigView::CanLogin() { |
| 93 static const size_t kMinWirelessPasswordLen = 5; | 204 static const size_t kMinWirelessPasswordLen = 5; |
| 94 | 205 |
| 95 bool can_login = true; | |
| 96 if (!wifi_.get()) { | 206 if (!wifi_.get()) { |
| 97 // Enforce ssid is non empty. | 207 // Enforce ssid is non empty. |
| 208 if (GetSSID().empty()) | |
| 209 return false; | |
| 210 | |
| 98 // If security is not none, also enforce passphrase is non empty. | 211 // If security is not none, also enforce passphrase is non empty. |
| 99 can_login = !GetSSID().empty() && | 212 if (security_combobox_->selected_item() != SECURITY_INDEX_NONE && |
| 100 (security_combobox_->selected_item() == INDEX_NONE || | 213 passphrase_textfield_->text().length() < kMinWirelessPasswordLen) |
| 101 passphrase_textfield_->text().length() >= kMinWirelessPasswordLen); | 214 return false; |
| 102 } else { | 215 } else { |
| 103 // Connecting to an encrypted network | 216 if (is_8021x_) { |
| 104 if (passphrase_textfield_ != NULL) { | 217 // Make sure the EAP method is set |
| 105 // if the network requires a passphrase, make sure it is non empty. | 218 if (eap_method_combobox_->selected_item() == EAP_METHOD_INDEX_NONE) |
| 106 can_login &= | 219 return false; |
| 107 passphrase_textfield_->text().length() >= kMinWirelessPasswordLen; | 220 |
| 108 } | |
| 109 if (identity_textfield_ != NULL) { | |
| 110 // If we have an identity field, we can login if we have a non empty | 221 // If we have an identity field, we can login if we have a non empty |
| 111 // identity and a certificate path | 222 // identity and a certificate path |
| 112 can_login &= !identity_textfield_->text().empty() && | 223 if (identity_textfield_ != NULL && |
| 113 !certificate_path_.empty(); | 224 (identity_textfield_->text().empty() || certificate_path_.empty())) |
| 225 return false; | |
| 114 } | 226 } |
| 227 | |
| 228 // if the network requires a passphrase, make sure it is the right length. | |
| 229 if (passphrase_textfield_ != NULL && | |
| 230 passphrase_textfield_->text().length() < kMinWirelessPasswordLen) | |
| 231 return false; | |
| 115 } | 232 } |
| 233 return true; | |
| 234 } | |
| 116 | 235 |
| 117 // Update the login button enable/disable state if can_login_ changes. | 236 void WifiConfigView::UpdateCanLogin() { |
|
stevenjb
2011/03/04 03:21:02
nit: rename this to something like UpdateDialog()?
| |
| 118 if (can_login != can_login_) { | 237 parent_->GetDialogClientView()->UpdateDialogButtons(); |
| 119 can_login_ = can_login; | |
| 120 parent_->GetDialogClientView()->UpdateDialogButtons(); | |
| 121 } | |
| 122 } | 238 } |
| 123 | 239 |
| 124 void WifiConfigView::UpdateErrorLabel(bool failed) { | 240 void WifiConfigView::UpdateErrorLabel(bool failed) { |
| 125 static const int kNoError = -1; | 241 static const int kNoError = -1; |
| 126 int id = kNoError; | 242 int id = kNoError; |
| 127 if (wifi_.get()) { | 243 if (wifi_.get()) { |
| 128 // Right now, only displaying bad_passphrase and bad_wepkey errors. | 244 // Right now, only displaying bad_passphrase and bad_wepkey errors. |
| 129 if (wifi_->error() == ERROR_BAD_PASSPHRASE) | 245 if (wifi_->error() == ERROR_BAD_PASSPHRASE) |
| 130 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE; | 246 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE; |
| 131 else if (wifi_->error() == ERROR_BAD_WEPKEY) | 247 else if (wifi_->error() == ERROR_BAD_WEPKEY) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 NULL : | 289 NULL : |
| 174 parent_->GetNativeWindow(), | 290 parent_->GetNativeWindow(), |
| 175 NULL); | 291 NULL); |
| 176 } else { | 292 } else { |
| 177 NOTREACHED(); | 293 NOTREACHED(); |
| 178 } | 294 } |
| 179 } | 295 } |
| 180 | 296 |
| 181 void WifiConfigView::ItemChanged(views::Combobox* combo_box, | 297 void WifiConfigView::ItemChanged(views::Combobox* combo_box, |
| 182 int prev_index, int new_index) { | 298 int prev_index, int new_index) { |
| 183 // If changed to no security, then disable combobox and clear it. | 299 if (new_index == prev_index) |
| 184 // Otherwise, enable it. Also, update can login. | 300 return; |
| 185 if (new_index == INDEX_NONE) { | 301 if (combo_box == security_combobox_) { |
| 186 passphrase_textfield_->SetEnabled(false); | 302 // If changed to no security, then disable combobox and clear it. |
| 187 passphrase_textfield_->SetText(string16()); | 303 // Otherwise, enable it. Also, update can login. |
| 188 } else { | 304 if (new_index == SECURITY_INDEX_NONE) { |
| 189 passphrase_textfield_->SetEnabled(true); | 305 passphrase_textfield_->SetEnabled(false); |
| 306 passphrase_textfield_->SetText(string16()); | |
| 307 } else { | |
| 308 passphrase_textfield_->SetEnabled(true); | |
| 309 } | |
| 310 } else if (combo_box == eap_method_combobox_) { | |
| 311 // If EAP method changes, the phase 2 auth choices may have changed also. | |
| 312 phase_2_auth_combobox_->ModelChanged(); | |
| 313 phase_2_auth_combobox_->SetSelectedItem(0); | |
| 314 phase_2_auth_combobox_->SetEnabled( | |
| 315 phase_2_auth_combobox_->model()->GetItemCount() > 1); | |
| 316 | |
| 317 // No password for EAP-TLS | |
| 318 if (eap_method_combobox_->selected_item() == EAP_METHOD_INDEX_TLS) { | |
| 319 passphrase_textfield_->SetEnabled(false); | |
| 320 passphrase_textfield_->SetText(string16()); | |
| 321 } else { | |
| 322 passphrase_textfield_->SetEnabled(true); | |
| 323 } | |
| 324 | |
| 325 // No client certs for EAP-TTLS, PEAP, or LEAP | |
| 326 | |
| 327 // No server certs for LEAP | |
| 328 | |
| 329 // No anonymous identity if no phase 2 auth. | |
| 330 if (phase_2_auth_combobox_->model()->GetItemCount() > 1) { | |
| 331 identity_anonymous_textfield_->SetEnabled(true); | |
| 332 } else { | |
| 333 identity_anonymous_textfield_->SetEnabled(false); | |
| 334 identity_anonymous_textfield_->SetText(string16()); | |
| 335 } | |
| 190 } | 336 } |
| 191 UpdateCanLogin(); | 337 UpdateCanLogin(); |
| 192 } | 338 } |
| 193 | 339 |
| 194 void WifiConfigView::FileSelected(const FilePath& path, | 340 void WifiConfigView::FileSelected(const FilePath& path, |
| 195 int index, void* params) { | 341 int index, void* params) { |
| 196 certificate_path_ = path.value(); | 342 certificate_path_ = path.value(); |
| 197 if (certificate_browse_button_) { | 343 if (certificate_browse_button_) { |
| 198 certificate_browse_button_->SetLabel( | 344 certificate_browse_button_->SetLabel( |
| 199 UTF16ToWide(path.BaseName().LossyDisplayName())); | 345 UTF16ToWide(path.BaseName().LossyDisplayName())); |
| 200 } | 346 } |
| 201 UpdateCanLogin(); // TODO(njw) Check if the passphrase decrypts the key. | 347 UpdateCanLogin(); // TODO(njw) Check if the passphrase decrypts the key. |
| 202 } | 348 } |
| 203 | 349 |
| 204 bool WifiConfigView::Login() { | 350 bool WifiConfigView::Login() { |
| 205 std::string identity_string; | 351 std::string identity_string; |
| 206 if (identity_textfield_ != NULL) { | 352 if (identity_textfield_ != NULL) { |
| 207 identity_string = UTF16ToUTF8(identity_textfield_->text()); | 353 identity_string = UTF16ToUTF8(identity_textfield_->text()); |
| 208 } | 354 } |
| 209 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 355 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 210 bool connected = false; | 356 bool connected = false; |
| 211 if (!wifi_.get()) { | 357 if (!wifi_.get()) { |
| 212 ConnectionSecurity sec = SECURITY_UNKNOWN; | 358 ConnectionSecurity sec = SECURITY_UNKNOWN; |
| 213 int index = security_combobox_->selected_item(); | 359 int index = security_combobox_->selected_item(); |
| 214 if (index == INDEX_NONE) | 360 if (index == SECURITY_INDEX_NONE) |
| 215 sec = SECURITY_NONE; | 361 sec = SECURITY_NONE; |
| 216 else if (index == INDEX_WEP) | 362 else if (index == SECURITY_INDEX_WEP) |
| 217 sec = SECURITY_WEP; | 363 sec = SECURITY_WEP; |
| 218 else if (index == INDEX_WPA) | 364 else if (index == SECURITY_INDEX_WPA) |
| 219 sec = SECURITY_WPA; | 365 sec = SECURITY_WPA; |
| 220 else if (index == INDEX_RSN) | 366 else if (index == SECURITY_INDEX_RSN) |
| 221 sec = SECURITY_RSN; | 367 sec = SECURITY_RSN; |
| 222 connected = cros->ConnectToWifiNetwork( | 368 connected = cros->ConnectToWifiNetwork( |
| 223 sec, GetSSID(), GetPassphrase(), | 369 sec, GetSSID(), GetPassphrase(), |
| 224 identity_string, certificate_path_, true); | 370 identity_string, certificate_path_, true); |
| 225 } else { | 371 } else { |
| 226 Save(); | 372 Save(); |
| 227 connected = cros->ConnectToWifiNetwork( | 373 connected = cros->ConnectToWifiNetwork( |
| 228 wifi_.get(), GetPassphrase(), | 374 wifi_.get(), GetPassphrase(), |
| 229 identity_string, certificate_path_); | 375 identity_string, certificate_path_); |
| 230 } | 376 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 return result; | 422 return result; |
| 277 } | 423 } |
| 278 | 424 |
| 279 const std::string WifiConfigView::GetPassphrase() const { | 425 const std::string WifiConfigView::GetPassphrase() const { |
| 280 std::string result; | 426 std::string result; |
| 281 if (passphrase_textfield_ != NULL) | 427 if (passphrase_textfield_ != NULL) |
| 282 result = UTF16ToUTF8(passphrase_textfield_->text()); | 428 result = UTF16ToUTF8(passphrase_textfield_->text()); |
| 283 return result; | 429 return result; |
| 284 } | 430 } |
| 285 | 431 |
| 432 // This will initialize the view depending on if we have a wifi network or not. | |
| 433 // And if we are doing simple password encyption or the more complicated | |
| 434 // 802.1x encryption. | |
| 435 // If we are creating the "Join other network..." dialog, we will allow user | |
| 436 // to enter the data. And if they select the 802.1x encryption, we will show | |
| 437 // the 802.1x fields. | |
| 286 void WifiConfigView::Init() { | 438 void WifiConfigView::Init() { |
| 287 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | 439 views::GridLayout* layout = views::GridLayout::CreatePanel(this); |
| 288 SetLayoutManager(layout); | 440 SetLayoutManager(layout); |
| 289 | 441 |
| 290 int column_view_set_id = 0; | 442 int column_view_set_id = 0; |
| 291 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); | 443 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); |
| 292 // Label | 444 // Label |
| 293 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | 445 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
| 294 views::GridLayout::USE_PREF, 0, 0); | 446 views::GridLayout::USE_PREF, 0, 0); |
| 295 // Textfield | 447 // Textfield |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 307 ssid_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 459 ssid_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
| 308 ssid_textfield_->SetController(this); | 460 ssid_textfield_->SetController(this); |
| 309 layout->AddView(ssid_textfield_); | 461 layout->AddView(ssid_textfield_); |
| 310 } else { | 462 } else { |
| 311 views::Label* label = new views::Label(ASCIIToWide(wifi_->name())); | 463 views::Label* label = new views::Label(ASCIIToWide(wifi_->name())); |
| 312 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 464 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 313 layout->AddView(label); | 465 layout->AddView(label); |
| 314 } | 466 } |
| 315 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 467 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 316 | 468 |
| 469 // Security select | |
| 470 if (!wifi_.get()) { | |
| 471 layout->StartRow(0, column_view_set_id); | |
| 472 layout->AddView(new views::Label(UTF16ToWide(l10n_util::GetStringUTF16( | |
| 473 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY)))); | |
| 474 security_combobox_ = new views::Combobox(new SecurityComboboxModel()); | |
| 475 security_combobox_->set_listener(this); | |
| 476 layout->AddView(security_combobox_); | |
| 477 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 478 } | |
| 479 | |
| 317 // Certificate input | 480 // Certificate input |
| 318 // Loaded certificates (i.e. stored in a pkcs11 device) do not require | 481 // Loaded certificates (i.e. stored in a pkcs11 device) do not require |
| 319 // a passphrase. | 482 // a passphrase. |
| 320 bool certificate_loaded = false; | 483 bool certificate_loaded = false; |
| 321 | 484 |
| 322 // Add ID and cert password if we're using 802.1x | 485 // Add ID and cert password if we're using 802.1x |
| 323 // XXX we're cheating and assuming 802.1x means EAP-TLS - not true | 486 // XXX we're cheating and assuming 802.1x means EAP-TLS - not true |
| 324 // in general, but very common. WPA Supplicant doesn't report the | 487 // in general, but very common. WPA Supplicant doesn't report the |
| 325 // EAP type because it's unknown until the process begins, and we'd | 488 // EAP type because it's unknown until the process begins, and we'd |
| 326 // need some kind of callback. | 489 // need some kind of callback. |
| 327 if (wifi_.get() && wifi_->encrypted() && | 490 is_8021x_ = wifi_.get() && wifi_->encrypted() && |
| 328 wifi_->encryption() == SECURITY_8021X) { | 491 wifi_->encryption() == SECURITY_8021X; |
| 492 if (is_8021x_) { | |
| 493 // EAP Method | |
| 329 layout->StartRow(0, column_view_set_id); | 494 layout->StartRow(0, column_view_set_id); |
| 330 layout->AddView(new views::Label(UTF16ToWide(l10n_util::GetStringUTF16( | 495 layout->AddView(new views::Label(UTF16ToWide(l10n_util::GetStringUTF16( |
| 331 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY)))); | 496 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD)))); |
| 332 identity_textfield_ = new views::Textfield( | 497 eap_method_combobox_ = new views::Combobox(new EAPMethodComboboxModel()); |
| 333 views::Textfield::STYLE_DEFAULT); | 498 eap_method_combobox_->set_listener(this); |
| 334 identity_textfield_->SetController(this); | 499 layout->AddView(eap_method_combobox_); |
| 335 if (!wifi_->identity().empty()) | |
| 336 identity_textfield_->SetText(UTF8ToUTF16(wifi_->identity())); | |
| 337 layout->AddView(identity_textfield_); | |
| 338 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 500 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 501 | |
| 502 // Phase 2 Authentication | |
| 503 layout->StartRow(0, column_view_set_id); | |
| 504 layout->AddView(new views::Label(UTF16ToWide(l10n_util::GetStringUTF16( | |
| 505 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH)))); | |
| 506 phase_2_auth_combobox_ = new views::Combobox( | |
| 507 new Phase2AuthComboboxModel(eap_method_combobox_)); | |
| 508 phase_2_auth_combobox_->SetEnabled(false); | |
| 509 phase_2_auth_combobox_->set_listener(this); | |
| 510 layout->AddView(phase_2_auth_combobox_); | |
| 511 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 512 | |
| 513 // Certificate | |
| 339 layout->StartRow(0, column_view_set_id); | 514 layout->StartRow(0, column_view_set_id); |
| 340 layout->AddView(new views::Label(UTF16ToWide(l10n_util::GetStringUTF16( | 515 layout->AddView(new views::Label(UTF16ToWide(l10n_util::GetStringUTF16( |
| 341 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT)))); | 516 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT)))); |
| 342 if (!wifi_->cert_path().empty()) { | 517 if (!wifi_->cert_path().empty()) { |
| 343 certificate_path_ = wifi_->cert_path(); | 518 certificate_path_ = wifi_->cert_path(); |
| 344 certificate_loaded = wifi_->IsCertificateLoaded(); | 519 certificate_loaded = wifi_->IsCertificateLoaded(); |
| 345 } | 520 } |
| 346 if (certificate_loaded) { | 521 if (certificate_loaded) { |
| 347 std::wstring label = UTF16ToWide(l10n_util::GetStringUTF16( | 522 std::wstring label = UTF16ToWide(l10n_util::GetStringUTF16( |
| 348 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_INSTALLED)); | 523 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_INSTALLED)); |
| 349 views::Label* cert_text = new views::Label(label); | 524 views::Label* cert_text = new views::Label(label); |
| 350 cert_text->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 525 cert_text->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 351 layout->AddView(cert_text); | 526 layout->AddView(cert_text); |
| 352 } else { | 527 } else { |
| 353 std::wstring label; | 528 std::wstring label; |
| 354 if (!certificate_path_.empty()) | 529 if (!certificate_path_.empty()) |
| 355 label = UTF8ToWide(certificate_path_); | 530 label = UTF8ToWide(certificate_path_); |
| 356 else | 531 else |
| 357 label = UTF16ToWide(l10n_util::GetStringUTF16( | 532 label = UTF16ToWide(l10n_util::GetStringUTF16( |
| 358 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_BUTTON)); | 533 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_BUTTON)); |
| 359 certificate_browse_button_ = new views::NativeButton(this, label); | 534 certificate_browse_button_ = new views::NativeButton(this, label); |
| 360 layout->AddView(certificate_browse_button_); | 535 layout->AddView(certificate_browse_button_); |
| 361 } | 536 } |
| 362 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 537 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 363 } | |
| 364 | 538 |
| 365 // Security select | 539 // Identity |
| 366 if (!wifi_.get()) { | |
| 367 layout->StartRow(0, column_view_set_id); | 540 layout->StartRow(0, column_view_set_id); |
| 368 layout->AddView(new views::Label(UTF16ToWide(l10n_util::GetStringUTF16( | 541 layout->AddView(new views::Label(UTF16ToWide(l10n_util::GetStringUTF16( |
| 369 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY)))); | 542 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY)))); |
| 370 security_combobox_ = new views::Combobox(new SecurityComboboxModel()); | 543 identity_textfield_ = new views::Textfield( |
| 371 security_combobox_->set_listener(this); | 544 views::Textfield::STYLE_DEFAULT); |
| 372 layout->AddView(security_combobox_); | 545 identity_textfield_->SetController(this); |
| 546 if (!wifi_->identity().empty()) | |
| 547 identity_textfield_->SetText(UTF8ToUTF16(wifi_->identity())); | |
| 548 layout->AddView(identity_textfield_); | |
| 549 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 550 | |
| 551 // Anonymous Identity | |
| 552 layout->StartRow(0, column_view_set_id); | |
| 553 layout->AddView(new views::Label(UTF16ToWide(l10n_util::GetStringUTF16( | |
| 554 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY_ANONYMOUS)))); | |
| 555 identity_anonymous_textfield_ = new views::Textfield( | |
| 556 views::Textfield::STYLE_DEFAULT); | |
| 557 identity_anonymous_textfield_->SetEnabled(false); | |
| 558 identity_anonymous_textfield_->SetController(this); | |
| 559 layout->AddView(identity_anonymous_textfield_); | |
| 373 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 560 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 374 } | 561 } |
| 375 | 562 |
| 376 // Passphrase input | 563 // Passphrase input |
| 377 layout->StartRow(0, column_view_set_id); | 564 layout->StartRow(0, column_view_set_id); |
| 378 int label_text_id; | 565 int label_text_id; |
| 379 if (wifi_.get() && wifi_->encryption() == SECURITY_8021X) { | 566 if (is_8021x_) |
| 380 label_text_id = | 567 label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PRIVATE_KEY_PASSWORD; |
| 381 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PRIVATE_KEY_PASSWORD; | 568 else |
| 382 } else { | |
| 383 label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE; | 569 label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE; |
| 384 } | |
| 385 layout->AddView(new views::Label( | 570 layout->AddView(new views::Label( |
| 386 UTF16ToWide(l10n_util::GetStringUTF16(label_text_id)))); | 571 UTF16ToWide(l10n_util::GetStringUTF16(label_text_id)))); |
| 387 passphrase_textfield_ = new views::Textfield( | 572 passphrase_textfield_ = new views::Textfield( |
| 388 views::Textfield::STYLE_PASSWORD); | 573 views::Textfield::STYLE_PASSWORD); |
| 389 passphrase_textfield_->SetController(this); | 574 passphrase_textfield_->SetController(this); |
| 390 if (wifi_.get() && !wifi_->passphrase().empty()) | 575 if (wifi_.get() && !wifi_->passphrase().empty()) |
| 391 passphrase_textfield_->SetText(UTF8ToUTF16(wifi_->passphrase())); | 576 passphrase_textfield_->SetText(UTF8ToUTF16(wifi_->passphrase())); |
| 392 // Disable passphrase input initially for other network. | 577 // Disable passphrase input initially for other network. |
| 393 if (!wifi_.get()) | 578 if (!wifi_.get()) |
| 394 passphrase_textfield_->SetEnabled(false); | 579 passphrase_textfield_->SetEnabled(false); |
| 395 layout->AddView(passphrase_textfield_); | 580 layout->AddView(passphrase_textfield_); |
| 396 // Password visible button. | 581 // Password visible button. |
| 397 passphrase_visible_button_ = new views::ImageButton(this); | 582 passphrase_visible_button_ = new views::ImageButton(this); |
| 398 passphrase_visible_button_->SetImage( | 583 passphrase_visible_button_->SetImage( |
| 399 views::ImageButton::BS_NORMAL, | 584 views::ImageButton::BS_NORMAL, |
| 400 ResourceBundle::GetSharedInstance(). | 585 ResourceBundle::GetSharedInstance(). |
| 401 GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); | 586 GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); |
| 402 passphrase_visible_button_->SetImageAlignment( | 587 passphrase_visible_button_->SetImageAlignment( |
| 403 views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE); | 588 views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE); |
| 404 layout->AddView(passphrase_visible_button_); | 589 layout->AddView(passphrase_visible_button_); |
| 405 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 590 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 406 | 591 |
| 407 // Create an error label. | 592 // Create an error label. |
| 408 layout->StartRow(0, column_view_set_id); | 593 layout->StartRow(0, column_view_set_id); |
| 409 layout->SkipColumns(1); | 594 layout->SkipColumns(1); |
| 410 error_label_ = new views::Label(); | 595 error_label_ = new views::Label(); |
| 411 error_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 596 error_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 412 error_label_->SetColor(SK_ColorRED); | 597 error_label_->SetColor(SK_ColorRED); |
| 413 layout->AddView(error_label_); | 598 layout->AddView(error_label_); |
| 414 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 599 |
| 415 // Set or hide the error text. | 600 // Set or hide the error text. |
| 416 UpdateErrorLabel(false); | 601 UpdateErrorLabel(false); |
| 417 } | 602 } |
| 418 | 603 |
| 419 } // namespace chromeos | 604 } // namespace chromeos |
| OLD | NEW |