Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / certificate_viewer_webui.h
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_WEBUI_CERTIFICATE_VIEWER_WEBUI_H_
6 #define CHROME_BROWSER_UI_WEBUI_CERTIFICATE_VIEWER_WEBUI_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/values.h"
13 #include "components/web_modal/native_web_contents_modal_dialog.h"
14 #include "content/public/browser/web_ui_message_handler.h"
15 #include "net/cert/x509_certificate.h"
16 #include "ui/gfx/native_widget_types.h"
17 #include "ui/web_dialogs/web_dialog_delegate.h"
18
19 namespace content {
20 class WebContents;
21 }
22
23 class ConstrainedWebDialogDelegate;
24
25 // Modal dialog for displaying detailed certificate information. This is used in
26 // chromeos builds to display detailed information in a modal dialog when the
27 // user clicks on "View" from the Certificate Manager dialog.
28 class CertificateViewerModalDialog : public ui::WebDialogDelegate {
29  public:
30   // Construct a certificate viewer for the passed in certificate. A reference
31   // to the certificate pointer is added for the lifetime of the certificate
32   // viewer.
33   explicit CertificateViewerModalDialog(
34       net::X509Certificate* cert);
35   ~CertificateViewerModalDialog() override;
36
37   virtual void Show(content::WebContents* web_contents,
38                     gfx::NativeWindow parent);
39   virtual web_modal::NativeWebContentsModalDialog
40   GetNativeWebContentsModalDialog();
41   const content::WebUI* GetWebUI() const { return webui_; }
42
43  protected:
44   // Overridden from ui::WebDialogDelegate:
45   ui::ModalType GetDialogModalType() const override;
46   base::string16 GetDialogTitle() const override;
47   GURL GetDialogContentURL() const override;
48   void GetWebUIMessageHandlers(
49       std::vector<content::WebUIMessageHandler*>* handlers) const override;
50   void GetDialogSize(gfx::Size* size) const override;
51   std::string GetDialogArgs() const override;
52   void OnDialogShown(content::WebUI* webui,
53                      content::RenderViewHost* render_view_host) override;
54   void OnDialogClosed(const std::string& json_retval) override;
55   void OnCloseContents(content::WebContents* source,
56                        bool* out_close_dialog) override;
57   bool ShouldShowDialogTitle() const override;
58
59   // The certificate being viewed.
60   scoped_refptr<net::X509Certificate> cert_;
61
62   // The title of the certificate viewer dialog, Certificate Viewer: CN.
63   base::string16 title_;
64
65  private:
66   content::WebUI* webui_;
67   gfx::NativeWindow window_;
68   DISALLOW_COPY_AND_ASSIGN(CertificateViewerModalDialog);
69 };
70
71 // Dialog for displaying detailed certificate information. This is used in linux
72 // and chromeos builds to display detailed information in a floating dialog when
73 // the user clicks on "Certificate Information" from the lock icon of a web site
74 // or "View" from the Certificate Manager.
75 class CertificateViewerDialog : public CertificateViewerModalDialog {
76  public:
77   // Construct a certificate viewer for the passed in certificate. A reference
78   // to the certificate pointer is added for the lifetime of the certificate
79   // viewer.
80   explicit CertificateViewerDialog(net::X509Certificate* cert);
81   ~CertificateViewerDialog() override;
82
83   // CertificateViewerModalDialog overrides.
84   void Show(content::WebContents* web_contents,
85             gfx::NativeWindow parent) override;
86   web_modal::NativeWebContentsModalDialog GetNativeWebContentsModalDialog()
87       override;
88
89  protected:
90   // Overridden from ui::WebDialogDelegate:
91   GURL GetDialogContentURL() const override;
92   ui::ModalType GetDialogModalType() const override;
93
94  private:
95   ConstrainedWebDialogDelegate* dialog_;
96
97   DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialog);
98 };
99
100 // Dialog handler which handles calls from the JS WebUI code to view certificate
101 // details and export the certificate.
102 class CertificateViewerDialogHandler : public content::WebUIMessageHandler {
103  public:
104   CertificateViewerDialogHandler(CertificateViewerModalDialog* dialog,
105                                  net::X509Certificate* cert);
106   ~CertificateViewerDialogHandler() override;
107
108   // Overridden from WebUIMessageHandler
109   void RegisterMessages() override;
110
111  private:
112   // Brings up the export certificate dialog for the chosen certificate in the
113   // chain.
114   //
115   // The input is an integer index to the certificate in the chain to export.
116   void ExportCertificate(const base::ListValue* args);
117
118   // Gets the details for a specific certificate in the certificate chain. Calls
119   // the javascript function cert_viewer.getCertificateFields with a tree
120   // structure containing the fields and values for certain nodes.
121   //
122   // The input is an integer index to the certificate in the chain to view.
123   void RequestCertificateFields(const base::ListValue* args);
124
125   // Helper function to get the certificate index from |args|. Returns -1 if
126   // the index is out of range.
127   int GetCertificateIndex(const base::ListValue* args) const;
128
129   // The certificate being viewed.
130   scoped_refptr<net::X509Certificate> cert_;
131
132   // The dialog.
133   CertificateViewerModalDialog* dialog_;
134
135   // The certificate chain. Does not take references, so only valid as long as
136   // |cert_| is.
137   net::X509Certificate::OSCertHandles cert_chain_;
138
139   DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialogHandler);
140 };
141
142 #endif  // CHROME_BROWSER_UI_WEBUI_CERTIFICATE_VIEWER_WEBUI_H_