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