| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "net/cert/x509_certificate.h" | 12 #include "net/ssl/client_cert_identity.h" |
| 13 #include "ui/views/controls/button/button.h" | 13 #include "ui/views/controls/button/button.h" |
| 14 #include "ui/views/controls/table/table_view_observer.h" | 14 #include "ui/views/controls/table/table_view_observer.h" |
| 15 #include "ui/views/window/dialog_delegate.h" | 15 #include "ui/views/window/dialog_delegate.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 class WebContents; | 18 class WebContents; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace views { | 21 namespace views { |
| 22 class LabelButton; | 22 class LabelButton; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 class CertificateSelector : public views::DialogDelegateView, | 38 class CertificateSelector : public views::DialogDelegateView, |
| 39 public views::ButtonListener, | 39 public views::ButtonListener, |
| 40 public views::TableViewObserver { | 40 public views::TableViewObserver { |
| 41 public: | 41 public: |
| 42 // Indicates if the dialog can be successfully shown. | 42 // Indicates if the dialog can be successfully shown. |
| 43 // TODO(davidben): Remove this when the certificate selector prompt is moved | 43 // TODO(davidben): Remove this when the certificate selector prompt is moved |
| 44 // to the WebContentsDelegate. https://crbug.com/456255. | 44 // to the WebContentsDelegate. https://crbug.com/456255. |
| 45 static bool CanShow(content::WebContents* web_contents); | 45 static bool CanShow(content::WebContents* web_contents); |
| 46 | 46 |
| 47 // |web_contents| must not be null. | 47 // |web_contents| must not be null. |
| 48 CertificateSelector(const net::CertificateList& certificates, | 48 CertificateSelector(net::ClientCertIdentityList identities, |
| 49 content::WebContents* web_contents); | 49 content::WebContents* web_contents); |
| 50 ~CertificateSelector() override; | 50 ~CertificateSelector() override; |
| 51 | 51 |
| 52 // Handles when the user chooses a certificate in the list. |
| 53 // The CertificateSelector will be destroyed after this method completes. |
| 54 virtual void AcceptCertificate( |
| 55 std::unique_ptr<net::ClientCertIdentity> identity) = 0; |
| 56 |
| 52 // Returns the currently selected certificate or null if none is selected. | 57 // Returns the currently selected certificate or null if none is selected. |
| 53 // Must be called after |InitWithText()|. | 58 // Must be called after |InitWithText()|. |
| 54 net::X509Certificate* GetSelectedCert() const; | 59 net::ClientCertIdentity* GetSelectedCert() const; |
| 55 | 60 |
| 56 // Shows this dialog as a constrained web modal dialog and focuses the first | 61 // Shows this dialog as a constrained web modal dialog and focuses the first |
| 57 // certificate. | 62 // certificate. |
| 58 // Must be called after |InitWithText()|. | 63 // Must be called after |InitWithText()|. |
| 59 void Show(); | 64 void Show(); |
| 60 | 65 |
| 61 // DialogDelegateView: | 66 // DialogDelegateView: |
| 67 bool Accept() override; |
| 62 bool CanResize() const override; | 68 bool CanResize() const override; |
| 63 base::string16 GetWindowTitle() const override; | 69 base::string16 GetWindowTitle() const override; |
| 64 bool IsDialogButtonEnabled(ui::DialogButton button) const override; | 70 bool IsDialogButtonEnabled(ui::DialogButton button) const override; |
| 65 views::View* GetInitiallyFocusedView() override; | 71 views::View* GetInitiallyFocusedView() override; |
| 66 views::View* CreateExtraView() override; | 72 views::View* CreateExtraView() override; |
| 67 ui::ModalType GetModalType() const override; | 73 ui::ModalType GetModalType() const override; |
| 68 | 74 |
| 69 // views::ButtonListener: | 75 // views::ButtonListener: |
| 70 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 76 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 71 | 77 |
| 72 // views::TableViewObserver: | 78 // views::TableViewObserver: |
| 73 void OnSelectionChanged() override; | 79 void OnSelectionChanged() override; |
| 74 void OnDoubleClick() override; | 80 void OnDoubleClick() override; |
| 75 | 81 |
| 76 protected: | 82 protected: |
| 77 // The dimensions of the certificate selector table view, in pixels. | 83 // The dimensions of the certificate selector table view, in pixels. |
| 78 static const int kTableViewWidth; | 84 static const int kTableViewWidth; |
| 79 static const int kTableViewHeight; | 85 static const int kTableViewHeight; |
| 80 | 86 |
| 81 // Initializes the dialog. |text| is shown above the list of certificates | 87 // Initializes the dialog. |text| is shown above the list of certificates |
| 82 // and is supposed to explain to the user what the implication of the | 88 // and is supposed to explain to the user what the implication of the |
| 83 // certificate selection is. | 89 // certificate selection is. |
| 84 void InitWithText(std::unique_ptr<views::View> text_label); | 90 void InitWithText(std::unique_ptr<views::View> text_label); |
| 85 | 91 |
| 86 ui::TableModel* table_model_for_testing() const; | 92 ui::TableModel* table_model_for_testing() const; |
| 87 | 93 |
| 88 private: | 94 private: |
| 89 class CertificateTableModel; | 95 class CertificateTableModel; |
| 90 | 96 |
| 91 net::CertificateList certificates_; | 97 net::ClientCertIdentityList identities_; |
| 92 | 98 |
| 93 // Whether to show the provider column in the table or not. Certificates | 99 // Whether to show the provider column in the table or not. Certificates |
| 94 // provided by the platform show the empty string as provider. That column is | 100 // provided by the platform show the empty string as provider. That column is |
| 95 // shown only if there is at least one non-empty provider, i.e. non-platform | 101 // shown only if there is at least one non-empty provider, i.e. non-platform |
| 96 // certificate. | 102 // certificate. |
| 97 bool show_provider_column_ = false; | 103 bool show_provider_column_ = false; |
| 98 std::unique_ptr<CertificateTableModel> model_; | 104 std::unique_ptr<CertificateTableModel> model_; |
| 99 | 105 |
| 100 content::WebContents* const web_contents_; | 106 content::WebContents* const web_contents_; |
| 101 | 107 |
| 102 views::TableView* table_; | 108 views::TableView* table_ = nullptr; |
| 103 views::LabelButton* view_cert_button_; | 109 views::LabelButton* view_cert_button_ = nullptr; |
| 104 | 110 |
| 105 DISALLOW_COPY_AND_ASSIGN(CertificateSelector); | 111 DISALLOW_COPY_AND_ASSIGN(CertificateSelector); |
| 106 }; | 112 }; |
| 107 | 113 |
| 108 } // namespace chrome | 114 } // namespace chrome |
| 109 | 115 |
| 110 #endif // CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_ | 116 #endif // CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_ |
| OLD | NEW |