Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / views / certificate_selector.h
blob2c1a63a1780ea0725ced7a8c2f8be629c64bc1cc
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"
16 namespace content {
17 class WebContents;
20 namespace views {
21 class LabelButton;
22 class TableView;
23 class View;
26 namespace chrome {
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
30 // certificate.
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 {
36 public:
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 class CertificateTableModel;
44 // |web_contents| must not be null.
45 CertificateSelector(const net::CertificateList& certificates,
46 content::WebContents* web_contents);
47 ~CertificateSelector() override;
49 // Returns the currently selected certificate or null if none is selected.
50 // Must be called after |InitWithText()|.
51 net::X509Certificate* GetSelectedCert() const;
53 // Shows this dialog as a constrained web modal dialog and focuses the first
54 // certificate.
55 // Must be called after |InitWithText()|.
56 void Show();
58 // DialogDelegateView:
59 bool CanResize() const override;
60 base::string16 GetWindowTitle() const override;
61 bool IsDialogButtonEnabled(ui::DialogButton button) const override;
62 views::View* GetInitiallyFocusedView() override;
63 views::View* CreateExtraView() override;
64 ui::ModalType GetModalType() const override;
66 // views::ButtonListener:
67 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
69 // views::TableViewObserver:
70 void OnSelectionChanged() override;
71 void OnDoubleClick() override;
73 protected:
74 // The dimensions of the certificate selector table view, in pixels.
75 static const int kTableViewWidth;
76 static const int kTableViewHeight;
78 // Initializes the dialog. |text| is shown above the list of certificates
79 // and is supposed to explain to the user what the implication of the
80 // certificate selection is.
81 void InitWithText(scoped_ptr<views::View> text_label);
83 private:
84 const net::CertificateList certificates_;
85 scoped_ptr<CertificateTableModel> model_;
87 content::WebContents* const web_contents_;
89 views::TableView* table_;
90 views::LabelButton* view_cert_button_;
92 DISALLOW_COPY_AND_ASSIGN(CertificateSelector);
95 } // namespace chrome
97 #endif // CHROME_BROWSER_UI_VIEWS_CERTIFICATE_SELECTOR_H_