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 ~CertificateViewerModalDialog() override;
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 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;
59 // The certificate being viewed.
60 scoped_refptr<net::X509Certificate> cert_;
62 // The title of the certificate viewer dialog, Certificate Viewer: CN.
63 base::string16 title_;
66 content::WebUI* webui_;
67 gfx::NativeWindow window_;
68 DISALLOW_COPY_AND_ASSIGN(CertificateViewerModalDialog);
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 {
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
80 explicit CertificateViewerDialog(net::X509Certificate* cert);
81 ~CertificateViewerDialog() override;
83 // CertificateViewerModalDialog overrides.
84 void Show(content::WebContents* web_contents,
85 gfx::NativeWindow parent) override;
86 web_modal::NativeWebContentsModalDialog GetNativeWebContentsModalDialog()
90 // Overridden from ui::WebDialogDelegate:
91 GURL GetDialogContentURL() const override;
92 ui::ModalType GetDialogModalType() const override;
95 ConstrainedWebDialogDelegate* dialog_;
97 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialog);
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 {
104 CertificateViewerDialogHandler(CertificateViewerModalDialog* dialog,
105 net::X509Certificate* cert);
106 ~CertificateViewerDialogHandler() override;
108 // Overridden from WebUIMessageHandler
109 void RegisterMessages() override;
112 // Brings up the export certificate dialog for the chosen certificate in the
115 // The input is an integer index to the certificate in the chain to export.
116 void ExportCertificate(const base::ListValue* args);
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.
122 // The input is an integer index to the certificate in the chain to view.
123 void RequestCertificateFields(const base::ListValue* args);
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;
129 // The certificate being viewed.
130 scoped_refptr<net::X509Certificate> cert_;
133 CertificateViewerModalDialog* dialog_;
135 // The certificate chain. Does not take references, so only valid as long as
137 net::X509Certificate::OSCertHandles cert_chain_;
139 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialogHandler);
142 #endif // CHROME_BROWSER_UI_WEBUI_CERTIFICATE_VIEWER_WEBUI_H_