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 "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" 17 18 namespace content { 19 class WebContents; 20 } 21 22 class ConstrainedWebDialogDelegate; 23 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 { 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 CertificateViewerDialog(net::X509Certificate* cert); 34 virtual ~CertificateViewerDialog(); 35 36 // Show the dialog using the given parent window. 37 void Show(content::WebContents* web_contents, gfx::NativeWindow parent); 38 39 ConstrainedWebDialogDelegate* dialog() { return dialog_; } 40 41 private: 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; 57 58 // The certificate being viewed. 59 scoped_refptr<net::X509Certificate> cert_; 60 61 ConstrainedWebDialogDelegate* dialog_; 62 63 // The title of the certificate viewer dialog, Certificate Viewer: CN. 64 base::string16 title_; 65 66 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialog); 67 }; 68 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 { 72 public: 73 CertificateViewerDialogHandler(CertificateViewerDialog* dialog, 74 net::X509Certificate* cert); 75 virtual ~CertificateViewerDialogHandler(); 76 77 // Overridden from WebUIMessageHandler 78 virtual void RegisterMessages() OVERRIDE; 79 80 private: 81 // Brings up the export certificate dialog for the chosen certificate in the 82 // chain. 83 // 84 // The input is an integer index to the certificate in the chain to export. 85 void ExportCertificate(const base::ListValue* args); 86 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. 90 // 91 // The input is an integer index to the certificate in the chain to view. 92 void RequestCertificateFields(const base::ListValue* args); 93 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; 97 98 // The certificate being viewed. 99 scoped_refptr<net::X509Certificate> cert_; 100 101 // The dialog. 102 CertificateViewerDialog* dialog_; 103 104 // The certificate chain. 105 net::X509Certificate::OSCertHandles cert_chain_; 106 107 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialogHandler); 108 }; 109 110 #endif // CHROME_BROWSER_UI_WEBUI_CERTIFICATE_VIEWER_WEBUI_H_ 111