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_VPN_CONFIG_VIEW_H_
6 #define CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/string16.h"
12 #include "chrome/browser/chromeos/cros/cert_library.h"
13 #include "chrome/browser/chromeos/options/network_config_view.h"
14 #include "chrome/browser/chromeos/options/passphrase_textfield.h"
15 #include "ui/views/controls/button/button.h"
16 #include "ui/views/controls/combobox/combobox_listener.h"
17 #include "ui/views/controls/textfield/textfield_controller.h"
18 #include "ui/views/view.h"
28 class ProviderTypeComboboxModel
;
29 class VpnServerCACertComboboxModel
;
30 class VpnUserCertComboboxModel
;
33 // A dialog box to allow configuration of VPN connection.
34 class VPNConfigView
: public ChildNetworkConfigView
,
35 public views::TextfieldController
,
36 public views::ButtonListener
,
37 public views::ComboboxListener
,
38 public CertLibrary::Observer
{
40 VPNConfigView(NetworkConfigView
* parent
, VirtualNetwork
* vpn
);
41 explicit VPNConfigView(NetworkConfigView
* parent
);
42 virtual ~VPNConfigView();
44 // views::TextfieldController:
45 virtual void ContentsChanged(views::Textfield
* sender
,
46 const string16
& new_contents
) OVERRIDE
;
47 virtual bool HandleKeyEvent(views::Textfield
* sender
,
48 const ui::KeyEvent
& key_event
) OVERRIDE
;
50 // views::ButtonListener:
51 virtual void ButtonPressed(views::Button
* sender
,
52 const ui::Event
& event
) OVERRIDE
;
54 // views::ComboboxListener:
55 virtual void OnSelectedIndexChanged(views::Combobox
* combobox
) OVERRIDE
;
57 // CertLibrary::Observer:
58 virtual void OnCertificatesLoaded(bool initial_load
) OVERRIDE
;
60 // ChildNetworkConfigView:
61 virtual views::View
* GetInitiallyFocusedView() OVERRIDE
;
62 virtual bool CanLogin() OVERRIDE
;
63 virtual bool Login() OVERRIDE
;
64 virtual void Cancel() OVERRIDE
;
65 virtual void InitFocus() OVERRIDE
;
68 // Initializes data members and create UI controls.
69 void Init(VirtualNetwork
* vpn
);
71 // Set and update all control values.
74 // Update various controls.
75 void UpdateControlsToEnable();
76 void UpdateControls();
77 void UpdateErrorLabel();
79 // Update state of the Login button.
80 void UpdateCanLogin();
82 // Returns true if the provider type requires a user certificate.
83 bool UserCertRequired() const;
85 // Returns true if there is at least one user certificate installed.
86 bool HaveUserCerts() const;
88 // Returns true if there is a selected user certificate and it is valid.
89 bool IsUserCertValid() const;
91 // Get text from input field.
92 const std::string
GetTextFromField(views::Textfield
* textfield
,
93 bool trim_whitespace
) const;
95 // Get passphrase from input field.
96 const std::string
GetPassphraseFromField(
97 PassphraseTextfield
* textfield
) const;
99 // Convenience methods to get text from input field or cached VirtualNetwork.
100 const std::string
GetService() const;
101 const std::string
GetServer() const;
102 const std::string
GetPSKPassphrase() const;
103 const std::string
GetUsername() const;
104 const std::string
GetUserPassphrase() const;
105 const std::string
GetOTP() const;
106 const std::string
GetGroupName() const;
107 const std::string
GetServerCACertNssNickname() const;
108 const std::string
GetUserCertID() const;
109 bool GetSaveCredentials() const;
111 // Parses a VPN UI |property| from the given |network|. |key| is the property
112 // name within the type-specific VPN subdictionary named |dict_key|.
113 void ParseVPNUIProperty(NetworkPropertyUIData
* property_ui_data
,
115 const std::string
& dict_key
,
116 const std::string
& key
);
118 CertLibrary
* cert_library_
;
120 std::string server_hostname_
;
121 string16 service_name_from_server_
;
122 bool service_text_modified_
;
124 // Initialized in Init():
126 ProviderType provider_type_
;
128 bool enable_psk_passphrase_
;
129 bool enable_user_cert_
;
130 bool enable_server_ca_cert_
;
132 bool enable_group_name_
;
134 NetworkPropertyUIData ca_cert_ui_data_
;
135 NetworkPropertyUIData psk_passphrase_ui_data_
;
136 NetworkPropertyUIData user_cert_ui_data_
;
137 NetworkPropertyUIData username_ui_data_
;
138 NetworkPropertyUIData user_passphrase_ui_data_
;
139 NetworkPropertyUIData group_name_ui_data_
;
140 NetworkPropertyUIData save_credentials_ui_data_
;
142 views::Textfield
* server_textfield_
;
143 views::Label
* service_text_
;
144 views::Textfield
* service_textfield_
;
145 scoped_ptr
<internal::ProviderTypeComboboxModel
> provider_type_combobox_model_
;
146 views::Combobox
* provider_type_combobox_
;
147 views::Label
* provider_type_text_label_
;
148 views::Label
* psk_passphrase_label_
;
149 PassphraseTextfield
* psk_passphrase_textfield_
;
150 views::Label
* user_cert_label_
;
151 scoped_ptr
<internal::VpnUserCertComboboxModel
> user_cert_combobox_model_
;
152 views::Combobox
* user_cert_combobox_
;
153 views::Label
* server_ca_cert_label_
;
154 scoped_ptr
<internal::VpnServerCACertComboboxModel
>
155 server_ca_cert_combobox_model_
;
156 views::Combobox
* server_ca_cert_combobox_
;
157 views::Textfield
* username_textfield_
;
158 PassphraseTextfield
* user_passphrase_textfield_
;
159 views::Label
* otp_label_
;
160 views::Textfield
* otp_textfield_
;
161 views::Label
* group_name_label_
;
162 views::Textfield
* group_name_textfield_
;
163 views::Checkbox
* save_credentials_checkbox_
;
164 views::Label
* error_label_
;
166 DISALLOW_COPY_AND_ASSIGN(VPNConfigView
);
169 } // namespace chromeos
171 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_