Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / certificate_viewer_webui.h
blob367f4510cf27523c3ec33665a0e2d115d27dc07b
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_
8 #include <string>
9 #include <vector>
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"
18 namespace content {
19 class WebContents;
22 class ConstrainedWebDialogDelegate;
24 // Modal dialog for displaying detailed certificate information. This is used in
25 // chromeos builds to display detailed information in a modal dialog when the
26 // user clicks on "View" from the Certificate Manager dialog.
27 class CertificateViewerModalDialog : public ui::WebDialogDelegate {
28 public:
29 // Construct a certificate viewer for the passed in certificate. A reference
30 // to the certificate pointer is added for the lifetime of the certificate
31 // viewer.
32 explicit CertificateViewerModalDialog(
33 net::X509Certificate* cert);
34 ~CertificateViewerModalDialog() override;
36 virtual void Show(content::WebContents* web_contents,
37 gfx::NativeWindow parent);
38 virtual gfx::NativeWindow GetNativeWebContentsModalDialog();
39 const content::WebUI* GetWebUI() const { return webui_; }
41 protected:
42 // Overridden from ui::WebDialogDelegate:
43 ui::ModalType GetDialogModalType() const override;
44 base::string16 GetDialogTitle() const override;
45 GURL GetDialogContentURL() const override;
46 void GetWebUIMessageHandlers(
47 std::vector<content::WebUIMessageHandler*>* handlers) const override;
48 void GetDialogSize(gfx::Size* size) const override;
49 std::string GetDialogArgs() const override;
50 void OnDialogShown(content::WebUI* webui,
51 content::RenderViewHost* render_view_host) override;
52 void OnDialogClosed(const std::string& json_retval) override;
53 void OnCloseContents(content::WebContents* source,
54 bool* out_close_dialog) override;
55 bool ShouldShowDialogTitle() const override;
57 // The certificate being viewed.
58 scoped_refptr<net::X509Certificate> cert_;
60 // The title of the certificate viewer dialog, Certificate Viewer: CN.
61 base::string16 title_;
63 private:
64 content::WebUI* webui_;
65 gfx::NativeWindow window_;
66 DISALLOW_COPY_AND_ASSIGN(CertificateViewerModalDialog);
69 // Dialog for displaying detailed certificate information. This is used in linux
70 // and chromeos builds to display detailed information in a floating dialog when
71 // the user clicks on "Certificate Information" from the lock icon of a web site
72 // or "View" from the Certificate Manager.
73 class CertificateViewerDialog : public CertificateViewerModalDialog {
74 public:
75 // Construct a certificate viewer for the passed in certificate. A reference
76 // to the certificate pointer is added for the lifetime of the certificate
77 // viewer.
78 explicit CertificateViewerDialog(net::X509Certificate* cert);
79 ~CertificateViewerDialog() override;
81 // CertificateViewerModalDialog overrides.
82 void Show(content::WebContents* web_contents,
83 gfx::NativeWindow parent) override;
84 gfx::NativeWindow GetNativeWebContentsModalDialog() override;
86 protected:
87 // Overridden from ui::WebDialogDelegate:
88 GURL GetDialogContentURL() const override;
89 ui::ModalType GetDialogModalType() const override;
91 private:
92 ConstrainedWebDialogDelegate* dialog_;
94 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialog);
97 // Dialog handler which handles calls from the JS WebUI code to view certificate
98 // details and export the certificate.
99 class CertificateViewerDialogHandler : public content::WebUIMessageHandler {
100 public:
101 CertificateViewerDialogHandler(CertificateViewerModalDialog* dialog,
102 net::X509Certificate* cert);
103 ~CertificateViewerDialogHandler() override;
105 // Overridden from WebUIMessageHandler
106 void RegisterMessages() override;
108 private:
109 // Brings up the export certificate dialog for the chosen certificate in the
110 // chain.
112 // The input is an integer index to the certificate in the chain to export.
113 void ExportCertificate(const base::ListValue* args);
115 // Gets the details for a specific certificate in the certificate chain. Calls
116 // the javascript function cert_viewer.getCertificateFields with a tree
117 // structure containing the fields and values for certain nodes.
119 // The input is an integer index to the certificate in the chain to view.
120 void RequestCertificateFields(const base::ListValue* args);
122 // Helper function to get the certificate index from |args|. Returns -1 if
123 // the index is out of range.
124 int GetCertificateIndex(const base::ListValue* args) const;
126 // The certificate being viewed.
127 scoped_refptr<net::X509Certificate> cert_;
129 // The dialog.
130 CertificateViewerModalDialog* dialog_;
132 // The certificate chain. Does not take references, so only valid as long as
133 // |cert_| is.
134 net::X509Certificate::OSCertHandles cert_chain_;
136 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialogHandler);
139 #endif // CHROME_BROWSER_UI_WEBUI_CERTIFICATE_VIEWER_WEBUI_H_