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"
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 "chrome/grit/generated_resources.h"
16 #include "chrome/grit/theme_resources.h"
17 #include "chromeos/login/login_state.h"
18 #include "chromeos/network/client_cert_util.h"
19 #include "chromeos/network/network_configuration_handler.h"
20 #include "chromeos/network/network_event_log.h"
21 #include "chromeos/network/network_handler.h"
22 #include "chromeos/network/network_state.h"
23 #include "chromeos/network/network_state_handler.h"
24 #include "chromeos/network/network_ui_data.h"
25 #include "chromeos/network/shill_property_util.h"
26 #include "components/onc/onc_constants.h"
27 #include "third_party/cros_system_api/dbus/service_constants.h"
28 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/chromeos/network/network_connect.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 ~ComboboxWithWidth() override
{}
55 gfx::Size
GetPreferredSize() const 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 ~SecurityComboboxModel() override
;
107 // Overridden from ui::ComboboxModel:
108 int GetItemCount() const override
;
109 base::string16
GetItemAt(int index
) override
;
112 DISALLOW_COPY_AND_ASSIGN(SecurityComboboxModel
);
115 class EAPMethodComboboxModel
: public ui::ComboboxModel
{
117 EAPMethodComboboxModel();
118 ~EAPMethodComboboxModel() override
;
120 // Overridden from ui::ComboboxModel:
121 int GetItemCount() const override
;
122 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 ~Phase2AuthComboboxModel() override
;
133 // Overridden from ui::ComboboxModel:
134 int GetItemCount() const override
;
135 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 ~ServerCACertComboboxModel() override
;
148 // Overridden from ui::ComboboxModel:
149 int GetItemCount() const override
;
150 base::string16
GetItemAt(int index
) override
;
153 DISALLOW_COPY_AND_ASSIGN(ServerCACertComboboxModel
);
156 class UserCertComboboxModel
: public ui::ComboboxModel
{
158 explicit UserCertComboboxModel(WifiConfigView
* owner
);
159 ~UserCertComboboxModel() override
;
161 // Overridden from ui::ComboboxModel:
162 int GetItemCount() const override
;
163 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())
317 return 1; // "None installed" (combobox must have at least 1 entry)
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 l10n_util::GetStringUTF16(
330 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED
);
331 if (CertLibrary::Get()->CertificatesLoading())
332 return l10n_util::GetStringUTF16(
333 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING
);
334 if (CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER
) == 0)
335 return l10n_util::GetStringUTF16(
336 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED
);
337 return CertLibrary::Get()->GetCertDisplayStringAt(
338 CertLibrary::CERT_TYPE_USER
, index
);
341 } // namespace internal
343 WifiConfigView::WifiConfigView(NetworkConfigView
* parent
,
344 const std::string
& service_path
,
346 : ChildNetworkConfigView(parent
, service_path
),
347 ssid_textfield_(NULL
),
348 eap_method_combobox_(NULL
),
349 phase_2_auth_label_(NULL
),
350 phase_2_auth_combobox_(NULL
),
351 user_cert_label_(NULL
),
352 user_cert_combobox_(NULL
),
353 server_ca_cert_label_(NULL
),
354 server_ca_cert_combobox_(NULL
),
355 subject_match_label_(NULL
),
356 subject_match_textfield_(NULL
),
357 identity_label_(NULL
),
358 identity_textfield_(NULL
),
359 identity_anonymous_label_(NULL
),
360 identity_anonymous_textfield_(NULL
),
361 save_credentials_checkbox_(NULL
),
362 share_network_checkbox_(NULL
),
363 shared_network_label_(NULL
),
364 security_combobox_(NULL
),
365 passphrase_label_(NULL
),
366 passphrase_textfield_(NULL
),
367 passphrase_visible_button_(NULL
),
369 weak_ptr_factory_(this) {
371 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE
);
374 WifiConfigView::~WifiConfigView() {
375 RemoveAllChildViews(true); // Destroy children before models
376 if (NetworkHandler::IsInitialized()) {
377 NetworkHandler::Get()->network_state_handler()->RemoveObserver(
380 CertLibrary::Get()->RemoveObserver(this);
383 base::string16
WifiConfigView::GetTitle() const {
384 const NetworkState
* network
= GetNetworkState();
385 if (network
&& network
->type() == shill::kTypeEthernet
)
386 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_CONFIGURE_ETHERNET
);
387 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_JOIN_WIFI_NETWORKS
);
390 views::View
* WifiConfigView::GetInitiallyFocusedView() {
391 // Return a reasonable widget for initial focus,
392 // depending on what we're showing.
394 return ssid_textfield_
;
395 else if (eap_method_combobox_
)
396 return eap_method_combobox_
;
397 else if (passphrase_textfield_
&& passphrase_textfield_
->enabled())
398 return passphrase_textfield_
;
403 bool WifiConfigView::CanLogin() {
404 static const size_t kMinPSKPasswordLen
= 5;
406 // We either have an existing network or the user entered an SSID.
407 if (service_path_
.empty() && GetSsid().empty())
410 // If a non-EAP network requires a passphrase, ensure it is the right length.
411 if (passphrase_textfield_
!= NULL
&&
412 passphrase_textfield_
->enabled() &&
413 !passphrase_textfield_
->show_fake() &&
414 !eap_method_combobox_
&&
415 passphrase_textfield_
->text().length() < kMinPSKPasswordLen
)
418 // If we're using EAP, we must have a method.
419 if (eap_method_combobox_
&&
420 eap_method_combobox_
->selected_index() == EAP_METHOD_INDEX_NONE
)
423 // Block login if certs are required but user has none.
424 if (UserCertRequired() && (!HaveUserCerts() || !IsUserCertValid()))
430 bool WifiConfigView::UserCertRequired() const {
431 return UserCertActive();
434 bool WifiConfigView::HaveUserCerts() const {
435 return CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER
) > 0;
438 bool WifiConfigView::IsUserCertValid() const {
439 if (!UserCertActive())
441 int index
= user_cert_combobox_
->selected_index();
444 // Currently only hardware-backed user certificates are valid.
445 if (!CertLibrary::Get()->IsCertHardwareBackedAt(CertLibrary::CERT_TYPE_USER
,
452 bool WifiConfigView::Phase2AuthActive() const {
453 if (phase_2_auth_combobox_
)
454 return phase_2_auth_combobox_
->model()->GetItemCount() > 1;
458 bool WifiConfigView::PassphraseActive() const {
459 if (eap_method_combobox_
) {
460 // No password for EAP-TLS.
461 int index
= eap_method_combobox_
->selected_index();
462 return index
!= EAP_METHOD_INDEX_NONE
&& index
!= EAP_METHOD_INDEX_TLS
;
463 } else if (security_combobox_
) {
464 return security_combobox_
->selected_index() != SECURITY_INDEX_NONE
;
469 bool WifiConfigView::UserCertActive() const {
470 // User certs only for EAP-TLS.
471 if (eap_method_combobox_
)
472 return eap_method_combobox_
->selected_index() == EAP_METHOD_INDEX_TLS
;
477 bool WifiConfigView::CaCertActive() const {
478 // No server CA certs for LEAP.
479 if (eap_method_combobox_
) {
480 int index
= eap_method_combobox_
->selected_index();
481 return index
!= EAP_METHOD_INDEX_NONE
&& index
!= EAP_METHOD_INDEX_LEAP
;
486 void WifiConfigView::UpdateDialogButtons() {
487 parent_
->GetDialogClientView()->UpdateDialogButtons();
490 void WifiConfigView::RefreshEapFields() {
491 // If EAP method changes, the phase 2 auth choices may have changed also.
492 phase_2_auth_combobox_
->ModelChanged();
493 phase_2_auth_combobox_
->SetSelectedIndex(0);
494 bool phase_2_auth_enabled
= Phase2AuthActive();
495 phase_2_auth_combobox_
->SetEnabled(phase_2_auth_enabled
&&
496 phase_2_auth_ui_data_
.IsEditable());
497 phase_2_auth_label_
->SetEnabled(phase_2_auth_enabled
);
500 bool passphrase_enabled
= PassphraseActive();
501 passphrase_textfield_
->SetEnabled(passphrase_enabled
&&
502 passphrase_ui_data_
.IsEditable());
503 passphrase_label_
->SetEnabled(passphrase_enabled
);
504 if (!passphrase_enabled
)
505 passphrase_textfield_
->SetText(base::string16());
508 bool certs_loading
= CertLibrary::Get()->CertificatesLoading();
509 bool user_cert_enabled
= UserCertActive();
510 user_cert_label_
->SetEnabled(user_cert_enabled
);
511 bool have_user_certs
= !certs_loading
&& HaveUserCerts();
512 user_cert_combobox_
->SetEnabled(user_cert_enabled
&&
514 user_cert_ui_data_
.IsEditable());
515 user_cert_combobox_
->ModelChanged();
516 user_cert_combobox_
->SetSelectedIndex(0);
519 bool ca_cert_enabled
= CaCertActive();
520 server_ca_cert_label_
->SetEnabled(ca_cert_enabled
);
521 server_ca_cert_combobox_
->SetEnabled(ca_cert_enabled
&&
523 server_ca_cert_ui_data_
.IsEditable());
524 server_ca_cert_combobox_
->ModelChanged();
525 server_ca_cert_combobox_
->SetSelectedIndex(0);
528 bool subject_match_enabled
=
529 ca_cert_enabled
&& eap_method_combobox_
&&
530 eap_method_combobox_
->selected_index() == EAP_METHOD_INDEX_TLS
;
531 subject_match_label_
->SetEnabled(subject_match_enabled
);
532 subject_match_textfield_
->SetEnabled(subject_match_enabled
);
533 if (!subject_match_enabled
)
534 subject_match_textfield_
->SetText(base::string16());
536 // No anonymous identity if no phase 2 auth.
537 bool identity_anonymous_enabled
= phase_2_auth_enabled
;
538 identity_anonymous_textfield_
->SetEnabled(
539 identity_anonymous_enabled
&& identity_anonymous_ui_data_
.IsEditable());
540 identity_anonymous_label_
->SetEnabled(identity_anonymous_enabled
);
541 if (!identity_anonymous_enabled
)
542 identity_anonymous_textfield_
->SetText(base::string16());
544 RefreshShareCheckbox();
547 void WifiConfigView::RefreshShareCheckbox() {
548 if (!share_network_checkbox_
)
551 if (security_combobox_
&&
552 security_combobox_
->selected_index() == SECURITY_INDEX_NONE
) {
553 share_network_checkbox_
->SetEnabled(false);
554 share_network_checkbox_
->SetChecked(true);
555 } else if (eap_method_combobox_
&&
556 (eap_method_combobox_
->selected_index() == EAP_METHOD_INDEX_TLS
||
557 user_cert_combobox_
->selected_index() != 0)) {
558 // Can not share TLS network (requires certificate), or any network where
559 // user certificates are enabled.
560 share_network_checkbox_
->SetEnabled(false);
561 share_network_checkbox_
->SetChecked(false);
564 bool enabled
= false;
565 ChildNetworkConfigView::GetShareStateForLoginState(&value
, &enabled
);
567 share_network_checkbox_
->SetChecked(value
);
568 share_network_checkbox_
->SetEnabled(enabled
);
572 void WifiConfigView::UpdateErrorLabel() {
573 base::string16 error_msg
;
574 if (UserCertRequired() && CertLibrary::Get()->CertificatesLoaded()) {
575 if (!HaveUserCerts()) {
576 if (!LoginState::Get()->IsUserLoggedIn() ||
577 LoginState::Get()->IsGuestSessionUser()) {
578 error_msg
= l10n_util::GetStringUTF16(
579 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_LOGIN_FOR_USER_CERT
);
581 error_msg
= l10n_util::GetStringUTF16(
582 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PLEASE_INSTALL_USER_CERT
);
584 } else if (!IsUserCertValid()) {
585 error_msg
= l10n_util::GetStringUTF16(
586 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_REQUIRE_HARDWARE_BACKED
);
589 if (error_msg
.empty() && !service_path_
.empty()) {
590 const NetworkState
* network
= GetNetworkState();
591 if (network
&& network
->connection_state() == shill::kStateFailure
) {
592 error_msg
= ui::NetworkConnect::Get()->GetShillErrorString(
593 network
->last_error(), network
->path());
596 if (!error_msg
.empty()) {
597 error_label_
->SetText(error_msg
);
598 error_label_
->SetVisible(true);
600 error_label_
->SetVisible(false);
604 void WifiConfigView::ContentsChanged(views::Textfield
* sender
,
605 const base::string16
& new_contents
) {
606 UpdateDialogButtons();
609 bool WifiConfigView::HandleKeyEvent(views::Textfield
* sender
,
610 const ui::KeyEvent
& key_event
) {
611 if (sender
== passphrase_textfield_
&&
612 key_event
.key_code() == ui::VKEY_RETURN
) {
613 parent_
->GetDialogClientView()->AcceptWindow();
618 void WifiConfigView::ButtonPressed(views::Button
* sender
,
619 const ui::Event
& event
) {
620 if (sender
== passphrase_visible_button_
&& passphrase_textfield_
) {
621 if (passphrase_textfield_
->GetTextInputType() == ui::TEXT_INPUT_TYPE_TEXT
) {
622 passphrase_textfield_
->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD
);
623 passphrase_visible_button_
->SetToggled(false);
625 passphrase_textfield_
->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT
);
626 passphrase_visible_button_
->SetToggled(true);
633 void WifiConfigView::OnPerformAction(views::Combobox
* combobox
) {
634 if (combobox
== security_combobox_
) {
635 bool passphrase_enabled
= PassphraseActive();
636 passphrase_label_
->SetEnabled(passphrase_enabled
);
637 passphrase_textfield_
->SetEnabled(passphrase_enabled
&&
638 passphrase_ui_data_
.IsEditable());
639 if (!passphrase_enabled
)
640 passphrase_textfield_
->SetText(base::string16());
641 RefreshShareCheckbox();
642 } else if (combobox
== user_cert_combobox_
) {
643 RefreshShareCheckbox();
644 } else if (combobox
== eap_method_combobox_
) {
647 UpdateDialogButtons();
651 void WifiConfigView::OnCertificatesLoaded(bool initial_load
) {
653 UpdateDialogButtons();
657 bool WifiConfigView::Login() {
658 const NetworkState
* network
= GetNetworkState();
660 // Set configuration properties.
661 base::DictionaryValue properties
;
663 // Default shared state for non-private networks is true.
664 const bool share_default
= !network
|| !network
->IsPrivate();
665 bool share_network
= GetShareNetwork(share_default
);
666 bool only_policy_autoconnect
=
667 onc::PolicyAllowsOnlyPolicyNetworksToAutoconnect(!share_network
);
668 if (only_policy_autoconnect
) {
669 properties
.SetBooleanWithoutPathExpansion(shill::kAutoConnectProperty
,
673 if (service_path_
.empty()) {
674 // TODO(stevenjb): Support modifying existing EAP configurations.
675 // Will probably wait to do this in WebUI instead.
676 properties
.SetStringWithoutPathExpansion(
677 shill::kTypeProperty
, shill::kTypeWifi
);
678 shill_property_util::SetSSID(GetSsid(), &properties
);
679 properties
.SetStringWithoutPathExpansion(
680 shill::kModeProperty
, shill::kModeManaged
);
681 properties
.SetBooleanWithoutPathExpansion(
682 shill::kSaveCredentialsProperty
, GetSaveCredentials());
683 std::string security_class
= shill::kSecurityNone
;
684 if (!eap_method_combobox_
) {
685 switch (security_combobox_
->selected_index()) {
686 case SECURITY_INDEX_NONE
:
687 security_class
= shill::kSecurityNone
;
689 case SECURITY_INDEX_WEP
:
690 security_class
= shill::kSecurityWep
;
692 case SECURITY_INDEX_PSK
:
693 security_class
= shill::kSecurityPsk
;
696 std::string passphrase
= GetPassphrase();
697 if (!passphrase
.empty()) {
698 properties
.SetStringWithoutPathExpansion(
699 shill::kPassphraseProperty
, GetPassphrase());
702 security_class
= shill::kSecurity8021x
;
703 SetEapProperties(&properties
, false /* not configured */);
705 properties
.SetStringWithoutPathExpansion(
706 shill::kSecurityClassProperty
, security_class
);
708 // Configure and connect to network.
709 ui::NetworkConnect::Get()->CreateConfigurationAndConnect(&properties
,
713 // Shill no longer knows about this network (edge case).
714 // TODO(stevenjb): Add notification for this.
715 NET_LOG_ERROR("Network not found", service_path_
);
716 return true; // Close dialog
718 if (eap_method_combobox_
) {
719 SetEapProperties(&properties
, true /* configured */);
720 properties
.SetBooleanWithoutPathExpansion(
721 shill::kSaveCredentialsProperty
, GetSaveCredentials());
723 const std::string passphrase
= GetPassphrase();
724 if (!passphrase
.empty()) {
725 properties
.SetStringWithoutPathExpansion(
726 shill::kPassphraseProperty
, passphrase
);
729 if (network
->type() == shill::kTypeEthernet
) {
730 // When configuring an ethernet service, we actually configure the
731 // EthernetEap service, which exists in the Profile only.
732 // See crbug.com/126870 for more info.
733 properties
.SetStringWithoutPathExpansion(shill::kTypeProperty
,
734 shill::kTypeEthernetEap
);
735 share_network
= false;
736 ui::NetworkConnect::Get()->CreateConfiguration(&properties
,
739 ui::NetworkConnect::Get()->ConfigureNetworkAndConnect(
740 service_path_
, properties
, share_network
);
743 return true; // dialog will be closed
746 std::string
WifiConfigView::GetSsid() const {
748 if (ssid_textfield_
!= NULL
) {
749 std::string untrimmed
= base::UTF16ToUTF8(ssid_textfield_
->text());
750 base::TrimWhitespaceASCII(untrimmed
, base::TRIM_ALL
, &result
);
755 std::string
WifiConfigView::GetPassphrase() const {
757 if (passphrase_textfield_
!= NULL
)
758 result
= base::UTF16ToUTF8(passphrase_textfield_
->text());
762 bool WifiConfigView::GetSaveCredentials() const {
763 if (!save_credentials_checkbox_
)
764 return true; // share networks by default (e.g. non 8021x).
765 return save_credentials_checkbox_
->checked();
768 bool WifiConfigView::GetShareNetwork(bool share_default
) const {
769 if (!share_network_checkbox_
)
770 return share_default
;
771 return share_network_checkbox_
->checked();
774 std::string
WifiConfigView::GetEapMethod() const {
775 DCHECK(eap_method_combobox_
);
776 switch (eap_method_combobox_
->selected_index()) {
777 case EAP_METHOD_INDEX_PEAP
:
778 return shill::kEapMethodPEAP
;
779 case EAP_METHOD_INDEX_TLS
:
780 return shill::kEapMethodTLS
;
781 case EAP_METHOD_INDEX_TTLS
:
782 return shill::kEapMethodTTLS
;
783 case EAP_METHOD_INDEX_LEAP
:
784 return shill::kEapMethodLEAP
;
785 case EAP_METHOD_INDEX_NONE
:
791 std::string
WifiConfigView::GetEapPhase2Auth() const {
792 DCHECK(phase_2_auth_combobox_
);
793 bool is_peap
= (GetEapMethod() == shill::kEapMethodPEAP
);
794 switch (phase_2_auth_combobox_
->selected_index()) {
795 case PHASE_2_AUTH_INDEX_MD5
:
796 return is_peap
? shill::kEapPhase2AuthPEAPMD5
797 : shill::kEapPhase2AuthTTLSMD5
;
798 case PHASE_2_AUTH_INDEX_MSCHAPV2
:
799 return is_peap
? shill::kEapPhase2AuthPEAPMSCHAPV2
800 : shill::kEapPhase2AuthTTLSMSCHAPV2
;
801 case PHASE_2_AUTH_INDEX_MSCHAP
:
802 return shill::kEapPhase2AuthTTLSMSCHAP
;
803 case PHASE_2_AUTH_INDEX_PAP
:
804 return shill::kEapPhase2AuthTTLSPAP
;
805 case PHASE_2_AUTH_INDEX_CHAP
:
806 return shill::kEapPhase2AuthTTLSCHAP
;
807 case PHASE_2_AUTH_INDEX_AUTO
:
813 std::string
WifiConfigView::GetEapServerCaCertPEM() const {
814 DCHECK(server_ca_cert_combobox_
);
815 int index
= server_ca_cert_combobox_
->selected_index();
817 // First item is "Default".
818 return std::string();
819 } else if (index
== server_ca_cert_combobox_
->model()->GetItemCount() - 1) {
820 // Last item is "Do not check".
821 return std::string();
823 int cert_index
= index
- 1;
824 return CertLibrary::Get()->GetServerCACertPEMAt(cert_index
);
828 bool WifiConfigView::GetEapUseSystemCas() const {
829 DCHECK(server_ca_cert_combobox_
);
830 // Only use system CAs if the first item ("Default") is selected.
831 return server_ca_cert_combobox_
->selected_index() == 0;
834 std::string
WifiConfigView::GetEapSubjectMatch() const {
835 DCHECK(subject_match_textfield_
);
836 return base::UTF16ToUTF8(subject_match_textfield_
->text());
839 void WifiConfigView::SetEapClientCertProperties(
840 base::DictionaryValue
* properties
) const {
841 DCHECK(user_cert_combobox_
);
842 if (!HaveUserCerts() || !UserCertActive()) {
843 // No certificate selected or not required.
844 client_cert::SetEmptyShillProperties(client_cert::CONFIG_TYPE_EAP
,
847 // Certificates are listed in the order they appear in the model.
848 int index
= user_cert_combobox_
->selected_index();
850 const std::string pkcs11_id
=
851 CertLibrary::Get()->GetUserCertPkcs11IdAt(index
, &slot_id
);
852 client_cert::SetShillProperties(
853 client_cert::CONFIG_TYPE_EAP
, slot_id
, pkcs11_id
, properties
);
857 std::string
WifiConfigView::GetEapIdentity() const {
858 DCHECK(identity_textfield_
);
859 return base::UTF16ToUTF8(identity_textfield_
->text());
862 std::string
WifiConfigView::GetEapAnonymousIdentity() const {
863 DCHECK(identity_anonymous_textfield_
);
864 return base::UTF16ToUTF8(identity_anonymous_textfield_
->text());
867 void WifiConfigView::SetEapProperties(base::DictionaryValue
* properties
,
869 properties
->SetStringWithoutPathExpansion(
870 shill::kEapIdentityProperty
, GetEapIdentity());
871 properties
->SetStringWithoutPathExpansion(
872 shill::kEapMethodProperty
, GetEapMethod());
873 properties
->SetStringWithoutPathExpansion(
874 shill::kEapPhase2AuthProperty
, GetEapPhase2Auth());
875 properties
->SetStringWithoutPathExpansion(
876 shill::kEapAnonymousIdentityProperty
, GetEapAnonymousIdentity());
877 properties
->SetStringWithoutPathExpansion(
878 shill::kEapSubjectMatchProperty
, GetEapSubjectMatch());
880 SetEapClientCertProperties(properties
);
882 properties
->SetBooleanWithoutPathExpansion(
883 shill::kEapUseSystemCasProperty
, GetEapUseSystemCas());
884 if (!configured
|| passphrase_textfield_
->changed()) {
885 properties
->SetStringWithoutPathExpansion(
886 shill::kEapPasswordProperty
, GetPassphrase());
888 base::ListValue
* pem_list
= new base::ListValue
;
889 std::string ca_cert_pem
= GetEapServerCaCertPEM();
890 if (!ca_cert_pem
.empty())
891 pem_list
->AppendString(ca_cert_pem
);
892 properties
->SetWithoutPathExpansion(
893 shill::kEapCaCertPemProperty
, pem_list
);
896 void WifiConfigView::Cancel() {
899 void WifiConfigView::Init(bool show_8021x
) {
900 const NetworkState
* network
= GetNetworkState();
902 if (network
->type() == shill::kTypeWifi
) {
903 if (network
->security_class() == shill::kSecurity8021x
)
905 } else if (network
->type() == shill::kTypeEthernet
) {
908 NOTREACHED() << "Unexpected network type for WifiConfigView: "
909 << network
->type() << " Path: " << service_path_
;
911 ParseEAPUIProperty(&eap_method_ui_data_
, network
, ::onc::eap::kOuter
);
912 ParseEAPUIProperty(&phase_2_auth_ui_data_
, network
, ::onc::eap::kInner
);
914 &user_cert_ui_data_
, network
, ::onc::client_cert::kClientCertRef
);
916 &server_ca_cert_ui_data_
, network
, ::onc::eap::kServerCARef
);
917 if (server_ca_cert_ui_data_
.IsManaged()) {
919 &server_ca_cert_ui_data_
, network
, ::onc::eap::kUseSystemCAs
);
921 ParseEAPUIProperty(&identity_ui_data_
, network
, ::onc::eap::kIdentity
);
923 &identity_anonymous_ui_data_
, network
, ::onc::eap::kAnonymousIdentity
);
925 &save_credentials_ui_data_
, network
, ::onc::eap::kSaveCredentials
);
927 ParseEAPUIProperty(&passphrase_ui_data_
, network
, ::onc::eap::kPassword
);
929 ParseUIProperty(&passphrase_ui_data_
, network
, ::onc::wifi::kPassphrase
);
932 views::GridLayout
* layout
= views::GridLayout::CreatePanel(this);
933 SetLayoutManager(layout
);
935 const int column_view_set_id
= 0;
936 views::ColumnSet
* column_set
= layout
->AddColumnSet(column_view_set_id
);
937 const int kPasswordVisibleWidth
= 20;
939 column_set
->AddColumn(views::GridLayout::LEADING
, views::GridLayout::FILL
, 1,
940 views::GridLayout::USE_PREF
, 0, 0);
941 column_set
->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing
);
942 // Textfield, combobox.
943 column_set
->AddColumn(views::GridLayout::FILL
, views::GridLayout::FILL
, 1,
944 views::GridLayout::USE_PREF
, 0,
945 ChildNetworkConfigView::kInputFieldMinWidth
);
946 column_set
->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing
);
947 // Password visible button / policy indicator.
948 column_set
->AddColumn(views::GridLayout::CENTER
, views::GridLayout::FILL
, 1,
949 views::GridLayout::USE_PREF
, 0, kPasswordVisibleWidth
);
952 if (!network
|| network
->type() != shill::kTypeEthernet
) {
953 layout
->StartRow(0, column_view_set_id
);
954 layout
->AddView(new views::Label(l10n_util::GetStringUTF16(
955 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID
)));
957 ssid_textfield_
= new views::Textfield();
958 ssid_textfield_
->set_controller(this);
959 ssid_textfield_
->SetAccessibleName(l10n_util::GetStringUTF16(
960 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID
));
961 layout
->AddView(ssid_textfield_
);
963 views::Label
* label
=
964 new views::Label(base::UTF8ToUTF16(network
->name()));
965 label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
966 layout
->AddView(label
);
968 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
972 if (!network
&& !show_8021x
) {
973 layout
->StartRow(0, column_view_set_id
);
974 base::string16 label_text
= l10n_util::GetStringUTF16(
975 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY
);
976 layout
->AddView(new views::Label(label_text
));
977 security_combobox_model_
.reset(new internal::SecurityComboboxModel
);
978 security_combobox_
= new views::Combobox(security_combobox_model_
.get());
979 security_combobox_
->SetAccessibleName(label_text
);
980 security_combobox_
->set_listener(this);
981 layout
->AddView(security_combobox_
);
982 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
985 // Only enumerate certificates in the data model for 802.1X networks.
987 // Observer any changes to the certificate list.
988 CertLibrary::Get()->AddObserver(this);
991 layout
->StartRow(0, column_view_set_id
);
992 base::string16 eap_label_text
= l10n_util::GetStringUTF16(
993 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_METHOD
);
994 layout
->AddView(new views::Label(eap_label_text
));
995 eap_method_combobox_model_
.reset(new internal::EAPMethodComboboxModel
);
996 eap_method_combobox_
= new views::Combobox(
997 eap_method_combobox_model_
.get());
998 eap_method_combobox_
->SetAccessibleName(eap_label_text
);
999 eap_method_combobox_
->set_listener(this);
1000 eap_method_combobox_
->SetEnabled(eap_method_ui_data_
.IsEditable());
1001 layout
->AddView(eap_method_combobox_
);
1002 layout
->AddView(new ControlledSettingIndicatorView(eap_method_ui_data_
));
1003 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1005 // Phase 2 authentication
1006 layout
->StartRow(0, column_view_set_id
);
1007 base::string16 phase_2_label_text
= l10n_util::GetStringUTF16(
1008 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PHASE_2_AUTH
);
1009 phase_2_auth_label_
= new views::Label(phase_2_label_text
);
1010 layout
->AddView(phase_2_auth_label_
);
1011 phase_2_auth_combobox_model_
.reset(
1012 new internal::Phase2AuthComboboxModel(eap_method_combobox_
));
1013 phase_2_auth_combobox_
= new views::Combobox(
1014 phase_2_auth_combobox_model_
.get());
1015 phase_2_auth_combobox_
->SetAccessibleName(phase_2_label_text
);
1016 phase_2_auth_label_
->SetEnabled(false);
1017 phase_2_auth_combobox_
->SetEnabled(false);
1018 phase_2_auth_combobox_
->set_listener(this);
1019 layout
->AddView(phase_2_auth_combobox_
);
1020 layout
->AddView(new ControlledSettingIndicatorView(phase_2_auth_ui_data_
));
1021 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1023 // Server CA certificate
1024 layout
->StartRow(0, column_view_set_id
);
1025 base::string16 server_ca_cert_label_text
= l10n_util::GetStringUTF16(
1026 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA
);
1027 server_ca_cert_label_
= new views::Label(server_ca_cert_label_text
);
1028 layout
->AddView(server_ca_cert_label_
);
1029 server_ca_cert_combobox_model_
.reset(
1030 new internal::ServerCACertComboboxModel());
1031 server_ca_cert_combobox_
= new ComboboxWithWidth(
1032 server_ca_cert_combobox_model_
.get(),
1033 ChildNetworkConfigView::kInputFieldMinWidth
);
1034 server_ca_cert_combobox_
->SetAccessibleName(server_ca_cert_label_text
);
1035 server_ca_cert_label_
->SetEnabled(false);
1036 server_ca_cert_combobox_
->SetEnabled(false);
1037 server_ca_cert_combobox_
->set_listener(this);
1038 layout
->AddView(server_ca_cert_combobox_
);
1040 new ControlledSettingIndicatorView(server_ca_cert_ui_data_
));
1041 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1044 layout
->StartRow(0, column_view_set_id
);
1045 base::string16 subject_match_label_text
= l10n_util::GetStringUTF16(
1046 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EAP_SUBJECT_MATCH
);
1047 subject_match_label_
= new views::Label(subject_match_label_text
);
1048 layout
->AddView(subject_match_label_
);
1049 subject_match_textfield_
= new views::Textfield();
1050 subject_match_textfield_
->SetAccessibleName(subject_match_label_text
);
1051 subject_match_textfield_
->set_controller(this);
1052 layout
->AddView(subject_match_textfield_
);
1053 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1056 layout
->StartRow(0, column_view_set_id
);
1057 base::string16 user_cert_label_text
= l10n_util::GetStringUTF16(
1058 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT
);
1059 user_cert_label_
= new views::Label(user_cert_label_text
);
1060 layout
->AddView(user_cert_label_
);
1061 user_cert_combobox_model_
.reset(new internal::UserCertComboboxModel(this));
1062 user_cert_combobox_
= new views::Combobox(user_cert_combobox_model_
.get());
1063 user_cert_combobox_
->SetAccessibleName(user_cert_label_text
);
1064 user_cert_label_
->SetEnabled(false);
1065 user_cert_combobox_
->SetEnabled(false);
1066 user_cert_combobox_
->set_listener(this);
1067 layout
->AddView(user_cert_combobox_
);
1068 layout
->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_
));
1069 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1072 layout
->StartRow(0, column_view_set_id
);
1073 base::string16 identity_label_text
= l10n_util::GetStringUTF16(
1074 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY
);
1075 identity_label_
= new views::Label(identity_label_text
);
1076 layout
->AddView(identity_label_
);
1077 identity_textfield_
= new views::Textfield();
1078 identity_textfield_
->SetAccessibleName(identity_label_text
);
1079 identity_textfield_
->set_controller(this);
1080 identity_textfield_
->SetEnabled(identity_ui_data_
.IsEditable());
1081 layout
->AddView(identity_textfield_
);
1082 layout
->AddView(new ControlledSettingIndicatorView(identity_ui_data_
));
1083 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1087 layout
->StartRow(0, column_view_set_id
);
1088 int label_text_id
= IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE
;
1089 base::string16 passphrase_label_text
=
1090 l10n_util::GetStringUTF16(label_text_id
);
1091 passphrase_label_
= new views::Label(passphrase_label_text
);
1092 layout
->AddView(passphrase_label_
);
1093 passphrase_textfield_
= new PassphraseTextfield();
1094 passphrase_textfield_
->set_controller(this);
1095 // Disable passphrase input initially for other network.
1096 passphrase_label_
->SetEnabled(network
);
1097 passphrase_textfield_
->SetEnabled(network
&&
1098 passphrase_ui_data_
.IsEditable());
1099 passphrase_textfield_
->SetAccessibleName(passphrase_label_text
);
1100 layout
->AddView(passphrase_textfield_
);
1102 if (passphrase_ui_data_
.IsManaged()) {
1103 layout
->AddView(new ControlledSettingIndicatorView(passphrase_ui_data_
));
1105 // Password visible button.
1106 passphrase_visible_button_
= new views::ToggleImageButton(this);
1107 passphrase_visible_button_
->SetFocusable(true);
1108 passphrase_visible_button_
->SetTooltipText(
1109 l10n_util::GetStringUTF16(
1110 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE_SHOW
));
1111 passphrase_visible_button_
->SetToggledTooltipText(
1112 l10n_util::GetStringUTF16(
1113 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE_HIDE
));
1114 passphrase_visible_button_
->SetImage(
1115 views::ImageButton::STATE_NORMAL
,
1116 ResourceBundle::GetSharedInstance().
1117 GetImageSkiaNamed(IDR_NETWORK_SHOW_PASSWORD
));
1118 passphrase_visible_button_
->SetImage(
1119 views::ImageButton::STATE_HOVERED
,
1120 ResourceBundle::GetSharedInstance().
1121 GetImageSkiaNamed(IDR_NETWORK_SHOW_PASSWORD_HOVER
));
1122 passphrase_visible_button_
->SetToggledImage(
1123 views::ImageButton::STATE_NORMAL
,
1124 ResourceBundle::GetSharedInstance().
1125 GetImageSkiaNamed(IDR_NETWORK_HIDE_PASSWORD
));
1126 passphrase_visible_button_
->SetToggledImage(
1127 views::ImageButton::STATE_HOVERED
,
1128 ResourceBundle::GetSharedInstance().
1129 GetImageSkiaNamed(IDR_NETWORK_HIDE_PASSWORD_HOVER
));
1130 passphrase_visible_button_
->SetImageAlignment(
1131 views::ImageButton::ALIGN_CENTER
, views::ImageButton::ALIGN_MIDDLE
);
1132 layout
->AddView(passphrase_visible_button_
);
1135 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1138 // Anonymous identity
1139 layout
->StartRow(0, column_view_set_id
);
1140 identity_anonymous_label_
=
1141 new views::Label(l10n_util::GetStringUTF16(
1142 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY_ANONYMOUS
));
1143 layout
->AddView(identity_anonymous_label_
);
1144 identity_anonymous_textfield_
= new views::Textfield();
1145 identity_anonymous_label_
->SetEnabled(false);
1146 identity_anonymous_textfield_
->SetEnabled(false);
1147 identity_anonymous_textfield_
->set_controller(this);
1148 layout
->AddView(identity_anonymous_textfield_
);
1150 new ControlledSettingIndicatorView(identity_anonymous_ui_data_
));
1151 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1158 layout
->StartRow(0, column_view_set_id
);
1159 save_credentials_checkbox_
= new views::Checkbox(
1160 l10n_util::GetStringUTF16(
1161 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS
));
1162 save_credentials_checkbox_
->SetEnabled(
1163 save_credentials_ui_data_
.IsEditable());
1164 layout
->SkipColumns(1);
1165 layout
->AddView(save_credentials_checkbox_
);
1167 new ControlledSettingIndicatorView(save_credentials_ui_data_
));
1171 if (!network
|| network
->profile_path().empty()) {
1172 layout
->StartRow(0, column_view_set_id
);
1173 share_network_checkbox_
= new views::Checkbox(
1174 l10n_util::GetStringUTF16(
1175 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHARE_NETWORK
));
1176 layout
->SkipColumns(1);
1177 layout
->AddView(share_network_checkbox_
);
1179 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1181 // Create an error label.
1182 layout
->StartRow(0, column_view_set_id
);
1183 layout
->SkipColumns(1);
1184 error_label_
= new views::Label();
1185 error_label_
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
1186 error_label_
->SetEnabledColor(SK_ColorRED
);
1187 layout
->AddView(error_label_
);
1189 // Initialize the field and checkbox values.
1191 if (!network
&& show_8021x
)
1194 RefreshShareCheckbox();
1198 NetworkHandler::Get()->network_configuration_handler()->GetShillProperties(
1199 service_path_
, base::Bind(&WifiConfigView::InitFromProperties
,
1200 weak_ptr_factory_
.GetWeakPtr(), show_8021x
),
1201 base::Bind(&ShillError
, "GetProperties"));
1205 void WifiConfigView::InitFromProperties(
1207 const std::string
& service_path
,
1208 const base::DictionaryValue
& properties
) {
1210 std::string passphrase
;
1211 properties
.GetStringWithoutPathExpansion(
1212 shill::kPassphraseProperty
, &passphrase
);
1213 passphrase_textfield_
->SetText(base::UTF8ToUTF16(passphrase
));
1218 std::string eap_method
;
1219 properties
.GetStringWithoutPathExpansion(
1220 shill::kEapMethodProperty
, &eap_method
);
1221 if (eap_method
== shill::kEapMethodPEAP
)
1222 eap_method_combobox_
->SetSelectedIndex(EAP_METHOD_INDEX_PEAP
);
1223 else if (eap_method
== shill::kEapMethodTTLS
)
1224 eap_method_combobox_
->SetSelectedIndex(EAP_METHOD_INDEX_TTLS
);
1225 else if (eap_method
== shill::kEapMethodTLS
)
1226 eap_method_combobox_
->SetSelectedIndex(EAP_METHOD_INDEX_TLS
);
1227 else if (eap_method
== shill::kEapMethodLEAP
)
1228 eap_method_combobox_
->SetSelectedIndex(EAP_METHOD_INDEX_LEAP
);
1231 // Phase 2 authentication and anonymous identity.
1232 if (Phase2AuthActive()) {
1233 std::string eap_phase_2_auth
;
1234 properties
.GetStringWithoutPathExpansion(
1235 shill::kEapPhase2AuthProperty
, &eap_phase_2_auth
);
1236 if (eap_phase_2_auth
== shill::kEapPhase2AuthTTLSMD5
)
1237 phase_2_auth_combobox_
->SetSelectedIndex(PHASE_2_AUTH_INDEX_MD5
);
1238 else if (eap_phase_2_auth
== shill::kEapPhase2AuthTTLSMSCHAPV2
)
1239 phase_2_auth_combobox_
->SetSelectedIndex(PHASE_2_AUTH_INDEX_MSCHAPV2
);
1240 else if (eap_phase_2_auth
== shill::kEapPhase2AuthTTLSMSCHAP
)
1241 phase_2_auth_combobox_
->SetSelectedIndex(PHASE_2_AUTH_INDEX_MSCHAP
);
1242 else if (eap_phase_2_auth
== shill::kEapPhase2AuthTTLSPAP
)
1243 phase_2_auth_combobox_
->SetSelectedIndex(PHASE_2_AUTH_INDEX_PAP
);
1244 else if (eap_phase_2_auth
== shill::kEapPhase2AuthTTLSCHAP
)
1245 phase_2_auth_combobox_
->SetSelectedIndex(PHASE_2_AUTH_INDEX_CHAP
);
1247 std::string eap_anonymous_identity
;
1248 properties
.GetStringWithoutPathExpansion(
1249 shill::kEapAnonymousIdentityProperty
, &eap_anonymous_identity
);
1250 identity_anonymous_textfield_
->SetText(
1251 base::UTF8ToUTF16(eap_anonymous_identity
));
1255 std::string subject_match
;
1256 properties
.GetStringWithoutPathExpansion(
1257 shill::kEapSubjectMatchProperty
, &subject_match
);
1258 subject_match_textfield_
->SetText(base::UTF8ToUTF16(subject_match
));
1260 // Server CA certificate.
1261 if (CaCertActive()) {
1262 std::string eap_ca_cert_pem
;
1263 const base::ListValue
* pems
= NULL
;
1264 if (properties
.GetListWithoutPathExpansion(
1265 shill::kEapCaCertPemProperty
, &pems
))
1266 pems
->GetString(0, &eap_ca_cert_pem
);
1267 if (eap_ca_cert_pem
.empty()) {
1268 bool eap_use_system_cas
= false;
1269 properties
.GetBooleanWithoutPathExpansion(
1270 shill::kEapUseSystemCasProperty
, &eap_use_system_cas
);
1271 if (eap_use_system_cas
) {
1273 server_ca_cert_combobox_
->SetSelectedIndex(0);
1276 server_ca_cert_combobox_
->SetSelectedIndex(
1277 server_ca_cert_combobox_
->model()->GetItemCount() - 1);
1280 // Select the certificate if available.
1282 CertLibrary::Get()->GetServerCACertIndexByPEM(eap_ca_cert_pem
);
1283 if (cert_index
>= 0) {
1284 // Skip item for "Default".
1285 server_ca_cert_combobox_
->SetSelectedIndex(1 + cert_index
);
1288 server_ca_cert_combobox_
->SetSelectedIndex(0);
1293 // User certificate.
1294 if (UserCertActive()) {
1295 std::string eap_cert_id
;
1296 properties
.GetStringWithoutPathExpansion(
1297 shill::kEapCertIdProperty
, &eap_cert_id
);
1298 int unused_slot_id
= 0;
1299 std::string pkcs11_id
= client_cert::GetPkcs11AndSlotIdFromEapCertId(
1300 eap_cert_id
, &unused_slot_id
);
1301 if (!pkcs11_id
.empty()) {
1303 CertLibrary::Get()->GetUserCertIndexByPkcs11Id(pkcs11_id
);
1304 if (cert_index
>= 0)
1305 user_cert_combobox_
->SetSelectedIndex(cert_index
);
1309 // Identity is always active.
1310 std::string eap_identity
;
1311 properties
.GetStringWithoutPathExpansion(
1312 shill::kEapIdentityProperty
, &eap_identity
);
1313 identity_textfield_
->SetText(base::UTF8ToUTF16(eap_identity
));
1316 if (PassphraseActive()) {
1317 std::string eap_password
;
1318 properties
.GetStringWithoutPathExpansion(
1319 shill::kEapPasswordProperty
, &eap_password
);
1320 passphrase_textfield_
->SetText(base::UTF8ToUTF16(eap_password
));
1321 // If 'Connectable' is True, show a fake passphrase to indicate that it
1322 // has already been set.
1323 bool connectable
= false;
1324 properties
.GetBooleanWithoutPathExpansion(
1325 shill::kConnectableProperty
, &connectable
);
1326 passphrase_textfield_
->SetShowFake(connectable
);
1330 bool save_credentials
= false;
1331 properties
.GetBooleanWithoutPathExpansion(
1332 shill::kSaveCredentialsProperty
, &save_credentials
);
1333 save_credentials_checkbox_
->SetChecked(save_credentials
);
1335 UpdateDialogButtons();
1336 RefreshShareCheckbox();
1340 void WifiConfigView::InitFocus() {
1341 views::View
* view_to_focus
= GetInitiallyFocusedView();
1343 view_to_focus
->RequestFocus();
1346 bool WifiConfigView::IsConfigureDialog() {
1347 const NetworkState
* network
= GetNetworkState();
1348 return network
&& network
->type() == shill::kTypeEthernet
;
1351 void WifiConfigView::NetworkPropertiesUpdated(const NetworkState
* network
) {
1352 if (network
->path() != service_path_
)
1357 const NetworkState
* WifiConfigView::GetNetworkState() const {
1358 if (service_path_
.empty())
1360 return NetworkHandler::Get()->network_state_handler()->GetNetworkState(
1365 void WifiConfigView::ParseUIProperty(NetworkPropertyUIData
* property_ui_data
,
1366 const NetworkState
* network
,
1367 const std::string
& key
) {
1368 ::onc::ONCSource onc_source
= ::onc::ONC_SOURCE_NONE
;
1369 const base::DictionaryValue
* onc
=
1370 onc::FindPolicyForActiveUser(network
->guid(), &onc_source
);
1371 std::string onc_tag
= network
->type() == shill::kTypeEthernet
1372 ? ::onc::network_config::kEthernet
1373 : ::onc::network_config::kWiFi
;
1374 property_ui_data
->ParseOncProperty(onc_source
, onc
, onc_tag
+ '.' + key
);
1378 void WifiConfigView::ParseEAPUIProperty(NetworkPropertyUIData
* property_ui_data
,
1379 const NetworkState
* network
,
1380 const std::string
& key
) {
1381 std::string onc_tag
= network
->type() == shill::kTypeEthernet
1382 ? ::onc::ethernet::kEAP
1383 : ::onc::wifi::kEAP
;
1384 ParseUIProperty(property_ui_data
, network
, onc_tag
+ '.' + key
);
1387 } // namespace chromeos