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 #include "chrome/browser/chromeos/options/vpn_config_view.h" | 5 #include "chrome/browser/chromeos/options/vpn_config_view.h" |
6 | 6 |
7 #include "ash/system/chromeos/network/network_connect.h" | |
7 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/cros/network_library.h" | |
11 #include "chrome/browser/chromeos/enrollment_dialog_view.h" | 11 #include "chrome/browser/chromeos/enrollment_dialog_view.h" |
12 #include "chrome/browser/chromeos/options/network_connect.h" | |
12 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/common/net/x509_certificate_model.h" | 14 #include "chrome/common/net/x509_certificate_model.h" |
15 #include "chromeos/network/network_configuration_handler.h" | |
16 #include "chromeos/network/network_event_log.h" | |
17 #include "chromeos/network/network_state.h" | |
18 #include "chromeos/network/network_state_handler.h" | |
14 #include "chromeos/network/network_ui_data.h" | 19 #include "chromeos/network/network_ui_data.h" |
15 #include "chromeos/network/onc/onc_constants.h" | 20 #include "chromeos/network/onc/onc_constants.h" |
16 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
17 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
18 #include "grit/locale_settings.h" | 23 #include "grit/locale_settings.h" |
19 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
25 #include "third_party/cros_system_api/dbus/service_constants.h" | |
20 #include "ui/base/events/event.h" | 26 #include "ui/base/events/event.h" |
21 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/models/combobox_model.h" | 28 #include "ui/base/models/combobox_model.h" |
23 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/views/controls/button/checkbox.h" | 30 #include "ui/views/controls/button/checkbox.h" |
25 #include "ui/views/controls/combobox/combobox.h" | 31 #include "ui/views/controls/combobox/combobox.h" |
26 #include "ui/views/controls/label.h" | 32 #include "ui/views/controls/label.h" |
27 #include "ui/views/controls/textfield/textfield.h" | 33 #include "ui/views/controls/textfield/textfield.h" |
28 #include "ui/views/layout/grid_layout.h" | 34 #include "ui/views/layout/grid_layout.h" |
29 #include "ui/views/layout/layout_constants.h" | 35 #include "ui/views/layout/layout_constants.h" |
30 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
31 #include "ui/views/window/dialog_client_view.h" | 37 #include "ui/views/window/dialog_client_view.h" |
32 | 38 |
33 namespace { | 39 namespace { |
34 | 40 |
35 // Root CA certificates that are built into Chrome use this token name. | 41 // Root CA certificates that are built into Chrome use this token name. |
36 const char* const kRootCertificateTokenName = "Builtin Object Token"; | 42 const char* const kRootCertificateTokenName = "Builtin Object Token"; |
37 | 43 |
38 string16 ProviderTypeToString(chromeos::ProviderType type) { | 44 enum ProviderTypeComboboxIndex { |
pneubeck (no reviews)
2013/08/06 15:45:19
You are using this even if the combobox doesn't ex
stevenjb
2013/08/06 20:23:55
Removed 'Combobox'
| |
39 switch (type) { | 45 PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK = 0, |
40 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_PSK: | 46 PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT = 1, |
47 PROVIDER_TYPE_INDEX_OPEN_VPN = 2, | |
48 PROVIDER_TYPE_INDEX_MAX = 3, | |
49 }; | |
50 | |
51 string16 ProviderTypeIndexToString(int index) { | |
52 switch (index) { | |
53 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK: | |
41 return l10n_util::GetStringUTF16( | 54 return l10n_util::GetStringUTF16( |
42 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_PSK); | 55 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_PSK); |
43 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: | 56 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT: |
44 return l10n_util::GetStringUTF16( | 57 return l10n_util::GetStringUTF16( |
45 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_USER_CERT); | 58 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_USER_CERT); |
46 case chromeos::PROVIDER_TYPE_OPEN_VPN: | 59 case PROVIDER_TYPE_INDEX_OPEN_VPN: |
47 return l10n_util::GetStringUTF16( | 60 return l10n_util::GetStringUTF16( |
48 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_OPEN_VPN); | 61 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_OPEN_VPN); |
49 case chromeos::PROVIDER_TYPE_MAX: | |
50 break; | |
51 } | 62 } |
52 NOTREACHED(); | 63 NOTREACHED(); |
53 return string16(); | 64 return string16(); |
54 } | 65 } |
55 | 66 |
67 ProviderTypeComboboxIndex ProviderTypeToIndex( | |
68 const std::string& provider_type, | |
69 const std::string& client_cert_id) { | |
70 if (provider_type == flimflam::kProviderL2tpIpsec) { | |
71 if (!client_cert_id.empty()) | |
72 return PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT; | |
73 else | |
74 return PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK; | |
75 } else { | |
76 DCHECK(provider_type == flimflam::kProviderOpenVpn); | |
77 return PROVIDER_TYPE_INDEX_OPEN_VPN; | |
78 } | |
79 } | |
80 | |
56 // Translates the provider type to the name of the respective ONC dictionary | 81 // Translates the provider type to the name of the respective ONC dictionary |
57 // containing configuration data for the type. | 82 // containing configuration data for the type. |
58 std::string ProviderTypeToONCDictKey(chromeos::ProviderType type) { | 83 std::string ProviderTypeToONCDictKey(const std::string& provider_type) { |
59 switch (type) { | 84 if (provider_type == flimflam::kProviderL2tpIpsec) |
60 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_PSK: | 85 return chromeos::onc::vpn::kIPsec; |
61 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: | 86 if (provider_type == flimflam::kProviderOpenVpn) |
62 return chromeos::onc::vpn::kIPsec; | 87 return chromeos::onc::vpn::kOpenVPN; |
63 case chromeos::PROVIDER_TYPE_OPEN_VPN: | 88 NOTREACHED() << "Unhandled provider type " << provider_type; |
64 return chromeos::onc::vpn::kOpenVPN; | 89 return std::string(); |
65 case chromeos::PROVIDER_TYPE_MAX: | 90 } |
66 break; | |
67 } | |
68 | 91 |
69 NOTREACHED() << "Unhandled provider type " << type; | 92 void ShillError(const std::string& function, |
70 return std::string(); | 93 const std::string& error_name, |
94 scoped_ptr<base::DictionaryValue> error_data) { | |
95 NET_LOG_ERROR("Shill Error from VpnConfigView: " + error_name, function); | |
71 } | 96 } |
72 | 97 |
73 } // namespace | 98 } // namespace |
74 | 99 |
75 namespace chromeos { | 100 namespace chromeos { |
76 | 101 |
77 namespace internal { | 102 namespace internal { |
78 | 103 |
79 class ProviderTypeComboboxModel : public ui::ComboboxModel { | 104 class ProviderTypeComboboxModel : public ui::ComboboxModel { |
80 public: | 105 public: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 | 142 |
118 // ProviderTypeComboboxModel --------------------------------------------------- | 143 // ProviderTypeComboboxModel --------------------------------------------------- |
119 | 144 |
120 ProviderTypeComboboxModel::ProviderTypeComboboxModel() { | 145 ProviderTypeComboboxModel::ProviderTypeComboboxModel() { |
121 } | 146 } |
122 | 147 |
123 ProviderTypeComboboxModel::~ProviderTypeComboboxModel() { | 148 ProviderTypeComboboxModel::~ProviderTypeComboboxModel() { |
124 } | 149 } |
125 | 150 |
126 int ProviderTypeComboboxModel::GetItemCount() const { | 151 int ProviderTypeComboboxModel::GetItemCount() const { |
127 return PROVIDER_TYPE_MAX; | 152 return PROVIDER_TYPE_INDEX_MAX; |
128 } | 153 } |
129 | 154 |
130 string16 ProviderTypeComboboxModel::GetItemAt(int index) { | 155 string16 ProviderTypeComboboxModel::GetItemAt(int index) { |
131 ProviderType type = static_cast<ProviderType>(index); | 156 return ProviderTypeIndexToString(index); |
132 return ProviderTypeToString(type); | |
133 } | 157 } |
134 | 158 |
135 // VpnServerCACertComboboxModel ------------------------------------------------ | 159 // VpnServerCACertComboboxModel ------------------------------------------------ |
136 | 160 |
137 VpnServerCACertComboboxModel::VpnServerCACertComboboxModel() { | 161 VpnServerCACertComboboxModel::VpnServerCACertComboboxModel() { |
138 } | 162 } |
139 | 163 |
140 VpnServerCACertComboboxModel::~VpnServerCACertComboboxModel() { | 164 VpnServerCACertComboboxModel::~VpnServerCACertComboboxModel() { |
141 } | 165 } |
142 | 166 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 if (CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER) == 0) { | 210 if (CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER) == 0) { |
187 return l10n_util::GetStringUTF16( | 211 return l10n_util::GetStringUTF16( |
188 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED); | 212 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED); |
189 } | 213 } |
190 return CertLibrary::Get()->GetCertDisplayStringAt( | 214 return CertLibrary::Get()->GetCertDisplayStringAt( |
191 CertLibrary::CERT_TYPE_USER, index); | 215 CertLibrary::CERT_TYPE_USER, index); |
192 } | 216 } |
193 | 217 |
194 } // namespace internal | 218 } // namespace internal |
195 | 219 |
196 VPNConfigView::VPNConfigView(NetworkConfigView* parent, VirtualNetwork* vpn) | 220 VPNConfigView::VPNConfigView(NetworkConfigView* parent, |
197 : ChildNetworkConfigView(parent, vpn), | 221 const std::string& service_path) |
198 title_(0) { | 222 : ChildNetworkConfigView(parent, service_path), |
199 Init(vpn); | 223 service_text_modified_(false), |
200 } | 224 enable_psk_passphrase_(false), |
201 | 225 enable_user_cert_(false), |
202 VPNConfigView::VPNConfigView(NetworkConfigView* parent) | 226 enable_server_ca_cert_(false), |
203 : ChildNetworkConfigView(parent), | 227 enable_otp_(false), |
204 title_(0) { | 228 enable_group_name_(false), |
205 Init(NULL); | 229 title_(0), |
230 layout_(NULL), | |
231 server_textfield_(NULL), | |
232 service_text_(NULL), | |
233 service_textfield_(NULL), | |
234 provider_type_combobox_(NULL), | |
235 provider_type_text_label_(NULL), | |
236 psk_passphrase_label_(NULL), | |
237 psk_passphrase_textfield_(NULL), | |
238 user_cert_label_(NULL), | |
239 user_cert_combobox_(NULL), | |
240 server_ca_cert_label_(NULL), | |
241 server_ca_cert_combobox_(NULL), | |
242 username_textfield_(NULL), | |
243 user_passphrase_textfield_(NULL), | |
244 otp_label_(NULL), | |
245 otp_textfield_(NULL), | |
246 group_name_label_(NULL), | |
247 group_name_textfield_(NULL), | |
248 save_credentials_checkbox_(NULL), | |
249 error_label_(NULL) { | |
250 Init(); | |
206 } | 251 } |
207 | 252 |
208 VPNConfigView::~VPNConfigView() { | 253 VPNConfigView::~VPNConfigView() { |
209 CertLibrary::Get()->RemoveObserver(this); | 254 CertLibrary::Get()->RemoveObserver(this); |
210 } | 255 } |
211 | 256 |
212 string16 VPNConfigView::GetTitle() const { | 257 string16 VPNConfigView::GetTitle() const { |
213 DCHECK_NE(title_, 0); | 258 DCHECK_NE(title_, 0); |
214 return l10n_util::GetStringUTF16(title_); | 259 return l10n_util::GetStringUTF16(title_); |
215 } | 260 } |
(...skipping 10 matching lines...) Expand all Loading... | |
226 return psk_passphrase_textfield_; | 271 return psk_passphrase_textfield_; |
227 else if (user_cert_combobox_ && user_cert_combobox_->enabled()) | 272 else if (user_cert_combobox_ && user_cert_combobox_->enabled()) |
228 return user_cert_combobox_; | 273 return user_cert_combobox_; |
229 else if (server_ca_cert_combobox_ && server_ca_cert_combobox_->enabled()) | 274 else if (server_ca_cert_combobox_ && server_ca_cert_combobox_->enabled()) |
230 return server_ca_cert_combobox_; | 275 return server_ca_cert_combobox_; |
231 else | 276 else |
232 return NULL; | 277 return NULL; |
233 } | 278 } |
234 | 279 |
235 bool VPNConfigView::CanLogin() { | 280 bool VPNConfigView::CanLogin() { |
281 int provider_type_index = GetProviderTypeIndex(); | |
pneubeck (no reviews)
2013/08/06 15:45:19
move it to it's usage.
stevenjb
2013/08/06 20:23:55
Done.
| |
282 | |
236 // Username is always required. | 283 // Username is always required. |
237 if (GetUsername().empty()) | 284 if (GetUsername().empty()) |
238 return false; | 285 return false; |
239 | 286 |
240 // TODO(stevenjb): min kMinPassphraseLen length? | 287 // TODO(stevenjb): min kMinPassphraseLen length? |
241 if (service_path_.empty() && | 288 if (service_path_.empty() && |
242 (GetService().empty() || GetServer().empty())) | 289 (GetService().empty() || GetServer().empty())) |
243 return false; | 290 return false; |
244 | 291 |
245 // Block login if certs are required but user has none. | 292 // Block login if certs are required but user has none. |
246 if (UserCertRequired() && (!HaveUserCerts() || !IsUserCertValid())) | 293 bool cert_required = |
294 provider_type_index == PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT; | |
295 if (cert_required && (!HaveUserCerts() || !IsUserCertValid())) | |
247 return false; | 296 return false; |
248 | 297 |
249 return true; | 298 return true; |
250 } | 299 } |
251 | 300 |
252 void VPNConfigView::ContentsChanged(views::Textfield* sender, | 301 void VPNConfigView::ContentsChanged(views::Textfield* sender, |
253 const string16& new_contents) { | 302 const string16& new_contents) { |
254 if (sender == server_textfield_ && !service_text_modified_) { | 303 if (sender == server_textfield_ && !service_text_modified_) { |
255 // Set the service name to the server name up to '.', unless it has | 304 // Set the service name to the server name up to '.', unless it has |
256 // been explicitly set by the user. | 305 // been explicitly set by the user. |
(...skipping 19 matching lines...) Expand all Loading... | |
276 parent_->GetDialogClientView()->AcceptWindow(); | 325 parent_->GetDialogClientView()->AcceptWindow(); |
277 } | 326 } |
278 return false; | 327 return false; |
279 } | 328 } |
280 | 329 |
281 void VPNConfigView::ButtonPressed(views::Button* sender, | 330 void VPNConfigView::ButtonPressed(views::Button* sender, |
282 const ui::Event& event) { | 331 const ui::Event& event) { |
283 } | 332 } |
284 | 333 |
285 void VPNConfigView::OnSelectedIndexChanged(views::Combobox* combobox) { | 334 void VPNConfigView::OnSelectedIndexChanged(views::Combobox* combobox) { |
286 if (combobox == provider_type_combobox_) { | 335 UpdateControls(); |
287 provider_type_ = static_cast<ProviderType>(combobox->selected_index()); | |
288 UpdateControls(); | |
289 } else if (combobox == user_cert_combobox_ || | |
290 combobox == server_ca_cert_combobox_) { | |
291 // Do nothing. | |
292 } else { | |
293 NOTREACHED(); | |
294 } | |
295 UpdateErrorLabel(); | 336 UpdateErrorLabel(); |
296 UpdateCanLogin(); | 337 UpdateCanLogin(); |
297 } | 338 } |
298 | 339 |
299 void VPNConfigView::OnCertificatesLoaded(bool initial_load) { | 340 void VPNConfigView::OnCertificatesLoaded(bool initial_load) { |
300 Refresh(); | 341 Refresh(); |
301 } | 342 } |
302 | 343 |
303 bool VPNConfigView::Login() { | 344 bool VPNConfigView::Login() { |
304 NetworkLibrary* cros = NetworkLibrary::Get(); | |
305 if (service_path_.empty()) { | 345 if (service_path_.empty()) { |
306 NetworkLibrary::VPNConfigData config_data; | 346 base::DictionaryValue properties; |
307 switch (provider_type_) { | 347 // Identifying properties |
308 case PROVIDER_TYPE_L2TP_IPSEC_PSK: | 348 properties.SetStringWithoutPathExpansion( |
309 config_data.psk = GetPSKPassphrase(); | 349 flimflam::kTypeProperty, flimflam::kTypeVPN); |
310 config_data.username = GetUsername(); | 350 properties.SetStringWithoutPathExpansion( |
311 config_data.user_passphrase = GetUserPassphrase(); | 351 flimflam::kNameProperty, GetService()); |
312 config_data.group_name = GetGroupName(); | 352 properties.SetStringWithoutPathExpansion( |
313 break; | 353 flimflam::kProviderHostProperty, GetServer()); |
314 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: { | 354 properties.SetStringWithoutPathExpansion( |
315 config_data.server_ca_cert_pem = GetServerCACertPEM(); | 355 flimflam::kProviderTypeProperty, GetProviderTypeString()); |
316 config_data.client_cert_pkcs11_id = GetUserCertID(); | 356 |
317 config_data.username = GetUsername(); | 357 SetCredentials(&properties); |
318 config_data.user_passphrase = GetUserPassphrase(); | 358 ash::network_connect::CreateConfigurationAndConnect( |
319 config_data.group_name = GetGroupName(); | 359 &properties, false /* shared */); |
320 break; | 360 } else { |
321 } | 361 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> |
322 case PROVIDER_TYPE_OPEN_VPN: | 362 GetNetworkState(service_path_); |
323 config_data.server_ca_cert_pem = GetServerCACertPEM(); | 363 if (!vpn) { |
324 config_data.client_cert_pkcs11_id = GetUserCertID(); | 364 // Shill no longer knows about this network (edge case). |
325 config_data.username = GetUsername(); | 365 // TODO(stevenjb): Add notification for this. |
326 config_data.user_passphrase = GetUserPassphrase(); | 366 NET_LOG_ERROR("Network not found", service_path_); |
327 config_data.otp = GetOTP(); | 367 return true; // Close dialog |
328 break; | |
329 case PROVIDER_TYPE_MAX: | |
330 break; | |
331 } | 368 } |
332 config_data.save_credentials = GetSaveCredentials(); | 369 base::DictionaryValue properties; |
333 cros->ConnectToUnconfiguredVirtualNetwork( | 370 SetCredentials(&properties); |
334 GetService(), GetServer(), provider_type_, config_data); | 371 ash::network_connect::ConfigureNetworkAndConnect(service_path_, properties); |
335 } else { | |
336 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); | |
337 if (!vpn) { | |
338 // TODO(stevenjb): Add notification for this. | |
339 LOG(WARNING) << "VPN no longer exists: " << service_path_; | |
340 return true; // Close dialog. | |
341 } | |
342 switch (provider_type_) { | |
343 case PROVIDER_TYPE_L2TP_IPSEC_PSK: | |
344 vpn->SetL2TPIPsecPSKCredentials(GetPSKPassphrase(), | |
345 GetUsername(), | |
346 GetUserPassphrase(), | |
347 GetGroupName()); | |
348 break; | |
349 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: { | |
350 vpn->SetL2TPIPsecCertCredentials(GetUserCertID(), | |
351 GetUsername(), | |
352 GetUserPassphrase(), | |
353 GetGroupName()); | |
354 break; | |
355 } | |
356 case PROVIDER_TYPE_OPEN_VPN: { | |
357 vpn->SetOpenVPNCredentials(GetUserCertID(), | |
358 GetUsername(), | |
359 GetUserPassphrase(), | |
360 GetOTP()); | |
361 break; | |
362 } | |
363 case PROVIDER_TYPE_MAX: | |
364 break; | |
365 } | |
366 vpn->SetEnrollmentDelegate( | |
367 CreateEnrollmentDelegate(GetWidget()->GetNativeWindow(), | |
368 vpn->name(), | |
369 ProfileManager::GetLastUsedProfile())); | |
370 vpn->SetSaveCredentials(GetSaveCredentials()); | |
371 cros->ConnectToVirtualNetwork(vpn); | |
372 } | 372 } |
373 // Connection failures are responsible for updating the UI, including | |
374 // reopening dialogs. | |
375 return true; // Close dialog. | 373 return true; // Close dialog. |
376 } | 374 } |
377 | 375 |
378 void VPNConfigView::Cancel() { | 376 void VPNConfigView::Cancel() { |
379 } | 377 } |
380 | 378 |
381 void VPNConfigView::InitFocus() { | 379 void VPNConfigView::InitFocus() { |
382 views::View* view_to_focus = GetInitiallyFocusedView(); | 380 views::View* view_to_focus = GetInitiallyFocusedView(); |
383 if (view_to_focus) | 381 if (view_to_focus) |
384 view_to_focus->RequestFocus(); | 382 view_to_focus->RequestFocus(); |
385 } | 383 } |
386 | 384 |
387 const std::string VPNConfigView::GetService() const { | 385 const std::string VPNConfigView::GetService() const { |
388 if (service_textfield_ != NULL) | 386 if (service_textfield_ != NULL) |
389 return GetTextFromField(service_textfield_, true); | 387 return GetTextFromField(service_textfield_, true); |
390 return service_path_; | 388 return service_path_; |
391 } | 389 } |
392 | 390 |
393 const std::string VPNConfigView::GetServer() const { | 391 const std::string VPNConfigView::GetServer() const { |
394 if (server_textfield_ != NULL) | 392 if (server_textfield_ != NULL) |
395 return GetTextFromField(server_textfield_, true); | 393 return GetTextFromField(server_textfield_, true); |
396 return server_hostname_; | 394 return std::string(); |
397 } | 395 } |
398 | 396 |
399 const std::string VPNConfigView::GetPSKPassphrase() const { | 397 const std::string VPNConfigView::GetPSKPassphrase() const { |
400 if (psk_passphrase_textfield_ && | 398 if (psk_passphrase_textfield_ && |
401 enable_psk_passphrase_ && | 399 enable_psk_passphrase_ && |
402 psk_passphrase_textfield_->visible()) | 400 psk_passphrase_textfield_->visible()) |
403 return GetPassphraseFromField(psk_passphrase_textfield_); | 401 return GetPassphraseFromField(psk_passphrase_textfield_); |
404 return std::string(); | 402 return std::string(); |
405 } | 403 } |
406 | 404 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 int index = user_cert_combobox_ ? user_cert_combobox_->selected_index() : 0; | 439 int index = user_cert_combobox_ ? user_cert_combobox_->selected_index() : 0; |
442 return CertLibrary::Get()->GetCertPkcs11IdAt( | 440 return CertLibrary::Get()->GetCertPkcs11IdAt( |
443 CertLibrary::CERT_TYPE_USER, index); | 441 CertLibrary::CERT_TYPE_USER, index); |
444 } | 442 } |
445 } | 443 } |
446 | 444 |
447 bool VPNConfigView::GetSaveCredentials() const { | 445 bool VPNConfigView::GetSaveCredentials() const { |
448 return save_credentials_checkbox_->checked(); | 446 return save_credentials_checkbox_->checked(); |
449 } | 447 } |
450 | 448 |
451 void VPNConfigView::Init(VirtualNetwork* vpn) { | 449 int VPNConfigView::GetProviderTypeIndex() const { |
452 if (vpn) { | 450 if (!provider_type_.empty()) |
pneubeck (no reviews)
2013/08/06 15:45:19
IMO, it would be less confusing if you would use s
stevenjb
2013/08/06 20:23:55
Refactored
| |
453 ProviderType type = vpn->provider_type(); | 451 return ProviderTypeToIndex(provider_type_, client_cert_id_); |
454 std::string type_dict_name = ProviderTypeToONCDictKey(type); | 452 if (provider_type_combobox_) |
453 return provider_type_combobox_->selected_index(); | |
454 return PROVIDER_TYPE_INDEX_MAX; | |
455 } | |
455 | 456 |
456 if (type == PROVIDER_TYPE_L2TP_IPSEC_PSK) { | 457 std::string VPNConfigView::GetProviderTypeString() const { |
457 ParseVPNUIProperty(&ca_cert_ui_data_, vpn, type_dict_name, | 458 int index = GetProviderTypeIndex(); |
458 onc::ipsec::kServerCARef); | 459 switch (index) { |
459 ParseVPNUIProperty(&psk_passphrase_ui_data_, vpn, type_dict_name, | 460 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK: |
460 onc::ipsec::kPSK); | 461 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT: |
461 ParseVPNUIProperty(&group_name_ui_data_, vpn, type_dict_name, | 462 return flimflam::kProviderL2tpIpsec; |
462 onc::ipsec::kGroup); | 463 case PROVIDER_TYPE_INDEX_OPEN_VPN: |
463 } else { // OpenVPN | 464 return flimflam::kProviderOpenVpn; |
464 ParseVPNUIProperty(&ca_cert_ui_data_, vpn, type_dict_name, | 465 } |
465 onc::openvpn::kServerCARef); | 466 NOTREACHED(); |
466 } | 467 return std::string(); |
467 ParseVPNUIProperty(&user_cert_ui_data_, vpn, type_dict_name, | 468 } |
468 onc::vpn::kClientCertRef); | |
469 | 469 |
470 const std::string credentials_dict_name( | 470 void VPNConfigView::Init() { |
471 type == PROVIDER_TYPE_L2TP_IPSEC_PSK ? | 471 const NetworkState* vpn = NULL; |
472 onc::vpn::kL2TP : type_dict_name); | 472 if (!service_path_.empty()) { |
473 ParseVPNUIProperty(&username_ui_data_, vpn, credentials_dict_name, | 473 vpn = NetworkHandler::Get()->network_state_handler()-> |
474 onc::vpn::kUsername); | 474 GetNetworkState(service_path_); |
475 ParseVPNUIProperty(&user_passphrase_ui_data_, vpn, credentials_dict_name, | 475 DCHECK(vpn->type() == flimflam::kTypeVPN); |
pneubeck (no reviews)
2013/08/06 15:45:19
DCHECK(vpn)
stevenjb
2013/08/06 20:23:55
Done.
| |
476 onc::vpn::kPassword); | |
477 ParseVPNUIProperty(&save_credentials_ui_data_, vpn, credentials_dict_name, | |
478 onc::vpn::kSaveCredentials); | |
479 } | 476 } |
480 | 477 layout_ = views::GridLayout::CreatePanel(this); |
481 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | 478 SetLayoutManager(layout_); |
482 SetLayoutManager(layout); | |
483 | 479 |
484 // Observer any changes to the certificate list. | 480 // Observer any changes to the certificate list. |
485 CertLibrary::Get()->AddObserver(this); | 481 CertLibrary::Get()->AddObserver(this); |
486 | 482 |
487 const int column_view_set_id = 0; | 483 views::ColumnSet* column_set = layout_->AddColumnSet(0); |
488 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); | |
489 // Label. | 484 // Label. |
490 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | 485 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
491 views::GridLayout::USE_PREF, 0, 0); | 486 views::GridLayout::USE_PREF, 0, 0); |
492 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); | 487 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); |
493 // Textfield, combobox. | 488 // Textfield, combobox. |
494 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 489 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
495 views::GridLayout::USE_PREF, 0, | 490 views::GridLayout::USE_PREF, 0, |
496 ChildNetworkConfigView::kInputFieldMinWidth); | 491 ChildNetworkConfigView::kInputFieldMinWidth); |
497 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); | 492 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); |
498 // Policy indicator. | 493 // Policy indicator. |
499 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, | 494 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, |
500 views::GridLayout::USE_PREF, 0, 0); | 495 views::GridLayout::USE_PREF, 0, 0); |
501 | 496 |
502 // Initialize members. | 497 // Initialize members. |
503 service_text_modified_ = false; | 498 service_text_modified_ = false; |
499 title_ = vpn ? IDS_OPTIONS_SETTINGS_JOIN_VPN : IDS_OPTIONS_SETTINGS_ADD_VPN; | |
500 | |
501 // Set up initial layout. | |
502 InitControls(); | |
503 | |
504 if (vpn) { | 504 if (vpn) { |
505 provider_type_ = vpn->provider_type(); | 505 NetworkHandler::Get()->network_configuration_handler()->GetProperties( |
506 // Sets enable_* based on the provider type which we use to control | 506 service_path_, |
507 // which controls to make visible. | 507 base::Bind(&VPNConfigView::InitFromProperties, AsWeakPtr()), |
pneubeck (no reviews)
2013/08/06 15:45:19
The dialog will be visible before the callback is
stevenjb
2013/08/06 20:23:55
Views Layout is... challenging. This creates all o
| |
508 UpdateControlsToEnable(); | 508 base::Bind(&VPNConfigView::GetPropertiesError, AsWeakPtr())); |
509 } else { | 509 } |
510 // Set the default provider type. | 510 } |
511 provider_type_ = PROVIDER_TYPE_L2TP_IPSEC_PSK; | 511 |
512 // Provider Type is user selectable, so enable all controls during init. | 512 void VPNConfigView::InitControls() { |
513 enable_psk_passphrase_ = true; | 513 // By default enable all controls. |
514 enable_user_cert_ = true; | 514 enable_psk_passphrase_ = true; |
515 enable_server_ca_cert_ = true; | 515 enable_user_cert_ = true; |
516 enable_otp_ = true; | 516 enable_server_ca_cert_ = true; |
517 enable_group_name_ = true; | 517 enable_otp_ = true; |
518 } | 518 enable_group_name_ = true; |
519 | |
520 // Initialize the title string ID used for the dialog. | |
521 title_ = vpn ? IDS_OPTIONS_SETTINGS_JOIN_VPN : IDS_OPTIONS_SETTINGS_ADD_VPN; | |
522 | 519 |
523 // Server label and input. | 520 // Server label and input. |
524 // Only provide Server name when configuring a new VPN. | 521 // Only provide Server name when configuring a new VPN. |
525 if (!vpn) { | 522 if (service_path_.empty()) { |
526 layout->StartRow(0, column_view_set_id); | 523 layout_->StartRow(0, 0); |
527 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 524 layout_->AddView(new views::Label(l10n_util::GetStringUTF16( |
528 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVER_HOSTNAME))); | 525 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVER_HOSTNAME))); |
529 server_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 526 server_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
530 server_textfield_->SetController(this); | 527 server_textfield_->SetController(this); |
531 layout->AddView(server_textfield_); | 528 layout_->AddView(server_textfield_); |
532 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 529 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
533 } else { | 530 } else { |
534 server_textfield_ = NULL; | 531 server_textfield_ = NULL; |
535 } | 532 } |
536 | 533 |
537 // Service label and name or input. | 534 // Service label and name or input. |
538 layout->StartRow(0, column_view_set_id); | 535 layout_->StartRow(0, 0); |
539 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 536 layout_->AddView(new views::Label(l10n_util::GetStringUTF16( |
540 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVICE_NAME))); | 537 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVICE_NAME))); |
541 if (!vpn) { | 538 if (service_path_.empty()) { |
542 service_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 539 service_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
543 service_textfield_->SetController(this); | 540 service_textfield_->SetController(this); |
544 layout->AddView(service_textfield_); | 541 layout_->AddView(service_textfield_); |
545 service_text_ = NULL; | 542 service_text_ = NULL; |
546 } else { | 543 } else { |
547 service_text_ = new views::Label(ASCIIToUTF16(vpn->name())); | 544 service_text_ = new views::Label(); |
548 service_text_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 545 service_text_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
549 layout->AddView(service_text_); | 546 layout_->AddView(service_text_); |
550 service_textfield_ = NULL; | 547 service_textfield_ = NULL; |
551 } | 548 } |
552 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 549 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
553 | 550 |
554 // Provider type label and select. | 551 // Provider type label and select. |
555 layout->StartRow(0, column_view_set_id); | 552 layout_->StartRow(0, 0); |
556 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 553 layout_->AddView(new views::Label(l10n_util::GetStringUTF16( |
557 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE))); | 554 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE))); |
558 if (!vpn) { | 555 if (service_path_.empty()) { |
559 provider_type_combobox_model_.reset( | 556 provider_type_combobox_model_.reset( |
560 new internal::ProviderTypeComboboxModel); | 557 new internal::ProviderTypeComboboxModel); |
561 provider_type_combobox_ = new views::Combobox( | 558 provider_type_combobox_ = new views::Combobox( |
562 provider_type_combobox_model_.get()); | 559 provider_type_combobox_model_.get()); |
563 provider_type_combobox_->set_listener(this); | 560 provider_type_combobox_->set_listener(this); |
564 layout->AddView(provider_type_combobox_); | 561 layout_->AddView(provider_type_combobox_); |
565 provider_type_text_label_ = NULL; | 562 provider_type_text_label_ = NULL; |
566 } else { | 563 } else { |
567 provider_type_text_label_ = | 564 provider_type_text_label_ = new views::Label(); |
568 new views::Label(ProviderTypeToString(provider_type_)); | |
569 provider_type_text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 565 provider_type_text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
570 layout->AddView(provider_type_text_label_); | 566 layout_->AddView(provider_type_text_label_); |
571 provider_type_combobox_ = NULL; | 567 provider_type_combobox_ = NULL; |
572 } | 568 } |
573 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 569 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
574 | 570 |
575 // PSK passphrase label, input and visible button. | 571 // PSK passphrase label, input and visible button. |
576 if (enable_psk_passphrase_) { | 572 layout_->StartRow(0, 0); |
577 layout->StartRow(0, column_view_set_id); | 573 psk_passphrase_label_ = new views::Label(l10n_util::GetStringUTF16( |
578 psk_passphrase_label_ = new views::Label(l10n_util::GetStringUTF16( | 574 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PSK_PASSPHRASE)); |
579 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PSK_PASSPHRASE)); | 575 layout_->AddView(psk_passphrase_label_); |
580 layout->AddView(psk_passphrase_label_); | 576 psk_passphrase_textfield_ = new PassphraseTextfield(); |
581 bool has_psk_passphrase = vpn && !vpn->IsPSKPassphraseRequired(); | 577 psk_passphrase_textfield_->SetController(this); |
582 psk_passphrase_textfield_ = new PassphraseTextfield(has_psk_passphrase); | 578 layout_->AddView(psk_passphrase_textfield_); |
583 psk_passphrase_textfield_->SetController(this); | 579 layout_->AddView( |
584 layout->AddView(psk_passphrase_textfield_); | 580 new ControlledSettingIndicatorView(psk_passphrase_ui_data_)); |
585 layout->AddView( | 581 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
586 new ControlledSettingIndicatorView(psk_passphrase_ui_data_)); | |
587 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
588 } else { | |
589 psk_passphrase_label_ = NULL; | |
590 psk_passphrase_textfield_ = NULL; | |
591 } | |
592 | 582 |
593 // Server CA certificate | 583 // Server CA certificate |
594 // Only provide Server CA when configuring a new VPN. | 584 if (service_path_.empty()) { |
595 if (!vpn) { | 585 layout_->StartRow(0, 0); |
596 layout->StartRow(0, column_view_set_id); | 586 server_ca_cert_label_ = new views::Label(l10n_util::GetStringUTF16( |
597 server_ca_cert_label_ = | 587 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); |
598 new views::Label(l10n_util::GetStringUTF16( | 588 layout_->AddView(server_ca_cert_label_); |
599 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); | |
600 layout->AddView(server_ca_cert_label_); | |
601 server_ca_cert_combobox_model_.reset( | 589 server_ca_cert_combobox_model_.reset( |
602 new internal::VpnServerCACertComboboxModel()); | 590 new internal::VpnServerCACertComboboxModel()); |
603 server_ca_cert_combobox_ = new views::Combobox( | 591 server_ca_cert_combobox_ = new views::Combobox( |
604 server_ca_cert_combobox_model_.get()); | 592 server_ca_cert_combobox_model_.get()); |
605 layout->AddView(server_ca_cert_combobox_); | 593 layout_->AddView(server_ca_cert_combobox_); |
606 layout->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); | 594 layout_->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); |
607 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 595 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
608 } else { | 596 } else { |
609 server_ca_cert_label_ = NULL; | 597 server_ca_cert_label_ = NULL; |
610 server_ca_cert_combobox_ = NULL; | 598 server_ca_cert_combobox_ = NULL; |
611 } | 599 } |
612 | 600 |
613 // User certificate label and input. | 601 // User certificate label and input. |
614 if (enable_user_cert_) { | 602 layout_->StartRow(0, 0); |
615 layout->StartRow(0, column_view_set_id); | 603 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( |
616 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( | 604 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); |
617 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); | 605 layout_->AddView(user_cert_label_); |
618 layout->AddView(user_cert_label_); | 606 user_cert_combobox_model_.reset( |
619 user_cert_combobox_model_.reset( | 607 new internal::VpnUserCertComboboxModel()); |
620 new internal::VpnUserCertComboboxModel()); | 608 user_cert_combobox_ = new views::Combobox(user_cert_combobox_model_.get()); |
621 user_cert_combobox_ = new views::Combobox(user_cert_combobox_model_.get()); | 609 user_cert_combobox_->set_listener(this); |
622 user_cert_combobox_->set_listener(this); | 610 layout_->AddView(user_cert_combobox_); |
623 layout->AddView(user_cert_combobox_); | 611 layout_->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); |
624 layout->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); | 612 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
625 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
626 } else { | |
627 user_cert_label_ = NULL; | |
628 user_cert_combobox_ = NULL; | |
629 } | |
630 | 613 |
631 // Username label and input. | 614 // Username label and input. |
632 layout->StartRow(0, column_view_set_id); | 615 layout_->StartRow(0, 0); |
633 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 616 layout_->AddView(new views::Label(l10n_util::GetStringUTF16( |
634 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USERNAME))); | 617 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USERNAME))); |
635 username_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 618 username_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
636 username_textfield_->SetController(this); | 619 username_textfield_->SetController(this); |
637 username_textfield_->SetEnabled(username_ui_data_.IsEditable()); | 620 username_textfield_->SetEnabled(username_ui_data_.IsEditable()); |
638 if (vpn && !vpn->username().empty()) | 621 layout_->AddView(username_textfield_); |
639 username_textfield_->SetText(UTF8ToUTF16(vpn->username())); | 622 layout_->AddView(new ControlledSettingIndicatorView(username_ui_data_)); |
640 layout->AddView(username_textfield_); | 623 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
641 layout->AddView(new ControlledSettingIndicatorView(username_ui_data_)); | |
642 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
643 | 624 |
644 // User passphrase label, input and visble button. | 625 // User passphrase label, input and visble button. |
645 layout->StartRow(0, column_view_set_id); | 626 layout_->StartRow(0, 0); |
646 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 627 layout_->AddView(new views::Label(l10n_util::GetStringUTF16( |
647 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_PASSPHRASE))); | 628 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_PASSPHRASE))); |
648 bool has_user_passphrase = vpn && !vpn->IsUserPassphraseRequired(); | 629 user_passphrase_textfield_ = new PassphraseTextfield(); |
pneubeck (no reviews)
2013/08/06 15:45:19
as feared, SetShowFake is never called the passwor
stevenjb
2013/08/06 20:23:55
We never set the value of this to the passphrase.
| |
649 user_passphrase_textfield_ = new PassphraseTextfield(has_user_passphrase); | |
650 user_passphrase_textfield_->SetController(this); | 630 user_passphrase_textfield_->SetController(this); |
651 user_passphrase_textfield_->SetEnabled(user_passphrase_ui_data_.IsEditable()); | 631 user_passphrase_textfield_->SetEnabled(user_passphrase_ui_data_.IsEditable()); |
652 layout->AddView(user_passphrase_textfield_); | 632 layout_->AddView(user_passphrase_textfield_); |
653 layout->AddView(new ControlledSettingIndicatorView(user_passphrase_ui_data_)); | 633 layout_->AddView( |
654 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 634 new ControlledSettingIndicatorView(user_passphrase_ui_data_)); |
635 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
655 | 636 |
656 // OTP label and input. | 637 // OTP label and input. |
657 if (enable_otp_) { | 638 layout_->StartRow(0, 0); |
658 layout->StartRow(0, column_view_set_id); | 639 otp_label_ = new views::Label(l10n_util::GetStringUTF16( |
659 otp_label_ = new views::Label(l10n_util::GetStringUTF16( | 640 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_OTP)); |
660 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_OTP)); | 641 layout_->AddView(otp_label_); |
661 layout->AddView(otp_label_); | 642 otp_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
662 otp_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 643 otp_textfield_->SetController(this); |
663 otp_textfield_->SetController(this); | 644 layout_->AddView(otp_textfield_); |
664 layout->AddView(otp_textfield_); | 645 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
665 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
666 } else { | |
667 otp_label_ = NULL; | |
668 otp_textfield_ = NULL; | |
669 } | |
670 | 646 |
671 // Group Name label and input. | 647 // Group Name label and input. |
672 if (enable_group_name_) { | 648 layout_->StartRow(0, 0); |
673 layout->StartRow(0, column_view_set_id); | 649 group_name_label_ = new views::Label(l10n_util::GetStringUTF16( |
674 group_name_label_ = new views::Label(l10n_util::GetStringUTF16( | 650 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_GROUP_NAME)); |
675 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_GROUP_NAME)); | 651 layout_->AddView(group_name_label_); |
676 layout->AddView(group_name_label_); | 652 group_name_textfield_ = |
677 group_name_textfield_ = | 653 new views::Textfield(views::Textfield::STYLE_DEFAULT); |
678 new views::Textfield(views::Textfield::STYLE_DEFAULT); | 654 group_name_textfield_->SetController(this); |
679 group_name_textfield_->SetController(this); | 655 layout_->AddView(group_name_textfield_); |
680 if (vpn && !vpn->group_name().empty()) | 656 layout_->AddView(new ControlledSettingIndicatorView(group_name_ui_data_)); |
681 group_name_textfield_->SetText(UTF8ToUTF16(vpn->group_name())); | 657 layout_->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
682 layout->AddView(group_name_textfield_); | |
683 layout->AddView(new ControlledSettingIndicatorView(group_name_ui_data_)); | |
684 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
685 } else { | |
686 group_name_label_ = NULL; | |
687 group_name_textfield_ = NULL; | |
688 } | |
689 | 658 |
690 // Save credentials | 659 // Save credentials |
691 layout->StartRow(0, column_view_set_id); | 660 layout_->StartRow(0, 0); |
692 save_credentials_checkbox_ = new views::Checkbox( | 661 save_credentials_checkbox_ = new views::Checkbox( |
693 l10n_util::GetStringUTF16( | 662 l10n_util::GetStringUTF16( |
694 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS)); | 663 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS)); |
695 save_credentials_checkbox_->SetEnabled( | 664 save_credentials_checkbox_->SetEnabled( |
696 save_credentials_ui_data_.IsEditable()); | 665 save_credentials_ui_data_.IsEditable()); |
697 bool save_credentials = vpn ? vpn->save_credentials() : false; | 666 layout_->SkipColumns(1); |
698 save_credentials_checkbox_->SetChecked(save_credentials); | 667 layout_->AddView(save_credentials_checkbox_); |
699 layout->SkipColumns(1); | 668 layout_->AddView( |
700 layout->AddView(save_credentials_checkbox_); | |
701 layout->AddView( | |
702 new ControlledSettingIndicatorView(save_credentials_ui_data_)); | 669 new ControlledSettingIndicatorView(save_credentials_ui_data_)); |
703 | 670 |
704 // Error label. | 671 // Error label. |
705 layout->StartRow(0, column_view_set_id); | 672 layout_->StartRow(0, 0); |
706 layout->SkipColumns(1); | 673 layout_->SkipColumns(1); |
707 error_label_ = new views::Label(); | 674 error_label_ = new views::Label(); |
708 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 675 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
709 error_label_->SetEnabledColor(SK_ColorRED); | 676 error_label_->SetEnabledColor(SK_ColorRED); |
710 layout->AddView(error_label_); | 677 layout_->AddView(error_label_); |
711 | 678 |
712 // Set or hide the UI, update comboboxes and error labels. | 679 // Set or hide the UI, update comboboxes and error labels. |
713 Refresh(); | 680 Refresh(); |
pneubeck (no reviews)
2013/08/06 15:45:19
Shouldn't this be called from InitFromProperties?
stevenjb
2013/08/06 20:23:55
It should really be called by both, done.
| |
714 } | 681 } |
715 | 682 |
683 void VPNConfigView::InitFromProperties( | |
684 const std::string& service_path, | |
685 const base::DictionaryValue& service_properties) { | |
686 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> | |
687 GetNetworkState(service_path); | |
688 if (!vpn) { | |
689 NET_LOG_ERROR("Shill Error getting properties VpnConfigView", service_path); | |
690 return; | |
691 } | |
692 | |
693 std::string server_hostname, username, group_name; | |
694 bool psk_passphrase_required = false; | |
695 const base::DictionaryValue* provider_properties; | |
696 if (service_properties.GetDictionaryWithoutPathExpansion( | |
697 flimflam::kProviderProperty, &provider_properties)) { | |
698 provider_properties->GetStringWithoutPathExpansion( | |
699 flimflam::kTypeProperty, &provider_type_); | |
700 service_properties.GetStringWithoutPathExpansion( | |
pneubeck (no reviews)
2013/08/06 15:45:19
provider_properties->
stevenjb
2013/08/06 20:23:55
Bah, good catch, Done.
| |
701 flimflam::kHostProperty, &server_hostname); | |
702 } | |
703 if (provider_type_ == flimflam::kProviderL2tpIpsec) { | |
704 service_properties.GetStringWithoutPathExpansion( | |
pneubeck (no reviews)
2013/08/06 15:45:19
provider_properties->
most vpn properties (both l
stevenjb
2013/08/06 20:23:55
Done.
| |
705 flimflam::kL2tpIpsecClientCertIdProperty, &client_cert_id_); | |
706 service_properties.GetStringWithoutPathExpansion( | |
707 shill::kL2tpIpsecCaCertPemProperty, &ca_cert_pem_); | |
pneubeck (no reviews)
2013/08/06 15:45:19
CaCertPemProperty is a list, not a string.
You can
stevenjb
2013/08/06 20:23:55
Gah. Done.
| |
708 service_properties.GetBooleanWithoutPathExpansion( | |
709 flimflam::kL2tpIpsecPskRequiredProperty, &psk_passphrase_required); | |
710 service_properties.GetStringWithoutPathExpansion( | |
711 flimflam::kL2tpIpsecUserProperty, &username); | |
712 service_properties.GetStringWithoutPathExpansion( | |
713 shill::kL2tpIpsecTunnelGroupProperty, &group_name); | |
714 } else if (provider_type_ == flimflam::kProviderOpenVpn) { | |
715 service_properties.GetStringWithoutPathExpansion( | |
716 flimflam::kOpenVPNClientCertIdProperty, &client_cert_id_); | |
717 service_properties.GetStringWithoutPathExpansion( | |
718 shill::kOpenVPNCaCertPemProperty, &ca_cert_pem_); | |
pneubeck (no reviews)
2013/08/06 15:45:19
CaCertPemProperty is a list, not a string.
You can
stevenjb
2013/08/06 20:23:55
Done.
| |
719 service_properties.GetStringWithoutPathExpansion( | |
720 flimflam::kOpenVPNUserProperty, &username); | |
721 } | |
722 bool save_credentials = false; | |
723 service_properties.GetBooleanWithoutPathExpansion( | |
724 flimflam::kSaveCredentialsProperty, &save_credentials); | |
725 | |
726 ProviderTypeComboboxIndex provider_type_index = | |
727 ProviderTypeToIndex(provider_type_, client_cert_id_); | |
728 ParseUIProperties(vpn, provider_type_index); | |
729 | |
730 if (service_text_) | |
731 service_text_->SetText(ASCIIToUTF16(vpn->name())); | |
732 if (provider_type_text_label_) | |
733 provider_type_text_label_->SetText( | |
734 ProviderTypeIndexToString(provider_type_index)); | |
735 | |
736 if (server_textfield_ && !server_hostname.empty()) | |
737 server_textfield_->SetText(UTF8ToUTF16(server_hostname)); | |
738 if (username_textfield_ && !username.empty()) | |
739 username_textfield_->SetText(UTF8ToUTF16(username)); | |
740 if (group_name_textfield_ && !group_name.empty()) | |
741 group_name_textfield_->SetText(UTF8ToUTF16(group_name)); | |
742 if (psk_passphrase_textfield_) | |
743 psk_passphrase_textfield_->SetShowFake(!psk_passphrase_required); | |
744 if (save_credentials_checkbox_) | |
745 save_credentials_checkbox_->SetChecked(save_credentials); | |
746 } | |
747 | |
748 void VPNConfigView::ParseUIProperties(const NetworkState* vpn, | |
749 int provider_type_index) { | |
750 std::string type_dict_name = ProviderTypeToONCDictKey(provider_type_); | |
pneubeck (no reviews)
2013/08/06 15:45:19
nit: indentation
pneubeck (no reviews)
2013/08/06 15:45:19
that's again confusing: there is a provider_type_
stevenjb
2013/08/06 20:23:55
Done.
stevenjb
2013/08/06 20:23:55
Done.
| |
751 if (provider_type_index == PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK) { | |
752 ParseVPNUIProperty(vpn, type_dict_name, onc::ipsec::kServerCARef, | |
753 &ca_cert_ui_data_); | |
754 ParseVPNUIProperty(vpn, type_dict_name, onc::ipsec::kPSK, | |
755 &psk_passphrase_ui_data_); | |
756 ParseVPNUIProperty(vpn, type_dict_name, onc::ipsec::kGroup, | |
757 &group_name_ui_data_); | |
758 } else if (provider_type_index == PROVIDER_TYPE_INDEX_OPEN_VPN) { | |
759 ParseVPNUIProperty(vpn, type_dict_name, onc::openvpn::kServerCARef, | |
760 &ca_cert_ui_data_); | |
761 } | |
762 ParseVPNUIProperty(vpn, type_dict_name, onc::vpn::kClientCertRef, | |
763 &user_cert_ui_data_); | |
764 | |
765 const std::string credentials_dict_name( | |
766 provider_type_index == PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK ? | |
767 onc::vpn::kL2TP : type_dict_name); | |
768 ParseVPNUIProperty(vpn, credentials_dict_name, onc::vpn::kUsername, | |
769 &username_ui_data_); | |
770 ParseVPNUIProperty(vpn, credentials_dict_name, onc::vpn::kPassword, | |
771 &user_passphrase_ui_data_); | |
772 ParseVPNUIProperty(vpn, credentials_dict_name, onc::vpn::kSaveCredentials, | |
773 &save_credentials_ui_data_); | |
774 } | |
775 | |
776 void VPNConfigView::GetPropertiesError( | |
777 const std::string& error_name, | |
778 scoped_ptr<base::DictionaryValue> error_data) { | |
779 NET_LOG_ERROR("Shill Error from VpnConfigView: " + error_name, ""); | |
780 } | |
781 | |
782 void VPNConfigView::SetCredentials(base::DictionaryValue* properties) { | |
783 int provider_type_index = GetProviderTypeIndex(); | |
784 std::string user_passphrase = GetUserPassphrase(); | |
785 std::string user_name = GetUsername(); | |
786 std::string group_name = GetGroupName(); | |
pneubeck (no reviews)
2013/08/06 15:45:19
nit:
this is not a credential.
similarly CACerts a
stevenjb
2013/08/06 20:23:55
Named SetConfigProperties
| |
787 switch (provider_type_index) { | |
788 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK: { | |
789 std::string psk_passphrase = GetPSKPassphrase(); | |
790 if (!psk_passphrase.empty()) { | |
791 properties->SetStringWithoutPathExpansion( | |
792 flimflam::kL2tpIpsecPskProperty, GetPSKPassphrase()); | |
793 } | |
794 if (!group_name.empty()) { | |
795 properties->SetStringWithoutPathExpansion( | |
796 shill::kL2tpIpsecTunnelGroupProperty, group_name); | |
797 } | |
798 if (!user_name.empty()) { | |
799 properties->SetStringWithoutPathExpansion( | |
800 flimflam::kL2tpIpsecUserProperty, user_name); | |
801 } | |
802 if (!user_passphrase.empty()) { | |
803 properties->SetStringWithoutPathExpansion( | |
804 flimflam::kL2tpIpsecPasswordProperty, user_passphrase); | |
805 } | |
806 break; | |
807 } | |
808 case PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT: { | |
809 std::string ca_cert_pem = GetServerCACertPEM(); | |
810 if (!ca_cert_pem.empty()) { | |
811 properties->SetStringWithoutPathExpansion( | |
812 shill::kL2tpIpsecCaCertPemProperty, ca_cert_pem); | |
813 } | |
814 properties->SetStringWithoutPathExpansion( | |
815 flimflam::kL2tpIpsecClientCertIdProperty, GetUserCertID()); | |
816 if (!group_name.empty()) { | |
817 properties->SetStringWithoutPathExpansion( | |
818 shill::kL2tpIpsecTunnelGroupProperty, GetGroupName()); | |
819 } | |
820 if (!user_name.empty()) { | |
821 properties->SetStringWithoutPathExpansion( | |
822 flimflam::kL2tpIpsecUserProperty, user_name); | |
823 } | |
824 if (!user_passphrase.empty()) { | |
825 properties->SetStringWithoutPathExpansion( | |
826 flimflam::kL2tpIpsecPasswordProperty, user_passphrase); | |
827 } | |
828 break; | |
829 } | |
830 case PROVIDER_TYPE_INDEX_OPEN_VPN: { | |
831 std::string ca_cert_pem = GetServerCACertPEM(); | |
832 if (!ca_cert_pem.empty()) { | |
833 base::ListValue* pem_list = new base::ListValue; | |
834 pem_list->AppendString(GetServerCACertPEM()); | |
835 properties->SetWithoutPathExpansion( | |
836 shill::kOpenVPNCaCertPemProperty, pem_list); | |
837 } | |
838 properties->SetStringWithoutPathExpansion( | |
839 flimflam::kOpenVPNClientCertIdProperty, GetUserCertID()); | |
840 properties->SetStringWithoutPathExpansion( | |
841 flimflam::kOpenVPNUserProperty, GetUsername()); | |
842 if (!user_passphrase.empty()) { | |
843 properties->SetStringWithoutPathExpansion( | |
844 flimflam::kOpenVPNPasswordProperty, user_passphrase); | |
845 } | |
846 std::string otp = GetOTP(); | |
847 if (!otp.empty()) { | |
848 properties->SetStringWithoutPathExpansion( | |
849 flimflam::kOpenVPNOTPProperty, otp); | |
850 } | |
851 break; | |
852 } | |
853 case PROVIDER_TYPE_INDEX_MAX: | |
854 NOTREACHED(); | |
855 break; | |
856 } | |
857 properties->SetBooleanWithoutPathExpansion( | |
858 flimflam::kSaveCredentialsProperty, GetSaveCredentials()); | |
859 } | |
860 | |
716 void VPNConfigView::Refresh() { | 861 void VPNConfigView::Refresh() { |
717 NetworkLibrary* cros = NetworkLibrary::Get(); | |
718 | |
719 UpdateControls(); | 862 UpdateControls(); |
720 | 863 |
721 // Set certificate combo boxes. | 864 // Set certificate combo boxes. |
722 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); | |
723 if (server_ca_cert_combobox_) { | 865 if (server_ca_cert_combobox_) { |
724 server_ca_cert_combobox_->ModelChanged(); | 866 server_ca_cert_combobox_->ModelChanged(); |
725 if (enable_server_ca_cert_ && | 867 if (enable_server_ca_cert_ && !ca_cert_pem_.empty()) { |
726 (vpn && !vpn->ca_cert_pem().empty())) { | |
727 // Select the current server CA certificate in the combobox. | 868 // Select the current server CA certificate in the combobox. |
728 int cert_index = CertLibrary::Get()->GetCertIndexByPEM( | 869 int cert_index = CertLibrary::Get()->GetCertIndexByPEM( |
729 CertLibrary::CERT_TYPE_SERVER_CA, vpn->ca_cert_pem()); | 870 CertLibrary::CERT_TYPE_SERVER_CA, ca_cert_pem_); |
730 if (cert_index >= 0) { | 871 if (cert_index >= 0) { |
731 // Skip item for "Default" | 872 // Skip item for "Default" |
732 server_ca_cert_combobox_->SetSelectedIndex(1 + cert_index); | 873 server_ca_cert_combobox_->SetSelectedIndex(1 + cert_index); |
733 } else { | 874 } else { |
734 server_ca_cert_combobox_->SetSelectedIndex(0); | 875 server_ca_cert_combobox_->SetSelectedIndex(0); |
735 } | 876 } |
736 } else { | 877 } else { |
737 server_ca_cert_combobox_->SetSelectedIndex(0); | 878 server_ca_cert_combobox_->SetSelectedIndex(0); |
738 } | 879 } |
739 } | 880 } |
740 | 881 |
741 if (user_cert_combobox_) { | 882 if (user_cert_combobox_) { |
742 user_cert_combobox_->ModelChanged(); | 883 user_cert_combobox_->ModelChanged(); |
743 if (enable_user_cert_ && | 884 if (enable_user_cert_ && !client_cert_id_.empty()) { |
744 (vpn && !vpn->client_cert_id().empty())) { | |
745 int cert_index = CertLibrary::Get()->GetCertIndexByPkcs11Id( | 885 int cert_index = CertLibrary::Get()->GetCertIndexByPkcs11Id( |
746 CertLibrary::CERT_TYPE_USER, vpn->client_cert_id()); | 886 CertLibrary::CERT_TYPE_USER, client_cert_id_); |
747 if (cert_index >= 0) | 887 if (cert_index >= 0) |
748 user_cert_combobox_->SetSelectedIndex(cert_index); | 888 user_cert_combobox_->SetSelectedIndex(cert_index); |
749 else | 889 else |
750 user_cert_combobox_->SetSelectedIndex(0); | 890 user_cert_combobox_->SetSelectedIndex(0); |
751 } else { | 891 } else { |
752 user_cert_combobox_->SetSelectedIndex(0); | 892 user_cert_combobox_->SetSelectedIndex(0); |
753 } | 893 } |
754 } | 894 } |
755 | 895 |
756 UpdateErrorLabel(); | 896 UpdateErrorLabel(); |
757 } | 897 } |
758 | 898 |
759 void VPNConfigView::UpdateControlsToEnable() { | 899 void VPNConfigView::UpdateControlsToEnable() { |
760 // Set which controls are enabled. | |
761 enable_psk_passphrase_ = false; | 900 enable_psk_passphrase_ = false; |
762 enable_user_cert_ = false; | 901 enable_user_cert_ = false; |
763 enable_server_ca_cert_ = false; | 902 enable_server_ca_cert_ = false; |
764 enable_otp_ = false; | 903 enable_otp_ = false; |
765 enable_group_name_ = false; | 904 enable_group_name_ = false; |
766 switch (provider_type_) { | 905 int provider_type_index = GetProviderTypeIndex(); |
767 case PROVIDER_TYPE_L2TP_IPSEC_PSK: | 906 if (provider_type_index == PROVIDER_TYPE_INDEX_L2TP_IPSEC_PSK) { |
768 enable_psk_passphrase_ = true; | 907 enable_psk_passphrase_ = true; |
769 enable_group_name_ = true; | 908 enable_group_name_ = true; |
770 break; | 909 } else if (provider_type_index == PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT) { |
771 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: | 910 enable_server_ca_cert_ = true; |
772 enable_server_ca_cert_ = true; | 911 enable_user_cert_ = HaveUserCerts(); |
773 enable_user_cert_ = HaveUserCerts(); | 912 enable_group_name_ = true; |
774 enable_group_name_ = true; | 913 } else { // PROVIDER_TYPE_INDEX_OPEN_VPN (default) |
775 break; | 914 enable_server_ca_cert_ = true; |
776 case PROVIDER_TYPE_OPEN_VPN: | 915 enable_user_cert_ = HaveUserCerts(); |
777 enable_server_ca_cert_ = true; | 916 enable_otp_ = true; |
778 enable_user_cert_ = HaveUserCerts(); | |
779 enable_otp_ = true; | |
780 break; | |
781 default: | |
782 NOTREACHED(); | |
783 break; | |
784 } | 917 } |
785 } | 918 } |
786 | 919 |
787 void VPNConfigView::UpdateControls() { | 920 void VPNConfigView::UpdateControls() { |
788 UpdateControlsToEnable(); | 921 UpdateControlsToEnable(); |
789 | 922 |
790 if (psk_passphrase_label_) | 923 if (psk_passphrase_label_) |
791 psk_passphrase_label_->SetEnabled(enable_psk_passphrase_); | 924 psk_passphrase_label_->SetEnabled(enable_psk_passphrase_); |
792 if (psk_passphrase_textfield_) | 925 if (psk_passphrase_textfield_) |
793 psk_passphrase_textfield_->SetEnabled(enable_psk_passphrase_ && | 926 psk_passphrase_textfield_->SetEnabled(enable_psk_passphrase_ && |
(...skipping 17 matching lines...) Expand all Loading... | |
811 otp_textfield_->SetEnabled(enable_otp_); | 944 otp_textfield_->SetEnabled(enable_otp_); |
812 | 945 |
813 if (group_name_label_) | 946 if (group_name_label_) |
814 group_name_label_->SetEnabled(enable_group_name_); | 947 group_name_label_->SetEnabled(enable_group_name_); |
815 if (group_name_textfield_) | 948 if (group_name_textfield_) |
816 group_name_textfield_->SetEnabled(enable_group_name_ && | 949 group_name_textfield_->SetEnabled(enable_group_name_ && |
817 group_name_ui_data_.IsEditable()); | 950 group_name_ui_data_.IsEditable()); |
818 } | 951 } |
819 | 952 |
820 void VPNConfigView::UpdateErrorLabel() { | 953 void VPNConfigView::UpdateErrorLabel() { |
821 NetworkLibrary* cros = NetworkLibrary::Get(); | |
822 | |
823 // Error message. | 954 // Error message. |
824 std::string error_msg; | 955 string16 error_msg; |
825 if (UserCertRequired() && CertLibrary::Get()->CertificatesLoaded()) { | 956 bool cert_required = |
957 GetProviderTypeIndex() == PROVIDER_TYPE_INDEX_L2TP_IPSEC_USER_CERT; | |
958 if (cert_required && CertLibrary::Get()->CertificatesLoaded()) { | |
826 if (!HaveUserCerts()) { | 959 if (!HaveUserCerts()) { |
827 error_msg = l10n_util::GetStringUTF8( | 960 error_msg = l10n_util::GetStringUTF16( |
828 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PLEASE_INSTALL_USER_CERT); | 961 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PLEASE_INSTALL_USER_CERT); |
829 } else if (!IsUserCertValid()) { | 962 } else if (!IsUserCertValid()) { |
830 error_msg = l10n_util::GetStringUTF8( | 963 error_msg = l10n_util::GetStringUTF16( |
831 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_REQUIRE_HARDWARE_BACKED); | 964 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_REQUIRE_HARDWARE_BACKED); |
832 } | 965 } |
833 } | 966 } |
834 if (error_msg.empty() && !service_path_.empty()) { | 967 if (error_msg.empty() && !service_path_.empty()) { |
835 // TODO(kuan): differentiate between bad psk and user passphrases. | 968 // TODO(kuan): differentiate between bad psk and user passphrases. |
836 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); | 969 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> |
837 if (vpn && vpn->failed()) { | 970 GetNetworkState(service_path_); |
838 if (vpn->error() == ERROR_BAD_PASSPHRASE) { | 971 if (vpn && vpn->connection_state() == flimflam::kStateFailure) |
839 error_msg = l10n_util::GetStringUTF8( | 972 error_msg = ash::network_connect::ErrorString(vpn->error()); |
840 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE); | |
841 } else { | |
842 error_msg = vpn->GetErrorString(); | |
843 } | |
844 } | |
845 } | 973 } |
846 if (!error_msg.empty()) { | 974 if (!error_msg.empty()) { |
847 error_label_->SetText(UTF8ToUTF16(error_msg)); | 975 error_label_->SetText(error_msg); |
848 error_label_->SetVisible(true); | 976 error_label_->SetVisible(true); |
849 } else { | 977 } else { |
850 error_label_->SetVisible(false); | 978 error_label_->SetVisible(false); |
851 } | 979 } |
852 } | 980 } |
853 | 981 |
854 void VPNConfigView::UpdateCanLogin() { | 982 void VPNConfigView::UpdateCanLogin() { |
855 parent_->GetDialogClientView()->UpdateDialogButtons(); | 983 parent_->GetDialogClientView()->UpdateDialogButtons(); |
856 } | 984 } |
857 | 985 |
858 bool VPNConfigView::UserCertRequired() const { | |
859 return provider_type_ == PROVIDER_TYPE_L2TP_IPSEC_USER_CERT; | |
860 } | |
861 | |
862 bool VPNConfigView::HaveUserCerts() const { | 986 bool VPNConfigView::HaveUserCerts() const { |
863 return CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER) > 0; | 987 return CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER) > 0; |
864 } | 988 } |
865 | 989 |
866 bool VPNConfigView::IsUserCertValid() const { | 990 bool VPNConfigView::IsUserCertValid() const { |
867 if (!user_cert_combobox_ || !enable_user_cert_) | 991 if (!user_cert_combobox_ || !enable_user_cert_) |
868 return false; | 992 return false; |
869 int index = user_cert_combobox_->selected_index(); | 993 int index = user_cert_combobox_->selected_index(); |
870 if (index < 0) | 994 if (index < 0) |
871 return false; | 995 return false; |
(...skipping 17 matching lines...) Expand all Loading... | |
889 return result; | 1013 return result; |
890 } | 1014 } |
891 | 1015 |
892 const std::string VPNConfigView::GetPassphraseFromField( | 1016 const std::string VPNConfigView::GetPassphraseFromField( |
893 PassphraseTextfield* textfield) const { | 1017 PassphraseTextfield* textfield) const { |
894 if (!textfield) | 1018 if (!textfield) |
895 return std::string(); | 1019 return std::string(); |
896 return textfield->GetPassphrase(); | 1020 return textfield->GetPassphrase(); |
897 } | 1021 } |
898 | 1022 |
899 void VPNConfigView::ParseVPNUIProperty(NetworkPropertyUIData* property_ui_data, | 1023 void VPNConfigView::ParseVPNUIProperty( |
900 Network* network, | 1024 const NetworkState* network, |
901 const std::string& dict_key, | 1025 const std::string& dict_key, |
902 const std::string& key) { | 1026 const std::string& key, |
1027 NetworkPropertyUIData* property_ui_data) { | |
903 onc::ONCSource onc_source = onc::ONC_SOURCE_NONE; | 1028 onc::ONCSource onc_source = onc::ONC_SOURCE_NONE; |
904 const base::DictionaryValue* onc = | 1029 const base::DictionaryValue* onc = |
905 NetworkConfigView::FindPolicyForActiveUser(network, &onc_source); | 1030 network_connect::FindPolicyForActiveUser(network, &onc_source); |
906 | 1031 |
907 VLOG_IF(1, !onc) << "No ONC found for VPN network " << network->unique_id(); | 1032 VLOG_IF(1, !onc) << "No ONC found for VPN network " << network->guid(); |
908 property_ui_data->ParseOncProperty( | 1033 property_ui_data->ParseOncProperty( |
909 onc_source, | 1034 onc_source, |
910 onc, | 1035 onc, |
911 base::StringPrintf("%s.%s.%s", | 1036 base::StringPrintf("%s.%s.%s", |
912 onc::network_config::kVPN, | 1037 onc::network_config::kVPN, |
913 dict_key.c_str(), | 1038 dict_key.c_str(), |
914 key.c_str())); | 1039 key.c_str())); |
915 } | 1040 } |
916 | 1041 |
917 } // namespace chromeos | 1042 } // namespace chromeos |
OLD | NEW |