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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_
6 #define CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string16.h"
11 #include "net/cert/x509_certificate.h"
12 #include "ui/views/controls/button/button.h"
13 #include "ui/views/controls/table/table_view_observer.h"
14 #include "ui/views/window/dialog_delegate.h"
28 // A base class for dialogs that show a given list of certificates to the user.
29 // The user can select a single certificate and look at details of each
31 // The currently selected certificate can be obtained using |GetSelectedCert()|.
32 // The explanatory text shown to the user must be provided to |InitWithText()|.
33 class CertificateSelector
: public views::DialogDelegateView
,
34 public views::ButtonListener
,
35 public views::TableViewObserver
{
37 // Indicates if the dialog can be successfully shown.
38 // TODO(davidben): Remove this when the certificate selector prompt is moved
39 // to the WebContentsDelegate. https://crbug.com/456255.
40 static bool CanShow(content::WebContents
* web_contents
);
42 // |web_contents| must not be null.
43 CertificateSelector(const net::CertificateList
& certificates
,
44 content::WebContents
* web_contents
);
45 ~CertificateSelector() override
;
47 // Returns the currently selected certificate or null if none is selected.
48 // Must be called after |InitWithText()|.
49 net::X509Certificate
* GetSelectedCert() const;
51 // Shows this dialog as a constrained web modal dialog and focuses the first
53 // Must be called after |InitWithText()|.
56 // DialogDelegateView:
57 bool CanResize() const override
;
58 base::string16
GetWindowTitle() const override
;
59 bool IsDialogButtonEnabled(ui::DialogButton button
) const override
;
60 views::View
* GetInitiallyFocusedView() override
;
61 views::View
* CreateExtraView() override
;
62 ui::ModalType
GetModalType() const override
;
64 // views::ButtonListener:
65 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
67 // views::TableViewObserver:
68 void OnSelectionChanged() override
;
69 void OnDoubleClick() override
;
72 // The dimensions of the certificate selector table view, in pixels.
73 static const int kTableViewWidth
;
74 static const int kTableViewHeight
;
76 // Initializes the dialog. |text| is shown above the list of certificates
77 // and is supposed to explain to the user what the implication of the
78 // certificate selection is.
79 void InitWithText(scoped_ptr
<views::View
> text_label
);
82 class CertificateTableModel
;
84 net::CertificateList certificates_
;
86 // Whether to show the provider column in the table or not. Certificates
87 // provided by the platform show the empty string as provider. That column is
88 // shown only if there is at least one non-empty provider, i.e. non-platform
90 bool show_provider_column_
= false;
91 scoped_ptr
<CertificateTableModel
> model_
;
93 content::WebContents
* const web_contents_
;
95 views::TableView
* table_
;
96 views::LabelButton
* view_cert_button_
;
98 DISALLOW_COPY_AND_ASSIGN(CertificateSelector
);
101 } // namespace chrome
103 #endif // CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_