Home | History | Annotate | Download | only in views
      1 // Copyright (c) 2010 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 #include "content/browser/certificate_viewer.h"
      6 
      7 #include <windows.h>
      8 #include <cryptuiapi.h>
      9 #pragma comment(lib, "cryptui.lib")
     10 
     11 #include "net/base/x509_certificate.h"
     12 
     13 void ShowCertificateViewer(gfx::NativeWindow parent,
     14                            net::X509Certificate* cert) {
     15   CRYPTUI_VIEWCERTIFICATE_STRUCT view_info = { 0 };
     16   view_info.dwSize = sizeof(view_info);
     17   // We set our parent to the tab window. This makes the cert dialog created
     18   // in CryptUIDlgViewCertificate modal to the browser.
     19   view_info.hwndParent = parent;
     20   view_info.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES |
     21                       CRYPTUI_DISABLE_ADDTOSTORE;
     22   view_info.pCertContext = cert->os_cert_handle();
     23   // Search the cert store that 'cert' is in when building the cert chain.
     24   HCERTSTORE cert_store = view_info.pCertContext->hCertStore;
     25   view_info.cStores = 1;
     26   view_info.rghStores = &cert_store;
     27   BOOL properties_changed;
     28 
     29   // This next call blocks but keeps processing windows messages, making it
     30   // modal to the browser window.
     31   BOOL rv = ::CryptUIDlgViewCertificate(&view_info, &properties_changed);
     32 }
     33