| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_OPEN_VPN); | 45 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_OPEN_VPN); |
| 46 case chromeos::PROVIDER_TYPE_MAX: | 46 case chromeos::PROVIDER_TYPE_MAX: |
| 47 break; | 47 break; |
| 48 } | 48 } |
| 49 NOTREACHED(); | 49 NOTREACHED(); |
| 50 return string16(); | 50 return string16(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| 54 | 54 |
| 55 namespace chromeos { | 55 namespace internal { |
| 56 | 56 |
| 57 class ProviderTypeComboboxModel : public ui::ComboboxModel { | 57 class ProviderTypeComboboxModel : public ui::ComboboxModel { |
| 58 public: | 58 public: |
| 59 ProviderTypeComboboxModel() {} | 59 ProviderTypeComboboxModel(); |
| 60 virtual ~ProviderTypeComboboxModel() {} | 60 virtual ~ProviderTypeComboboxModel(); |
| 61 | 61 |
| 62 // Overridden from ui::ComboboxModel: | 62 // Overridden from ui::ComboboxModel: |
| 63 virtual int GetItemCount() const OVERRIDE { | 63 virtual int GetItemCount() const OVERRIDE; |
| 64 return chromeos::PROVIDER_TYPE_MAX; | 64 virtual string16 GetItemAt(int index) OVERRIDE; |
| 65 } | |
| 66 virtual string16 GetItemAt(int index) OVERRIDE { | |
| 67 ProviderType type = static_cast<ProviderType>(index); | |
| 68 return ProviderTypeToString(type); | |
| 69 } | |
| 70 | 65 |
| 71 private: | 66 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(ProviderTypeComboboxModel); | 67 DISALLOW_COPY_AND_ASSIGN(ProviderTypeComboboxModel); |
| 73 }; | 68 }; |
| 74 | 69 |
| 75 class ServerCACertComboboxModel : public ui::ComboboxModel { | 70 class ServerCACertComboboxModel : public ui::ComboboxModel { |
| 76 public: | 71 public: |
| 77 explicit ServerCACertComboboxModel(CertLibrary* cert_library) | 72 explicit ServerCACertComboboxModel(chromeos::CertLibrary* cert_library); |
| 78 : cert_library_(cert_library) { | 73 virtual ~ServerCACertComboboxModel(); |
| 79 } | |
| 80 virtual ~ServerCACertComboboxModel() {} | |
| 81 | 74 |
| 82 // Overridden from ui::ComboboxModel: | 75 // Overridden from ui::ComboboxModel: |
| 83 virtual int GetItemCount() const OVERRIDE { | 76 virtual int GetItemCount() const OVERRIDE; |
| 84 if (cert_library_->CertificatesLoading()) | 77 virtual string16 GetItemAt(int index) OVERRIDE; |
| 85 return 1; // "Loading" | |
| 86 // "Default" + certs. | |
| 87 return cert_library_->GetCACertificates().Size() + 1; | |
| 88 } | |
| 89 virtual string16 GetItemAt(int index) OVERRIDE { | |
| 90 if (cert_library_->CertificatesLoading()) | |
| 91 return l10n_util::GetStringUTF16( | |
| 92 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING); | |
| 93 if (index == 0) | |
| 94 return l10n_util::GetStringUTF16( | |
| 95 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA_DEFAULT); | |
| 96 int cert_index = index - 1; | |
| 97 return cert_library_->GetCACertificates().GetDisplayStringAt(cert_index); | |
| 98 } | |
| 99 | 78 |
| 100 private: | 79 private: |
| 101 CertLibrary* cert_library_; | 80 chromeos::CertLibrary* cert_library_; |
| 102 | 81 |
| 103 DISALLOW_COPY_AND_ASSIGN(ServerCACertComboboxModel); | 82 DISALLOW_COPY_AND_ASSIGN(ServerCACertComboboxModel); |
| 104 }; | 83 }; |
| 105 | 84 |
| 106 class UserCertComboboxModel : public ui::ComboboxModel { | 85 class UserCertComboboxModel : public ui::ComboboxModel { |
| 107 public: | 86 public: |
| 108 explicit UserCertComboboxModel(CertLibrary* cert_library) | 87 explicit UserCertComboboxModel(chromeos::CertLibrary* cert_library); |
| 109 : cert_library_(cert_library) { | 88 virtual ~UserCertComboboxModel(); |
| 110 } | |
| 111 virtual ~UserCertComboboxModel() {} | |
| 112 | 89 |
| 113 // Overridden from ui::ComboboxModel: | 90 // Overridden from ui::ComboboxModel: |
| 114 virtual int GetItemCount() const OVERRIDE { | 91 virtual int GetItemCount() const OVERRIDE; |
| 115 if (cert_library_->CertificatesLoading()) | 92 virtual string16 GetItemAt(int index) OVERRIDE; |
| 116 return 1; // "Loading" | |
| 117 int num_certs = cert_library_->GetUserCertificates().Size(); | |
| 118 if (num_certs == 0) | |
| 119 return 1; // "None installed" | |
| 120 return num_certs; | |
| 121 } | |
| 122 virtual string16 GetItemAt(int index) OVERRIDE { | |
| 123 if (cert_library_->CertificatesLoading()) { | |
| 124 return l10n_util::GetStringUTF16( | |
| 125 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING); | |
| 126 } | |
| 127 if (cert_library_->GetUserCertificates().Size() == 0) { | |
| 128 return l10n_util::GetStringUTF16( | |
| 129 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED); | |
| 130 } | |
| 131 return cert_library_->GetUserCertificates().GetDisplayStringAt(index); | |
| 132 } | |
| 133 | 93 |
| 134 private: | 94 private: |
| 135 CertLibrary* cert_library_; | 95 chromeos::CertLibrary* cert_library_; |
| 96 |
| 136 DISALLOW_COPY_AND_ASSIGN(UserCertComboboxModel); | 97 DISALLOW_COPY_AND_ASSIGN(UserCertComboboxModel); |
| 137 }; | 98 }; |
| 138 | 99 |
| 100 // ProviderTypeComboboxModel --------------------------------------------------- |
| 101 |
| 102 ProviderTypeComboboxModel::ProviderTypeComboboxModel() { |
| 103 } |
| 104 |
| 105 ProviderTypeComboboxModel::~ProviderTypeComboboxModel() { |
| 106 } |
| 107 |
| 108 int ProviderTypeComboboxModel::GetItemCount() const { |
| 109 return chromeos::PROVIDER_TYPE_MAX; |
| 110 } |
| 111 |
| 112 string16 ProviderTypeComboboxModel::GetItemAt(int index) { |
| 113 chromeos::ProviderType type = static_cast<chromeos::ProviderType>(index); |
| 114 return ProviderTypeToString(type); |
| 115 } |
| 116 |
| 117 // ServerCACertComboboxModel --------------------------------------------------- |
| 118 |
| 119 ServerCACertComboboxModel::ServerCACertComboboxModel( |
| 120 chromeos::CertLibrary* cert_library) |
| 121 : cert_library_(cert_library) { |
| 122 } |
| 123 |
| 124 ServerCACertComboboxModel::~ServerCACertComboboxModel() { |
| 125 } |
| 126 |
| 127 int ServerCACertComboboxModel::GetItemCount() const { |
| 128 if (cert_library_->CertificatesLoading()) |
| 129 return 1; // "Loading" |
| 130 // "Default" + certs. |
| 131 return cert_library_->GetCACertificates().Size() + 1; |
| 132 } |
| 133 |
| 134 string16 ServerCACertComboboxModel::GetItemAt(int index) { |
| 135 if (cert_library_->CertificatesLoading()) |
| 136 return l10n_util::GetStringUTF16( |
| 137 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING); |
| 138 if (index == 0) |
| 139 return l10n_util::GetStringUTF16( |
| 140 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA_DEFAULT); |
| 141 int cert_index = index - 1; |
| 142 return cert_library_->GetCACertificates().GetDisplayStringAt(cert_index); |
| 143 } |
| 144 |
| 145 // UserCertComboboxModel ------------------------------------------------------- |
| 146 |
| 147 UserCertComboboxModel::UserCertComboboxModel( |
| 148 chromeos::CertLibrary* cert_library) |
| 149 : cert_library_(cert_library) { |
| 150 } |
| 151 |
| 152 UserCertComboboxModel::~UserCertComboboxModel() { |
| 153 } |
| 154 |
| 155 int UserCertComboboxModel::GetItemCount() const { |
| 156 if (cert_library_->CertificatesLoading()) |
| 157 return 1; // "Loading" |
| 158 int num_certs = cert_library_->GetUserCertificates().Size(); |
| 159 if (num_certs == 0) |
| 160 return 1; // "None installed" |
| 161 return num_certs; |
| 162 } |
| 163 |
| 164 string16 UserCertComboboxModel::GetItemAt(int index) { |
| 165 if (cert_library_->CertificatesLoading()) { |
| 166 return l10n_util::GetStringUTF16( |
| 167 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_LOADING); |
| 168 } |
| 169 if (cert_library_->GetUserCertificates().Size() == 0) { |
| 170 return l10n_util::GetStringUTF16( |
| 171 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USER_CERT_NONE_INSTALLED); |
| 172 } |
| 173 return cert_library_->GetUserCertificates().GetDisplayStringAt(index); |
| 174 } |
| 175 |
| 176 } // namespace internal |
| 177 |
| 178 namespace chromeos { |
| 179 |
| 139 VPNConfigView::VPNConfigView(NetworkConfigView* parent, VirtualNetwork* vpn) | 180 VPNConfigView::VPNConfigView(NetworkConfigView* parent, VirtualNetwork* vpn) |
| 140 : ChildNetworkConfigView(parent, vpn), | 181 : ChildNetworkConfigView(parent, vpn), |
| 141 cert_library_(NULL) { | 182 cert_library_(NULL) { |
| 142 Init(vpn); | 183 Init(vpn); |
| 143 } | 184 } |
| 144 | 185 |
| 145 VPNConfigView::VPNConfigView(NetworkConfigView* parent) | 186 VPNConfigView::VPNConfigView(NetworkConfigView* parent) |
| 146 : ChildNetworkConfigView(parent), | 187 : ChildNetworkConfigView(parent), |
| 147 cert_library_(NULL) { | 188 cert_library_(NULL) { |
| 148 Init(NULL); | 189 Init(NULL); |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 layout->AddView(service_text_); | 512 layout->AddView(service_text_); |
| 472 service_textfield_ = NULL; | 513 service_textfield_ = NULL; |
| 473 } | 514 } |
| 474 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 515 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 475 | 516 |
| 476 // Provider type label and select. | 517 // Provider type label and select. |
| 477 layout->StartRow(0, column_view_set_id); | 518 layout->StartRow(0, column_view_set_id); |
| 478 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 519 layout->AddView(new views::Label(l10n_util::GetStringUTF16( |
| 479 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE))); | 520 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE))); |
| 480 if (!vpn) { | 521 if (!vpn) { |
| 481 provider_type_combobox_ = | 522 provider_type_combobox_model_.reset( |
| 482 new views::Combobox(new ProviderTypeComboboxModel()); | 523 new internal::ProviderTypeComboboxModel); |
| 524 provider_type_combobox_ = new views::Combobox( |
| 525 provider_type_combobox_model_.get()); |
| 483 provider_type_combobox_->set_listener(this); | 526 provider_type_combobox_->set_listener(this); |
| 484 layout->AddView(provider_type_combobox_); | 527 layout->AddView(provider_type_combobox_); |
| 485 provider_type_text_label_ = NULL; | 528 provider_type_text_label_ = NULL; |
| 486 } else { | 529 } else { |
| 487 provider_type_text_label_ = | 530 provider_type_text_label_ = |
| 488 new views::Label(ProviderTypeToString(provider_type_)); | 531 new views::Label(ProviderTypeToString(provider_type_)); |
| 489 provider_type_text_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 532 provider_type_text_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 490 layout->AddView(provider_type_text_label_); | 533 layout->AddView(provider_type_text_label_); |
| 491 provider_type_combobox_ = NULL; | 534 provider_type_combobox_ = NULL; |
| 492 } | 535 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 511 } | 554 } |
| 512 | 555 |
| 513 // Server CA certificate | 556 // Server CA certificate |
| 514 // Only provide Server CA when configuring a new VPN. | 557 // Only provide Server CA when configuring a new VPN. |
| 515 if (!vpn) { | 558 if (!vpn) { |
| 516 layout->StartRow(0, column_view_set_id); | 559 layout->StartRow(0, column_view_set_id); |
| 517 server_ca_cert_label_ = | 560 server_ca_cert_label_ = |
| 518 new views::Label(l10n_util::GetStringUTF16( | 561 new views::Label(l10n_util::GetStringUTF16( |
| 519 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); | 562 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); |
| 520 layout->AddView(server_ca_cert_label_); | 563 layout->AddView(server_ca_cert_label_); |
| 521 ServerCACertComboboxModel* server_ca_cert_model = | 564 server_ca_cert_combobox_model_.reset( |
| 522 new ServerCACertComboboxModel(cert_library_); | 565 new internal::ServerCACertComboboxModel(cert_library_)); |
| 523 server_ca_cert_combobox_ = new views::Combobox(server_ca_cert_model); | 566 server_ca_cert_combobox_ = new views::Combobox( |
| 567 server_ca_cert_combobox_model_.get()); |
| 524 layout->AddView(server_ca_cert_combobox_); | 568 layout->AddView(server_ca_cert_combobox_); |
| 525 layout->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); | 569 layout->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); |
| 526 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 570 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 527 } else { | 571 } else { |
| 528 server_ca_cert_label_ = NULL; | 572 server_ca_cert_label_ = NULL; |
| 529 server_ca_cert_combobox_ = NULL; | 573 server_ca_cert_combobox_ = NULL; |
| 530 } | 574 } |
| 531 | 575 |
| 532 // User certificate label and input. | 576 // User certificate label and input. |
| 533 if (enable_user_cert_) { | 577 if (enable_user_cert_) { |
| 534 layout->StartRow(0, column_view_set_id); | 578 layout->StartRow(0, column_view_set_id); |
| 535 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( | 579 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( |
| 536 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); | 580 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); |
| 537 layout->AddView(user_cert_label_); | 581 layout->AddView(user_cert_label_); |
| 538 UserCertComboboxModel* user_cert_model = | 582 user_cert_combobox_model_.reset( |
| 539 new UserCertComboboxModel(cert_library_); | 583 new internal::UserCertComboboxModel(cert_library_)); |
| 540 user_cert_combobox_ = new views::Combobox(user_cert_model); | 584 user_cert_combobox_ = new views::Combobox(user_cert_combobox_model_.get()); |
| 541 user_cert_combobox_->set_listener(this); | 585 user_cert_combobox_->set_listener(this); |
| 542 layout->AddView(user_cert_combobox_); | 586 layout->AddView(user_cert_combobox_); |
| 543 layout->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); | 587 layout->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); |
| 544 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 588 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 545 } else { | 589 } else { |
| 546 user_cert_label_ = NULL; | 590 user_cert_label_ = NULL; |
| 547 user_cert_combobox_ = NULL; | 591 user_cert_combobox_ = NULL; |
| 548 } | 592 } |
| 549 | 593 |
| 550 // Username label and input. | 594 // Username label and input. |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 std::string vpn_type; | 863 std::string vpn_type; |
| 820 if (!vpn_dict || !vpn_dict->GetString(onc::kType, &vpn_type)) | 864 if (!vpn_dict || !vpn_dict->GetString(onc::kType, &vpn_type)) |
| 821 return; | 865 return; |
| 822 | 866 |
| 823 property_ui_data->ParseOncProperty( | 867 property_ui_data->ParseOncProperty( |
| 824 network->ui_data(), onc, | 868 network->ui_data(), onc, |
| 825 base::StringPrintf("%s.%s.%s", onc::kVPN, vpn_type.c_str(), key.c_str())); | 869 base::StringPrintf("%s.%s.%s", onc::kVPN, vpn_type.c_str(), key.c_str())); |
| 826 } | 870 } |
| 827 | 871 |
| 828 } // namespace chromeos | 872 } // namespace chromeos |
| OLD | NEW |