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

Unified Diff: chrome/browser/ui/views/certificate_selector.cc

Issue 2898573002: Refactor client cert private key handling. (Closed)
Patch Set: removed no longer needed forward declaration Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/certificate_selector.cc
diff --git a/chrome/browser/ui/views/certificate_selector.cc b/chrome/browser/ui/views/certificate_selector.cc
index 4ae2049f9d15d6252ed46d6ea1a65c373db4bad8..dc75b6eb7d89e75b6837b9d17fa3f7d0da2efda8 100644
--- a/chrome/browser/ui/views/certificate_selector.cc
+++ b/chrome/browser/ui/views/certificate_selector.cc
@@ -45,8 +45,8 @@ const int CertificateSelector::kTableViewHeight = 150;
class CertificateSelector::CertificateTableModel : public ui::TableModel {
public:
- // |certs| and |provider_names| must have the same size.
- CertificateTableModel(const net::CertificateList& certs,
+ // |identities| and |provider_names| must have the same size.
+ CertificateTableModel(const net::ClientCertIdentityList& identities,
const std::vector<std::string>& provider_names);
// ui::TableModel:
@@ -67,11 +67,11 @@ class CertificateSelector::CertificateTableModel : public ui::TableModel {
};
CertificateSelector::CertificateTableModel::CertificateTableModel(
- const net::CertificateList& certs,
+ const net::ClientCertIdentityList& identities,
const std::vector<std::string>& provider_names) {
- DCHECK_EQ(certs.size(), provider_names.size());
- for (size_t i = 0; i < certs.size(); i++) {
- net::X509Certificate* cert = certs[i].get();
+ DCHECK_EQ(identities.size(), provider_names.size());
+ for (size_t i = 0; i < identities.size(); i++) {
+ net::X509Certificate* cert = identities[i]->certificate();
Row row;
row.subject = base::UTF8ToUTF16(cert->subject().GetDisplayName());
row.issuer = base::UTF8ToUTF16(cert->issuer().GetDisplayName());
@@ -113,14 +113,13 @@ base::string16 CertificateSelector::CertificateTableModel::GetText(
void CertificateSelector::CertificateTableModel::SetObserver(
ui::TableModelObserver* observer) {}
-CertificateSelector::CertificateSelector(
- const net::CertificateList& certificates,
- content::WebContents* web_contents)
- : web_contents_(web_contents), table_(nullptr), view_cert_button_(nullptr) {
+CertificateSelector::CertificateSelector(net::ClientCertIdentityList identities,
+ content::WebContents* web_contents)
+ : web_contents_(web_contents) {
CHECK(web_contents_);
- // |provider_names| and |certificates_| are parallel arrays.
- // The entry at index |i| is the provider name for |certificates_[i]|.
+ // |provider_names| and |identities_| are parallel arrays.
+ // The entry at index |i| is the provider name for |identities_[i]|.
std::vector<std::string> provider_names;
#if defined(OS_CHROMEOS)
chromeos::CertificateProviderService* service =
@@ -130,11 +129,12 @@ CertificateSelector::CertificateSelector(
extensions::ExtensionRegistryFactory::GetForBrowserContext(
web_contents->GetBrowserContext());
- for (const auto& cert : certificates) {
+ for (auto& identity : identities) {
std::string provider_name;
bool has_extension = false;
std::string extension_id;
- if (service->LookUpCertificate(*cert, &has_extension, &extension_id)) {
+ if (service->LookUpCertificate(*identity->certificate(), &has_extension,
+ &extension_id)) {
if (!has_extension) {
// This certificate was provided by an extension but isn't provided by
// any extension currently. Don't expose it to the user.
@@ -151,15 +151,15 @@ CertificateSelector::CertificateSelector(
show_provider_column_ = true;
} // Otherwise the certificate is provided by the platform.
- certificates_.push_back(cert);
+ identities_.push_back(std::move(identity));
provider_names.push_back(provider_name);
}
#else
- provider_names.assign(certificates.size(), std::string());
- certificates_ = certificates;
+ provider_names.assign(identities.size(), std::string());
+ identities_ = std::move(identities);
#endif
- model_.reset(new CertificateTableModel(certificates_, provider_names));
+ model_.reset(new CertificateTableModel(identities_, provider_names));
}
CertificateSelector::~CertificateSelector() {
@@ -181,11 +181,11 @@ void CertificateSelector::Show() {
// TODO(isandrk): A certificate that was previously provided by *both* the
// platform and an extension will get incorrectly filtered out if the
// extension stops providing it (both instances will be filtered out), hence
- // the |certificates_| array will be empty. Displaying a dialog with an empty
+ // the |identities_| array will be empty. Displaying a dialog with an empty
// list won't make much sense for the user, and also there are some CHECKs in
// the code that will fail when the list is empty and that's why an early exit
// is performed here. See crbug.com/641440 for more details.
- if (certificates_.empty()) {
+ if (identities_.empty()) {
GetWidget()->Close();
return;
}
@@ -239,12 +239,22 @@ ui::TableModel* CertificateSelector::table_model_for_testing() const {
return model_.get();
}
-net::X509Certificate* CertificateSelector::GetSelectedCert() const {
+net::ClientCertIdentity* CertificateSelector::GetSelectedCert() const {
const int selected = table_->FirstSelectedRow();
if (selected < 0) // Nothing is selected in |table_|.
return nullptr;
- CHECK_LT(static_cast<size_t>(selected), certificates_.size());
- return certificates_[selected].get();
+ DCHECK_LT(static_cast<size_t>(selected), identities_.size());
+ return identities_[selected].get();
+}
+
+bool CertificateSelector::Accept() {
+ const int selected = table_->FirstSelectedRow();
+ if (selected < 0) // Nothing is selected in |table_|.
+ return false;
+
+ DCHECK_LT(static_cast<size_t>(selected), identities_.size());
+ AcceptCertificate(std::move(identities_[selected]));
+ return true;
}
bool CertificateSelector::CanResize() const {
@@ -278,10 +288,12 @@ ui::ModalType CertificateSelector::GetModalType() const {
void CertificateSelector::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == view_cert_button_) {
- net::X509Certificate* const cert = GetSelectedCert();
- if (cert)
+ net::ClientCertIdentity* const cert = GetSelectedCert();
+ if (cert) {
ShowCertificateViewer(web_contents_,
- web_contents_->GetTopLevelNativeWindow(), cert);
+ web_contents_->GetTopLevelNativeWindow(),
+ cert->certificate());
+ }
}
}
« no previous file with comments | « chrome/browser/ui/views/certificate_selector.h ('k') | chrome/browser/ui/views/certificate_selector_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698