| Index: ui/shell_dialogs/certificate_viewer_dialog_win.cc
|
| diff --git a/ui/shell_dialogs/certificate_viewer_dialog_win.cc b/ui/shell_dialogs/certificate_viewer_dialog_win.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..61cb27d86fa995a774eaa0bdd798e932eec96a32
|
| --- /dev/null
|
| +++ b/ui/shell_dialogs/certificate_viewer_dialog_win.cc
|
| @@ -0,0 +1,74 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ui/shell_dialogs/certificate_viewer_dialog_win.h"
|
| +
|
| +#include <windows.h>
|
| +#include <cryptuiapi.h>
|
| +#pragma comment(lib, "crypt32.lib")
|
| +#pragma comment(lib, "cryptui.lib")
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/threading/thread.h"
|
| +#include "net/cert/x509_certificate.h"
|
| +
|
| +namespace ui {
|
| +
|
| +CertificateViewerDialogWin::CertificateViewerDialogWin(
|
| + HWND owning_window,
|
| + net::X509Certificate* certificate) {
|
| + // Create a new cert context and store containing just the certificate
|
| + // and its intermediate certificates. We do this here because we don't own
|
| + // the lifetime of |certificate|.
|
| + PCCERT_CONTEXT cert_list = certificate->CreateOSCertChainForCert();
|
| + CHECK(cert_list);
|
| +
|
| + ExecuteCertificateViewerParams execute_params(
|
| + BeginRun(owning_window), owning_window, cert_list);
|
| + execute_params.run_state.dialog_thread->message_loop()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&CertificateViewerDialogWin::ExecuteCertificateViewer,
|
| + base::Unretained(this),
|
| + execute_params));
|
| +}
|
| +
|
| +void CertificateViewerDialogWin::Show(HWND owning_window,
|
| + net::X509Certificate* certificate) {
|
| + // Frees itself in |CertificateViewerCompleted|.
|
| + new CertificateViewerDialogWin(owning_window, certificate);
|
| +}
|
| +
|
| +void CertificateViewerDialogWin::ExecuteCertificateViewer(
|
| + const ExecuteCertificateViewerParams& params) {
|
| + CRYPTUI_VIEWCERTIFICATE_STRUCT view_info = { 0 };
|
| + view_info.dwSize = sizeof(view_info);
|
| + // We set our parent to the tab window. This makes the cert dialog created
|
| + // in CryptUIDlgViewCertificate modal to the browser.
|
| + view_info.hwndParent = params.owner;
|
| + view_info.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES |
|
| + CRYPTUI_DISABLE_ADDTOSTORE;
|
| + view_info.pCertContext = params.cert_list;
|
| + HCERTSTORE cert_store = params.cert_list->hCertStore;
|
| + view_info.cStores = 1;
|
| + view_info.rghStores = &cert_store;
|
| + BOOL properties_changed;
|
| +
|
| + // This next call blocks.
|
| + BOOL rv = ::CryptUIDlgViewCertificate(&view_info, &properties_changed);
|
| + params.ui_proxy->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&CertificateViewerDialogWin::CertificateViewerCompleted,
|
| + base::Unretained(this),
|
| + params));
|
| +}
|
| +
|
| +void CertificateViewerDialogWin::CertificateViewerCompleted(
|
| + const ExecuteCertificateViewerParams& params) {
|
| + // Free back on UI thread.
|
| + CertFreeCertificateContext(params.cert_list);
|
| + EndRun(params.run_state);
|
| + delete this;
|
| +}
|
| +
|
| +} // namespace ui
|
|
|