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

Side by Side Diff: chrome/browser/ui/views/certificate_selector.cc

Issue 2898573002: Refactor client cert private key handling. (Closed)
Patch Set: rebase on https://codereview.chromium.org/2899083006/ Created 3 years, 7 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ui/views/certificate_selector.h" 5 #include "chrome/browser/ui/views/certificate_selector.h"
6 6
7 #include <stddef.h> // For size_t. 7 #include <stddef.h> // For size_t.
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 28 matching lines...) Expand all
39 #endif 39 #endif
40 40
41 namespace chrome { 41 namespace chrome {
42 42
43 const int CertificateSelector::kTableViewWidth = 500; 43 const int CertificateSelector::kTableViewWidth = 500;
44 const int CertificateSelector::kTableViewHeight = 150; 44 const int CertificateSelector::kTableViewHeight = 150;
45 45
46 class CertificateSelector::CertificateTableModel : public ui::TableModel { 46 class CertificateSelector::CertificateTableModel : public ui::TableModel {
47 public: 47 public:
48 // |certs| and |provider_names| must have the same size. 48 // |certs| and |provider_names| must have the same size.
49 CertificateTableModel(const net::CertificateList& certs, 49 CertificateTableModel(const net::ClientCertIdentityList& certs,
50 const std::vector<std::string>& provider_names); 50 const std::vector<std::string>& provider_names);
51 51
52 // ui::TableModel: 52 // ui::TableModel:
53 int RowCount() override; 53 int RowCount() override;
54 base::string16 GetText(int index, int column_id) override; 54 base::string16 GetText(int index, int column_id) override;
55 void SetObserver(ui::TableModelObserver* observer) override; 55 void SetObserver(ui::TableModelObserver* observer) override;
56 56
57 private: 57 private:
58 struct Row { 58 struct Row {
59 base::string16 subject; 59 base::string16 subject;
60 base::string16 issuer; 60 base::string16 issuer;
61 base::string16 provider; 61 base::string16 provider;
62 base::string16 serial; 62 base::string16 serial;
63 }; 63 };
64 std::vector<Row> rows_; 64 std::vector<Row> rows_;
65 65
66 DISALLOW_COPY_AND_ASSIGN(CertificateTableModel); 66 DISALLOW_COPY_AND_ASSIGN(CertificateTableModel);
67 }; 67 };
68 68
69 CertificateSelector::CertificateTableModel::CertificateTableModel( 69 CertificateSelector::CertificateTableModel::CertificateTableModel(
70 const net::CertificateList& certs, 70 const net::ClientCertIdentityList& certs,
71 const std::vector<std::string>& provider_names) { 71 const std::vector<std::string>& provider_names) {
72 DCHECK_EQ(certs.size(), provider_names.size()); 72 DCHECK_EQ(certs.size(), provider_names.size());
73 for (size_t i = 0; i < certs.size(); i++) { 73 for (size_t i = 0; i < certs.size(); i++) {
74 net::X509Certificate* cert = certs[i].get(); 74 net::X509Certificate* cert = certs[i]->certificate();
75 Row row; 75 Row row;
76 row.subject = base::UTF8ToUTF16(cert->subject().GetDisplayName()); 76 row.subject = base::UTF8ToUTF16(cert->subject().GetDisplayName());
77 row.issuer = base::UTF8ToUTF16(cert->issuer().GetDisplayName()); 77 row.issuer = base::UTF8ToUTF16(cert->issuer().GetDisplayName());
78 row.provider = base::UTF8ToUTF16(provider_names[i]); 78 row.provider = base::UTF8ToUTF16(provider_names[i]);
79 if (cert->serial_number().size() < std::numeric_limits<size_t>::max() / 2) { 79 if (cert->serial_number().size() < std::numeric_limits<size_t>::max() / 2) {
80 row.serial = base::UTF8ToUTF16(base::HexEncode( 80 row.serial = base::UTF8ToUTF16(base::HexEncode(
81 cert->serial_number().data(), cert->serial_number().size())); 81 cert->serial_number().data(), cert->serial_number().size()));
82 } 82 }
83 rows_.push_back(row); 83 rows_.push_back(row);
84 } 84 }
(...skipping 22 matching lines...) Expand all
107 default: 107 default:
108 NOTREACHED(); 108 NOTREACHED();
109 } 109 }
110 return base::string16(); 110 return base::string16();
111 } 111 }
112 112
113 void CertificateSelector::CertificateTableModel::SetObserver( 113 void CertificateSelector::CertificateTableModel::SetObserver(
114 ui::TableModelObserver* observer) {} 114 ui::TableModelObserver* observer) {}
115 115
116 CertificateSelector::CertificateSelector( 116 CertificateSelector::CertificateSelector(
117 const net::CertificateList& certificates, 117 net::ClientCertIdentityList certificates,
118 content::WebContents* web_contents) 118 content::WebContents* web_contents)
119 : web_contents_(web_contents), table_(nullptr), view_cert_button_(nullptr) { 119 : web_contents_(web_contents), table_(nullptr), view_cert_button_(nullptr) {
120 CHECK(web_contents_); 120 CHECK(web_contents_);
121 121
122 // |provider_names| and |certificates_| are parallel arrays. 122 // |provider_names| and |certificates_| are parallel arrays.
123 // The entry at index |i| is the provider name for |certificates_[i]|. 123 // The entry at index |i| is the provider name for |certificates_[i]|.
124 std::vector<std::string> provider_names; 124 std::vector<std::string> provider_names;
125 #if defined(OS_CHROMEOS) 125 #if defined(OS_CHROMEOS)
126 chromeos::CertificateProviderService* service = 126 chromeos::CertificateProviderService* service =
127 chromeos::CertificateProviderServiceFactory::GetForBrowserContext( 127 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
128 web_contents->GetBrowserContext()); 128 web_contents->GetBrowserContext());
129 extensions::ExtensionRegistry* extension_registry = 129 extensions::ExtensionRegistry* extension_registry =
130 extensions::ExtensionRegistryFactory::GetForBrowserContext( 130 extensions::ExtensionRegistryFactory::GetForBrowserContext(
131 web_contents->GetBrowserContext()); 131 web_contents->GetBrowserContext());
132 132
133 for (const auto& cert : certificates) { 133 for (auto& cert : certificates) {
134 std::string provider_name; 134 std::string provider_name;
135 bool has_extension = false; 135 bool has_extension = false;
136 std::string extension_id; 136 std::string extension_id;
137 if (service->LookUpCertificate(*cert, &has_extension, &extension_id)) { 137 // XXX UGH.
138 if (service->LookUpCertificate(*cert->certificate(), &has_extension,
139 &extension_id)) {
138 if (!has_extension) { 140 if (!has_extension) {
139 // This certificate was provided by an extension but isn't provided by 141 // This certificate was provided by an extension but isn't provided by
140 // any extension currently. Don't expose it to the user. 142 // any extension currently. Don't expose it to the user.
141 continue; 143 continue;
142 } 144 }
143 const auto* extension = extension_registry->GetExtensionById( 145 const auto* extension = extension_registry->GetExtensionById(
144 extension_id, extensions::ExtensionRegistry::ENABLED); 146 extension_id, extensions::ExtensionRegistry::ENABLED);
145 if (!extension) { 147 if (!extension) {
146 // This extension was unloaded in the meantime. Don't show the 148 // This extension was unloaded in the meantime. Don't show the
147 // certificate. 149 // certificate.
148 continue; 150 continue;
149 } 151 }
150 provider_name = extension->short_name(); 152 provider_name = extension->short_name();
151 show_provider_column_ = true; 153 show_provider_column_ = true;
152 } // Otherwise the certificate is provided by the platform. 154 } // Otherwise the certificate is provided by the platform.
153 155
154 certificates_.push_back(cert); 156 certificates_.push_back(std::move(cert));
155 provider_names.push_back(provider_name); 157 provider_names.push_back(provider_name);
156 } 158 }
157 #else 159 #else
158 provider_names.assign(certificates.size(), std::string()); 160 provider_names.assign(certificates.size(), std::string());
159 certificates_ = certificates; 161 certificates_ = std::move(certificates);
160 #endif 162 #endif
161 163
162 model_.reset(new CertificateTableModel(certificates_, provider_names)); 164 model_.reset(new CertificateTableModel(certificates_, provider_names));
163 } 165 }
164 166
165 CertificateSelector::~CertificateSelector() { 167 CertificateSelector::~CertificateSelector() {
166 table_->SetModel(nullptr); 168 table_->SetModel(nullptr);
167 } 169 }
168 170
169 // static 171 // static
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 views::GridLayout::FILL, views::GridLayout::FILL, 234 views::GridLayout::FILL, views::GridLayout::FILL,
233 kTableViewWidth, kTableViewHeight); 235 kTableViewWidth, kTableViewHeight);
234 236
235 layout->AddPaddingRow(0, vertical_spacing); 237 layout->AddPaddingRow(0, vertical_spacing);
236 } 238 }
237 239
238 ui::TableModel* CertificateSelector::table_model_for_testing() const { 240 ui::TableModel* CertificateSelector::table_model_for_testing() const {
239 return model_.get(); 241 return model_.get();
240 } 242 }
241 243
242 net::X509Certificate* CertificateSelector::GetSelectedCert() const { 244 net::ClientCertIdentity* CertificateSelector::GetSelectedCert() const {
243 const int selected = table_->FirstSelectedRow(); 245 const int selected = table_->FirstSelectedRow();
244 if (selected < 0) // Nothing is selected in |table_|. 246 if (selected < 0) // Nothing is selected in |table_|.
245 return nullptr; 247 return nullptr;
246 CHECK_LT(static_cast<size_t>(selected), certificates_.size()); 248 CHECK_LT(static_cast<size_t>(selected), certificates_.size());
247 return certificates_[selected].get(); 249 return certificates_[selected].get();
248 } 250 }
249 251
250 bool CertificateSelector::CanResize() const { 252 bool CertificateSelector::CanResize() const {
251 return true; 253 return true;
252 } 254 }
(...skipping 17 matching lines...) Expand all
270 this, l10n_util::GetStringUTF16(IDS_PAGE_INFO_CERT_INFO_BUTTON)); 272 this, l10n_util::GetStringUTF16(IDS_PAGE_INFO_CERT_INFO_BUTTON));
271 return view_cert_button_; 273 return view_cert_button_;
272 } 274 }
273 275
274 ui::ModalType CertificateSelector::GetModalType() const { 276 ui::ModalType CertificateSelector::GetModalType() const {
275 return ui::MODAL_TYPE_CHILD; 277 return ui::MODAL_TYPE_CHILD;
276 } 278 }
277 279
278 void CertificateSelector::ButtonPressed(views::Button* sender, 280 void CertificateSelector::ButtonPressed(views::Button* sender,
279 const ui::Event& event) { 281 const ui::Event& event) {
280 if (sender == view_cert_button_) { 282 if (sender == view_cert_button_ && GetSelectedCert()) {
281 net::X509Certificate* const cert = GetSelectedCert(); 283 ShowCertificateViewer(web_contents_,
282 if (cert) 284 web_contents_->GetTopLevelNativeWindow(),
283 ShowCertificateViewer(web_contents_, 285 GetSelectedCert()->certificate());
284 web_contents_->GetTopLevelNativeWindow(), cert);
285 } 286 }
286 } 287 }
287 288
288 void CertificateSelector::OnSelectionChanged() { 289 void CertificateSelector::OnSelectionChanged() {
289 GetDialogClientView()->ok_button()->SetEnabled(GetSelectedCert() != nullptr); 290 GetDialogClientView()->ok_button()->SetEnabled(GetSelectedCert() != nullptr);
290 } 291 }
291 292
292 void CertificateSelector::OnDoubleClick() { 293 void CertificateSelector::OnDoubleClick() {
293 if (GetSelectedCert()) 294 if (GetSelectedCert())
294 GetDialogClientView()->AcceptWindow(); 295 GetDialogClientView()->AcceptWindow();
295 } 296 }
296 297
297 } // namespace chrome 298 } // namespace chrome
OLDNEW
« 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