Home | History | Annotate | Download | only in views
      1 // Copyright (c) 2012 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.
      4 
      5 #ifndef CHROME_BROWSER_UI_VIEWS_SSL_CLIENT_CERTIFICATE_SELECTOR_H_
      6 #define CHROME_BROWSER_UI_VIEWS_SSL_CLIENT_CERTIFICATE_SELECTOR_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/memory/ref_counted.h"
     13 #include "base/strings/string16.h"
     14 #include "chrome/browser/ssl/ssl_client_auth_observer.h"
     15 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
     16 #include "ui/views/controls/button/button.h"
     17 #include "ui/views/controls/table/table_view_observer.h"
     18 #include "ui/views/view.h"
     19 #include "ui/views/window/dialog_delegate.h"
     20 
     21 // This header file exists only for testing.  Chrome should access the
     22 // certificate selector only through the cross-platform interface
     23 // chrome/browser/ssl_client_certificate_selector.h.
     24 
     25 namespace net {
     26 class SSLCertRequestInfo;
     27 class X509Certificate;
     28 }
     29 
     30 namespace views {
     31 class LabelButton;
     32 class TableView;
     33 class Widget;
     34 }
     35 
     36 class CertificateSelectorTableModel;
     37 
     38 class SSLClientCertificateSelector : public SSLClientAuthObserver,
     39                                      public views::DialogDelegateView,
     40                                      public views::ButtonListener,
     41                                      public views::TableViewObserver {
     42  public:
     43   SSLClientCertificateSelector(
     44       content::WebContents* web_contents,
     45       const net::HttpNetworkSession* network_session,
     46       net::SSLCertRequestInfo* cert_request_info,
     47       const chrome::SelectCertificateCallback& callback);
     48   virtual ~SSLClientCertificateSelector();
     49 
     50   void Init();
     51 
     52   net::X509Certificate* GetSelectedCert() const;
     53 
     54   // SSLClientAuthObserver implementation:
     55   virtual void OnCertSelectedByNotification() OVERRIDE;
     56 
     57   // DialogDelegateView:
     58   virtual bool CanResize() const OVERRIDE;
     59   virtual string16 GetWindowTitle() const OVERRIDE;
     60   virtual void DeleteDelegate() OVERRIDE;
     61   virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
     62   virtual bool Cancel() OVERRIDE;
     63   virtual bool Accept() OVERRIDE;
     64   virtual views::NonClientFrameView* CreateNonClientFrameView(
     65       views::Widget* widget) OVERRIDE;
     66   virtual views::View* GetInitiallyFocusedView() OVERRIDE;
     67   virtual views::View* CreateExtraView() OVERRIDE;
     68   virtual ui::ModalType GetModalType() const OVERRIDE;
     69 
     70   // views::ButtonListener:
     71   virtual void ButtonPressed(views::Button* sender,
     72                              const ui::Event& event) OVERRIDE;
     73 
     74   // views::TableViewObserver:
     75   virtual void OnSelectionChanged() OVERRIDE;
     76   virtual void OnDoubleClick() OVERRIDE;
     77 
     78  private:
     79   void CreateCertTable();
     80 
     81   scoped_ptr<CertificateSelectorTableModel> model_;
     82 
     83   content::WebContents* web_contents_;
     84 
     85   views::Widget* window_;
     86   views::TableView* table_;
     87   views::LabelButton* view_cert_button_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(SSLClientCertificateSelector);
     90 };
     91 
     92 #endif  // CHROME_BROWSER_UI_VIEWS_SSL_CLIENT_CERTIFICATE_SELECTOR_H_
     93