OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ |
6 #define CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ | 6 #define CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "chrome/browser/chromeos/cros/cert_library.h" | 12 #include "chrome/browser/chromeos/cros/cert_library.h" |
13 #include "chrome/browser/chromeos/cros/network_property_ui_data.h" | 13 #include "chrome/browser/chromeos/cros/network_property_ui_data.h" |
14 #include "chrome/browser/chromeos/options/network_config_view.h" | 14 #include "chrome/browser/chromeos/options/network_config_view.h" |
15 #include "chrome/browser/chromeos/options/passphrase_textfield.h" | 15 #include "chrome/browser/chromeos/options/passphrase_textfield.h" |
16 #include "ui/views/controls/button/button.h" | 16 #include "ui/views/controls/button/button.h" |
17 #include "ui/views/controls/combobox/combobox_listener.h" | 17 #include "ui/views/controls/combobox/combobox_listener.h" |
18 #include "ui/views/controls/textfield/textfield_controller.h" | 18 #include "ui/views/controls/textfield/textfield_controller.h" |
19 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
20 | 20 |
| 21 namespace base { |
| 22 class DictionaryValue; |
| 23 } |
| 24 |
21 namespace views { | 25 namespace views { |
22 class Checkbox; | 26 class Checkbox; |
| 27 class GridLayout; |
23 class Label; | 28 class Label; |
24 } | 29 } |
25 | 30 |
26 namespace chromeos { | 31 namespace chromeos { |
27 | 32 |
| 33 class NetworkState; |
| 34 |
28 namespace internal { | 35 namespace internal { |
29 class ProviderTypeComboboxModel; | 36 class ProviderTypeComboboxModel; |
30 class VpnServerCACertComboboxModel; | 37 class VpnServerCACertComboboxModel; |
31 class VpnUserCertComboboxModel; | 38 class VpnUserCertComboboxModel; |
32 } | 39 } |
33 | 40 |
34 // A dialog box to allow configuration of VPN connection. | 41 // A dialog box to allow configuration of VPN connection. |
35 class VPNConfigView : public ChildNetworkConfigView, | 42 class VPNConfigView : public ChildNetworkConfigView, |
36 public views::TextfieldController, | 43 public views::TextfieldController, |
37 public views::ButtonListener, | 44 public views::ButtonListener, |
38 public views::ComboboxListener, | 45 public views::ComboboxListener, |
39 public CertLibrary::Observer { | 46 public CertLibrary::Observer { |
40 public: | 47 public: |
41 VPNConfigView(NetworkConfigView* parent, VirtualNetwork* vpn); | 48 VPNConfigView(NetworkConfigView* parent, const std::string& service_path); |
42 explicit VPNConfigView(NetworkConfigView* parent); | |
43 virtual ~VPNConfigView(); | 49 virtual ~VPNConfigView(); |
44 | 50 |
45 // views::TextfieldController: | 51 // views::TextfieldController: |
46 virtual void ContentsChanged(views::Textfield* sender, | 52 virtual void ContentsChanged(views::Textfield* sender, |
47 const string16& new_contents) OVERRIDE; | 53 const string16& new_contents) OVERRIDE; |
48 virtual bool HandleKeyEvent(views::Textfield* sender, | 54 virtual bool HandleKeyEvent(views::Textfield* sender, |
49 const ui::KeyEvent& key_event) OVERRIDE; | 55 const ui::KeyEvent& key_event) OVERRIDE; |
50 | 56 |
51 // views::ButtonListener: | 57 // views::ButtonListener: |
52 virtual void ButtonPressed(views::Button* sender, | 58 virtual void ButtonPressed(views::Button* sender, |
53 const ui::Event& event) OVERRIDE; | 59 const ui::Event& event) OVERRIDE; |
54 | 60 |
55 // views::ComboboxListener: | 61 // views::ComboboxListener: |
56 virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE; | 62 virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE; |
57 | 63 |
58 // CertLibrary::Observer: | 64 // CertLibrary::Observer: |
59 virtual void OnCertificatesLoaded(bool initial_load) OVERRIDE; | 65 virtual void OnCertificatesLoaded(bool initial_load) OVERRIDE; |
60 | 66 |
61 // ChildNetworkConfigView: | 67 // ChildNetworkConfigView: |
62 virtual string16 GetTitle() const OVERRIDE; | 68 virtual string16 GetTitle() const OVERRIDE; |
63 virtual views::View* GetInitiallyFocusedView() OVERRIDE; | 69 virtual views::View* GetInitiallyFocusedView() OVERRIDE; |
64 virtual bool CanLogin() OVERRIDE; | 70 virtual bool CanLogin() OVERRIDE; |
65 virtual bool Login() OVERRIDE; | 71 virtual bool Login() OVERRIDE; |
66 virtual void Cancel() OVERRIDE; | 72 virtual void Cancel() OVERRIDE; |
67 virtual void InitFocus() OVERRIDE; | 73 virtual void InitFocus() OVERRIDE; |
68 | 74 |
69 private: | 75 private: |
70 // Initializes data members and create UI controls. | 76 // Initializes data members and create UI controls. |
71 void Init(VirtualNetwork* vpn); | 77 void Init(); |
| 78 |
| 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); |
| 85 |
| 86 // Helper function to set configurable properties. |
| 87 void SetConfigProperties(base::DictionaryValue* properties); |
72 | 88 |
73 // Set and update all control values. | 89 // Set and update all control values. |
74 void Refresh(); | 90 void Refresh(); |
75 | 91 |
76 // Update various controls. | 92 // Update various controls. |
77 void UpdateControlsToEnable(); | 93 void UpdateControlsToEnable(); |
78 void UpdateControls(); | 94 void UpdateControls(); |
79 void UpdateErrorLabel(); | 95 void UpdateErrorLabel(); |
80 | 96 |
81 // Update state of the Login button. | 97 // Update state of the Login button. |
82 void UpdateCanLogin(); | 98 void UpdateCanLogin(); |
83 | 99 |
84 // Returns true if the provider type requires a user certificate. | |
85 bool UserCertRequired() const; | |
86 | |
87 // Returns true if there is at least one user certificate installed. | 100 // Returns true if there is at least one user certificate installed. |
88 bool HaveUserCerts() const; | 101 bool HaveUserCerts() const; |
89 | 102 |
90 // Returns true if there is a selected user certificate and it is valid. | 103 // Returns true if there is a selected user certificate and it is valid. |
91 bool IsUserCertValid() const; | 104 bool IsUserCertValid() const; |
92 | 105 |
93 // Get text from input field. | 106 // Get text from input field. |
94 const std::string GetTextFromField(views::Textfield* textfield, | 107 const std::string GetTextFromField(views::Textfield* textfield, |
95 bool trim_whitespace) const; | 108 bool trim_whitespace) const; |
96 | 109 |
97 // Get passphrase from input field. | 110 // Get passphrase from input field. |
98 const std::string GetPassphraseFromField( | 111 const std::string GetPassphraseFromField( |
99 PassphraseTextfield* textfield) const; | 112 PassphraseTextfield* textfield) const; |
100 | 113 |
101 // Convenience methods to get text from input field or cached VirtualNetwork. | 114 // Convenience methods to get text from input field or cached VirtualNetwork. |
102 const std::string GetService() const; | 115 const std::string GetService() const; |
103 const std::string GetServer() const; | 116 const std::string GetServer() const; |
104 const std::string GetPSKPassphrase() const; | 117 const std::string GetPSKPassphrase() const; |
105 const std::string GetUsername() const; | 118 const std::string GetUsername() const; |
106 const std::string GetUserPassphrase() const; | 119 const std::string GetUserPassphrase() const; |
107 const std::string GetOTP() const; | 120 const std::string GetOTP() const; |
108 const std::string GetGroupName() const; | 121 const std::string GetGroupName() const; |
109 const std::string GetServerCACertPEM() const; | 122 const std::string GetServerCACertPEM() const; |
110 const std::string GetUserCertID() const; | 123 const std::string GetUserCertID() const; |
111 bool GetSaveCredentials() const; | 124 bool GetSaveCredentials() const; |
| 125 int GetProviderTypeIndex() const; |
| 126 std::string GetProviderTypeString() const; |
112 | 127 |
113 // Parses a VPN UI |property| from the given |network|. |key| is the property | 128 // Parses a VPN UI |property| from the given |network|. |key| is the property |
114 // name within the type-specific VPN subdictionary named |dict_key|. | 129 // name within the type-specific VPN subdictionary named |dict_key|. |
115 void ParseVPNUIProperty(NetworkPropertyUIData* property_ui_data, | 130 void ParseVPNUIProperty(const NetworkState* network, |
116 Network* network, | |
117 const std::string& dict_key, | 131 const std::string& dict_key, |
118 const std::string& key); | 132 const std::string& key, |
| 133 NetworkPropertyUIData* property_ui_data); |
119 | 134 |
120 std::string server_hostname_; | |
121 string16 service_name_from_server_; | 135 string16 service_name_from_server_; |
122 bool service_text_modified_; | 136 bool service_text_modified_; |
123 | 137 |
124 // Initialized in Init(): | 138 // Initialized in Init(): |
125 | 139 |
126 ProviderType provider_type_; | |
127 | |
128 bool enable_psk_passphrase_; | 140 bool enable_psk_passphrase_; |
129 bool enable_user_cert_; | 141 bool enable_user_cert_; |
130 bool enable_server_ca_cert_; | 142 bool enable_server_ca_cert_; |
131 bool enable_otp_; | 143 bool enable_otp_; |
132 bool enable_group_name_; | 144 bool enable_group_name_; |
133 | 145 |
134 NetworkPropertyUIData ca_cert_ui_data_; | 146 NetworkPropertyUIData ca_cert_ui_data_; |
135 NetworkPropertyUIData psk_passphrase_ui_data_; | 147 NetworkPropertyUIData psk_passphrase_ui_data_; |
136 NetworkPropertyUIData user_cert_ui_data_; | 148 NetworkPropertyUIData user_cert_ui_data_; |
137 NetworkPropertyUIData username_ui_data_; | 149 NetworkPropertyUIData username_ui_data_; |
138 NetworkPropertyUIData user_passphrase_ui_data_; | 150 NetworkPropertyUIData user_passphrase_ui_data_; |
139 NetworkPropertyUIData group_name_ui_data_; | 151 NetworkPropertyUIData group_name_ui_data_; |
140 NetworkPropertyUIData save_credentials_ui_data_; | 152 NetworkPropertyUIData save_credentials_ui_data_; |
141 | 153 |
142 int title_; | 154 int title_; |
143 | 155 |
| 156 views::GridLayout* layout_; |
144 views::Textfield* server_textfield_; | 157 views::Textfield* server_textfield_; |
145 views::Label* service_text_; | 158 views::Label* service_text_; |
146 views::Textfield* service_textfield_; | 159 views::Textfield* service_textfield_; |
147 scoped_ptr<internal::ProviderTypeComboboxModel> provider_type_combobox_model_; | 160 scoped_ptr<internal::ProviderTypeComboboxModel> provider_type_combobox_model_; |
148 views::Combobox* provider_type_combobox_; | 161 views::Combobox* provider_type_combobox_; |
149 views::Label* provider_type_text_label_; | 162 views::Label* provider_type_text_label_; |
150 views::Label* psk_passphrase_label_; | 163 views::Label* psk_passphrase_label_; |
151 PassphraseTextfield* psk_passphrase_textfield_; | 164 PassphraseTextfield* psk_passphrase_textfield_; |
152 views::Label* user_cert_label_; | 165 views::Label* user_cert_label_; |
153 scoped_ptr<internal::VpnUserCertComboboxModel> user_cert_combobox_model_; | 166 scoped_ptr<internal::VpnUserCertComboboxModel> user_cert_combobox_model_; |
154 views::Combobox* user_cert_combobox_; | 167 views::Combobox* user_cert_combobox_; |
155 views::Label* server_ca_cert_label_; | 168 views::Label* server_ca_cert_label_; |
156 scoped_ptr<internal::VpnServerCACertComboboxModel> | 169 scoped_ptr<internal::VpnServerCACertComboboxModel> |
157 server_ca_cert_combobox_model_; | 170 server_ca_cert_combobox_model_; |
158 views::Combobox* server_ca_cert_combobox_; | 171 views::Combobox* server_ca_cert_combobox_; |
159 views::Textfield* username_textfield_; | 172 views::Textfield* username_textfield_; |
160 PassphraseTextfield* user_passphrase_textfield_; | 173 PassphraseTextfield* user_passphrase_textfield_; |
161 views::Label* otp_label_; | 174 views::Label* otp_label_; |
162 views::Textfield* otp_textfield_; | 175 views::Textfield* otp_textfield_; |
163 views::Label* group_name_label_; | 176 views::Label* group_name_label_; |
164 views::Textfield* group_name_textfield_; | 177 views::Textfield* group_name_textfield_; |
165 views::Checkbox* save_credentials_checkbox_; | 178 views::Checkbox* save_credentials_checkbox_; |
166 views::Label* error_label_; | 179 views::Label* error_label_; |
167 | 180 |
| 181 // Cached VPN properties, only set when configuring an existing network. |
| 182 int provider_type_index_; |
| 183 std::string ca_cert_pem_; |
| 184 std::string client_cert_id_; |
| 185 |
| 186 base::WeakPtrFactory<VPNConfigView> weak_ptr_factory_; |
| 187 |
168 DISALLOW_COPY_AND_ASSIGN(VPNConfigView); | 188 DISALLOW_COPY_AND_ASSIGN(VPNConfigView); |
169 }; | 189 }; |
170 | 190 |
171 } // namespace chromeos | 191 } // namespace chromeos |
172 | 192 |
173 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ | 193 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ |
OLD | NEW |