Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: chrome/browser/chromeos/options/vpn_config_view.cc

Issue 9875001: views: Rename Combobox "selected getter/setter" accessors to something more accurate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: combo box -> combobox Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/options/wifi_config_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 const std::string VPNConfigView::GetGroupName() const { 356 const std::string VPNConfigView::GetGroupName() const {
357 return GetTextFromField(group_name_textfield_, false); 357 return GetTextFromField(group_name_textfield_, false);
358 } 358 }
359 359
360 const std::string VPNConfigView::GetOTP() const { 360 const std::string VPNConfigView::GetOTP() const {
361 return GetTextFromField(otp_textfield_, true); 361 return GetTextFromField(otp_textfield_, true);
362 } 362 }
363 363
364 const std::string VPNConfigView::GetServerCACertNssNickname() const { 364 const std::string VPNConfigView::GetServerCACertNssNickname() const {
365 DCHECK(cert_library_); 365 DCHECK(cert_library_);
366 int selected = 366 int index = server_ca_cert_combobox_ ?
367 server_ca_cert_combobox_ ? server_ca_cert_combobox_->selected_item() : 0; 367 server_ca_cert_combobox_->selected_index() : 0;
368 if (selected == 0) { 368 if (index == 0) {
369 // First item is "Default". 369 // First item is "Default".
370 return std::string(); 370 return std::string();
371 } else { 371 } else {
372 DCHECK(cert_library_); 372 DCHECK(cert_library_);
373 DCHECK_GT(cert_library_->GetCACertificates().Size(), 0); 373 DCHECK_GT(cert_library_->GetCACertificates().Size(), 0);
374 int cert_index = selected - 1; 374 int cert_index = index - 1;
375 return cert_library_->GetCACertificates().GetNicknameAt(cert_index); 375 return cert_library_->GetCACertificates().GetNicknameAt(cert_index);
376 } 376 }
377 } 377 }
378 378
379 const std::string VPNConfigView::GetUserCertID() const { 379 const std::string VPNConfigView::GetUserCertID() const {
380 DCHECK(cert_library_); 380 DCHECK(cert_library_);
381 if (!HaveUserCerts()) { 381 if (!HaveUserCerts()) {
382 return std::string(); // "None installed" 382 return std::string(); // "None installed"
383 } else { 383 } else {
384 // Certificates are listed in the order they appear in the model. 384 // Certificates are listed in the order they appear in the model.
385 int selected = 385 int index = user_cert_combobox_ ? user_cert_combobox_->selected_index() : 0;
386 user_cert_combobox_ ? user_cert_combobox_->selected_item() : 0; 386 return cert_library_->GetUserCertificates().GetPkcs11IdAt(index);
387 return cert_library_->GetUserCertificates().GetPkcs11IdAt(selected);
388 } 387 }
389 } 388 }
390 389
391 void VPNConfigView::Init(VirtualNetwork* vpn) { 390 void VPNConfigView::Init(VirtualNetwork* vpn) {
392 if (vpn) { 391 if (vpn) {
393 ParseVPNUIProperty(&ca_cert_ui_data_, vpn, onc::vpn::kServerCARef); 392 ParseVPNUIProperty(&ca_cert_ui_data_, vpn, onc::vpn::kServerCARef);
394 ParseVPNUIProperty(&psk_passphrase_ui_data_, vpn, onc::vpn::kPSK); 393 ParseVPNUIProperty(&psk_passphrase_ui_data_, vpn, onc::vpn::kPSK);
395 ParseVPNUIProperty(&user_cert_ui_data_, vpn, onc::vpn::kClientCertRef); 394 ParseVPNUIProperty(&user_cert_ui_data_, vpn, onc::vpn::kClientCertRef);
396 ParseVPNUIProperty(&username_ui_data_, vpn, onc::vpn::kUsername); 395 ParseVPNUIProperty(&username_ui_data_, vpn, onc::vpn::kUsername);
397 ParseVPNUIProperty(&user_passphrase_ui_data_, vpn, onc::vpn::kPassword); 396 ParseVPNUIProperty(&user_passphrase_ui_data_, vpn, onc::vpn::kPassword);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); 630 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_);
632 if (server_ca_cert_combobox_) { 631 if (server_ca_cert_combobox_) {
633 server_ca_cert_combobox_->ModelChanged(); 632 server_ca_cert_combobox_->ModelChanged();
634 if (enable_server_ca_cert_ && 633 if (enable_server_ca_cert_ &&
635 (vpn && !vpn->ca_cert_nss().empty())) { 634 (vpn && !vpn->ca_cert_nss().empty())) {
636 // Select the current server CA certificate in the combobox. 635 // Select the current server CA certificate in the combobox.
637 int cert_index = cert_library_->GetCACertificates().FindCertByNickname( 636 int cert_index = cert_library_->GetCACertificates().FindCertByNickname(
638 vpn->ca_cert_nss()); 637 vpn->ca_cert_nss());
639 if (cert_index >= 0) { 638 if (cert_index >= 0) {
640 // Skip item for "Default" 639 // Skip item for "Default"
641 server_ca_cert_combobox_->SetSelectedItem(1 + cert_index); 640 server_ca_cert_combobox_->SetSelectedIndex(1 + cert_index);
642 } else { 641 } else {
643 server_ca_cert_combobox_->SetSelectedItem(0); 642 server_ca_cert_combobox_->SetSelectedIndex(0);
644 } 643 }
645 } else { 644 } else {
646 server_ca_cert_combobox_->SetSelectedItem(0); 645 server_ca_cert_combobox_->SetSelectedIndex(0);
647 } 646 }
648 } 647 }
649 648
650 if (user_cert_combobox_) { 649 if (user_cert_combobox_) {
651 user_cert_combobox_->ModelChanged(); 650 user_cert_combobox_->ModelChanged();
652 if (enable_user_cert_ && 651 if (enable_user_cert_ &&
653 (vpn && !vpn->client_cert_id().empty())) { 652 (vpn && !vpn->client_cert_id().empty())) {
654 int cert_index = cert_library_->GetUserCertificates().FindCertByPkcs11Id( 653 int cert_index = cert_library_->GetUserCertificates().FindCertByPkcs11Id(
655 vpn->client_cert_id()); 654 vpn->client_cert_id());
656 if (cert_index >= 0) 655 if (cert_index >= 0)
657 user_cert_combobox_->SetSelectedItem(cert_index); 656 user_cert_combobox_->SetSelectedIndex(cert_index);
658 else 657 else
659 user_cert_combobox_->SetSelectedItem(0); 658 user_cert_combobox_->SetSelectedIndex(0);
660 } else { 659 } else {
661 user_cert_combobox_->SetSelectedItem(0); 660 user_cert_combobox_->SetSelectedIndex(0);
662 } 661 }
663 } 662 }
664 663
665 UpdateErrorLabel(); 664 UpdateErrorLabel();
666 } 665 }
667 666
668 void VPNConfigView::UpdateControlsToEnable() { 667 void VPNConfigView::UpdateControlsToEnable() {
669 // Set which controls are enabled. 668 // Set which controls are enabled.
670 enable_psk_passphrase_ = false; 669 enable_psk_passphrase_ = false;
671 enable_user_cert_ = false; 670 enable_user_cert_ = false;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 return provider_type_ == PROVIDER_TYPE_L2TP_IPSEC_USER_CERT; 767 return provider_type_ == PROVIDER_TYPE_L2TP_IPSEC_USER_CERT;
769 } 768 }
770 769
771 bool VPNConfigView::HaveUserCerts() const { 770 bool VPNConfigView::HaveUserCerts() const {
772 return cert_library_->GetUserCertificates().Size() > 0; 771 return cert_library_->GetUserCertificates().Size() > 0;
773 } 772 }
774 773
775 bool VPNConfigView::IsUserCertValid() const { 774 bool VPNConfigView::IsUserCertValid() const {
776 if (!user_cert_combobox_ || !enable_user_cert_) 775 if (!user_cert_combobox_ || !enable_user_cert_)
777 return false; 776 return false;
778 int selected = user_cert_combobox_->selected_item(); 777 int index = user_cert_combobox_->selected_index();
779 if (selected < 0) 778 if (index < 0)
780 return false; 779 return false;
781 // Currently only hardware-backed user certificates are valid. 780 // Currently only hardware-backed user certificates are valid.
782 if (cert_library_->IsHardwareBacked() && 781 if (cert_library_->IsHardwareBacked() &&
783 !cert_library_->GetUserCertificates().IsHardwareBackedAt(selected)) 782 !cert_library_->GetUserCertificates().IsHardwareBackedAt(index))
784 return false; 783 return false;
785 return true; 784 return true;
786 } 785 }
787 786
788 const std::string VPNConfigView::GetTextFromField( 787 const std::string VPNConfigView::GetTextFromField(views::Textfield* textfield,
789 views::Textfield* textfield, bool trim_whitespace) const { 788 bool trim_whitespace) const {
790 if (!textfield) 789 if (!textfield)
791 return std::string(); 790 return std::string();
792 std::string untrimmed = UTF16ToUTF8(textfield->text()); 791 std::string untrimmed = UTF16ToUTF8(textfield->text());
793 if (!trim_whitespace) 792 if (!trim_whitespace)
794 return untrimmed; 793 return untrimmed;
795 std::string result; 794 std::string result;
796 TrimWhitespaceASCII(untrimmed, TRIM_ALL, &result); 795 TrimWhitespaceASCII(untrimmed, TRIM_ALL, &result);
797 return result; 796 return result;
798 } 797 }
799 798
(...skipping 18 matching lines...) Expand all
818 std::string vpn_type; 817 std::string vpn_type;
819 if (!vpn_dict || !vpn_dict->GetString(onc::kType, &vpn_type)) 818 if (!vpn_dict || !vpn_dict->GetString(onc::kType, &vpn_type))
820 return; 819 return;
821 820
822 property_ui_data->ParseOncProperty( 821 property_ui_data->ParseOncProperty(
823 network->ui_data(), onc, 822 network->ui_data(), onc,
824 base::StringPrintf("%s.%s.%s", onc::kVPN, vpn_type.c_str(), key.c_str())); 823 base::StringPrintf("%s.%s.%s", onc::kVPN, vpn_type.c_str(), key.c_str()));
825 } 824 }
826 825
827 } // namespace chromeos 826 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/options/wifi_config_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698