Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / options / wifi_config_view.h
blob448299749e98ee51164a323b9e9b7d29da681621
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_
8 #include <string>
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"
26 namespace views {
27 class Checkbox;
28 class Label;
29 class ToggleImageButton;
32 namespace chromeos {
34 class NetworkState;
35 class PassphraseTextfield;
37 namespace internal {
38 class EAPMethodComboboxModel;
39 class Phase2AuthComboboxModel;
40 class SecurityComboboxModel;
41 class ServerCACertComboboxModel;
42 class UserCertComboboxModel;
45 // A dialog box for configuring Wifi and Ethernet networks
47 class WifiConfigView : public ChildNetworkConfigView,
48 public views::TextfieldController,
49 public views::ButtonListener,
50 public views::ComboboxListener,
51 public CertLibrary::Observer,
52 public NetworkStateHandlerObserver {
53 public:
54 // If |service_path| is not empty it identifies the network to be configured.
55 // Otherwise |show_8021x| determines whether or not to show the 'advanced'
56 // 8021x configuration UI for a hidden WiFi network.
57 WifiConfigView(NetworkConfigView* parent,
58 const std::string& service_path,
59 bool show_8021x);
60 ~WifiConfigView() override;
62 // views::TextfieldController
63 void ContentsChanged(views::Textfield* sender,
64 const base::string16& new_contents) override;
65 bool HandleKeyEvent(views::Textfield* sender,
66 const ui::KeyEvent& key_event) override;
68 // views::ButtonListener
69 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
71 // views::ComboboxListener
72 void OnPerformAction(views::Combobox* combobox) override;
74 // CertLibrary::Observer
75 void OnCertificatesLoaded(bool initial_load) override;
77 // ChildNetworkConfigView
78 base::string16 GetTitle() const override;
79 views::View* GetInitiallyFocusedView() override;
80 bool CanLogin() override;
81 bool Login() override;
82 void Cancel() override;
83 void InitFocus() override;
84 bool IsConfigureDialog() override;
86 // NetworkStateHandlerObserver
87 void NetworkPropertiesUpdated(const NetworkState* network) override;
89 // Parses a UI |property| from the ONC associated with |network|. |key|
90 // is the property name within the ONC dictionary.
91 static void ParseUIProperty(NetworkPropertyUIData* property_ui_data,
92 const NetworkState* network,
93 const std::string& key);
95 // Parses an EAP UI |property| from the ONC associated with |network|.
96 // |key| is the property name within the ONC EAP dictionary.
97 static void ParseEAPUIProperty(NetworkPropertyUIData* property_ui_data,
98 const NetworkState* network,
99 const std::string& key);
101 private:
102 friend class internal::UserCertComboboxModel;
104 // This will initialize the view depending on whether an existing network
105 // is being configured, the type of network, and the security model (i.e.
106 // simple password encryption or 802.1x).
107 void Init(bool show_8021x);
109 // Callback to initialize fields from uncached network properties.
110 void InitFromProperties(bool show_8021x,
111 const std::string& service_path,
112 const base::DictionaryValue& dictionary);
114 // Get input values.
115 std::string GetSsid() const;
116 std::string GetPassphrase() const;
117 bool GetSaveCredentials() const;
118 bool GetShareNetwork(bool share_default) const;
120 // Get various 802.1X EAP values from the widgets.
121 std::string GetEapMethod() const;
122 std::string GetEapPhase2Auth() const;
123 std::string GetEapServerCaCertPEM() const;
124 bool GetEapUseSystemCas() const;
125 std::string GetEapSubjectMatch() const;
126 std::string GetEapClientCertPkcs11Id() const;
127 std::string GetEapIdentity() const;
128 std::string GetEapAnonymousIdentity() const;
130 // Fill in |properties| with the properties for the selected client
131 // certificate or empty properties if no client cert is required.
132 void SetEapClientCertProperties(base::DictionaryValue* properties) const;
134 // Fill in |properties| with the appropriate values. If |configured| is
135 // true then this is for an already configured network.
136 void SetEapProperties(base::DictionaryValue* properties,
137 bool configured);
139 // Returns true if the EAP method requires a user certificate.
140 bool UserCertRequired() const;
142 // Returns true if at least one user certificate is installed.
143 bool HaveUserCerts() const;
145 // Returns true if there is a selected user certificate and it is valid.
146 bool IsUserCertValid() const;
148 // Returns true if the phase 2 auth is relevant.
149 bool Phase2AuthActive() const;
151 // Returns whether the current configuration requires a passphrase.
152 bool PassphraseActive() const;
154 // Returns true if a user cert should be selected.
155 bool UserCertActive() const;
157 // Returns true if a CA cert selection should be allowed.
158 bool CaCertActive() const;
160 // Updates state of the Login button.
161 void UpdateDialogButtons();
163 // Enable/Disable EAP fields as appropriate based on selected EAP method.
164 void RefreshEapFields();
166 // Enable/Disable "share this network" checkbox.
167 void RefreshShareCheckbox();
169 // Updates the error text label.
170 void UpdateErrorLabel();
172 // Helper method, returns NULL if |service_path_| is empty, otherwise returns
173 // the NetworkState* associated with |service_path_| or NULL if none exists.
174 const NetworkState* GetNetworkState() const;
176 NetworkPropertyUIData eap_method_ui_data_;
177 NetworkPropertyUIData phase_2_auth_ui_data_;
178 NetworkPropertyUIData user_cert_ui_data_;
179 NetworkPropertyUIData server_ca_cert_ui_data_;
180 NetworkPropertyUIData identity_ui_data_;
181 NetworkPropertyUIData identity_anonymous_ui_data_;
182 NetworkPropertyUIData save_credentials_ui_data_;
183 NetworkPropertyUIData passphrase_ui_data_;
185 views::Textfield* ssid_textfield_;
186 scoped_ptr<internal::EAPMethodComboboxModel> eap_method_combobox_model_;
187 views::Combobox* eap_method_combobox_;
188 views::Label* phase_2_auth_label_;
189 scoped_ptr<internal::Phase2AuthComboboxModel> phase_2_auth_combobox_model_;
190 views::Combobox* phase_2_auth_combobox_;
191 views::Label* user_cert_label_;
192 scoped_ptr<internal::UserCertComboboxModel> user_cert_combobox_model_;
193 views::Combobox* user_cert_combobox_;
194 views::Label* server_ca_cert_label_;
195 scoped_ptr<internal::ServerCACertComboboxModel>
196 server_ca_cert_combobox_model_;
197 views::Combobox* server_ca_cert_combobox_;
198 views::Label* subject_match_label_;
199 views::Textfield* subject_match_textfield_;
200 views::Label* identity_label_;
201 views::Textfield* identity_textfield_;
202 views::Label* identity_anonymous_label_;
203 views::Textfield* identity_anonymous_textfield_;
204 views::Checkbox* save_credentials_checkbox_;
205 views::Checkbox* share_network_checkbox_;
206 views::Label* shared_network_label_;
207 scoped_ptr<internal::SecurityComboboxModel> security_combobox_model_;
208 views::Combobox* security_combobox_;
209 views::Label* passphrase_label_;
210 PassphraseTextfield* passphrase_textfield_;
211 views::ToggleImageButton* passphrase_visible_button_;
212 views::Label* error_label_;
214 base::WeakPtrFactory<WifiConfigView> weak_ptr_factory_;
216 DISALLOW_COPY_AND_ASSIGN(WifiConfigView);
219 } // namespace chromeos
221 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_WIFI_CONFIG_VIEW_H_