| OLD | NEW |
| 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_VIEWS_SSL_CLIENT_CERTIFICATE_SELECTOR_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_SSL_CLIENT_CERTIFICATE_SELECTOR_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include "base/macros.h" |
| 9 #include <vector> | 9 #include "base/memory/scoped_ptr.h" |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 13 #include "chrome/browser/ssl/ssl_client_auth_observer.h" | 11 #include "net/cert/x509_certificate.h" |
| 14 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" | |
| 15 #include "ui/views/controls/button/button.h" | 12 #include "ui/views/controls/button/button.h" |
| 16 #include "ui/views/controls/table/table_view_observer.h" | 13 #include "ui/views/controls/table/table_view_observer.h" |
| 17 #include "ui/views/window/dialog_delegate.h" | 14 #include "ui/views/window/dialog_delegate.h" |
| 18 | 15 |
| 19 // This header file exists only for testing. Chrome should access the | 16 namespace content { |
| 20 // certificate selector only through the cross-platform interface | 17 class WebContents; |
| 21 // chrome/browser/ssl_client_certificate_selector.h. | |
| 22 | |
| 23 namespace net { | |
| 24 class SSLCertRequestInfo; | |
| 25 class X509Certificate; | |
| 26 } | 18 } |
| 27 | 19 |
| 28 namespace views { | 20 namespace views { |
| 29 class LabelButton; | 21 class LabelButton; |
| 30 class TableView; | 22 class TableView; |
| 31 class Widget; | |
| 32 } | 23 } |
| 33 | 24 |
| 34 class CertificateSelectorTableModel; | 25 namespace chrome { |
| 35 | 26 |
| 36 class SSLClientCertificateSelector : public SSLClientAuthObserver, | 27 // A base class for dialogs that show a given list of certificates to the user. |
| 37 public views::DialogDelegateView, | 28 // The user can select a single certificate and look at details of each |
| 38 public views::ButtonListener, | 29 // certificate. |
| 39 public views::TableViewObserver { | 30 // The currently selected certificate can be obtained using |GetSelectedCert()|. |
| 31 // The explanatory text shown to the user must be provided to |InitWithText()|. |
| 32 class CertificateSelector : public views::DialogDelegateView, |
| 33 public views::ButtonListener, |
| 34 public views::TableViewObserver { |
| 40 public: | 35 public: |
| 41 SSLClientCertificateSelector( | 36 class CertificateTableModel; |
| 42 content::WebContents* web_contents, | |
| 43 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, | |
| 44 const chrome::SelectCertificateCallback& callback); | |
| 45 ~SSLClientCertificateSelector() override; | |
| 46 | 37 |
| 47 void Init(); | 38 // |web_contents| must not be null. |
| 39 CertificateSelector(const net::CertificateList& certificates, |
| 40 content::WebContents* web_contents); |
| 41 ~CertificateSelector() override; |
| 48 | 42 |
| 43 // Returns the currently selected certificate or null if none is selected. |
| 44 // Must be called after |InitWithText()|. |
| 49 net::X509Certificate* GetSelectedCert() const; | 45 net::X509Certificate* GetSelectedCert() const; |
| 50 | 46 |
| 51 // SSLClientAuthObserver implementation: | 47 // Shows this dialog as a constrained web modal dialog and focuses the first |
| 52 void OnCertSelectedByNotification() override; | 48 // certificate. |
| 49 // Must be called after |InitWithText()|. |
| 50 void Show(); |
| 53 | 51 |
| 54 // DialogDelegateView: | 52 // DialogDelegateView: |
| 55 bool CanResize() const override; | 53 bool CanResize() const override; |
| 56 base::string16 GetWindowTitle() const override; | 54 base::string16 GetWindowTitle() const override; |
| 57 void DeleteDelegate() override; | |
| 58 bool IsDialogButtonEnabled(ui::DialogButton button) const override; | 55 bool IsDialogButtonEnabled(ui::DialogButton button) const override; |
| 59 bool Cancel() override; | |
| 60 bool Accept() override; | |
| 61 views::View* GetInitiallyFocusedView() override; | 56 views::View* GetInitiallyFocusedView() override; |
| 62 views::View* CreateExtraView() override; | 57 views::View* CreateExtraView() override; |
| 63 ui::ModalType GetModalType() const override; | 58 ui::ModalType GetModalType() const override; |
| 64 | 59 |
| 65 // views::ButtonListener: | 60 // views::ButtonListener: |
| 66 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 61 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 67 | 62 |
| 68 // views::TableViewObserver: | 63 // views::TableViewObserver: |
| 69 void OnSelectionChanged() override; | 64 void OnSelectionChanged() override; |
| 70 void OnDoubleClick() override; | 65 void OnDoubleClick() override; |
| 71 | 66 |
| 67 protected: |
| 68 // Initializes the dialog. |text| is shown above the list of certificates |
| 69 // and is supposed to explain to the user what the implication of the |
| 70 // certificate selection is. |
| 71 void InitWithText(const base::string16& text); |
| 72 |
| 72 private: | 73 private: |
| 73 void CreateCertTable(); | 74 const net::CertificateList certificates_; |
| 75 scoped_ptr<CertificateTableModel> model_; |
| 74 | 76 |
| 75 // Callback after unlocking certificate slot. | 77 content::WebContents* const web_contents_; |
| 76 void Unlocked(net::X509Certificate* cert); | |
| 77 | |
| 78 scoped_ptr<CertificateSelectorTableModel> model_; | |
| 79 | |
| 80 content::WebContents* web_contents_; | |
| 81 | 78 |
| 82 views::TableView* table_; | 79 views::TableView* table_; |
| 83 views::LabelButton* view_cert_button_; | 80 views::LabelButton* view_cert_button_; |
| 84 | 81 |
| 85 DISALLOW_COPY_AND_ASSIGN(SSLClientCertificateSelector); | 82 DISALLOW_COPY_AND_ASSIGN(CertificateSelector); |
| 86 }; | 83 }; |
| 87 | 84 |
| 88 #endif // CHROME_BROWSER_UI_VIEWS_SSL_CLIENT_CERTIFICATE_SELECTOR_H_ | 85 } // namespace chrome |
| 86 |
| 87 #endif // CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_ |
| OLD | NEW |