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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/options/wifi_config_view.h"
7 #include "ash/system/chromeos/network/network_connect.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/chromeos/enrollment_dialog_view.h"
12 #include "chrome/browser/chromeos/net/onc_utils.h"
13 #include "chrome/browser/chromeos/options/passphrase_textfield.h"
14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chromeos/login/login_state.h"
16 #include "chromeos/network/network_configuration_handler.h"
17 #include "chromeos/network/network_event_log.h"
18 #include "chromeos/network/network_handler.h"
19 #include "chromeos/network/network_state.h"
20 #include "chromeos/network/network_state_handler.h"
21 #include "chromeos/network/network_ui_data.h"
22 #include "chromeos/network/shill_property_util.h"
23 #include "components/onc/onc_constants.h"
24 #include "grit/chromium_strings.h"
25 #include "grit/generated_resources.h"
26 #include "grit/locale_settings.h"
27 #include "grit/theme_resources.h"
28 #include "third_party/cros_system_api/dbus/service_constants.h"
29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/events/event.h"
32 #include "ui/views/controls/button/checkbox.h"
33 #include "ui/views/controls/button/image_button.h"
34 #include "ui/views/controls/combobox/combobox.h"
35 #include "ui/views/controls/label.h"
36 #include "ui/views/controls/textfield/textfield.h"
37 #include "ui/views/layout/grid_layout.h"
38 #include "ui/views/layout/layout_constants.h"
39 #include "ui/views/widget/widget.h"
40 #include "ui/views/window/dialog_client_view.h"
46 // Combobox that supports a preferred width. Used by Server CA combobox
47 // because the strings inside it are too wide.
48 class ComboboxWithWidth
: public views::Combobox
{
50 ComboboxWithWidth(ui::ComboboxModel
* model
, int width
)
54 virtual ~ComboboxWithWidth() {}
55 virtual gfx::Size
GetPreferredSize() OVERRIDE
{
56 gfx::Size size
= Combobox::GetPreferredSize();
57 size
.set_width(width_
);
62 DISALLOW_COPY_AND_ASSIGN(ComboboxWithWidth
);
65 enum SecurityComboboxIndex
{
66 SECURITY_INDEX_NONE
= 0,
67 SECURITY_INDEX_WEP
= 1,
68 SECURITY_INDEX_PSK
= 2,
69 SECURITY_INDEX_COUNT
= 3
72 // Methods in alphabetical order.
73 enum EAPMethodComboboxIndex
{
74 EAP_METHOD_INDEX_NONE
= 0,
75 EAP_METHOD_INDEX_LEAP
= 1,
76 EAP_METHOD_INDEX_PEAP
= 2,
77 EAP_METHOD_INDEX_TLS
= 3,
78 EAP_METHOD_INDEX_TTLS
= 4,
79 EAP_METHOD_INDEX_COUNT
= 5
82 enum Phase2AuthComboboxIndex
{
83 PHASE_2_AUTH_INDEX_AUTO
= 0, // LEAP, EAP-TLS have only this auth.
84 PHASE_2_AUTH_INDEX_MD5
= 1,
85 PHASE_2_AUTH_INDEX_MSCHAPV2
= 2, // PEAP has up to this auth.
86 PHASE_2_AUTH_INDEX_MSCHAP
= 3,
87 PHASE_2_AUTH_INDEX_PAP
= 4,
88 PHASE_2_AUTH_INDEX_CHAP
= 5, // EAP-TTLS has up to this auth.
89 PHASE_2_AUTH_INDEX_COUNT
= 6
92 void ShillError(const std::string
& function
,
93 const std::string
& error_name
,
94 scoped_ptr
<base::DictionaryValue
> error_data
) {
95 NET_LOG_ERROR("Shill Error from WifiConfigView: " + error_name
, function
);
102 class SecurityComboboxModel
: public ui::ComboboxModel
{
104 SecurityComboboxModel();
105 virtual ~SecurityComboboxModel();
107 // Overridden from ui::ComboboxModel:
108 virtual int GetItemCount() const OVERRIDE
;
109 virtual base::string16
GetItemAt(int index
) OVERRIDE
;
112 DISALLOW_COPY_AND_ASSIGN(SecurityComboboxModel
);
115 class EAPMethodComboboxModel
: public ui::ComboboxModel
{
117 EAPMethodComboboxModel();
118 virtual ~EAPMethodComboboxModel();
120 // Overridden from ui::ComboboxModel:
121 virtual int GetItemCount() const OVERRIDE
;
122 virtual base::string16
GetItemAt(int index
) OVERRIDE
;
125 DISALLOW_COPY_AND_ASSIGN(EAPMethodComboboxModel
);
128 class Phase2AuthComboboxModel
: public ui::ComboboxModel
{
130 explicit Phase2AuthComboboxModel(views::Combobox
* eap_method_combobox
);
131 virtual ~Phase2AuthComboboxModel();
133 // Overridden from ui::ComboboxModel:
134 virtual int GetItemCount() const OVERRIDE
;
135 virtual base::string16
GetItemAt(int index
) OVERRIDE
;
138 views::Combobox
* eap_method_combobox_
;
140 DISALLOW_COPY_AND_ASSIGN(Phase2AuthComboboxModel
);
143 class ServerCACertComboboxModel
: public ui::ComboboxModel
{
145 ServerCACertComboboxModel();
146 virtual ~ServerCACertComboboxModel();
148 // Overridden from ui::ComboboxModel:
149 virtual int GetItemCount() const OVERRIDE
;
150 virtual base::string16
GetItemAt(int index
) OVERRIDE
;
153 DISALLOW_COPY_AND_ASSIGN(ServerCACertComboboxModel
);
156 class UserCertComboboxModel
: public ui::ComboboxModel
{
158 explicit UserCertComboboxModel(WifiConfigView
* owner
);
159 virtual ~UserCertComboboxModel();
161 // Overridden from ui::ComboboxModel:
162 virtual int GetItemCount() const OVERRIDE
;
163 virtual base::string16
GetItemAt(int index
) OVERRIDE
;
166 WifiConfigView
* owner_
;
168 DISALLOW_COPY_AND_ASSIGN(UserCertComboboxModel
);
171 // SecurityComboboxModel -------------------------------------------------------
173 SecurityComboboxModel::SecurityComboboxModel() {
176 SecurityComboboxModel::~SecurityComboboxModel() {
179 int SecurityComboboxModel::GetItemCount() const {
180 return SECURITY_INDEX_COUNT
;
182 base::string16
SecurityComboboxModel::GetItemAt(int index
) {
183 if (index
== SECURITY_INDEX_NONE
)
184 return l10n_util::GetStringUTF16(
185 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_NONE
);
186 else if (index
== SECURITY_INDEX_WEP
)
187 return l10n_util::GetStringUTF16(
188 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_WEP
);
189 else if (index
== SECURITY_INDEX_PSK
)
190 return l10n_util::GetStringUTF16(
191 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_PSK
);
193 return base::string16();
196 // EAPMethodComboboxModel ------------------------------------------------------
198 EAPMethodComboboxModel::EAPMethodComboboxModel() {
201 EAPMethodComboboxModel::~EAPMethodComboboxModel() {
204 int EAPMethodComboboxModel::GetItemCount() const {
205 return EAP_METHOD_INDEX_COUNT
;
207 base::string16
EAPMethodComboboxModel::GetItemAt(int index
) {
208 if (index
== EAP_METHOD_INDEX_NONE
)
209 return l10n_util::GetStringUTF16(
210 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD_NONE
);
211 else if (index
== EAP_METHOD_INDEX_LEAP
)
212 return l10n_util::GetStringUTF16(
213 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD_LEAP
);
214 else if (index
== EAP_METHOD_INDEX_PEAP
)
215 return l10n_util::GetStringUTF16(
216 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD_PEAP
);
217 else if (index
== EAP_METHOD_INDEX_TLS
)
218 return l10n_util::GetStringUTF16(
219 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD_TLS
);
220 else if (index
== EAP_METHOD_INDEX_TTLS
)
221 return l10n_util::GetStringUTF16(
222 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD_TTLS
);
224 return base::string16();
227 // Phase2AuthComboboxModel -----------------------------------------------------
229 Phase2AuthComboboxModel::Phase2AuthComboboxModel(
230 views::Combobox
* eap_method_combobox
)
231 : eap_method_combobox_(eap_method_combobox
) {
234 Phase2AuthComboboxModel::~Phase2AuthComboboxModel() {
237 int Phase2AuthComboboxModel::GetItemCount() const {
238 switch (eap_method_combobox_
->selected_index()) {
239 case EAP_METHOD_INDEX_NONE
:
240 case EAP_METHOD_INDEX_TLS
:
241 case EAP_METHOD_INDEX_LEAP
:
242 return PHASE_2_AUTH_INDEX_AUTO
+ 1;
243 case EAP_METHOD_INDEX_PEAP
:
244 return PHASE_2_AUTH_INDEX_MSCHAPV2
+ 1;
245 case EAP_METHOD_INDEX_TTLS
:
246 return PHASE_2_AUTH_INDEX_CHAP
+ 1;
252 base::string16
Phase2AuthComboboxModel::GetItemAt(int index
) {
253 if (index
== PHASE_2_AUTH_INDEX_AUTO
)
254 return l10n_util::GetStringUTF16(
255 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_AUTO
);
256 else if (index
== PHASE_2_AUTH_INDEX_MD5
)
257 return l10n_util::GetStringUTF16(
258 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_MD5
);
259 else if (index
== PHASE_2_AUTH_INDEX_MSCHAPV2
)
260 return l10n_util::GetStringUTF16(
261 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_MSCHAPV2
);
262 else if (index
== PHASE_2_AUTH_INDEX_MSCHAP
)
263 return l10n_util::GetStringUTF16(
264 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_MSCHAP
);
265 else if (index
== PHASE_2_AUTH_INDEX_PAP
)
266 return l10n_util::GetStringUTF16(
267 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_PAP
);
268 else if (index
== PHASE_2_AUTH_INDEX_CHAP
)
269 return l10n_util::GetStringUTF16(
270 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH_CHAP
);
272 return base::string16();
275 // ServerCACertComboboxModel ---------------------------------------------------
277 ServerCACertComboboxModel::ServerCACertComboboxModel() {
280 ServerCACertComboboxModel::~ServerCACertComboboxModel() {
283 int ServerCACertComboboxModel::GetItemCount() const {
284 if (CertLibrary::Get()->CertificatesLoading())
285 return 1; // "Loading"
286 // First "Default", then the certs, then "Do not check".
287 return CertLibrary::Get()->NumCertificates(
288 CertLibrary::CERT_TYPE_SERVER_CA
) + 2;
291 base::string16
ServerCACertComboboxModel::GetItemAt(int index
) {
292 if (CertLibrary::Get()->CertificatesLoading())
293 return l10n_util::GetStringUTF16(
294 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING
);
296 return l10n_util::GetStringUTF16(
297 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA_DEFAULT
);
298 if (index
== GetItemCount() - 1)
299 return l10n_util::GetStringUTF16(
300 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA_DO_NOT_CHECK
);
301 int cert_index
= index
- 1;
302 return CertLibrary::Get()->GetCertDisplayStringAt(
303 CertLibrary::CERT_TYPE_SERVER_CA
, cert_index
);
306 // UserCertComboboxModel -------------------------------------------------------
308 UserCertComboboxModel::UserCertComboboxModel(WifiConfigView
* owner
)
312 UserCertComboboxModel::~UserCertComboboxModel() {
315 int UserCertComboboxModel::GetItemCount() const {
316 if (!owner_
->UserCertActive())
318 if (CertLibrary::Get()->CertificatesLoading())
319 return 1; // "Loading"
321 CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER
);
323 return 1; // "None installed"
327 base::string16
UserCertComboboxModel::GetItemAt(int index
) {
328 if (!owner_
->UserCertActive())
329 return base::string16();
330 if (CertLibrary::Get()->CertificatesLoading())
331 return l10n_util::GetStringUTF16(
332 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING
);
333 if (CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER
) == 0)
334 return l10n_util::GetStringUTF16(
335 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED
);
336 return CertLibrary::Get()->GetCertDisplayStringAt(
337 CertLibrary::CERT_TYPE_USER
, index
);
340 } // namespace internal
342 WifiConfigView::WifiConfigView(NetworkConfigView
* parent
,
343 const std::string
& service_path
,
345 : ChildNetworkConfigView(parent
, service_path
),
346 ssid_textfield_(NULL
),
347 eap_method_combobox_(NULL
),
348 phase_2_auth_label_(NULL
),
349 phase_2_auth_combobox_(NULL
),
350 user_cert_label_(NULL
),
351 user_cert_combobox_(NULL
),
352 server_ca_cert_label_(NULL
),
353 server_ca_cert_combobox_(NULL
),
354 subject_match_label_(NULL
),
355 subject_match_textfield_(NULL
),
356 identity_label_(NULL
),
357 identity_textfield_(NULL
),
358 identity_anonymous_label_(NULL
),
359 identity_anonymous_textfield_(NULL
),
360 save_credentials_checkbox_(NULL
),
361 share_network_checkbox_(NULL
),
362 shared_network_label_(NULL
),
363 security_combobox_(NULL
),
364 passphrase_label_(NULL
),
365 passphrase_textfield_(NULL
),
366 passphrase_visible_button_(NULL
),
368 weak_ptr_factory_(this) {
370 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE
);
373 WifiConfigView::~WifiConfigView() {
374 RemoveAllChildViews(true); // Destroy children before models
375 if (NetworkHandler::IsInitialized()) {
376 NetworkHandler::Get()->network_state_handler()->RemoveObserver(
379 CertLibrary::Get()->RemoveObserver(this);
382 base::string16
WifiConfigView::GetTitle() const {
383 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_JOIN_WIFI_NETWORKS
);
386 views::View
* WifiConfigView::GetInitiallyFocusedView() {
387 // Return a reasonable widget for initial focus,
388 // depending on what we're showing.
390 return ssid_textfield_
;
391 else if (eap_method_combobox_
)
392 return eap_method_combobox_
;
393 else if (passphrase_textfield_
&& passphrase_textfield_
->enabled())
394 return passphrase_textfield_
;
399 bool WifiConfigView::CanLogin() {
400 static const size_t kMinWirelessPasswordLen
= 5;
402 // We either have an existing wifi network or the user entered an SSID.
403 if (service_path_
.empty() && GetSsid().empty())
406 // If the network requires a passphrase, make sure it is the right length.
407 if (passphrase_textfield_
!= NULL
&&
408 passphrase_textfield_
->enabled() &&
409 !passphrase_textfield_
->show_fake() &&
410 passphrase_textfield_
->text().length() < kMinWirelessPasswordLen
)
413 // If we're using EAP, we must have a method.
414 if (eap_method_combobox_
&&
415 eap_method_combobox_
->selected_index() == EAP_METHOD_INDEX_NONE
)
418 // Block login if certs are required but user has none.
419 if (UserCertRequired() && (!HaveUserCerts() || !IsUserCertValid()))
425 bool WifiConfigView::UserCertRequired() const {
426 return UserCertActive();
429 bool WifiConfigView::HaveUserCerts() const {
430 return CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER
) > 0;
433 bool WifiConfigView::IsUserCertValid() const {
434 if (!UserCertActive())
436 int index
= user_cert_combobox_
->selected_index();
439 // Currently only hardware-backed user certificates are valid.
440 if (CertLibrary::Get()->IsHardwareBacked() &&
441 !CertLibrary::Get()->IsCertHardwareBackedAt(
442 CertLibrary::CERT_TYPE_USER
, index
))
447 bool WifiConfigView::Phase2AuthActive() const {
448 if (phase_2_auth_combobox_
)
449 return phase_2_auth_combobox_
->model()->GetItemCount() > 1;
453 bool WifiConfigView::PassphraseActive() const {
454 if (eap_method_combobox_
) {
455 // No password for EAP-TLS.
456 int index
= eap_method_combobox_
->selected_index();
457 return index
!= EAP_METHOD_INDEX_NONE
&& index
!= EAP_METHOD_INDEX_TLS
;
458 } else if (security_combobox_
) {
459 return security_combobox_
->selected_index() != SECURITY_INDEX_NONE
;
464 bool WifiConfigView::UserCertActive() const {
465 // User certs only for EAP-TLS.
466 if (eap_method_combobox_
)
467 return eap_method_combobox_
->selected_index() == EAP_METHOD_INDEX_TLS
;
472 bool WifiConfigView::CaCertActive() const {
473 // No server CA certs for LEAP.
474 if (eap_method_combobox_
) {
475 int index
= eap_method_combobox_
->selected_index();
476 return index
!= EAP_METHOD_INDEX_NONE
&& index
!= EAP_METHOD_INDEX_LEAP
;
481 void WifiConfigView::UpdateDialogButtons() {
482 parent_
->GetDialogClientView()->UpdateDialogButtons();
485 void WifiConfigView::RefreshEapFields() {
486 // If EAP method changes, the phase 2 auth choices may have changed also.
487 phase_2_auth_combobox_
->ModelChanged();
488 phase_2_auth_combobox_
->SetSelectedIndex(0);
489 bool phase_2_auth_enabled
= Phase2AuthActive();
490 phase_2_auth_combobox_
->SetEnabled(phase_2_auth_enabled
&&
491 phase_2_auth_ui_data_
.IsEditable());
492 phase_2_auth_label_
->SetEnabled(phase_2_auth_enabled
);
495 bool passphrase_enabled
= PassphraseActive();
496 passphrase_textfield_
->SetEnabled(passphrase_enabled
&&
497 passphrase_ui_data_
.IsEditable());
498 passphrase_label_
->SetEnabled(passphrase_enabled
);
499 if (!passphrase_enabled
)
500 passphrase_textfield_
->SetText(base::string16());
503 bool certs_loading
= CertLibrary::Get()->CertificatesLoading();
504 bool user_cert_enabled
= UserCertActive();
505 user_cert_label_
->SetEnabled(user_cert_enabled
);
506 bool have_user_certs
= !certs_loading
&& HaveUserCerts();
507 user_cert_combobox_
->SetEnabled(user_cert_enabled
&&
509 user_cert_ui_data_
.IsEditable());
510 user_cert_combobox_
->ModelChanged();
511 user_cert_combobox_
->SetSelectedIndex(0);
514 bool ca_cert_enabled
= CaCertActive();
515 server_ca_cert_label_
->SetEnabled(ca_cert_enabled
);
516 server_ca_cert_combobox_
->SetEnabled(ca_cert_enabled
&&
518 server_ca_cert_ui_data_
.IsEditable());
519 server_ca_cert_combobox_
->ModelChanged();
520 server_ca_cert_combobox_
->SetSelectedIndex(0);
523 bool subject_match_enabled
=
524 ca_cert_enabled
&& eap_method_combobox_
&&
525 eap_method_combobox_
->selected_index() == EAP_METHOD_INDEX_TLS
;
526 subject_match_label_
->SetEnabled(subject_match_enabled
);
527 subject_match_textfield_
->SetEnabled(subject_match_enabled
);
528 if (!subject_match_enabled
)
529 subject_match_textfield_
->SetText(base::string16());
531 // No anonymous identity if no phase 2 auth.
532 bool identity_anonymous_enabled
= phase_2_auth_enabled
;
533 identity_anonymous_textfield_
->SetEnabled(
534 identity_anonymous_enabled
&& identity_anonymous_ui_data_
.IsEditable());
535 identity_anonymous_label_
->SetEnabled(identity_anonymous_enabled
);
536 if (!identity_anonymous_enabled
)
537 identity_anonymous_textfield_
->SetText(base::string16());
539 RefreshShareCheckbox();
542 void WifiConfigView::RefreshShareCheckbox() {
543 if (!share_network_checkbox_
)
546 if (security_combobox_
&&
547 security_combobox_
->selected_index() == SECURITY_INDEX_NONE
) {
548 share_network_checkbox_
->SetEnabled(false);
549 share_network_checkbox_
->SetChecked(true);
550 } else if (eap_method_combobox_
&&
551 (eap_method_combobox_
->selected_index() == EAP_METHOD_INDEX_TLS
||
552 user_cert_combobox_
->selected_index() != 0)) {
553 // Can not share TLS network (requires certificate), or any network where
554 // user certificates are enabled.
555 share_network_checkbox_
->SetEnabled(false);
556 share_network_checkbox_
->SetChecked(false);
557 } else if (!LoginState::Get()->IsUserAuthenticated()) {
558 // If not logged in as an authenticated user, networks must be shared.
559 share_network_checkbox_
->SetEnabled(false);
560 share_network_checkbox_
->SetChecked(true);
562 share_network_checkbox_
->SetEnabled(true);
563 share_network_checkbox_
->SetChecked(false); // Default to unshared.
567 void WifiConfigView::UpdateErrorLabel() {
568 base::string16 error_msg
;
569 if (UserCertRequired() && CertLibrary::Get()->CertificatesLoaded()) {
570 if (!HaveUserCerts()) {
571 if (!LoginState::Get()->IsUserAuthenticated()) {
572 error_msg
= l10n_util::GetStringUTF16(
573 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_LOGIN_FOR_USER_CERT
);
575 error_msg
= l10n_util::GetStringUTF16(
576 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PLEASE_INSTALL_USER_CERT
);
578 } else if (!IsUserCertValid()) {
579 error_msg
= l10n_util::GetStringUTF16(
580 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_REQUIRE_HARDWARE_BACKED
);
583 if (error_msg
.empty() && !service_path_
.empty()) {
584 const NetworkState
* wifi
= NetworkHandler::Get()->network_state_handler()->
585 GetNetworkState(service_path_
);
586 if (wifi
&& wifi
->connection_state() == shill::kStateFailure
)
587 error_msg
= ash::network_connect::ErrorString(
588 wifi
->error(), wifi
->path());
590 if (!error_msg
.empty()) {
591 error_label_
->SetText(error_msg
);
592 error_label_
->SetVisible(true);
594 error_label_
->SetVisible(false);
598 void WifiConfigView::ContentsChanged(views::Textfield
* sender
,
599 const base::string16
& new_contents
) {
600 UpdateDialogButtons();
603 bool WifiConfigView::HandleKeyEvent(views::Textfield
* sender
,
604 const ui::KeyEvent
& key_event
) {
605 if (sender
== passphrase_textfield_
&&
606 key_event
.key_code() == ui::VKEY_RETURN
) {
607 parent_
->GetDialogClientView()->AcceptWindow();
612 void WifiConfigView::ButtonPressed(views::Button
* sender
,
613 const ui::Event
& event
) {
614 if (sender
== passphrase_visible_button_
&& passphrase_textfield_
) {
615 if (passphrase_textfield_
->GetTextInputType() == ui::TEXT_INPUT_TYPE_TEXT
) {
616 passphrase_textfield_
->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD
);
617 passphrase_visible_button_
->SetToggled(false);
619 passphrase_textfield_
->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT
);
620 passphrase_visible_button_
->SetToggled(true);
627 void WifiConfigView::OnSelectedIndexChanged(views::Combobox
* combobox
) {
628 if (combobox
== security_combobox_
) {
629 bool passphrase_enabled
= PassphraseActive();
630 passphrase_label_
->SetEnabled(passphrase_enabled
);
631 passphrase_textfield_
->SetEnabled(passphrase_enabled
&&
632 passphrase_ui_data_
.IsEditable());
633 if (!passphrase_enabled
)
634 passphrase_textfield_
->SetText(base::string16());
635 RefreshShareCheckbox();
636 } else if (combobox
== user_cert_combobox_
) {
637 RefreshShareCheckbox();
638 } else if (combobox
== eap_method_combobox_
) {
641 UpdateDialogButtons();
645 void WifiConfigView::OnCertificatesLoaded(bool initial_load
) {
647 UpdateDialogButtons();
651 bool WifiConfigView::Login() {
652 const NetworkState
* wifi
= !service_path_
.empty() ?
653 NetworkHandler::Get()->network_state_handler()->
654 GetNetworkState(service_path_
) :
657 // Set configuration properties.
658 base::DictionaryValue properties
;
660 // Default shared state for non-private networks is true.
661 const bool share_default
= !wifi
|| !wifi
->IsPrivate();
662 bool share_network
= GetShareNetwork(share_default
);
663 bool only_policy_autoconnect
=
664 onc::PolicyAllowsOnlyPolicyNetworksToAutoconnect(!share_network
);
665 if (only_policy_autoconnect
) {
666 properties
.SetBooleanWithoutPathExpansion(shill::kAutoConnectProperty
,
670 if (service_path_
.empty()) {
671 properties
.SetStringWithoutPathExpansion(
672 shill::kTypeProperty
, shill::kTypeWifi
);
673 shill_property_util::SetSSID(GetSsid(), &properties
);
674 properties
.SetStringWithoutPathExpansion(
675 shill::kModeProperty
, shill::kModeManaged
);
676 properties
.SetBooleanWithoutPathExpansion(
677 shill::kSaveCredentialsProperty
, GetSaveCredentials());
678 std::string security
= shill::kSecurityNone
;
679 if (!eap_method_combobox_
) {
680 // Hidden ordinary Wi-Fi connection.
681 switch (security_combobox_
->selected_index()) {
682 case SECURITY_INDEX_NONE
:
683 security
= shill::kSecurityNone
;
685 case SECURITY_INDEX_WEP
:
686 security
= shill::kSecurityWep
;
688 case SECURITY_INDEX_PSK
:
689 security
= shill::kSecurityPsk
;
692 std::string passphrase
= GetPassphrase();
693 if (!passphrase
.empty()) {
694 properties
.SetStringWithoutPathExpansion(
695 shill::kPassphraseProperty
, GetPassphrase());
698 // Hidden 802.1X EAP Wi-Fi connection.
699 security
= shill::kSecurity8021x
;
700 SetEapProperties(&properties
);
702 properties
.SetStringWithoutPathExpansion(
703 shill::kSecurityProperty
, security
);
705 // Configure and connect to network.
706 ash::network_connect::CreateConfigurationAndConnect(&properties
,
710 // Shill no longer knows about this wifi network (edge case).
711 // TODO(stevenjb): Add notification for this.
712 NET_LOG_ERROR("Network not found", service_path_
);
713 return true; // Close dialog
715 if (eap_method_combobox_
) {
716 // Visible 802.1X EAP Wi-Fi connection.
717 SetEapProperties(&properties
);
718 properties
.SetBooleanWithoutPathExpansion(
719 shill::kSaveCredentialsProperty
, GetSaveCredentials());
721 // Visible ordinary Wi-Fi connection.
722 const std::string passphrase
= GetPassphrase();
723 if (!passphrase
.empty()) {
724 properties
.SetStringWithoutPathExpansion(
725 shill::kPassphraseProperty
, passphrase
);
728 ash::network_connect::ConfigureNetworkAndConnect(
729 service_path_
, properties
, share_network
);
731 return true; // dialog will be closed
734 std::string
WifiConfigView::GetSsid() const {
736 if (ssid_textfield_
!= NULL
) {
737 std::string untrimmed
= base::UTF16ToUTF8(ssid_textfield_
->text());
738 TrimWhitespaceASCII(untrimmed
, TRIM_ALL
, &result
);
743 std::string
WifiConfigView::GetPassphrase() const {
745 if (passphrase_textfield_
!= NULL
)
746 result
= base::UTF16ToUTF8(passphrase_textfield_
->text());
750 bool WifiConfigView::GetSaveCredentials() const {
751 if (!save_credentials_checkbox_
)
752 return true; // share networks by default (e.g. non 8021x).
753 return save_credentials_checkbox_
->checked();
756 bool WifiConfigView::GetShareNetwork(bool share_default
) const {
757 if (!share_network_checkbox_
)
758 return share_default
;
759 return share_network_checkbox_
->checked();
762 std::string
WifiConfigView::GetEapMethod() const {
763 DCHECK(eap_method_combobox_
);
764 switch (eap_method_combobox_
->selected_index()) {
765 case EAP_METHOD_INDEX_PEAP
:
766 return shill::kEapMethodPEAP
;
767 case EAP_METHOD_INDEX_TLS
:
768 return shill::kEapMethodTLS
;
769 case EAP_METHOD_INDEX_TTLS
:
770 return shill::kEapMethodTTLS
;
771 case EAP_METHOD_INDEX_LEAP
:
772 return shill::kEapMethodLEAP
;
773 case EAP_METHOD_INDEX_NONE
:
779 std::string
WifiConfigView::GetEapPhase2Auth() const {
780 DCHECK(phase_2_auth_combobox_
);
781 bool is_peap
= (GetEapMethod() == shill::kEapMethodPEAP
);
782 switch (phase_2_auth_combobox_
->selected_index()) {
783 case PHASE_2_AUTH_INDEX_MD5
:
784 return is_peap
? shill::kEapPhase2AuthPEAPMD5
785 : shill::kEapPhase2AuthTTLSMD5
;
786 case PHASE_2_AUTH_INDEX_MSCHAPV2
:
787 return is_peap
? shill::kEapPhase2AuthPEAPMSCHAPV2
788 : shill::kEapPhase2AuthTTLSMSCHAPV2
;
789 case PHASE_2_AUTH_INDEX_MSCHAP
:
790 return shill::kEapPhase2AuthTTLSMSCHAP
;
791 case PHASE_2_AUTH_INDEX_PAP
:
792 return shill::kEapPhase2AuthTTLSPAP
;
793 case PHASE_2_AUTH_INDEX_CHAP
:
794 return shill::kEapPhase2AuthTTLSCHAP
;
795 case PHASE_2_AUTH_INDEX_AUTO
:
801 std::string
WifiConfigView::GetEapServerCaCertPEM() const {
802 DCHECK(server_ca_cert_combobox_
);
803 int index
= server_ca_cert_combobox_
->selected_index();
805 // First item is "Default".
806 return std::string();
807 } else if (index
== server_ca_cert_combobox_
->model()->GetItemCount() - 1) {
808 // Last item is "Do not check".
809 return std::string();
811 int cert_index
= index
- 1;
812 return CertLibrary::Get()->GetCertPEMAt(
813 CertLibrary::CERT_TYPE_SERVER_CA
, cert_index
);
817 bool WifiConfigView::GetEapUseSystemCas() const {
818 DCHECK(server_ca_cert_combobox_
);
819 // Only use system CAs if the first item ("Default") is selected.
820 return server_ca_cert_combobox_
->selected_index() == 0;
823 std::string
WifiConfigView::GetEapSubjectMatch() const {
824 DCHECK(subject_match_textfield_
);
825 return base::UTF16ToUTF8(subject_match_textfield_
->text());
828 std::string
WifiConfigView::GetEapClientCertPkcs11Id() const {
829 DCHECK(user_cert_combobox_
);
830 if (!HaveUserCerts() || !UserCertActive()) {
831 return std::string(); // No certificate selected or not required.
833 // Certificates are listed in the order they appear in the model.
834 int index
= user_cert_combobox_
->selected_index();
835 return CertLibrary::Get()->GetCertPkcs11IdAt(
836 CertLibrary::CERT_TYPE_USER
, index
);
840 std::string
WifiConfigView::GetEapIdentity() const {
841 DCHECK(identity_textfield_
);
842 return base::UTF16ToUTF8(identity_textfield_
->text());
845 std::string
WifiConfigView::GetEapAnonymousIdentity() const {
846 DCHECK(identity_anonymous_textfield_
);
847 return base::UTF16ToUTF8(identity_anonymous_textfield_
->text());
850 void WifiConfigView::SetEapProperties(base::DictionaryValue
* properties
) {
851 properties
->SetStringWithoutPathExpansion(
852 shill::kEapIdentityProperty
, GetEapIdentity());
853 properties
->SetStringWithoutPathExpansion(
854 shill::kEapMethodProperty
, GetEapMethod());
855 properties
->SetStringWithoutPathExpansion(
856 shill::kEapPhase2AuthProperty
, GetEapPhase2Auth());
857 properties
->SetStringWithoutPathExpansion(
858 shill::kEapAnonymousIdentityProperty
, GetEapAnonymousIdentity());
859 properties
->SetStringWithoutPathExpansion(
860 shill::kEapSubjectMatchProperty
, GetEapSubjectMatch());
862 // shill requires both CertID and KeyID for TLS connections, despite
863 // the fact that by convention they are the same ID.
864 properties
->SetStringWithoutPathExpansion(
865 shill::kEapCertIdProperty
, GetEapClientCertPkcs11Id());
866 properties
->SetStringWithoutPathExpansion(
867 shill::kEapKeyIdProperty
, GetEapClientCertPkcs11Id());
869 properties
->SetBooleanWithoutPathExpansion(
870 shill::kEapUseSystemCasProperty
, GetEapUseSystemCas());
871 properties
->SetStringWithoutPathExpansion(
872 shill::kEapPasswordProperty
, GetPassphrase());
874 base::ListValue
* pem_list
= new base::ListValue
;
875 pem_list
->AppendString(GetEapServerCaCertPEM());
876 properties
->SetWithoutPathExpansion(
877 shill::kEapCaCertPemProperty
, pem_list
);
880 void WifiConfigView::Cancel() {
883 // This will initialize the view depending on if we have a wifi network or not.
884 // And if we are doing simple password encryption or the more complicated
885 // 802.1x encryption.
886 // If we are creating the "Join other network..." dialog, we will allow user
887 // to enter the data. And if they select the 802.1x encryption, we will show
888 // the 802.1x fields.
889 void WifiConfigView::Init(bool show_8021x
) {
890 const NetworkState
* wifi
= NetworkHandler::Get()->network_state_handler()->
891 GetNetworkState(service_path_
);
893 DCHECK(wifi
->type() == shill::kTypeWifi
);
894 if (wifi
->security() == shill::kSecurity8021x
)
896 ParseWiFiEAPUIProperty(&eap_method_ui_data_
, wifi
, ::onc::eap::kOuter
);
897 ParseWiFiEAPUIProperty(&phase_2_auth_ui_data_
, wifi
, ::onc::eap::kInner
);
898 ParseWiFiEAPUIProperty(&user_cert_ui_data_
, wifi
,
899 ::onc::eap::kClientCertRef
);
900 ParseWiFiEAPUIProperty(&server_ca_cert_ui_data_
, wifi
,
901 ::onc::eap::kServerCARef
);
902 if (server_ca_cert_ui_data_
.IsManaged()) {
903 ParseWiFiEAPUIProperty(&server_ca_cert_ui_data_
, wifi
,
904 ::onc::eap::kUseSystemCAs
);
906 ParseWiFiEAPUIProperty(&identity_ui_data_
, wifi
, ::onc::eap::kIdentity
);
907 ParseWiFiEAPUIProperty(&identity_anonymous_ui_data_
, wifi
,
908 ::onc::eap::kAnonymousIdentity
);
909 ParseWiFiEAPUIProperty(&save_credentials_ui_data_
, wifi
,
910 ::onc::eap::kSaveCredentials
);
912 ParseWiFiEAPUIProperty(&passphrase_ui_data_
, wifi
, ::onc::eap::kPassword
);
914 ParseWiFiUIProperty(&passphrase_ui_data_
, wifi
, ::onc::wifi::kPassphrase
);
917 views::GridLayout
* layout
= views::GridLayout::CreatePanel(this);
918 SetLayoutManager(layout
);
920 const int column_view_set_id
= 0;
921 views::ColumnSet
* column_set
= layout
->AddColumnSet(column_view_set_id
);
922 const int kPasswordVisibleWidth
= 20;
924 column_set
->AddColumn(views::GridLayout::LEADING
, views::GridLayout::FILL
, 1,
925 views::GridLayout::USE_PREF
, 0, 0);
926 column_set
->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing
);
927 // Textfield, combobox.
928 column_set
->AddColumn(views::GridLayout::FILL
, views::GridLayout::FILL
, 1,
929 views::GridLayout::USE_PREF
, 0,
930 ChildNetworkConfigView::kInputFieldMinWidth
);
931 column_set
->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing
);
932 // Password visible button / policy indicator.
933 column_set
->AddColumn(views::GridLayout::CENTER
, views::GridLayout::FILL
, 1,
934 views::GridLayout::USE_PREF
, 0, kPasswordVisibleWidth
);
937 layout
->StartRow(0, column_view_set_id
);
938 layout
->AddView(new views::Label(l10n_util::GetStringUTF16(
939 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID
)));
941 ssid_textfield_
= new views::Textfield();
942 ssid_textfield_
->set_controller(this);
943 ssid_textfield_
->SetAccessibleName(l10n_util::GetStringUTF16(
944 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID
));
945 layout
->AddView(ssid_textfield_
);
947 views::Label
* label
= new views::Label(base::UTF8ToUTF16(wifi
->name()));
948 label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
949 layout
->AddView(label
);
951 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
954 if (!wifi
&& !show_8021x
) {
955 layout
->StartRow(0, column_view_set_id
);
956 base::string16 label_text
= l10n_util::GetStringUTF16(
957 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY
);
958 layout
->AddView(new views::Label(label_text
));
959 security_combobox_model_
.reset(new internal::SecurityComboboxModel
);
960 security_combobox_
= new views::Combobox(security_combobox_model_
.get());
961 security_combobox_
->SetAccessibleName(label_text
);
962 security_combobox_
->set_listener(this);
963 layout
->AddView(security_combobox_
);
964 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
967 // Only enumerate certificates in the data model for 802.1X networks.
969 // Observer any changes to the certificate list.
970 CertLibrary::Get()->AddObserver(this);
973 layout
->StartRow(0, column_view_set_id
);
974 base::string16 eap_label_text
= l10n_util::GetStringUTF16(
975 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD
);
976 layout
->AddView(new views::Label(eap_label_text
));
977 eap_method_combobox_model_
.reset(new internal::EAPMethodComboboxModel
);
978 eap_method_combobox_
= new views::Combobox(
979 eap_method_combobox_model_
.get());
980 eap_method_combobox_
->SetAccessibleName(eap_label_text
);
981 eap_method_combobox_
->set_listener(this);
982 eap_method_combobox_
->SetEnabled(eap_method_ui_data_
.IsEditable());
983 layout
->AddView(eap_method_combobox_
);
984 layout
->AddView(new ControlledSettingIndicatorView(eap_method_ui_data_
));
985 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
987 // Phase 2 authentication
988 layout
->StartRow(0, column_view_set_id
);
989 base::string16 phase_2_label_text
= l10n_util::GetStringUTF16(
990 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH
);
991 phase_2_auth_label_
= new views::Label(phase_2_label_text
);
992 layout
->AddView(phase_2_auth_label_
);
993 phase_2_auth_combobox_model_
.reset(
994 new internal::Phase2AuthComboboxModel(eap_method_combobox_
));
995 phase_2_auth_combobox_
= new views::Combobox(
996 phase_2_auth_combobox_model_
.get());
997 phase_2_auth_combobox_
->SetAccessibleName(phase_2_label_text
);
998 phase_2_auth_label_
->SetEnabled(false);
999 phase_2_auth_combobox_
->SetEnabled(false);
1000 phase_2_auth_combobox_
->set_listener(this);
1001 layout
->AddView(phase_2_auth_combobox_
);
1002 layout
->AddView(new ControlledSettingIndicatorView(phase_2_auth_ui_data_
));
1003 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1005 // Server CA certificate
1006 layout
->StartRow(0, column_view_set_id
);
1007 base::string16 server_ca_cert_label_text
= l10n_util::GetStringUTF16(
1008 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA
);
1009 server_ca_cert_label_
= new views::Label(server_ca_cert_label_text
);
1010 layout
->AddView(server_ca_cert_label_
);
1011 server_ca_cert_combobox_model_
.reset(
1012 new internal::ServerCACertComboboxModel());
1013 server_ca_cert_combobox_
= new ComboboxWithWidth(
1014 server_ca_cert_combobox_model_
.get(),
1015 ChildNetworkConfigView::kInputFieldMinWidth
);
1016 server_ca_cert_combobox_
->SetAccessibleName(server_ca_cert_label_text
);
1017 server_ca_cert_label_
->SetEnabled(false);
1018 server_ca_cert_combobox_
->SetEnabled(false);
1019 server_ca_cert_combobox_
->set_listener(this);
1020 layout
->AddView(server_ca_cert_combobox_
);
1022 new ControlledSettingIndicatorView(server_ca_cert_ui_data_
));
1023 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1026 layout
->StartRow(0, column_view_set_id
);
1027 base::string16 subject_match_label_text
= l10n_util::GetStringUTF16(
1028 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_SUBJECT_MATCH
);
1029 subject_match_label_
= new views::Label(subject_match_label_text
);
1030 layout
->AddView(subject_match_label_
);
1031 subject_match_textfield_
= new views::Textfield();
1032 subject_match_textfield_
->SetAccessibleName(subject_match_label_text
);
1033 subject_match_textfield_
->set_controller(this);
1034 layout
->AddView(subject_match_textfield_
);
1035 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1038 layout
->StartRow(0, column_view_set_id
);
1039 base::string16 user_cert_label_text
= l10n_util::GetStringUTF16(
1040 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT
);
1041 user_cert_label_
= new views::Label(user_cert_label_text
);
1042 layout
->AddView(user_cert_label_
);
1043 user_cert_combobox_model_
.reset(new internal::UserCertComboboxModel(this));
1044 user_cert_combobox_
= new views::Combobox(user_cert_combobox_model_
.get());
1045 user_cert_combobox_
->SetAccessibleName(user_cert_label_text
);
1046 user_cert_label_
->SetEnabled(false);
1047 user_cert_combobox_
->SetEnabled(false);
1048 user_cert_combobox_
->set_listener(this);
1049 layout
->AddView(user_cert_combobox_
);
1050 layout
->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_
));
1051 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1054 layout
->StartRow(0, column_view_set_id
);
1055 base::string16 identity_label_text
= l10n_util::GetStringUTF16(
1056 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY
);
1057 identity_label_
= new views::Label(identity_label_text
);
1058 layout
->AddView(identity_label_
);
1059 identity_textfield_
= new views::Textfield();
1060 identity_textfield_
->SetAccessibleName(identity_label_text
);
1061 identity_textfield_
->set_controller(this);
1062 identity_textfield_
->SetEnabled(identity_ui_data_
.IsEditable());
1063 layout
->AddView(identity_textfield_
);
1064 layout
->AddView(new ControlledSettingIndicatorView(identity_ui_data_
));
1065 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1069 layout
->StartRow(0, column_view_set_id
);
1070 int label_text_id
= IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE
;
1071 base::string16 passphrase_label_text
=
1072 l10n_util::GetStringUTF16(label_text_id
);
1073 passphrase_label_
= new views::Label(passphrase_label_text
);
1074 layout
->AddView(passphrase_label_
);
1075 passphrase_textfield_
= new PassphraseTextfield();
1076 passphrase_textfield_
->set_controller(this);
1077 // Disable passphrase input initially for other network.
1078 passphrase_label_
->SetEnabled(wifi
);
1079 passphrase_textfield_
->SetEnabled(wifi
&& passphrase_ui_data_
.IsEditable());
1080 passphrase_textfield_
->SetAccessibleName(passphrase_label_text
);
1081 layout
->AddView(passphrase_textfield_
);
1083 if (passphrase_ui_data_
.IsManaged()) {
1084 layout
->AddView(new ControlledSettingIndicatorView(passphrase_ui_data_
));
1086 // Password visible button.
1087 passphrase_visible_button_
= new views::ToggleImageButton(this);
1088 passphrase_visible_button_
->SetFocusable(true);
1089 passphrase_visible_button_
->SetTooltipText(
1090 l10n_util::GetStringUTF16(
1091 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE_SHOW
));
1092 passphrase_visible_button_
->SetToggledTooltipText(
1093 l10n_util::GetStringUTF16(
1094 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE_HIDE
));
1095 passphrase_visible_button_
->SetImage(
1096 views::ImageButton::STATE_NORMAL
,
1097 ResourceBundle::GetSharedInstance().
1098 GetImageSkiaNamed(IDR_NETWORK_SHOW_PASSWORD
));
1099 passphrase_visible_button_
->SetImage(
1100 views::ImageButton::STATE_HOVERED
,
1101 ResourceBundle::GetSharedInstance().
1102 GetImageSkiaNamed(IDR_NETWORK_SHOW_PASSWORD_HOVER
));
1103 passphrase_visible_button_
->SetToggledImage(
1104 views::ImageButton::STATE_NORMAL
,
1105 ResourceBundle::GetSharedInstance().
1106 GetImageSkiaNamed(IDR_NETWORK_HIDE_PASSWORD
));
1107 passphrase_visible_button_
->SetToggledImage(
1108 views::ImageButton::STATE_HOVERED
,
1109 ResourceBundle::GetSharedInstance().
1110 GetImageSkiaNamed(IDR_NETWORK_HIDE_PASSWORD_HOVER
));
1111 passphrase_visible_button_
->SetImageAlignment(
1112 views::ImageButton::ALIGN_CENTER
, views::ImageButton::ALIGN_MIDDLE
);
1113 layout
->AddView(passphrase_visible_button_
);
1116 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1119 // Anonymous identity
1120 layout
->StartRow(0, column_view_set_id
);
1121 identity_anonymous_label_
=
1122 new views::Label(l10n_util::GetStringUTF16(
1123 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY_ANONYMOUS
));
1124 layout
->AddView(identity_anonymous_label_
);
1125 identity_anonymous_textfield_
= new views::Textfield();
1126 identity_anonymous_label_
->SetEnabled(false);
1127 identity_anonymous_textfield_
->SetEnabled(false);
1128 identity_anonymous_textfield_
->set_controller(this);
1129 layout
->AddView(identity_anonymous_textfield_
);
1131 new ControlledSettingIndicatorView(identity_anonymous_ui_data_
));
1132 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1139 layout
->StartRow(0, column_view_set_id
);
1140 save_credentials_checkbox_
= new views::Checkbox(
1141 l10n_util::GetStringUTF16(
1142 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS
));
1143 save_credentials_checkbox_
->SetEnabled(
1144 save_credentials_ui_data_
.IsEditable());
1145 layout
->SkipColumns(1);
1146 layout
->AddView(save_credentials_checkbox_
);
1148 new ControlledSettingIndicatorView(save_credentials_ui_data_
));
1152 if (!wifi
|| wifi
->profile_path().empty()) {
1153 layout
->StartRow(0, column_view_set_id
);
1154 share_network_checkbox_
= new views::Checkbox(
1155 l10n_util::GetStringUTF16(
1156 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHARE_NETWORK
));
1157 layout
->SkipColumns(1);
1158 layout
->AddView(share_network_checkbox_
);
1160 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1162 // Create an error label.
1163 layout
->StartRow(0, column_view_set_id
);
1164 layout
->SkipColumns(1);
1165 error_label_
= new views::Label();
1166 error_label_
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
1167 error_label_
->SetEnabledColor(SK_ColorRED
);
1168 layout
->AddView(error_label_
);
1170 // Initialize the field and checkbox values.
1172 if (!wifi
&& show_8021x
)
1175 RefreshShareCheckbox();
1179 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
1181 base::Bind(&WifiConfigView::InitFromProperties
,
1182 weak_ptr_factory_
.GetWeakPtr(), show_8021x
),
1183 base::Bind(&ShillError
, "GetProperties"));
1187 void WifiConfigView::InitFromProperties(
1189 const std::string
& service_path
,
1190 const base::DictionaryValue
& properties
) {
1192 std::string passphrase
;
1193 properties
.GetStringWithoutPathExpansion(
1194 shill::kPassphraseProperty
, &passphrase
);
1195 passphrase_textfield_
->SetText(base::UTF8ToUTF16(passphrase
));
1200 std::string eap_method
;
1201 properties
.GetStringWithoutPathExpansion(
1202 shill::kEapMethodProperty
, &eap_method
);
1203 if (eap_method
== shill::kEapMethodPEAP
)
1204 eap_method_combobox_
->SetSelectedIndex(EAP_METHOD_INDEX_PEAP
);
1205 else if (eap_method
== shill::kEapMethodTTLS
)
1206 eap_method_combobox_
->SetSelectedIndex(EAP_METHOD_INDEX_TTLS
);
1207 else if (eap_method
== shill::kEapMethodTLS
)
1208 eap_method_combobox_
->SetSelectedIndex(EAP_METHOD_INDEX_TLS
);
1209 else if (eap_method
== shill::kEapMethodLEAP
)
1210 eap_method_combobox_
->SetSelectedIndex(EAP_METHOD_INDEX_LEAP
);
1213 // Phase 2 authentication and anonymous identity.
1214 if (Phase2AuthActive()) {
1215 std::string eap_phase_2_auth
;
1216 properties
.GetStringWithoutPathExpansion(
1217 shill::kEapPhase2AuthProperty
, &eap_phase_2_auth
);
1218 if (eap_phase_2_auth
== shill::kEapPhase2AuthTTLSMD5
)
1219 phase_2_auth_combobox_
->SetSelectedIndex(PHASE_2_AUTH_INDEX_MD5
);
1220 else if (eap_phase_2_auth
== shill::kEapPhase2AuthTTLSMSCHAPV2
)
1221 phase_2_auth_combobox_
->SetSelectedIndex(PHASE_2_AUTH_INDEX_MSCHAPV2
);
1222 else if (eap_phase_2_auth
== shill::kEapPhase2AuthTTLSMSCHAP
)
1223 phase_2_auth_combobox_
->SetSelectedIndex(PHASE_2_AUTH_INDEX_MSCHAP
);
1224 else if (eap_phase_2_auth
== shill::kEapPhase2AuthTTLSPAP
)
1225 phase_2_auth_combobox_
->SetSelectedIndex(PHASE_2_AUTH_INDEX_PAP
);
1226 else if (eap_phase_2_auth
== shill::kEapPhase2AuthTTLSCHAP
)
1227 phase_2_auth_combobox_
->SetSelectedIndex(PHASE_2_AUTH_INDEX_CHAP
);
1229 std::string eap_anonymous_identity
;
1230 properties
.GetStringWithoutPathExpansion(
1231 shill::kEapAnonymousIdentityProperty
, &eap_anonymous_identity
);
1232 identity_anonymous_textfield_
->SetText(
1233 base::UTF8ToUTF16(eap_anonymous_identity
));
1237 std::string subject_match
;
1238 properties
.GetStringWithoutPathExpansion(
1239 shill::kEapSubjectMatchProperty
, &subject_match
);
1240 subject_match_textfield_
->SetText(base::UTF8ToUTF16(subject_match
));
1242 // Server CA certificate.
1243 if (CaCertActive()) {
1244 std::string eap_ca_cert_pem
;
1245 const base::ListValue
* pems
= NULL
;
1246 if (properties
.GetListWithoutPathExpansion(
1247 shill::kEapCaCertPemProperty
, &pems
))
1248 pems
->GetString(0, &eap_ca_cert_pem
);
1249 if (eap_ca_cert_pem
.empty()) {
1250 bool eap_use_system_cas
= false;
1251 properties
.GetBooleanWithoutPathExpansion(
1252 shill::kEapUseSystemCasProperty
, &eap_use_system_cas
);
1253 if (eap_use_system_cas
) {
1255 server_ca_cert_combobox_
->SetSelectedIndex(0);
1258 server_ca_cert_combobox_
->SetSelectedIndex(
1259 server_ca_cert_combobox_
->model()->GetItemCount() - 1);
1262 // Select the certificate if available.
1263 int cert_index
= CertLibrary::Get()->GetCertIndexByPEM(
1264 CertLibrary::CERT_TYPE_SERVER_CA
, eap_ca_cert_pem
);
1265 if (cert_index
>= 0) {
1266 // Skip item for "Default".
1267 server_ca_cert_combobox_
->SetSelectedIndex(1 + cert_index
);
1270 server_ca_cert_combobox_
->SetSelectedIndex(0);
1275 // User certificate.
1276 if (UserCertActive()) {
1277 std::string eap_cert_id
;
1278 properties
.GetStringWithoutPathExpansion(
1279 shill::kEapCertIdProperty
, &eap_cert_id
);
1280 if (!eap_cert_id
.empty()) {
1281 int cert_index
= CertLibrary::Get()->GetCertIndexByPkcs11Id(
1282 CertLibrary::CERT_TYPE_USER
, eap_cert_id
);
1283 if (cert_index
>= 0)
1284 user_cert_combobox_
->SetSelectedIndex(cert_index
);
1288 // Identity is always active.
1289 std::string eap_identity
;
1290 properties
.GetStringWithoutPathExpansion(
1291 shill::kEapIdentityProperty
, &eap_identity
);
1292 identity_textfield_
->SetText(base::UTF8ToUTF16(eap_identity
));
1295 if (PassphraseActive()) {
1296 std::string eap_password
;
1297 properties
.GetStringWithoutPathExpansion(
1298 shill::kEapPasswordProperty
, &eap_password
);
1299 passphrase_textfield_
->SetText(base::UTF8ToUTF16(eap_password
));
1300 // If 'Connectable' is True, show a fake passphrase to indicate that it
1301 // has already been set.
1302 bool connectable
= false;
1303 properties
.GetBooleanWithoutPathExpansion(
1304 shill::kConnectableProperty
, &connectable
);
1305 passphrase_textfield_
->SetShowFake(connectable
);
1309 bool save_credentials
= false;
1310 properties
.GetBooleanWithoutPathExpansion(
1311 shill::kSaveCredentialsProperty
, &save_credentials
);
1312 save_credentials_checkbox_
->SetChecked(save_credentials
);
1314 UpdateDialogButtons();
1315 RefreshShareCheckbox();
1319 void WifiConfigView::InitFocus() {
1320 views::View
* view_to_focus
= GetInitiallyFocusedView();
1322 view_to_focus
->RequestFocus();
1325 void WifiConfigView::NetworkPropertiesUpdated(const NetworkState
* network
) {
1326 if (network
->path() != service_path_
)
1332 void WifiConfigView::ParseWiFiUIProperty(
1333 NetworkPropertyUIData
* property_ui_data
,
1334 const NetworkState
* network
,
1335 const std::string
& key
) {
1336 ::onc::ONCSource onc_source
= ::onc::ONC_SOURCE_NONE
;
1337 const base::DictionaryValue
* onc
=
1338 onc::FindPolicyForActiveUser(network
->guid(), &onc_source
);
1340 property_ui_data
->ParseOncProperty(
1343 base::StringPrintf("%s.%s", ::onc::network_config::kWiFi
, key
.c_str()));
1347 void WifiConfigView::ParseWiFiEAPUIProperty(
1348 NetworkPropertyUIData
* property_ui_data
,
1349 const NetworkState
* network
,
1350 const std::string
& key
) {
1351 ParseWiFiUIProperty(
1352 property_ui_data
, network
,
1353 base::StringPrintf("%s.%s", ::onc::wifi::kEAP
, key
.c_str()));
1356 } // namespace chromeos