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 // This function should return true if the window can be closed after it | |
54 // returns, or false if it must remain open. | |
55 virtual bool AcceptCertificate( | |
56 std::unique_ptr<net::ClientCertIdentity> identity) = 0; | |
57 | |
52 // Returns the currently selected certificate or null if none is selected. | 58 // Returns the currently selected certificate or null if none is selected. |
53 // Must be called after |InitWithText()|. | 59 // Must be called after |InitWithText()|. |
54 net::X509Certificate* GetSelectedCert() const; | 60 net::ClientCertIdentity* GetSelectedCert() const; |
55 | 61 |
56 // Shows this dialog as a constrained web modal dialog and focuses the first | 62 // Shows this dialog as a constrained web modal dialog and focuses the first |
57 // certificate. | 63 // certificate. |
58 // Must be called after |InitWithText()|. | 64 // Must be called after |InitWithText()|. |
59 void Show(); | 65 void Show(); |
60 | 66 |
61 // DialogDelegateView: | 67 // DialogDelegateView: |
68 bool Accept() override; | |
62 bool CanResize() const override; | 69 bool CanResize() const override; |
63 base::string16 GetWindowTitle() const override; | 70 base::string16 GetWindowTitle() const override; |
64 bool IsDialogButtonEnabled(ui::DialogButton button) const override; | 71 bool IsDialogButtonEnabled(ui::DialogButton button) const override; |
65 views::View* GetInitiallyFocusedView() override; | 72 views::View* GetInitiallyFocusedView() override; |
66 views::View* CreateExtraView() override; | 73 views::View* CreateExtraView() override; |
67 ui::ModalType GetModalType() const override; | 74 ui::ModalType GetModalType() const override; |
68 | 75 |
69 // views::ButtonListener: | 76 // views::ButtonListener: |
70 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 77 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
71 | 78 |
72 // views::TableViewObserver: | 79 // views::TableViewObserver: |
73 void OnSelectionChanged() override; | 80 void OnSelectionChanged() override; |
74 void OnDoubleClick() override; | 81 void OnDoubleClick() override; |
75 | 82 |
76 protected: | 83 protected: |
77 // The dimensions of the certificate selector table view, in pixels. | 84 // The dimensions of the certificate selector table view, in pixels. |
78 static const int kTableViewWidth; | 85 static const int kTableViewWidth; |
79 static const int kTableViewHeight; | 86 static const int kTableViewHeight; |
80 | 87 |
81 // Initializes the dialog. |text| is shown above the list of certificates | 88 // 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 | 89 // and is supposed to explain to the user what the implication of the |
83 // certificate selection is. | 90 // certificate selection is. |
84 void InitWithText(std::unique_ptr<views::View> text_label); | 91 void InitWithText(std::unique_ptr<views::View> text_label); |
85 | 92 |
86 ui::TableModel* table_model_for_testing() const; | 93 ui::TableModel* table_model_for_testing() const; |
87 | 94 |
88 private: | 95 private: |
89 class CertificateTableModel; | 96 class CertificateTableModel; |
90 | 97 |
91 net::CertificateList certificates_; | 98 net::ClientCertIdentityList identities_; |
99 | |
100 // Whether a certificate has been selected. |identities_| should not be | |
101 // accessed after this is true. | |
102 bool certificate_accepted_ = false; | |
Peter Kasting
2017/06/16 23:29:52
Nit: Not necessary if you don't want since the fil
mattm
2017/06/17 03:20:07
Done.
| |
92 | 103 |
93 // Whether to show the provider column in the table or not. Certificates | 104 // 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 | 105 // 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 | 106 // shown only if there is at least one non-empty provider, i.e. non-platform |
96 // certificate. | 107 // certificate. |
97 bool show_provider_column_ = false; | 108 bool show_provider_column_ = false; |
98 std::unique_ptr<CertificateTableModel> model_; | 109 std::unique_ptr<CertificateTableModel> model_; |
99 | 110 |
100 content::WebContents* const web_contents_; | 111 content::WebContents* const web_contents_; |
101 | 112 |
102 views::TableView* table_; | 113 views::TableView* table_; |
103 views::LabelButton* view_cert_button_; | 114 views::LabelButton* view_cert_button_; |
104 | 115 |
105 DISALLOW_COPY_AND_ASSIGN(CertificateSelector); | 116 DISALLOW_COPY_AND_ASSIGN(CertificateSelector); |
106 }; | 117 }; |
107 | 118 |
108 } // namespace chrome | 119 } // namespace chrome |
109 | 120 |
110 #endif // CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_ | 121 #endif // CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_ |
OLD | NEW |