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/strings/string16.h"
12 #include "chrome/browser/chromeos/options/cert_library.h"
13 #include "chrome/browser/chromeos/options/network_config_view.h"
14 #include "chrome/browser/chromeos/options/network_property_ui_data.h"
15 #include "chrome/browser/chromeos/options/passphrase_textfield.h"
16 #include "chromeos/network/client_cert_util.h"
17 #include "ui/views/controls/button/button.h"
18 #include "ui/views/controls/combobox/combobox_listener.h"
19 #include "ui/views/controls/textfield/textfield_controller.h"
20 #include "ui/views/view.h"
23 class DictionaryValue
;
37 class ProviderTypeComboboxModel
;
38 class VpnServerCACertComboboxModel
;
39 class VpnUserCertComboboxModel
;
42 // A dialog box to allow configuration of VPN connection.
43 class VPNConfigView
: public ChildNetworkConfigView
,
44 public views::TextfieldController
,
45 public views::ButtonListener
,
46 public views::ComboboxListener
,
47 public CertLibrary::Observer
{
49 VPNConfigView(NetworkConfigView
* parent
, const std::string
& service_path
);
50 ~VPNConfigView() override
;
52 // views::TextfieldController:
53 void ContentsChanged(views::Textfield
* sender
,
54 const base::string16
& new_contents
) override
;
55 bool HandleKeyEvent(views::Textfield
* sender
,
56 const ui::KeyEvent
& key_event
) override
;
58 // views::ButtonListener:
59 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
61 // views::ComboboxListener:
62 void OnPerformAction(views::Combobox
* combobox
) override
;
64 // CertLibrary::Observer:
65 void OnCertificatesLoaded(bool initial_load
) override
;
67 // ChildNetworkConfigView:
68 base::string16
GetTitle() const override
;
69 views::View
* GetInitiallyFocusedView() override
;
70 bool CanLogin() override
;
71 bool Login() override
;
72 void Cancel() override
;
73 void InitFocus() override
;
76 // Initializes data members and create UI controls.
79 // Callback to initialize fields from uncached network properties.
80 void InitFromProperties(const std::string
& service_path
,
81 const base::DictionaryValue
& dictionary
);
82 void ParseUIProperties(const NetworkState
* vpn
);
83 void GetPropertiesError(const std::string
& error_name
,
84 scoped_ptr
<base::DictionaryValue
> error_data
);
86 // Fill in |properties| with the properties for the selected client (user)
87 // certificate or empty properties if no client cert is required.
88 void SetUserCertProperties(chromeos::client_cert::ConfigType client_cert_type
,
89 base::DictionaryValue
* properties
) const;
91 // Helper function to set configurable properties.
92 void SetConfigProperties(base::DictionaryValue
* properties
);
94 // Set and update all control values.
97 // Update various controls.
98 void UpdateControlsToEnable();
99 void UpdateControls();
100 void UpdateErrorLabel();
102 // Update state of the Login button.
103 void UpdateCanLogin();
105 // Returns true if there is at least one user certificate installed.
106 bool HaveUserCerts() const;
108 // Returns true if there is a selected user certificate and it is valid.
109 bool IsUserCertValid() const;
111 // Get text from input field.
112 const std::string
GetTextFromField(views::Textfield
* textfield
,
113 bool trim_whitespace
) const;
115 // Get passphrase from input field.
116 const std::string
GetPassphraseFromField(
117 PassphraseTextfield
* textfield
) const;
119 // Convenience methods to get text from input field or cached VirtualNetwork.
120 const std::string
GetService() const;
121 const std::string
GetServer() const;
122 const std::string
GetPSKPassphrase() const;
123 const std::string
GetUsername() const;
124 const std::string
GetUserPassphrase() const;
125 const std::string
GetOTP() const;
126 const std::string
GetGroupName() const;
127 const std::string
GetServerCACertPEM() const;
128 bool GetSaveCredentials() const;
129 int GetProviderTypeIndex() const;
130 std::string
GetProviderTypeString() const;
132 // Parses a VPN UI |property| from the given |network|. |key| is the property
133 // name within the type-specific VPN subdictionary named |dict_key|.
134 void ParseVPNUIProperty(const NetworkState
* network
,
135 const std::string
& dict_key
,
136 const std::string
& key
,
137 NetworkPropertyUIData
* property_ui_data
);
139 base::string16 service_name_from_server_
;
140 bool service_text_modified_
;
142 // Initialized in Init():
144 bool enable_psk_passphrase_
;
145 bool enable_user_cert_
;
146 bool enable_server_ca_cert_
;
148 bool enable_group_name_
;
149 bool user_passphrase_required_
;
151 NetworkPropertyUIData ca_cert_ui_data_
;
152 NetworkPropertyUIData psk_passphrase_ui_data_
;
153 NetworkPropertyUIData user_cert_ui_data_
;
154 NetworkPropertyUIData username_ui_data_
;
155 NetworkPropertyUIData user_passphrase_ui_data_
;
156 NetworkPropertyUIData group_name_ui_data_
;
157 NetworkPropertyUIData save_credentials_ui_data_
;
161 views::GridLayout
* layout_
;
162 views::Textfield
* server_textfield_
;
163 views::Label
* service_text_
;
164 views::Textfield
* service_textfield_
;
165 scoped_ptr
<internal::ProviderTypeComboboxModel
> provider_type_combobox_model_
;
166 views::Combobox
* provider_type_combobox_
;
167 views::Label
* provider_type_text_label_
;
168 views::Label
* psk_passphrase_label_
;
169 PassphraseTextfield
* psk_passphrase_textfield_
;
170 views::Label
* user_cert_label_
;
171 scoped_ptr
<internal::VpnUserCertComboboxModel
> user_cert_combobox_model_
;
172 views::Combobox
* user_cert_combobox_
;
173 views::Label
* server_ca_cert_label_
;
174 scoped_ptr
<internal::VpnServerCACertComboboxModel
>
175 server_ca_cert_combobox_model_
;
176 views::Combobox
* server_ca_cert_combobox_
;
177 views::Textfield
* username_textfield_
;
178 PassphraseTextfield
* user_passphrase_textfield_
;
179 views::Label
* otp_label_
;
180 views::Textfield
* otp_textfield_
;
181 views::Label
* group_name_label_
;
182 views::Textfield
* group_name_textfield_
;
183 views::Checkbox
* save_credentials_checkbox_
;
184 views::Label
* error_label_
;
186 // Cached VPN properties, only set when configuring an existing network.
187 int provider_type_index_
;
188 std::string ca_cert_pem_
;
189 std::string client_cert_id_
;
191 base::WeakPtrFactory
<VPNConfigView
> weak_ptr_factory_
;
193 DISALLOW_COPY_AND_ASSIGN(VPNConfigView
);
196 } // namespace chromeos
198 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_