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 "content/public/browser/web_ui_message_handler.h"
14 #include "net/cert/x509_certificate.h"
15 #include "ui/gfx/native_widget_types.h"
16 #include "ui/web_dialogs/web_dialog_delegate.h"
22 class ConstrainedWebDialogDelegate
;
24 // Dialog for displaying detailed certificate information. This is used in linux
25 // and chromeos builds to display detailed information in a floating dialog when
26 // the user clicks on "Certificate Information" from the lock icon of a web site
27 // or "View" from the Certificate Manager.
28 class CertificateViewerDialog
: private 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 CertificateViewerDialog(net::X509Certificate
* cert
);
34 virtual ~CertificateViewerDialog();
36 // Show the dialog using the given parent window.
37 void Show(content::WebContents
* web_contents
, gfx::NativeWindow parent
);
39 ConstrainedWebDialogDelegate
* dialog() { return dialog_
; }
42 // Overridden from ui::WebDialogDelegate:
43 virtual ui::ModalType
GetDialogModalType() const OVERRIDE
;
44 virtual base::string16
GetDialogTitle() const OVERRIDE
;
45 virtual GURL
GetDialogContentURL() const OVERRIDE
;
46 virtual void GetWebUIMessageHandlers(
47 std::vector
<content::WebUIMessageHandler
*>* handlers
) const OVERRIDE
;
48 virtual void GetDialogSize(gfx::Size
* size
) const OVERRIDE
;
49 virtual std::string
GetDialogArgs() const OVERRIDE
;
50 virtual void OnDialogShown(
51 content::WebUI
* webui
,
52 content::RenderViewHost
* render_view_host
) OVERRIDE
;
53 virtual void OnDialogClosed(const std::string
& json_retval
) OVERRIDE
;
54 virtual void OnCloseContents(
55 content::WebContents
* source
, bool* out_close_dialog
) OVERRIDE
;
56 virtual bool ShouldShowDialogTitle() const OVERRIDE
;
58 // The certificate being viewed.
59 scoped_refptr
<net::X509Certificate
> cert_
;
61 ConstrainedWebDialogDelegate
* dialog_
;
63 // The title of the certificate viewer dialog, Certificate Viewer: CN.
64 base::string16 title_
;
66 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialog
);
69 // Dialog handler which handles calls from the JS WebUI code to view certificate
70 // details and export the certificate.
71 class CertificateViewerDialogHandler
: public content::WebUIMessageHandler
{
73 CertificateViewerDialogHandler(CertificateViewerDialog
* dialog
,
74 net::X509Certificate
* cert
);
75 virtual ~CertificateViewerDialogHandler();
77 // Overridden from WebUIMessageHandler
78 virtual void RegisterMessages() OVERRIDE
;
81 // Brings up the export certificate dialog for the chosen certificate in the
84 // The input is an integer index to the certificate in the chain to export.
85 void ExportCertificate(const base::ListValue
* args
);
87 // Gets the details for a specific certificate in the certificate chain. Calls
88 // the javascript function cert_viewer.getCertificateFields with a tree
89 // structure containing the fields and values for certain nodes.
91 // The input is an integer index to the certificate in the chain to view.
92 void RequestCertificateFields(const base::ListValue
* args
);
94 // Helper function to get the certificate index from |args|. Returns -1 if
95 // the index is out of range.
96 int GetCertificateIndex(const base::ListValue
* args
) const;
98 // The certificate being viewed.
99 scoped_refptr
<net::X509Certificate
> cert_
;
102 CertificateViewerDialog
* dialog_
;
104 // The certificate chain.
105 net::X509Certificate::OSCertHandles cert_chain_
;
107 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialogHandler
);
110 #endif // CHROME_BROWSER_UI_WEBUI_CERTIFICATE_VIEWER_WEBUI_H_