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 "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 // Overridden from ui::ComboboxModel: | 83 // Overridden from ui::ComboboxModel: |
84 virtual int GetItemCount() const OVERRIDE; | 84 virtual int GetItemCount() const OVERRIDE; |
85 virtual string16 GetItemAt(int index) OVERRIDE; | 85 virtual string16 GetItemAt(int index) OVERRIDE; |
86 | 86 |
87 private: | 87 private: |
88 DISALLOW_COPY_AND_ASSIGN(ProviderTypeComboboxModel); | 88 DISALLOW_COPY_AND_ASSIGN(ProviderTypeComboboxModel); |
89 }; | 89 }; |
90 | 90 |
91 class VpnServerCACertComboboxModel : public ui::ComboboxModel { | 91 class VpnServerCACertComboboxModel : public ui::ComboboxModel { |
92 public: | 92 public: |
93 explicit VpnServerCACertComboboxModel(CertLibrary* cert_library); | 93 VpnServerCACertComboboxModel(); |
94 virtual ~VpnServerCACertComboboxModel(); | 94 virtual ~VpnServerCACertComboboxModel(); |
95 | 95 |
96 // Overridden from ui::ComboboxModel: | 96 // Overridden from ui::ComboboxModel: |
97 virtual int GetItemCount() const OVERRIDE; | 97 virtual int GetItemCount() const OVERRIDE; |
98 virtual string16 GetItemAt(int index) OVERRIDE; | 98 virtual string16 GetItemAt(int index) OVERRIDE; |
99 | 99 |
100 private: | 100 private: |
101 CertLibrary* cert_library_; | |
102 | |
103 DISALLOW_COPY_AND_ASSIGN(VpnServerCACertComboboxModel); | 101 DISALLOW_COPY_AND_ASSIGN(VpnServerCACertComboboxModel); |
104 }; | 102 }; |
105 | 103 |
106 class VpnUserCertComboboxModel : public ui::ComboboxModel { | 104 class VpnUserCertComboboxModel : public ui::ComboboxModel { |
107 public: | 105 public: |
108 explicit VpnUserCertComboboxModel(CertLibrary* cert_library); | 106 VpnUserCertComboboxModel(); |
109 virtual ~VpnUserCertComboboxModel(); | 107 virtual ~VpnUserCertComboboxModel(); |
110 | 108 |
111 // Overridden from ui::ComboboxModel: | 109 // Overridden from ui::ComboboxModel: |
112 virtual int GetItemCount() const OVERRIDE; | 110 virtual int GetItemCount() const OVERRIDE; |
113 virtual string16 GetItemAt(int index) OVERRIDE; | 111 virtual string16 GetItemAt(int index) OVERRIDE; |
114 | 112 |
115 private: | 113 private: |
116 CertLibrary* cert_library_; | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(VpnUserCertComboboxModel); | 114 DISALLOW_COPY_AND_ASSIGN(VpnUserCertComboboxModel); |
119 }; | 115 }; |
120 | 116 |
121 // ProviderTypeComboboxModel --------------------------------------------------- | 117 // ProviderTypeComboboxModel --------------------------------------------------- |
122 | 118 |
123 ProviderTypeComboboxModel::ProviderTypeComboboxModel() { | 119 ProviderTypeComboboxModel::ProviderTypeComboboxModel() { |
124 } | 120 } |
125 | 121 |
126 ProviderTypeComboboxModel::~ProviderTypeComboboxModel() { | 122 ProviderTypeComboboxModel::~ProviderTypeComboboxModel() { |
127 } | 123 } |
128 | 124 |
129 int ProviderTypeComboboxModel::GetItemCount() const { | 125 int ProviderTypeComboboxModel::GetItemCount() const { |
130 return PROVIDER_TYPE_MAX; | 126 return PROVIDER_TYPE_MAX; |
131 } | 127 } |
132 | 128 |
133 string16 ProviderTypeComboboxModel::GetItemAt(int index) { | 129 string16 ProviderTypeComboboxModel::GetItemAt(int index) { |
134 ProviderType type = static_cast<ProviderType>(index); | 130 ProviderType type = static_cast<ProviderType>(index); |
135 return ProviderTypeToString(type); | 131 return ProviderTypeToString(type); |
136 } | 132 } |
137 | 133 |
138 // VpnServerCACertComboboxModel ------------------------------------------------ | 134 // VpnServerCACertComboboxModel ------------------------------------------------ |
139 | 135 |
140 VpnServerCACertComboboxModel::VpnServerCACertComboboxModel( | 136 VpnServerCACertComboboxModel::VpnServerCACertComboboxModel() { |
141 CertLibrary* cert_library) | |
142 : cert_library_(cert_library) { | |
143 } | 137 } |
144 | 138 |
145 VpnServerCACertComboboxModel::~VpnServerCACertComboboxModel() { | 139 VpnServerCACertComboboxModel::~VpnServerCACertComboboxModel() { |
146 } | 140 } |
147 | 141 |
148 int VpnServerCACertComboboxModel::GetItemCount() const { | 142 int VpnServerCACertComboboxModel::GetItemCount() const { |
149 if (cert_library_->CertificatesLoading()) | 143 if (CertLibrary::Get()->CertificatesLoading()) |
150 return 1; // "Loading" | 144 return 1; // "Loading" |
151 // "Default" + certs. | 145 // "Default" + certs. |
152 return cert_library_->GetCACertificates().Size() + 1; | 146 return CertLibrary::Get()->NumCertificates( |
147 CertLibrary::CERT_TYPE_SERVER_CA) + 1; | |
153 } | 148 } |
154 | 149 |
155 string16 VpnServerCACertComboboxModel::GetItemAt(int index) { | 150 string16 VpnServerCACertComboboxModel::GetItemAt(int index) { |
156 if (cert_library_->CertificatesLoading()) | 151 if (CertLibrary::Get()->CertificatesLoading()) |
157 return l10n_util::GetStringUTF16( | 152 return l10n_util::GetStringUTF16( |
158 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING); | 153 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING); |
159 if (index == 0) | 154 if (index == 0) |
160 return l10n_util::GetStringUTF16( | 155 return l10n_util::GetStringUTF16( |
161 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA_DEFAULT); | 156 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA_DEFAULT); |
162 int cert_index = index - 1; | 157 int cert_index = index - 1; |
163 return cert_library_->GetCACertificates().GetDisplayStringAt(cert_index); | 158 return CertLibrary::Get()->GetCertDisplayStringAt( |
159 CertLibrary::CERT_TYPE_SERVER_CA, cert_index); | |
164 } | 160 } |
165 | 161 |
166 // VpnUserCertComboboxModel ---------------------------------------------------- | 162 // VpnUserCertComboboxModel ---------------------------------------------------- |
167 | 163 |
168 VpnUserCertComboboxModel::VpnUserCertComboboxModel( | 164 VpnUserCertComboboxModel::VpnUserCertComboboxModel() { |
169 CertLibrary* cert_library) | |
170 : cert_library_(cert_library) { | |
171 } | 165 } |
172 | 166 |
173 VpnUserCertComboboxModel::~VpnUserCertComboboxModel() { | 167 VpnUserCertComboboxModel::~VpnUserCertComboboxModel() { |
174 } | 168 } |
175 | 169 |
176 int VpnUserCertComboboxModel::GetItemCount() const { | 170 int VpnUserCertComboboxModel::GetItemCount() const { |
177 if (cert_library_->CertificatesLoading()) | 171 if (CertLibrary::Get()->CertificatesLoading()) |
178 return 1; // "Loading" | 172 return 1; // "Loading" |
179 int num_certs = cert_library_->GetUserCertificates().Size(); | 173 int num_certs = |
174 CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER); | |
180 if (num_certs == 0) | 175 if (num_certs == 0) |
181 return 1; // "None installed" | 176 return 1; // "None installed" |
182 return num_certs; | 177 return num_certs; |
183 } | 178 } |
184 | 179 |
185 string16 VpnUserCertComboboxModel::GetItemAt(int index) { | 180 string16 VpnUserCertComboboxModel::GetItemAt(int index) { |
186 if (cert_library_->CertificatesLoading()) { | 181 if (CertLibrary::Get()->CertificatesLoading()) { |
187 return l10n_util::GetStringUTF16( | 182 return l10n_util::GetStringUTF16( |
188 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING); | 183 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING); |
189 } | 184 } |
190 if (cert_library_->GetUserCertificates().Size() == 0) { | 185 if (CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER) == 0) { |
191 return l10n_util::GetStringUTF16( | 186 return l10n_util::GetStringUTF16( |
192 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED); | 187 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED); |
193 } | 188 } |
194 return cert_library_->GetUserCertificates().GetDisplayStringAt(index); | 189 return CertLibrary::Get()->GetCertDisplayStringAt( |
190 CertLibrary::CERT_TYPE_USER, index); | |
195 } | 191 } |
196 | 192 |
197 } // namespace internal | 193 } // namespace internal |
198 | 194 |
199 VPNConfigView::VPNConfigView(NetworkConfigView* parent, VirtualNetwork* vpn) | 195 VPNConfigView::VPNConfigView(NetworkConfigView* parent, VirtualNetwork* vpn) |
200 : ChildNetworkConfigView(parent, vpn), | 196 : ChildNetworkConfigView(parent, vpn) { |
201 cert_library_(NULL) { | |
202 Init(vpn); | 197 Init(vpn); |
203 } | 198 } |
204 | 199 |
205 VPNConfigView::VPNConfigView(NetworkConfigView* parent) | 200 VPNConfigView::VPNConfigView(NetworkConfigView* parent) |
206 : ChildNetworkConfigView(parent), | 201 : ChildNetworkConfigView(parent) { |
207 cert_library_(NULL) { | |
208 Init(NULL); | 202 Init(NULL); |
209 } | 203 } |
210 | 204 |
211 VPNConfigView::~VPNConfigView() { | 205 VPNConfigView::~VPNConfigView() { |
212 if (cert_library_) | 206 CertLibrary::Get()->RemoveObserver(this); |
213 cert_library_->RemoveObserver(this); | |
214 } | 207 } |
215 | 208 |
216 views::View* VPNConfigView::GetInitiallyFocusedView() { | 209 views::View* VPNConfigView::GetInitiallyFocusedView() { |
217 // Put focus in the first editable field. | 210 // Put focus in the first editable field. |
218 if (server_textfield_) | 211 if (server_textfield_) |
219 return server_textfield_; | 212 return server_textfield_; |
220 else if (service_textfield_) | 213 else if (service_textfield_) |
221 return service_textfield_; | 214 return service_textfield_; |
222 else if (provider_type_combobox_) | 215 else if (provider_type_combobox_) |
223 return provider_type_combobox_; | 216 return provider_type_combobox_; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 | 406 |
414 const std::string VPNConfigView::GetGroupName() const { | 407 const std::string VPNConfigView::GetGroupName() const { |
415 return GetTextFromField(group_name_textfield_, false); | 408 return GetTextFromField(group_name_textfield_, false); |
416 } | 409 } |
417 | 410 |
418 const std::string VPNConfigView::GetOTP() const { | 411 const std::string VPNConfigView::GetOTP() const { |
419 return GetTextFromField(otp_textfield_, true); | 412 return GetTextFromField(otp_textfield_, true); |
420 } | 413 } |
421 | 414 |
422 const std::string VPNConfigView::GetServerCACertNssNickname() const { | 415 const std::string VPNConfigView::GetServerCACertNssNickname() const { |
423 DCHECK(cert_library_); | |
424 int index = server_ca_cert_combobox_ ? | 416 int index = server_ca_cert_combobox_ ? |
425 server_ca_cert_combobox_->selected_index() : 0; | 417 server_ca_cert_combobox_->selected_index() : 0; |
426 if (index == 0) { | 418 if (index == 0) { |
427 // First item is "Default". | 419 // First item is "Default". |
428 return std::string(); | 420 return std::string(); |
429 } else { | 421 } else { |
430 DCHECK(cert_library_); | 422 DCHECK_GT(CertLibrary::Get()->NumCertificates( |
431 DCHECK_GT(cert_library_->GetCACertificates().Size(), 0); | 423 CertLibrary::CERT_TYPE_SERVER_CA), 0); |
pneubeck (no reviews)
2013/05/03 09:42:54
shouldn't this compare NumCertificates with cert_i
stevenjb
2013/05/03 17:02:32
CertLibrary already does these checks; removed thi
| |
432 int cert_index = index - 1; | 424 int cert_index = index - 1; |
433 return cert_library_->GetCACertificates().GetNicknameAt(cert_index); | 425 return CertLibrary::Get()->GetCertNicknameAt( |
426 CertLibrary::CERT_TYPE_SERVER_CA, cert_index); | |
434 } | 427 } |
435 } | 428 } |
436 | 429 |
437 const std::string VPNConfigView::GetUserCertID() const { | 430 const std::string VPNConfigView::GetUserCertID() const { |
438 DCHECK(cert_library_); | |
439 if (!HaveUserCerts()) { | 431 if (!HaveUserCerts()) { |
440 return std::string(); // "None installed" | 432 return std::string(); // "None installed" |
441 } else { | 433 } else { |
442 // Certificates are listed in the order they appear in the model. | 434 // Certificates are listed in the order they appear in the model. |
443 int index = user_cert_combobox_ ? user_cert_combobox_->selected_index() : 0; | 435 int index = user_cert_combobox_ ? user_cert_combobox_->selected_index() : 0; |
444 return cert_library_->GetUserCertificates().GetPkcs11IdAt(index); | 436 return CertLibrary::Get()->GetCertPkcs11IdAt( |
437 CertLibrary::CERT_TYPE_USER, index); | |
445 } | 438 } |
446 } | 439 } |
447 | 440 |
448 bool VPNConfigView::GetSaveCredentials() const { | 441 bool VPNConfigView::GetSaveCredentials() const { |
449 return save_credentials_checkbox_->checked(); | 442 return save_credentials_checkbox_->checked(); |
450 } | 443 } |
451 | 444 |
452 void VPNConfigView::Init(VirtualNetwork* vpn) { | 445 void VPNConfigView::Init(VirtualNetwork* vpn) { |
453 if (vpn) { | 446 if (vpn) { |
454 ProviderType type = vpn->provider_type(); | 447 ProviderType type = vpn->provider_type(); |
(...skipping 14 matching lines...) Expand all Loading... | |
469 onc::vpn::kUsername); | 462 onc::vpn::kUsername); |
470 ParseVPNUIProperty(&user_passphrase_ui_data_, vpn, credentials_dict_name, | 463 ParseVPNUIProperty(&user_passphrase_ui_data_, vpn, credentials_dict_name, |
471 onc::vpn::kPassword); | 464 onc::vpn::kPassword); |
472 ParseVPNUIProperty(&save_credentials_ui_data_, vpn, credentials_dict_name, | 465 ParseVPNUIProperty(&save_credentials_ui_data_, vpn, credentials_dict_name, |
473 onc::vpn::kSaveCredentials); | 466 onc::vpn::kSaveCredentials); |
474 } | 467 } |
475 | 468 |
476 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | 469 views::GridLayout* layout = views::GridLayout::CreatePanel(this); |
477 SetLayoutManager(layout); | 470 SetLayoutManager(layout); |
478 | 471 |
479 // VPN may require certificates, so always set the library and observe. | |
480 cert_library_ = CrosLibrary::Get()->GetCertLibrary(); | |
481 | |
482 // Setup a callback if certificates are yet to be loaded. | 472 // Setup a callback if certificates are yet to be loaded. |
483 if (!cert_library_->CertificatesLoaded()) | 473 if (!CertLibrary::Get()->CertificatesLoaded()) |
pneubeck (no reviews)
2013/05/03 09:42:54
Why this restriction? The comment should explain w
stevenjb
2013/05/03 17:02:32
Changed to always add.
| |
484 cert_library_->AddObserver(this); | 474 CertLibrary::Get()->AddObserver(this); |
485 | 475 |
486 const int column_view_set_id = 0; | 476 const int column_view_set_id = 0; |
487 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); | 477 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); |
488 // Label. | 478 // Label. |
489 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | 479 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
490 views::GridLayout::USE_PREF, 0, 0); | 480 views::GridLayout::USE_PREF, 0, 0); |
491 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); | 481 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); |
492 // Textfield, combobox. | 482 // Textfield, combobox. |
493 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 483 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
494 views::GridLayout::USE_PREF, 0, | 484 views::GridLayout::USE_PREF, 0, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 | 587 |
598 // Server CA certificate | 588 // Server CA certificate |
599 // Only provide Server CA when configuring a new VPN. | 589 // Only provide Server CA when configuring a new VPN. |
600 if (!vpn) { | 590 if (!vpn) { |
601 layout->StartRow(0, column_view_set_id); | 591 layout->StartRow(0, column_view_set_id); |
602 server_ca_cert_label_ = | 592 server_ca_cert_label_ = |
603 new views::Label(l10n_util::GetStringUTF16( | 593 new views::Label(l10n_util::GetStringUTF16( |
604 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); | 594 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); |
605 layout->AddView(server_ca_cert_label_); | 595 layout->AddView(server_ca_cert_label_); |
606 server_ca_cert_combobox_model_.reset( | 596 server_ca_cert_combobox_model_.reset( |
607 new internal::VpnServerCACertComboboxModel(cert_library_)); | 597 new internal::VpnServerCACertComboboxModel()); |
608 server_ca_cert_combobox_ = new views::Combobox( | 598 server_ca_cert_combobox_ = new views::Combobox( |
609 server_ca_cert_combobox_model_.get()); | 599 server_ca_cert_combobox_model_.get()); |
610 layout->AddView(server_ca_cert_combobox_); | 600 layout->AddView(server_ca_cert_combobox_); |
611 layout->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); | 601 layout->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); |
612 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 602 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
613 } else { | 603 } else { |
614 server_ca_cert_label_ = NULL; | 604 server_ca_cert_label_ = NULL; |
615 server_ca_cert_combobox_ = NULL; | 605 server_ca_cert_combobox_ = NULL; |
616 } | 606 } |
617 | 607 |
618 // User certificate label and input. | 608 // User certificate label and input. |
619 if (enable_user_cert_) { | 609 if (enable_user_cert_) { |
620 layout->StartRow(0, column_view_set_id); | 610 layout->StartRow(0, column_view_set_id); |
621 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( | 611 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( |
622 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); | 612 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); |
623 layout->AddView(user_cert_label_); | 613 layout->AddView(user_cert_label_); |
624 user_cert_combobox_model_.reset( | 614 user_cert_combobox_model_.reset( |
625 new internal::VpnUserCertComboboxModel(cert_library_)); | 615 new internal::VpnUserCertComboboxModel()); |
626 user_cert_combobox_ = new views::Combobox(user_cert_combobox_model_.get()); | 616 user_cert_combobox_ = new views::Combobox(user_cert_combobox_model_.get()); |
627 user_cert_combobox_->set_listener(this); | 617 user_cert_combobox_->set_listener(this); |
628 layout->AddView(user_cert_combobox_); | 618 layout->AddView(user_cert_combobox_); |
629 layout->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); | 619 layout->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); |
630 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 620 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
631 } else { | 621 } else { |
632 user_cert_label_ = NULL; | 622 user_cert_label_ = NULL; |
633 user_cert_combobox_ = NULL; | 623 user_cert_combobox_ = NULL; |
634 } | 624 } |
635 | 625 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
727 | 717 |
728 UpdateControls(); | 718 UpdateControls(); |
729 | 719 |
730 // Set certificate combo boxes. | 720 // Set certificate combo boxes. |
731 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); | 721 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); |
732 if (server_ca_cert_combobox_) { | 722 if (server_ca_cert_combobox_) { |
733 server_ca_cert_combobox_->ModelChanged(); | 723 server_ca_cert_combobox_->ModelChanged(); |
734 if (enable_server_ca_cert_ && | 724 if (enable_server_ca_cert_ && |
735 (vpn && !vpn->ca_cert_nss().empty())) { | 725 (vpn && !vpn->ca_cert_nss().empty())) { |
736 // Select the current server CA certificate in the combobox. | 726 // Select the current server CA certificate in the combobox. |
737 int cert_index = cert_library_->GetCACertificates().FindCertByNickname( | 727 int cert_index = CertLibrary::Get()->GetCertIndexByNickname( |
738 vpn->ca_cert_nss()); | 728 CertLibrary::CERT_TYPE_SERVER_CA, vpn->ca_cert_nss()); |
739 if (cert_index >= 0) { | 729 if (cert_index >= 0) { |
740 // Skip item for "Default" | 730 // Skip item for "Default" |
741 server_ca_cert_combobox_->SetSelectedIndex(1 + cert_index); | 731 server_ca_cert_combobox_->SetSelectedIndex(1 + cert_index); |
742 } else { | 732 } else { |
743 server_ca_cert_combobox_->SetSelectedIndex(0); | 733 server_ca_cert_combobox_->SetSelectedIndex(0); |
744 } | 734 } |
745 } else { | 735 } else { |
746 server_ca_cert_combobox_->SetSelectedIndex(0); | 736 server_ca_cert_combobox_->SetSelectedIndex(0); |
747 } | 737 } |
748 } | 738 } |
749 | 739 |
750 if (user_cert_combobox_) { | 740 if (user_cert_combobox_) { |
751 user_cert_combobox_->ModelChanged(); | 741 user_cert_combobox_->ModelChanged(); |
752 if (enable_user_cert_ && | 742 if (enable_user_cert_ && |
753 (vpn && !vpn->client_cert_id().empty())) { | 743 (vpn && !vpn->client_cert_id().empty())) { |
754 int cert_index = cert_library_->GetUserCertificates().FindCertByPkcs11Id( | 744 int cert_index = CertLibrary::Get()->GetCertIndexByPkcs11Id( |
755 vpn->client_cert_id()); | 745 CertLibrary::CERT_TYPE_USER, vpn->client_cert_id()); |
756 if (cert_index >= 0) | 746 if (cert_index >= 0) |
757 user_cert_combobox_->SetSelectedIndex(cert_index); | 747 user_cert_combobox_->SetSelectedIndex(cert_index); |
758 else | 748 else |
759 user_cert_combobox_->SetSelectedIndex(0); | 749 user_cert_combobox_->SetSelectedIndex(0); |
760 } else { | 750 } else { |
761 user_cert_combobox_->SetSelectedIndex(0); | 751 user_cert_combobox_->SetSelectedIndex(0); |
762 } | 752 } |
763 } | 753 } |
764 | 754 |
765 UpdateErrorLabel(); | 755 UpdateErrorLabel(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
824 if (group_name_textfield_) | 814 if (group_name_textfield_) |
825 group_name_textfield_->SetEnabled(enable_group_name_ && | 815 group_name_textfield_->SetEnabled(enable_group_name_ && |
826 group_name_ui_data_.editable()); | 816 group_name_ui_data_.editable()); |
827 } | 817 } |
828 | 818 |
829 void VPNConfigView::UpdateErrorLabel() { | 819 void VPNConfigView::UpdateErrorLabel() { |
830 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 820 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
831 | 821 |
832 // Error message. | 822 // Error message. |
833 std::string error_msg; | 823 std::string error_msg; |
834 if (UserCertRequired() && cert_library_->CertificatesLoaded()) { | 824 if (UserCertRequired() && CertLibrary::Get()->CertificatesLoaded()) { |
835 if (!HaveUserCerts()) { | 825 if (!HaveUserCerts()) { |
836 error_msg = l10n_util::GetStringUTF8( | 826 error_msg = l10n_util::GetStringUTF8( |
837 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PLEASE_INSTALL_USER_CERT); | 827 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PLEASE_INSTALL_USER_CERT); |
838 } else if (!IsUserCertValid()) { | 828 } else if (!IsUserCertValid()) { |
839 error_msg = l10n_util::GetStringUTF8( | 829 error_msg = l10n_util::GetStringUTF8( |
840 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_REQUIRE_HARDWARE_BACKED); | 830 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_REQUIRE_HARDWARE_BACKED); |
841 } | 831 } |
842 } | 832 } |
843 if (error_msg.empty() && !service_path_.empty()) { | 833 if (error_msg.empty() && !service_path_.empty()) { |
844 // TODO(kuan): differentiate between bad psk and user passphrases. | 834 // TODO(kuan): differentiate between bad psk and user passphrases. |
(...skipping 17 matching lines...) Expand all Loading... | |
862 | 852 |
863 void VPNConfigView::UpdateCanLogin() { | 853 void VPNConfigView::UpdateCanLogin() { |
864 parent_->GetDialogClientView()->UpdateDialogButtons(); | 854 parent_->GetDialogClientView()->UpdateDialogButtons(); |
865 } | 855 } |
866 | 856 |
867 bool VPNConfigView::UserCertRequired() const { | 857 bool VPNConfigView::UserCertRequired() const { |
868 return provider_type_ == PROVIDER_TYPE_L2TP_IPSEC_USER_CERT; | 858 return provider_type_ == PROVIDER_TYPE_L2TP_IPSEC_USER_CERT; |
869 } | 859 } |
870 | 860 |
871 bool VPNConfigView::HaveUserCerts() const { | 861 bool VPNConfigView::HaveUserCerts() const { |
872 return cert_library_->GetUserCertificates().Size() > 0; | 862 return CertLibrary::Get()->NumCertificates(CertLibrary::CERT_TYPE_USER) > 0; |
873 } | 863 } |
874 | 864 |
875 bool VPNConfigView::IsUserCertValid() const { | 865 bool VPNConfigView::IsUserCertValid() const { |
876 if (!user_cert_combobox_ || !enable_user_cert_) | 866 if (!user_cert_combobox_ || !enable_user_cert_) |
877 return false; | 867 return false; |
878 int index = user_cert_combobox_->selected_index(); | 868 int index = user_cert_combobox_->selected_index(); |
879 if (index < 0) | 869 if (index < 0) |
880 return false; | 870 return false; |
881 // Currently only hardware-backed user certificates are valid. | 871 // Currently only hardware-backed user certificates are valid. |
882 if (cert_library_->IsHardwareBacked() && | 872 if (CertLibrary::Get()->IsHardwareBacked() && |
883 !cert_library_->GetUserCertificates().IsHardwareBackedAt(index)) | 873 !CertLibrary::Get()->IsCertHardwareBackedAt( |
874 CertLibrary::CERT_TYPE_USER, index)) | |
884 return false; | 875 return false; |
885 return true; | 876 return true; |
886 } | 877 } |
887 | 878 |
888 const std::string VPNConfigView::GetTextFromField(views::Textfield* textfield, | 879 const std::string VPNConfigView::GetTextFromField(views::Textfield* textfield, |
889 bool trim_whitespace) const { | 880 bool trim_whitespace) const { |
890 if (!textfield) | 881 if (!textfield) |
891 return std::string(); | 882 return std::string(); |
892 std::string untrimmed = UTF16ToUTF8(textfield->text()); | 883 std::string untrimmed = UTF16ToUTF8(textfield->text()); |
893 if (!trim_whitespace) | 884 if (!trim_whitespace) |
(...skipping 21 matching lines...) Expand all Loading... | |
915 | 906 |
916 property_ui_data->ParseOncProperty( | 907 property_ui_data->ParseOncProperty( |
917 network->ui_data(), onc, | 908 network->ui_data(), onc, |
918 base::StringPrintf("%s.%s.%s", | 909 base::StringPrintf("%s.%s.%s", |
919 onc::network_config::kVPN, | 910 onc::network_config::kVPN, |
920 dict_key.c_str(), | 911 dict_key.c_str(), |
921 key.c_str())); | 912 key.c_str())); |
922 } | 913 } |
923 | 914 |
924 } // namespace chromeos | 915 } // namespace chromeos |
OLD | NEW |