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/cros/cert_library.h" 16#include "chrome/browser/chromeos/cros/network_property_ui_data.h" 17#include "chrome/browser/chromeos/options/network_config_view.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 26namespace views { 27class Checkbox; 28class Label; 29class ToggleImageButton; 30} 31 32namespace chromeos { 33 34class NetworkState; 35 36namespace internal { 37class EAPMethodComboboxModel; 38class Phase2AuthComboboxModel; 39class SecurityComboboxModel; 40class ServerCACertComboboxModel; 41class UserCertComboboxModel; 42} 43 44// A dialog box for showing a password textfield. 45class WifiConfigView : public ChildNetworkConfigView, 46 public views::TextfieldController, 47 public views::ButtonListener, 48 public views::ComboboxListener, 49 public CertLibrary::Observer, 50 public NetworkStateHandlerObserver { 51 public: 52 WifiConfigView(NetworkConfigView* parent, 53 const std::string& service_path, 54 bool show_8021x); 55 virtual ~WifiConfigView(); 56 57 // views::TextfieldController 58 virtual void ContentsChanged(views::Textfield* sender, 59 const string16& new_contents) OVERRIDE; 60 virtual bool HandleKeyEvent(views::Textfield* sender, 61 const ui::KeyEvent& key_event) OVERRIDE; 62 63 // views::ButtonListener 64 virtual void ButtonPressed(views::Button* sender, 65 const ui::Event& event) OVERRIDE; 66 67 // views::ComboboxListener 68 virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE; 69 70 // CertLibrary::Observer 71 virtual void OnCertificatesLoaded(bool initial_load) OVERRIDE; 72 73 // ChildNetworkConfigView 74 virtual string16 GetTitle() const OVERRIDE; 75 virtual views::View* GetInitiallyFocusedView() OVERRIDE; 76 virtual bool CanLogin() OVERRIDE; 77 virtual bool Login() OVERRIDE; 78 virtual void Cancel() OVERRIDE; 79 virtual void InitFocus() OVERRIDE; 80 81 // NetworkStateHandlerObserver 82 virtual void NetworkPropertiesUpdated(const NetworkState* network) OVERRIDE; 83 84 // Parses a WiFi UI |property| from the ONC associated with |network|. |key| 85 // is the property name within the ONC WiFi dictionary. 86 static void ParseWiFiUIProperty(NetworkPropertyUIData* property_ui_data, 87 const NetworkState* network, 88 const std::string& key); 89 90 // Parses a WiFi EAP UI |property| from the ONC associated with |network|. 91 // |key| is the property name within the ONC WiFi.EAP dictionary. 92 static void ParseWiFiEAPUIProperty(NetworkPropertyUIData* property_ui_data, 93 const NetworkState* network, 94 const std::string& key); 95 96 private: 97 friend class internal::UserCertComboboxModel; 98 99 // Initializes UI. If |show_8021x| includes 802.1x config options. 100 void Init(bool show_8021x); 101 102 // Callback to initialize fields from uncached network properties. 103 void InitFromProperties(bool show_8021x, 104 const std::string& service_path, 105 const base::DictionaryValue& dictionary); 106 107 // Get input values. 108 std::string GetSsid() const; 109 std::string GetPassphrase() const; 110 bool GetSaveCredentials() const; 111 bool GetShareNetwork(bool share_default) const; 112 113 // Get various 802.1X EAP values from the widgets. 114 std::string GetEapMethod() const; 115 std::string GetEapPhase2Auth() const; 116 std::string GetEapServerCaCertPEM() const; 117 bool GetEapUseSystemCas() const; 118 std::string GetEapClientCertPkcs11Id() const; 119 std::string GetEapIdentity() const; 120 std::string GetEapAnonymousIdentity() const; 121 122 // Fill in |properties| with the appropriate values. 123 void SetEapProperties(base::DictionaryValue* properties); 124 125 // Returns true if the EAP method requires a user certificate. 126 bool UserCertRequired() const; 127 128 // Returns true if at least one user certificate is installed. 129 bool HaveUserCerts() const; 130 131 // Returns true if there is a selected user certificate and it is valid. 132 bool IsUserCertValid() const; 133 134 // Returns true if the phase 2 auth is relevant. 135 bool Phase2AuthActive() const; 136 137 // Returns whether the current configuration requires a passphrase. 138 bool PassphraseActive() const; 139 140 // Returns true if a user cert should be selected. 141 bool UserCertActive() const; 142 143 // Returns true if a CA cert selection should be allowed. 144 bool CaCertActive() const; 145 146 // Updates state of the Login button. 147 void UpdateDialogButtons(); 148 149 // Enable/Disable EAP fields as appropriate based on selected EAP method. 150 void RefreshEapFields(); 151 152 // Enable/Disable "share this network" checkbox. 153 void RefreshShareCheckbox(); 154 155 // Updates the error text label. 156 void UpdateErrorLabel(); 157 158 NetworkPropertyUIData eap_method_ui_data_; 159 NetworkPropertyUIData phase_2_auth_ui_data_; 160 NetworkPropertyUIData user_cert_ui_data_; 161 NetworkPropertyUIData server_ca_cert_ui_data_; 162 NetworkPropertyUIData identity_ui_data_; 163 NetworkPropertyUIData identity_anonymous_ui_data_; 164 NetworkPropertyUIData save_credentials_ui_data_; 165 NetworkPropertyUIData passphrase_ui_data_; 166 167 views::Textfield* ssid_textfield_; 168 scoped_ptr<internal::EAPMethodComboboxModel> eap_method_combobox_model_; 169 views::Combobox* eap_method_combobox_; 170 views::Label* phase_2_auth_label_; 171 scoped_ptr<internal::Phase2AuthComboboxModel> phase_2_auth_combobox_model_; 172 views::Combobox* phase_2_auth_combobox_; 173 views::Label* user_cert_label_; 174 scoped_ptr<internal::UserCertComboboxModel> user_cert_combobox_model_; 175 views::Combobox* user_cert_combobox_; 176 views::Label* server_ca_cert_label_; 177 scoped_ptr<internal::ServerCACertComboboxModel> 178 server_ca_cert_combobox_model_; 179 views::Combobox* server_ca_cert_combobox_; 180 views::Label* identity_label_; 181 views::Textfield* identity_textfield_; 182 views::Label* identity_anonymous_label_; 183 views::Textfield* identity_anonymous_textfield_; 184 views::Checkbox* save_credentials_checkbox_; 185 views::Checkbox* share_network_checkbox_; 186 views::Label* shared_network_label_; 187 scoped_ptr<internal::SecurityComboboxModel> security_combobox_model_; 188 views::Combobox* security_combobox_; 189 views::Label* passphrase_label_; 190 views::Textfield* passphrase_textfield_; 191 views::ToggleImageButton* passphrase_visible_button_; 192 views::Label* error_label_; 193 194 base::WeakPtrFactory<WifiConfigView> weak_ptr_factory_; 195 196 DISALLOW_COPY_AND_ASSIGN(WifiConfigView); 197}; 198 199} // namespace chromeos 200 201#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_WIFI_CONFIG_VIEW_H_ 202