| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/certificate_viewer.h" | 5 #include "chrome/browser/certificate_viewer.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <cryptuiapi.h> | |
| 9 | 8 |
| 10 #include "base/bind.h" | 9 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 12 #include "base/location.h" | 11 #include "base/location.h" |
| 13 #include "base/logging.h" | 12 #include "base/logging.h" |
| 14 #include "base/macros.h" | 13 #include "base/macros.h" |
| 15 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 16 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
| 17 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "chrome/browser/ui/cryptuiapi_shim.h" |
| 19 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
| 20 #include "net/cert/x509_util_win.h" |
| 20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
| 22 #include "ui/shell_dialogs/base_shell_dialog_win.h" | 23 #include "ui/shell_dialogs/base_shell_dialog_win.h" |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // Shows a Windows certificate viewer dialog on a background thread to avoid | 27 // Shows a Windows certificate viewer dialog on a background thread to avoid |
| 27 // nested run loops. | 28 // nested run loops. |
| 28 class CertificateViewerDialog : public ui::BaseShellDialogImpl { | 29 class CertificateViewerDialog : public ui::BaseShellDialogImpl { |
| 29 public: | 30 public: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 46 base::Unretained(this), run_state, make_scoped_refptr(cert)), | 47 base::Unretained(this), run_state, make_scoped_refptr(cert)), |
| 47 base::Bind(&CertificateViewerDialog::OnDialogClosed, | 48 base::Bind(&CertificateViewerDialog::OnDialogClosed, |
| 48 base::Unretained(this), run_state, callback)); | 49 base::Unretained(this), run_state, callback)); |
| 49 } | 50 } |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 void ShowOnDialogThread(const RunState& run_state, | 53 void ShowOnDialogThread(const RunState& run_state, |
| 53 const scoped_refptr<net::X509Certificate>& cert) { | 54 const scoped_refptr<net::X509Certificate>& cert) { |
| 54 // Create a new cert context and store containing just the certificate | 55 // Create a new cert context and store containing just the certificate |
| 55 // and its intermediate certificates. | 56 // and its intermediate certificates. |
| 56 PCCERT_CONTEXT cert_list = cert->CreateOSCertChainForCert(); | 57 net::ScopedPCCERT_CONTEXT cert_list( |
| 57 CHECK(cert_list); | 58 net::x509_util::CreateCertContextWithChain(cert.get())); |
| 59 // Perhaps this should show an error instead of silently failing, but it's |
| 60 // probably not even possible to get here with a cert that can't be |
| 61 // converted to a CERT_CONTEXT. |
| 62 if (!cert_list) |
| 63 return; |
| 58 | 64 |
| 59 CRYPTUI_VIEWCERTIFICATE_STRUCT view_info = {0}; | 65 CRYPTUI_VIEWCERTIFICATE_STRUCT view_info = {0}; |
| 60 view_info.dwSize = sizeof(view_info); | 66 view_info.dwSize = sizeof(view_info); |
| 61 view_info.hwndParent = run_state.owner; | 67 view_info.hwndParent = run_state.owner; |
| 62 view_info.dwFlags = | 68 view_info.dwFlags = |
| 63 CRYPTUI_DISABLE_EDITPROPERTIES | CRYPTUI_DISABLE_ADDTOSTORE; | 69 CRYPTUI_DISABLE_EDITPROPERTIES | CRYPTUI_DISABLE_ADDTOSTORE; |
| 64 view_info.pCertContext = cert_list; | 70 view_info.pCertContext = cert_list.get(); |
| 65 HCERTSTORE cert_store = cert_list->hCertStore; | 71 HCERTSTORE cert_store = cert_list->hCertStore; |
| 66 view_info.cStores = 1; | 72 view_info.cStores = 1; |
| 67 view_info.rghStores = &cert_store; | 73 view_info.rghStores = &cert_store; |
| 68 | 74 |
| 69 BOOL properties_changed; | 75 BOOL properties_changed; |
| 70 ::CryptUIDlgViewCertificate(&view_info, &properties_changed); | 76 ::CryptUIDlgViewCertificate(&view_info, &properties_changed); |
| 71 | |
| 72 CertFreeCertificateContext(cert_list); | |
| 73 } | 77 } |
| 74 | 78 |
| 75 void OnDialogClosed(const RunState& run_state, | 79 void OnDialogClosed(const RunState& run_state, |
| 76 const base::Closure& callback) { | 80 const base::Closure& callback) { |
| 77 EndRun(run_state); | 81 EndRun(run_state); |
| 78 // May delete |this|. | 82 // May delete |this|. |
| 79 callback.Run(); | 83 callback.Run(); |
| 80 } | 84 } |
| 81 | 85 |
| 82 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialog); | 86 DISALLOW_COPY_AND_ASSIGN(CertificateViewerDialog); |
| 83 }; | 87 }; |
| 84 | 88 |
| 85 } // namespace | 89 } // namespace |
| 86 | 90 |
| 87 void ShowCertificateViewer(content::WebContents* web_contents, | 91 void ShowCertificateViewer(content::WebContents* web_contents, |
| 88 gfx::NativeWindow parent, | 92 gfx::NativeWindow parent, |
| 89 net::X509Certificate* cert) { | 93 net::X509Certificate* cert) { |
| 90 CertificateViewerDialog* dialog = new CertificateViewerDialog; | 94 CertificateViewerDialog* dialog = new CertificateViewerDialog; |
| 91 dialog->Show( | 95 dialog->Show( |
| 92 parent->GetHost()->GetAcceleratedWidget(), cert, | 96 parent->GetHost()->GetAcceleratedWidget(), cert, |
| 93 base::Bind(&base::DeletePointer<CertificateViewerDialog>, dialog)); | 97 base::Bind(&base::DeletePointer<CertificateViewerDialog>, dialog)); |
| 94 } | 98 } |
| OLD | NEW |