| 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/ui/views/ssl_client_certificate_selector.h" | 5 #include "chrome/browser/ui/views/ssl_client_certificate_selector.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/certificate_viewer.h" | 11 #include "chrome/browser/certificate_viewer.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 13 #include "chrome/browser/ui/views/constrained_window_views.h" | 13 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_view.h" | 16 #include "content/public/browser/web_contents_view.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "net/base/ssl_cert_request_info.h" |
| 18 #include "net/base/x509_certificate.h" | 19 #include "net/base/x509_certificate.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/models/table_model.h" | 21 #include "ui/base/models/table_model.h" |
| 21 #include "ui/base/models/table_model_observer.h" | 22 #include "ui/base/models/table_model_observer.h" |
| 22 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
| 23 #include "ui/views/controls/button/text_button.h" | 24 #include "ui/views/controls/button/text_button.h" |
| 24 #include "ui/views/controls/label.h" | 25 #include "ui/views/controls/label.h" |
| 25 #include "ui/views/controls/table/table_view.h" | 26 #include "ui/views/controls/table/table_view.h" |
| 26 #include "ui/views/layout/grid_layout.h" | 27 #include "ui/views/layout/grid_layout.h" |
| 27 #include "ui/views/layout/layout_constants.h" | 28 #include "ui/views/layout/layout_constants.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 82 |
| 82 void CertificateSelectorTableModel::SetObserver( | 83 void CertificateSelectorTableModel::SetObserver( |
| 83 ui::TableModelObserver* observer) { | 84 ui::TableModelObserver* observer) { |
| 84 } | 85 } |
| 85 | 86 |
| 86 /////////////////////////////////////////////////////////////////////////////// | 87 /////////////////////////////////////////////////////////////////////////////// |
| 87 // SSLClientCertificateSelector: | 88 // SSLClientCertificateSelector: |
| 88 | 89 |
| 89 SSLClientCertificateSelector::SSLClientCertificateSelector( | 90 SSLClientCertificateSelector::SSLClientCertificateSelector( |
| 90 TabContentsWrapper* wrapper, | 91 TabContentsWrapper* wrapper, |
| 92 const net::HttpNetworkSession* network_session, |
| 91 net::SSLCertRequestInfo* cert_request_info, | 93 net::SSLCertRequestInfo* cert_request_info, |
| 92 SSLClientAuthHandler* delegate) | 94 const base::Callback<void(net::X509Certificate*)>& callback) |
| 93 : SSLClientAuthObserver(cert_request_info, delegate), | 95 : SSLClientAuthObserver(network_session, cert_request_info, callback), |
| 94 cert_request_info_(cert_request_info), | |
| 95 delegate_(delegate), | |
| 96 model_(new CertificateSelectorTableModel(cert_request_info)), | 96 model_(new CertificateSelectorTableModel(cert_request_info)), |
| 97 wrapper_(wrapper), | 97 wrapper_(wrapper), |
| 98 window_(NULL), | 98 window_(NULL), |
| 99 table_(NULL), | 99 table_(NULL), |
| 100 view_cert_button_(NULL), | 100 view_cert_button_(NULL), |
| 101 view_cert_button_container_(NULL) { | 101 view_cert_button_container_(NULL) { |
| 102 DVLOG(1) << __FUNCTION__; | 102 DVLOG(1) << __FUNCTION__; |
| 103 } | 103 } |
| 104 | 104 |
| 105 SSLClientCertificateSelector::~SSLClientCertificateSelector() { | 105 SSLClientCertificateSelector::~SSLClientCertificateSelector() { |
| 106 table_->SetModel(NULL); | 106 table_->SetModel(NULL); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void SSLClientCertificateSelector::Init() { | 109 void SSLClientCertificateSelector::Init() { |
| 110 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | 110 views::GridLayout* layout = views::GridLayout::CreatePanel(this); |
| 111 SetLayoutManager(layout); | 111 SetLayoutManager(layout); |
| 112 | 112 |
| 113 const int column_set_id = 0; | 113 const int column_set_id = 0; |
| 114 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); | 114 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
| 115 column_set->AddColumn( | 115 column_set->AddColumn( |
| 116 views::GridLayout::FILL, views::GridLayout::FILL, | 116 views::GridLayout::FILL, views::GridLayout::FILL, |
| 117 1, views::GridLayout::USE_PREF, 0, 0); | 117 1, views::GridLayout::USE_PREF, 0, 0); |
| 118 | 118 |
| 119 layout->StartRow(0, column_set_id); | 119 layout->StartRow(0, column_set_id); |
| 120 string16 text = l10n_util::GetStringFUTF16( | 120 string16 text = l10n_util::GetStringFUTF16( |
| 121 IDS_CLIENT_CERT_DIALOG_TEXT, | 121 IDS_CLIENT_CERT_DIALOG_TEXT, |
| 122 ASCIIToUTF16(cert_request_info_->host_and_port)); | 122 ASCIIToUTF16(cert_request_info()->host_and_port)); |
| 123 views::Label* label = new views::Label(text); | 123 views::Label* label = new views::Label(text); |
| 124 label->SetMultiLine(true); | 124 label->SetMultiLine(true); |
| 125 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 125 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 126 label->SetAllowCharacterBreak(true); | 126 label->SetAllowCharacterBreak(true); |
| 127 layout->AddView(label); | 127 layout->AddView(label); |
| 128 | 128 |
| 129 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 129 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 130 | 130 |
| 131 CreateCertTable(); | 131 CreateCertTable(); |
| 132 layout->StartRow(1, column_set_id); | 132 layout->StartRow(1, column_set_id); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 144 | 144 |
| 145 // Select the first row automatically. This must be done after the dialog has | 145 // Select the first row automatically. This must be done after the dialog has |
| 146 // been created. | 146 // been created. |
| 147 table_->Select(0); | 147 table_->Select(0); |
| 148 } | 148 } |
| 149 | 149 |
| 150 net::X509Certificate* SSLClientCertificateSelector::GetSelectedCert() const { | 150 net::X509Certificate* SSLClientCertificateSelector::GetSelectedCert() const { |
| 151 int selected = table_->FirstSelectedRow(); | 151 int selected = table_->FirstSelectedRow(); |
| 152 if (selected >= 0 && | 152 if (selected >= 0 && |
| 153 selected < static_cast<int>( | 153 selected < static_cast<int>( |
| 154 cert_request_info_->client_certs.size())) | 154 cert_request_info()->client_certs.size())) |
| 155 return cert_request_info_->client_certs[selected]; | 155 return cert_request_info()->client_certs[selected]; |
| 156 return NULL; | 156 return NULL; |
| 157 } | 157 } |
| 158 | 158 |
| 159 /////////////////////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////////////////////// |
| 160 // SSLClientAuthObserver implementation: | 160 // SSLClientAuthObserver implementation: |
| 161 | 161 |
| 162 void SSLClientCertificateSelector::OnCertSelectedByNotification() { | 162 void SSLClientCertificateSelector::OnCertSelectedByNotification() { |
| 163 DVLOG(1) << __FUNCTION__; | 163 DVLOG(1) << __FUNCTION__; |
| 164 delegate_ = NULL; | |
| 165 DCHECK(window_); | 164 DCHECK(window_); |
| 166 window_->CloseConstrainedWindow(); | 165 window_->CloseConstrainedWindow(); |
| 167 } | 166 } |
| 168 | 167 |
| 169 /////////////////////////////////////////////////////////////////////////////// | 168 /////////////////////////////////////////////////////////////////////////////// |
| 170 // DialogDelegateView implementation: | 169 // DialogDelegateView implementation: |
| 171 | 170 |
| 172 bool SSLClientCertificateSelector::CanResize() const { | 171 bool SSLClientCertificateSelector::CanResize() const { |
| 173 return true; | 172 return true; |
| 174 } | 173 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 185 bool SSLClientCertificateSelector::IsDialogButtonEnabled( | 184 bool SSLClientCertificateSelector::IsDialogButtonEnabled( |
| 186 ui::DialogButton button) const { | 185 ui::DialogButton button) const { |
| 187 if (button == ui::DIALOG_BUTTON_OK) | 186 if (button == ui::DIALOG_BUTTON_OK) |
| 188 return !!GetSelectedCert(); | 187 return !!GetSelectedCert(); |
| 189 return true; | 188 return true; |
| 190 } | 189 } |
| 191 | 190 |
| 192 bool SSLClientCertificateSelector::Cancel() { | 191 bool SSLClientCertificateSelector::Cancel() { |
| 193 DVLOG(1) << __FUNCTION__; | 192 DVLOG(1) << __FUNCTION__; |
| 194 StopObserving(); | 193 StopObserving(); |
| 195 if (delegate_) { | 194 CertificateSelected(NULL); |
| 196 delegate_->CertificateSelected(NULL); | |
| 197 delegate_ = NULL; | |
| 198 } | |
| 199 | 195 |
| 200 return true; | 196 return true; |
| 201 } | 197 } |
| 202 | 198 |
| 203 bool SSLClientCertificateSelector::Accept() { | 199 bool SSLClientCertificateSelector::Accept() { |
| 204 DVLOG(1) << __FUNCTION__; | 200 DVLOG(1) << __FUNCTION__; |
| 205 net::X509Certificate* cert = GetSelectedCert(); | 201 net::X509Certificate* cert = GetSelectedCert(); |
| 206 if (cert) { | 202 if (cert) { |
| 207 StopObserving(); | 203 StopObserving(); |
| 208 delegate_->CertificateSelected(GetSelectedCert()); | 204 CertificateSelected(cert); |
| 209 delegate_ = NULL; | |
| 210 | |
| 211 return true; | 205 return true; |
| 212 } | 206 } |
| 213 | 207 |
| 214 return false; | 208 return false; |
| 215 } | 209 } |
| 216 | 210 |
| 217 views::View* SSLClientCertificateSelector::GetInitiallyFocusedView() { | 211 views::View* SSLClientCertificateSelector::GetInitiallyFocusedView() { |
| 218 return table_; | 212 return table_; |
| 219 } | 213 } |
| 220 | 214 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 layout->AddView(view_cert_button_); | 278 layout->AddView(view_cert_button_); |
| 285 } | 279 } |
| 286 | 280 |
| 287 /////////////////////////////////////////////////////////////////////////////// | 281 /////////////////////////////////////////////////////////////////////////////// |
| 288 // SSLClientCertificateSelector public interface: | 282 // SSLClientCertificateSelector public interface: |
| 289 | 283 |
| 290 namespace browser { | 284 namespace browser { |
| 291 | 285 |
| 292 void ShowNativeSSLClientCertificateSelector( | 286 void ShowNativeSSLClientCertificateSelector( |
| 293 TabContentsWrapper* wrapper, | 287 TabContentsWrapper* wrapper, |
| 288 const net::HttpNetworkSession* network_session, |
| 294 net::SSLCertRequestInfo* cert_request_info, | 289 net::SSLCertRequestInfo* cert_request_info, |
| 295 SSLClientAuthHandler* delegate) { | 290 const base::Callback<void(net::X509Certificate*)>& callback) { |
| 296 DVLOG(1) << __FUNCTION__ << " " << wrapper; | 291 DVLOG(1) << __FUNCTION__ << " " << wrapper; |
| 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 298 (new SSLClientCertificateSelector(wrapper, | 293 (new SSLClientCertificateSelector( |
| 299 cert_request_info, | 294 wrapper, network_session, cert_request_info, callback))->Init(); |
| 300 delegate))->Init(); | |
| 301 } | 295 } |
| 302 | 296 |
| 303 #if !defined(USE_NSS) && !defined(USE_OPENSSL) | 297 #if !defined(USE_NSS) && !defined(USE_OPENSSL) |
| 304 // The webui version of the SSL client cert selector is excluded from the build | 298 // The webui version of the SSL client cert selector is excluded from the build |
| 305 // under these conditions. Add stub implementation for the required method. | 299 // under these conditions. Add stub implementation for the required method. |
| 306 void ShowSSLClientCertificateSelector( | 300 void ShowSSLClientCertificateSelector( |
| 307 TabContentsWrapper* wrapper, | 301 TabContentsWrapper* wrapper, |
| 302 const net::HttpNetworkSession* network_session, |
| 308 net::SSLCertRequestInfo* cert_request_info, | 303 net::SSLCertRequestInfo* cert_request_info, |
| 309 SSLClientAuthHandler* delegate) { | 304 const base::Callback<void(net::X509Certificate*)>& callback) { |
| 310 ShowNativeSSLClientCertificateSelector(wrapper, cert_request_info, delegate); | 305 ShowNativeSSLClientCertificateSelector( |
| 306 wrapper, network_session, cert_request_info, callback); |
| 311 } | 307 } |
| 312 #endif | 308 #endif |
| 313 | 309 |
| 314 } // namespace browser | 310 } // namespace browser |
| OLD | NEW |