Index: chrome/browser/ui/views/certificate_selector.cc |
diff --git a/chrome/browser/ui/views/ssl_client_certificate_selector.cc b/chrome/browser/ui/views/certificate_selector.cc |
similarity index 40% |
copy from chrome/browser/ui/views/ssl_client_certificate_selector.cc |
copy to chrome/browser/ui/views/certificate_selector.cc |
index de31ce8f02a3c46810ae1a838aa29b848d1bfbf0..f19869707e214d84a906a8389f8a4f1cb2c2995c 100644 |
--- a/chrome/browser/ui/views/ssl_client_certificate_selector.cc |
+++ b/chrome/browser/ui/views/certificate_selector.cc |
@@ -1,19 +1,16 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/views/ssl_client_certificate_selector.h" |
+#include "chrome/browser/ui/views/certificate_selector.h" |
-#include "base/compiler_specific.h" |
#include "base/logging.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/certificate_viewer.h" |
#include "chrome/grit/generated_resources.h" |
#include "components/constrained_window/constrained_window_views.h" |
-#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/web_contents.h" |
#include "net/cert/x509_certificate.h" |
-#include "net/ssl/ssl_cert_request_info.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/models/table_model.h" |
#include "ui/base/models/table_model_observer.h" |
@@ -25,17 +22,11 @@ |
#include "ui/views/widget/widget.h" |
#include "ui/views/window/dialog_client_view.h" |
-#if defined(USE_NSS) |
-#include "chrome/browser/ui/crypto_module_password_dialog_nss.h" |
-#endif |
- |
-/////////////////////////////////////////////////////////////////////////////// |
-// CertificateSelectorTableModel: |
+namespace chrome { |
davidben
2015/02/18 20:32:01
To confirm: is //chrome namespaced these days? I r
pneubeck (no reviews)
2015/02/19 15:12:24
I found a few places that use 'namespace chrome'.
|
-class CertificateSelectorTableModel : public ui::TableModel { |
+class CertificateSelector::CertificateTableModel : public ui::TableModel { |
public: |
- explicit CertificateSelectorTableModel( |
- net::SSLCertRequestInfo* cert_request_info); |
+ explicit CertificateTableModel(const net::CertificateList& certificates); |
// ui::TableModel implementation: |
int RowCount() override; |
@@ -45,13 +36,12 @@ class CertificateSelectorTableModel : public ui::TableModel { |
private: |
std::vector<base::string16> items_; |
- DISALLOW_COPY_AND_ASSIGN(CertificateSelectorTableModel); |
+ DISALLOW_COPY_AND_ASSIGN(CertificateTableModel); |
}; |
-CertificateSelectorTableModel::CertificateSelectorTableModel( |
- net::SSLCertRequestInfo* cert_request_info) { |
- for (size_t i = 0; i < cert_request_info->client_certs.size(); ++i) { |
- net::X509Certificate* cert = cert_request_info->client_certs[i].get(); |
+CertificateSelector::CertificateTableModel::CertificateTableModel( |
+ const net::CertificateList& certificates) { |
+ for (const scoped_refptr<net::X509Certificate>& cert : certificates) { |
base::string16 text = l10n_util::GetStringFUTF16( |
IDS_CERT_SELECTOR_TABLE_CERT_FORMAT, |
base::UTF8ToUTF16(cert->subject().GetDisplayName()), |
@@ -60,12 +50,13 @@ CertificateSelectorTableModel::CertificateSelectorTableModel( |
} |
} |
-int CertificateSelectorTableModel::RowCount() { |
+int CertificateSelector::CertificateTableModel::RowCount() { |
return items_.size(); |
} |
-base::string16 CertificateSelectorTableModel::GetText(int index, |
- int column_id) { |
+base::string16 CertificateSelector::CertificateTableModel::GetText( |
+ int index, |
+ int column_id) { |
DCHECK_EQ(column_id, 0); |
DCHECK_GE(index, 0); |
DCHECK_LT(index, static_cast<int>(items_.size())); |
@@ -73,44 +64,37 @@ base::string16 CertificateSelectorTableModel::GetText(int index, |
return items_[index]; |
} |
-void CertificateSelectorTableModel::SetObserver( |
+void CertificateSelector::CertificateTableModel::SetObserver( |
ui::TableModelObserver* observer) { |
} |
-/////////////////////////////////////////////////////////////////////////////// |
-// SSLClientCertificateSelector: |
- |
-SSLClientCertificateSelector::SSLClientCertificateSelector( |
+CertificateSelector::CertificateSelector( |
content::WebContents* web_contents, |
- const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, |
- const chrome::SelectCertificateCallback& callback) |
- : SSLClientAuthObserver(web_contents->GetBrowserContext(), |
- cert_request_info, callback), |
- model_(new CertificateSelectorTableModel(cert_request_info.get())), |
+ const net::CertificateList& certificates, |
+ const SelectCertificateCallback& callback) |
+ : certificates_(certificates), |
+ callback_(callback), |
+ model_(new CertificateTableModel(certificates)), |
web_contents_(web_contents), |
- table_(NULL), |
- view_cert_button_(NULL) { |
+ table_(nullptr), |
+ view_cert_button_(nullptr) { |
DVLOG(1) << __FUNCTION__; |
} |
-SSLClientCertificateSelector::~SSLClientCertificateSelector() { |
- table_->SetModel(NULL); |
+CertificateSelector::~CertificateSelector() { |
+ table_->SetModel(nullptr); |
} |
-void SSLClientCertificateSelector::Init() { |
+void CertificateSelector::Init(const base::string16& text) { |
views::GridLayout* layout = views::GridLayout::CreatePanel(this); |
SetLayoutManager(layout); |
const int column_set_id = 0; |
views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
- column_set->AddColumn( |
- views::GridLayout::FILL, views::GridLayout::FILL, |
- 1, views::GridLayout::USE_PREF, 0, 0); |
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
+ views::GridLayout::USE_PREF, 0, 0); |
layout->StartRow(0, column_set_id); |
- base::string16 text = l10n_util::GetStringFUTF16( |
- IDS_CLIENT_CERT_DIALOG_TEXT, |
- base::ASCIIToUTF16(cert_request_info()->host_and_port.ToString())); |
views::Label* label = new views::Label(text); |
label->SetMultiLine(true); |
label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
@@ -126,13 +110,11 @@ void SSLClientCertificateSelector::Init() { |
CreateCertTable(); |
layout->StartRow(1, column_set_id); |
layout->AddView(table_->CreateParentIfNecessary(), 1, 1, |
- views::GridLayout::FILL, |
- views::GridLayout::FILL, kTableViewWidth, kTableViewHeight); |
+ views::GridLayout::FILL, views::GridLayout::FILL, |
+ kTableViewWidth, kTableViewHeight); |
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
- StartObserving(); |
- |
constrained_window::ShowWebModalDialogViews(this, web_contents_); |
// Select the first row automatically. This must be done after the dialog has |
@@ -140,123 +122,84 @@ void SSLClientCertificateSelector::Init() { |
table_->Select(0); |
} |
-net::X509Certificate* SSLClientCertificateSelector::GetSelectedCert() const { |
+net::X509Certificate* CertificateSelector::GetSelectedCert() const { |
int selected = table_->FirstSelectedRow(); |
- if (selected >= 0 && |
- selected < static_cast<int>(cert_request_info()->client_certs.size())) |
- return cert_request_info()->client_certs[selected].get(); |
- return NULL; |
-} |
- |
-/////////////////////////////////////////////////////////////////////////////// |
-// SSLClientAuthObserver implementation: |
- |
-void SSLClientCertificateSelector::OnCertSelectedByNotification() { |
- DVLOG(1) << __FUNCTION__; |
- GetWidget()->Close(); |
+ if (selected >= 0 && selected < static_cast<int>(certificates_.size())) |
+ return certificates_[selected].get(); |
+ return nullptr; |
} |
-/////////////////////////////////////////////////////////////////////////////// |
-// DialogDelegateView implementation: |
- |
-bool SSLClientCertificateSelector::CanResize() const { |
+bool CertificateSelector::CanResize() const { |
return true; |
} |
-base::string16 SSLClientCertificateSelector::GetWindowTitle() const { |
+base::string16 CertificateSelector::GetWindowTitle() const { |
return l10n_util::GetStringUTF16(IDS_CLIENT_CERT_DIALOG_TITLE); |
} |
-void SSLClientCertificateSelector::DeleteDelegate() { |
+void CertificateSelector::DeleteDelegate() { |
DVLOG(1) << __FUNCTION__; |
delete this; |
} |
-bool SSLClientCertificateSelector::IsDialogButtonEnabled( |
- ui::DialogButton button) const { |
+bool CertificateSelector::IsDialogButtonEnabled(ui::DialogButton button) const { |
if (button == ui::DIALOG_BUTTON_OK) |
- return !!GetSelectedCert(); |
+ return GetSelectedCert() != nullptr; |
return true; |
} |
-bool SSLClientCertificateSelector::Cancel() { |
+bool CertificateSelector::Cancel() { |
DVLOG(1) << __FUNCTION__; |
- StopObserving(); |
- CertificateSelected(NULL); |
+ callback_.Run(nullptr); |
return true; |
} |
-bool SSLClientCertificateSelector::Accept() { |
+bool CertificateSelector::Accept() { |
DVLOG(1) << __FUNCTION__; |
scoped_refptr<net::X509Certificate> cert = GetSelectedCert(); |
- if (cert.get()) { |
- // Remove the observer before we try unlocking, otherwise we might act on a |
- // notification while waiting for the unlock dialog, causing us to delete |
- // ourself before the Unlocked callback gets called. |
- StopObserving(); |
-#if defined(USE_NSS) |
- chrome::UnlockCertSlotIfNecessary( |
- cert.get(), |
- chrome::kCryptoModulePasswordClientAuth, |
- cert_request_info()->host_and_port, |
- GetWidget()->GetNativeView(), |
- base::Bind(&SSLClientCertificateSelector::Unlocked, |
- base::Unretained(this), |
- cert)); |
-#else |
- Unlocked(cert.get()); |
-#endif |
- return false; // Unlocked() will close the dialog. |
- } |
+ if (!cert.get()) |
+ return false; |
- return false; |
+ callback_.Run(cert); |
+ return true; |
} |
-views::View* SSLClientCertificateSelector::GetInitiallyFocusedView() { |
+views::View* CertificateSelector::GetInitiallyFocusedView() { |
return table_; |
} |
-views::View* SSLClientCertificateSelector::CreateExtraView() { |
+views::View* CertificateSelector::CreateExtraView() { |
DCHECK(!view_cert_button_); |
- view_cert_button_ = new views::LabelButton(this, |
- l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON)); |
+ view_cert_button_ = new views::LabelButton( |
+ this, l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON)); |
view_cert_button_->SetStyle(views::Button::STYLE_BUTTON); |
return view_cert_button_; |
} |
-ui::ModalType SSLClientCertificateSelector::GetModalType() const { |
+ui::ModalType CertificateSelector::GetModalType() const { |
return ui::MODAL_TYPE_CHILD; |
} |
-/////////////////////////////////////////////////////////////////////////////// |
-// views::ButtonListener implementation: |
- |
-void SSLClientCertificateSelector::ButtonPressed( |
- views::Button* sender, const ui::Event& event) { |
+void CertificateSelector::ButtonPressed(views::Button* sender, |
+ const ui::Event& event) { |
if (sender == view_cert_button_) { |
net::X509Certificate* cert = GetSelectedCert(); |
if (cert) |
ShowCertificateViewer(web_contents_, |
- web_contents_->GetTopLevelNativeWindow(), |
- cert); |
+ web_contents_->GetTopLevelNativeWindow(), cert); |
} |
} |
-/////////////////////////////////////////////////////////////////////////////// |
-// views::TableViewObserver implementation: |
-void SSLClientCertificateSelector::OnSelectionChanged() { |
- GetDialogClientView()->ok_button()->SetEnabled(!!GetSelectedCert()); |
+void CertificateSelector::OnSelectionChanged() { |
+ GetDialogClientView()->ok_button()->SetEnabled(GetSelectedCert() != nullptr); |
} |
-void SSLClientCertificateSelector::OnDoubleClick() { |
+void CertificateSelector::OnDoubleClick() { |
if (Accept()) |
GetWidget()->Close(); |
} |
-/////////////////////////////////////////////////////////////////////////////// |
-// SSLClientCertificateSelector private methods: |
- |
-void SSLClientCertificateSelector::CreateCertTable() { |
+void CertificateSelector::CreateCertTable() { |
std::vector<ui::TableColumn> columns; |
columns.push_back(ui::TableColumn()); |
table_ = new views::TableView(model_.get(), columns, views::TEXT_ONLY, |
@@ -264,22 +207,4 @@ void SSLClientCertificateSelector::CreateCertTable() { |
table_->SetObserver(this); |
} |
-void SSLClientCertificateSelector::Unlocked(net::X509Certificate* cert) { |
- DVLOG(1) << __FUNCTION__; |
- CertificateSelected(cert); |
- GetWidget()->Close(); |
-} |
- |
-namespace chrome { |
- |
-void ShowSSLClientCertificateSelector( |
- content::WebContents* contents, |
- net::SSLCertRequestInfo* cert_request_info, |
- const chrome::SelectCertificateCallback& callback) { |
- DVLOG(1) << __FUNCTION__ << " " << contents; |
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
- (new SSLClientCertificateSelector( |
- contents, cert_request_info, callback))->Init(); |
-} |
- |
} // namespace chrome |