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 #ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_WIFI_CONFIG_VIEW_H_
6 #define CHROME_BROWSER_CHROMEOS_OPTIONS_WIFI_CONFIG_VIEW_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string16.h"
15 #include "chrome/browser/chromeos/options/cert_library.h"
16 #include "chrome/browser/chromeos/options/network_config_view.h"
17 #include "chrome/browser/chromeos/options/network_property_ui_data.h"
18 #include "chromeos/network/network_state_handler_observer.h"
19 #include "third_party/cros_system_api/dbus/service_constants.h"
20 #include "ui/base/models/combobox_model.h"
21 #include "ui/views/controls/button/button.h"
22 #include "ui/views/controls/combobox/combobox_listener.h"
23 #include "ui/views/controls/textfield/textfield_controller.h"
24 #include "ui/views/view.h"
29 class ToggleImageButton
;
35 class PassphraseTextfield
;
38 class EAPMethodComboboxModel
;
39 class Phase2AuthComboboxModel
;
40 class SecurityComboboxModel
;
41 class ServerCACertComboboxModel
;
42 class UserCertComboboxModel
;
45 // A dialog box for showing a password textfield.
46 class WifiConfigView
: public ChildNetworkConfigView
,
47 public views::TextfieldController
,
48 public views::ButtonListener
,
49 public views::ComboboxListener
,
50 public CertLibrary::Observer
,
51 public NetworkStateHandlerObserver
{
53 // Configuration dialog for a WiFi network. If |service_path| is not empty
54 // it identifies the network to be configured. Otherwise |show_8021x|
55 // determines whether or not to show the 'advanced' 8021x configuration UI.
56 WifiConfigView(NetworkConfigView
* parent
,
57 const std::string
& service_path
,
59 virtual ~WifiConfigView();
61 // views::TextfieldController
62 virtual void ContentsChanged(views::Textfield
* sender
,
63 const base::string16
& new_contents
) OVERRIDE
;
64 virtual bool HandleKeyEvent(views::Textfield
* sender
,
65 const ui::KeyEvent
& key_event
) OVERRIDE
;
67 // views::ButtonListener
68 virtual void ButtonPressed(views::Button
* sender
,
69 const ui::Event
& event
) OVERRIDE
;
71 // views::ComboboxListener
72 virtual void OnSelectedIndexChanged(views::Combobox
* combobox
) OVERRIDE
;
74 // CertLibrary::Observer
75 virtual void OnCertificatesLoaded(bool initial_load
) OVERRIDE
;
77 // ChildNetworkConfigView
78 virtual base::string16
GetTitle() const OVERRIDE
;
79 virtual views::View
* GetInitiallyFocusedView() OVERRIDE
;
80 virtual bool CanLogin() OVERRIDE
;
81 virtual bool Login() OVERRIDE
;
82 virtual void Cancel() OVERRIDE
;
83 virtual void InitFocus() OVERRIDE
;
85 // NetworkStateHandlerObserver
86 virtual void NetworkPropertiesUpdated(const NetworkState
* network
) OVERRIDE
;
88 // Parses a WiFi UI |property| from the ONC associated with |network|. |key|
89 // is the property name within the ONC WiFi dictionary.
90 static void ParseWiFiUIProperty(NetworkPropertyUIData
* property_ui_data
,
91 const NetworkState
* network
,
92 const std::string
& key
);
94 // Parses a WiFi EAP UI |property| from the ONC associated with |network|.
95 // |key| is the property name within the ONC WiFi.EAP dictionary.
96 static void ParseWiFiEAPUIProperty(NetworkPropertyUIData
* property_ui_data
,
97 const NetworkState
* network
,
98 const std::string
& key
);
101 friend class internal::UserCertComboboxModel
;
103 // Initializes UI. If |show_8021x| includes 802.1x config options.
104 void Init(bool show_8021x
);
106 // Callback to initialize fields from uncached network properties.
107 void InitFromProperties(bool show_8021x
,
108 const std::string
& service_path
,
109 const base::DictionaryValue
& dictionary
);
112 std::string
GetSsid() const;
113 std::string
GetPassphrase() const;
114 bool GetSaveCredentials() const;
115 bool GetShareNetwork(bool share_default
) const;
117 // Get various 802.1X EAP values from the widgets.
118 std::string
GetEapMethod() const;
119 std::string
GetEapPhase2Auth() const;
120 std::string
GetEapServerCaCertPEM() const;
121 bool GetEapUseSystemCas() const;
122 std::string
GetEapSubjectMatch() const;
123 std::string
GetEapClientCertPkcs11Id() const;
124 std::string
GetEapIdentity() const;
125 std::string
GetEapAnonymousIdentity() const;
127 // Fill in |properties| with the appropriate values.
128 void SetEapProperties(base::DictionaryValue
* properties
);
130 // Returns true if the EAP method requires a user certificate.
131 bool UserCertRequired() const;
133 // Returns true if at least one user certificate is installed.
134 bool HaveUserCerts() const;
136 // Returns true if there is a selected user certificate and it is valid.
137 bool IsUserCertValid() const;
139 // Returns true if the phase 2 auth is relevant.
140 bool Phase2AuthActive() const;
142 // Returns whether the current configuration requires a passphrase.
143 bool PassphraseActive() const;
145 // Returns true if a user cert should be selected.
146 bool UserCertActive() const;
148 // Returns true if a CA cert selection should be allowed.
149 bool CaCertActive() const;
151 // Updates state of the Login button.
152 void UpdateDialogButtons();
154 // Enable/Disable EAP fields as appropriate based on selected EAP method.
155 void RefreshEapFields();
157 // Enable/Disable "share this network" checkbox.
158 void RefreshShareCheckbox();
160 // Updates the error text label.
161 void UpdateErrorLabel();
163 NetworkPropertyUIData eap_method_ui_data_
;
164 NetworkPropertyUIData phase_2_auth_ui_data_
;
165 NetworkPropertyUIData user_cert_ui_data_
;
166 NetworkPropertyUIData server_ca_cert_ui_data_
;
167 NetworkPropertyUIData identity_ui_data_
;
168 NetworkPropertyUIData identity_anonymous_ui_data_
;
169 NetworkPropertyUIData save_credentials_ui_data_
;
170 NetworkPropertyUIData passphrase_ui_data_
;
172 views::Textfield
* ssid_textfield_
;
173 scoped_ptr
<internal::EAPMethodComboboxModel
> eap_method_combobox_model_
;
174 views::Combobox
* eap_method_combobox_
;
175 views::Label
* phase_2_auth_label_
;
176 scoped_ptr
<internal::Phase2AuthComboboxModel
> phase_2_auth_combobox_model_
;
177 views::Combobox
* phase_2_auth_combobox_
;
178 views::Label
* user_cert_label_
;
179 scoped_ptr
<internal::UserCertComboboxModel
> user_cert_combobox_model_
;
180 views::Combobox
* user_cert_combobox_
;
181 views::Label
* server_ca_cert_label_
;
182 scoped_ptr
<internal::ServerCACertComboboxModel
>
183 server_ca_cert_combobox_model_
;
184 views::Combobox
* server_ca_cert_combobox_
;
185 views::Label
* subject_match_label_
;
186 views::Textfield
* subject_match_textfield_
;
187 views::Label
* identity_label_
;
188 views::Textfield
* identity_textfield_
;
189 views::Label
* identity_anonymous_label_
;
190 views::Textfield
* identity_anonymous_textfield_
;
191 views::Checkbox
* save_credentials_checkbox_
;
192 views::Checkbox
* share_network_checkbox_
;
193 views::Label
* shared_network_label_
;
194 scoped_ptr
<internal::SecurityComboboxModel
> security_combobox_model_
;
195 views::Combobox
* security_combobox_
;
196 views::Label
* passphrase_label_
;
197 PassphraseTextfield
* passphrase_textfield_
;
198 views::ToggleImageButton
* passphrase_visible_button_
;
199 views::Label
* error_label_
;
201 base::WeakPtrFactory
<WifiConfigView
> weak_ptr_factory_
;
203 DISALLOW_COPY_AND_ASSIGN(WifiConfigView
);
206 } // namespace chromeos
208 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_WIFI_CONFIG_VIEW_H_