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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_CERTIFICATE_VIEWER_WEBUI_H_
6 #define CHROME_BROWSER_UI_WEBUI_CERTIFICATE_VIEWER_WEBUI_H_
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"
23 class ConstrainedWebDialogDelegate
;
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
{
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
33 explicit CertificateViewerModalDialog(
34 net::X509Certificate
* cert
);
35 virtual ~CertificateViewerModalDialog();
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_
; }
44 // Overridden from ui::WebDialogDelegate:
45 virtual ui::ModalType
GetDialogModalType() const OVERRIDE
;
46 virtual base::string16
GetDialogTitle() const OVERRIDE
;
47 virtual GURL
GetDialogContentURL() const OVERRIDE
;
48 virtual void GetWebUIMessageHandlers(
49 std::vector
<content::WebUIMessageHandler
*>* handlers
) const OVERRIDE
;
50 virtual void GetDialogSize(gfx::Size
* size
) const OVERRIDE
;
51 virtual std::string
GetDialogArgs() const OVERRIDE
;
52 virtual void OnDialogShown(
53 content::WebUI
* webui
,
54 content::RenderViewHost
* render_view_host
) OVERRIDE
;
55 virtual void OnDialogClosed(const std::string
& json_retval
) OVERRIDE
;
56 virtual void OnCloseContents(
57 content::WebContents
* source
, bool* out_close_dialog
) OVERRIDE
;
58 virtual bool ShouldShowDialogTitle() const OVERRIDE
;
60 // The certificate being viewed.
61 scoped_refptr
<net::X509Certificate
> cert_
;
63 // The title of the certificate viewer dialog, Certificate Viewer: CN.
64 base::string16 title_
;
67 content::WebUI
* webui_
;
68 gfx::NativeWindow window_
;
69 DISALLOW_COPY_AND_ASSIGN(CertificateViewerModalDialog
);
72 // Dialog for displaying detailed certificate information. This is used in linux
73 // and chromeos builds to display detailed information in a floating dialog when
74 // the user clicks on "Certificate Information" from the lock icon of a web site
75 // or "View" from the Certificate Manager.
76 class CertificateViewerDialog
: public CertificateViewerModalDialog
{
78 // Construct a certificate viewer for the passed in certificate. A reference
79 // to the certificate pointer is added for the lifetime of the certificate
81 explicit CertificateViewerDialog(net::X509Certificate
* cert
);
82 virtual ~CertificateViewerDialog();
84 // CertificateViewerModalDialog overrides.
85 virtual void Show(content::WebContents
* web_contents
,
86 gfx::NativeWindow parent
) OVERRIDE
;
87 virtual web_modal::NativeWebContentsModalDialog
88 GetNativeWebContentsModalDialog() OVERRIDE
;
91 // Overridden from ui::WebDialogDelegate:
92 virtual GURL
GetDialogContentURL() const OVERRIDE
;
93 virtual ui::ModalType
GetDialogModalType() const OVERRIDE
;
96 ConstrainedWebDialogDelegate
* dialog_
;
98 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialog
);
101 // Dialog handler which handles calls from the JS WebUI code to view certificate
102 // details and export the certificate.
103 class CertificateViewerDialogHandler
: public content::WebUIMessageHandler
{
105 CertificateViewerDialogHandler(CertificateViewerModalDialog
* dialog
,
106 net::X509Certificate
* cert
);
107 virtual ~CertificateViewerDialogHandler();
109 // Overridden from WebUIMessageHandler
110 virtual void RegisterMessages() OVERRIDE
;
113 // Brings up the export certificate dialog for the chosen certificate in the
116 // The input is an integer index to the certificate in the chain to export.
117 void ExportCertificate(const base::ListValue
* args
);
119 // Gets the details for a specific certificate in the certificate chain. Calls
120 // the javascript function cert_viewer.getCertificateFields with a tree
121 // structure containing the fields and values for certain nodes.
123 // The input is an integer index to the certificate in the chain to view.
124 void RequestCertificateFields(const base::ListValue
* args
);
126 // Helper function to get the certificate index from |args|. Returns -1 if
127 // the index is out of range.
128 int GetCertificateIndex(const base::ListValue
* args
) const;
130 // The certificate being viewed.
131 scoped_refptr
<net::X509Certificate
> cert_
;
134 CertificateViewerModalDialog
* dialog_
;
136 // The certificate chain.
137 net::X509Certificate::OSCertHandles cert_chain_
;
139 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialogHandler
);
142 #endif // CHROME_BROWSER_UI_WEBUI_CERTIFICATE_VIEWER_WEBUI_H_