Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / chromeos / options / vpn_config_view.h
blob5ef9df405835a6d09e064799b354403277c78025
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_
8 #include <string>
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"
22 namespace base {
23 class DictionaryValue;
26 namespace views {
27 class Checkbox;
28 class GridLayout;
29 class Label;
32 namespace chromeos {
34 class NetworkState;
36 namespace internal {
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 {
48 public:
49 VPNConfigView(NetworkConfigView* parent, const std::string& service_path);
50 virtual ~VPNConfigView();
52 // views::TextfieldController:
53 virtual void ContentsChanged(views::Textfield* sender,
54 const base::string16& new_contents) override;
55 virtual bool HandleKeyEvent(views::Textfield* sender,
56 const ui::KeyEvent& key_event) override;
58 // views::ButtonListener:
59 virtual void ButtonPressed(views::Button* sender,
60 const ui::Event& event) override;
62 // views::ComboboxListener:
63 virtual void OnPerformAction(views::Combobox* combobox) override;
65 // CertLibrary::Observer:
66 virtual void OnCertificatesLoaded(bool initial_load) override;
68 // ChildNetworkConfigView:
69 virtual base::string16 GetTitle() const override;
70 virtual views::View* GetInitiallyFocusedView() override;
71 virtual bool CanLogin() override;
72 virtual bool Login() override;
73 virtual void Cancel() override;
74 virtual void InitFocus() override;
76 private:
77 // Initializes data members and create UI controls.
78 void Init();
80 // Callback to initialize fields from uncached network properties.
81 void InitFromProperties(const std::string& service_path,
82 const base::DictionaryValue& dictionary);
83 void ParseUIProperties(const NetworkState* vpn);
84 void GetPropertiesError(const std::string& error_name,
85 scoped_ptr<base::DictionaryValue> error_data);
87 // Fill in |properties| with the properties for the selected client (user)
88 // certificate or empty properties if no client cert is required.
89 void SetUserCertProperties(chromeos::client_cert::ConfigType client_cert_type,
90 base::DictionaryValue* properties) const;
92 // Helper function to set configurable properties.
93 void SetConfigProperties(base::DictionaryValue* properties);
95 // Set and update all control values.
96 void Refresh();
98 // Update various controls.
99 void UpdateControlsToEnable();
100 void UpdateControls();
101 void UpdateErrorLabel();
103 // Update state of the Login button.
104 void UpdateCanLogin();
106 // Returns true if there is at least one user certificate installed.
107 bool HaveUserCerts() const;
109 // Returns true if there is a selected user certificate and it is valid.
110 bool IsUserCertValid() const;
112 // Get text from input field.
113 const std::string GetTextFromField(views::Textfield* textfield,
114 bool trim_whitespace) const;
116 // Get passphrase from input field.
117 const std::string GetPassphraseFromField(
118 PassphraseTextfield* textfield) const;
120 // Convenience methods to get text from input field or cached VirtualNetwork.
121 const std::string GetService() const;
122 const std::string GetServer() const;
123 const std::string GetPSKPassphrase() const;
124 const std::string GetUsername() const;
125 const std::string GetUserPassphrase() const;
126 const std::string GetOTP() const;
127 const std::string GetGroupName() const;
128 const std::string GetServerCACertPEM() const;
129 bool GetSaveCredentials() const;
130 int GetProviderTypeIndex() const;
131 std::string GetProviderTypeString() const;
133 // Parses a VPN UI |property| from the given |network|. |key| is the property
134 // name within the type-specific VPN subdictionary named |dict_key|.
135 void ParseVPNUIProperty(const NetworkState* network,
136 const std::string& dict_key,
137 const std::string& key,
138 NetworkPropertyUIData* property_ui_data);
140 base::string16 service_name_from_server_;
141 bool service_text_modified_;
143 // Initialized in Init():
145 bool enable_psk_passphrase_;
146 bool enable_user_cert_;
147 bool enable_server_ca_cert_;
148 bool enable_otp_;
149 bool enable_group_name_;
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_;
159 int title_;
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_