1 // Copyright (c) 2011 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 #include "chrome/browser/certificate_viewer.h"
8 #include <cryptuiapi.h>
9 #pragma comment(lib, "cryptui.lib")
11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h"
13 #include "net/cert/x509_certificate.h"
16 #include "chrome/browser/ui/host_desktop.h"
17 #include "ui/aura/root_window.h"
18 #include "ui/aura/window.h"
23 void ShowCertificateViewerImpl(content::WebContents
* web_contents
,
25 net::X509Certificate
* cert
) {
26 // Create a new cert context and store containing just the certificate
27 // and its intermediate certificates.
28 PCCERT_CONTEXT cert_list
= cert
->CreateOSCertChainForCert();
31 CRYPTUI_VIEWCERTIFICATE_STRUCT view_info
= { 0 };
32 view_info
.dwSize
= sizeof(view_info
);
33 // We set our parent to the tab window. This makes the cert dialog created
34 // in CryptUIDlgViewCertificate modal to the browser.
35 view_info
.hwndParent
= parent
;
36 view_info
.dwFlags
= CRYPTUI_DISABLE_EDITPROPERTIES
|
37 CRYPTUI_DISABLE_ADDTOSTORE
;
38 view_info
.pCertContext
= cert_list
;
39 HCERTSTORE cert_store
= cert_list
->hCertStore
;
40 view_info
.cStores
= 1;
41 view_info
.rghStores
= &cert_store
;
42 BOOL properties_changed
;
44 // We must allow nested tasks to dispatch so that, e.g. gpu tasks are
45 // processed for painting. This allows a second window to continue painting
46 // while the the certificate dialog is open.
47 base::MessageLoop::ScopedNestableTaskAllower
allow(
48 base::MessageLoop::current());
49 // This next call blocks but keeps processing windows messages, making it
50 // modal to the browser window.
51 BOOL rv
= ::CryptUIDlgViewCertificate(&view_info
, &properties_changed
);
53 CertFreeCertificateContext(cert_list
);
59 void ShowCertificateViewer(content::WebContents
* web_contents
,
60 gfx::NativeWindow parent
,
61 net::X509Certificate
* cert
) {
62 if (chrome::GetHostDesktopTypeForNativeWindow(parent
) !=
63 chrome::HOST_DESKTOP_TYPE_ASH
) {
64 ShowCertificateViewerImpl(
66 parent
->GetDispatcher()->host()->GetAcceleratedWidget(), cert
);
72 void ShowCertificateViewer(content::WebContents
* web_contents
,
73 gfx::NativeWindow parent
,
74 net::X509Certificate
* cert
) {
75 ShowCertificateViewerImpl(web_contents
, parent
, cert
);