| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/ssl/ssl_client_auth_handler.h" | 5 #include "chrome/browser/ssl/ssl_client_auth_handler.h" |
| 6 | 6 |
| 7 #if defined (OS_WIN) | 7 #if defined (OS_WIN) |
| 8 #include <cryptuiapi.h> | 8 #include <cryptuiapi.h> |
| 9 #pragma comment(lib, "cryptui.lib") | 9 #pragma comment(lib, "cryptui.lib") |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
| 13 #include "base/message_loop.h" | |
| 14 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 15 #include "chrome/browser/browser_list.h" | 14 #include "chrome/browser/browser_list.h" |
| 16 #include "chrome/browser/browser.h" | 15 #include "chrome/browser/browser.h" |
| 17 #include "chrome/browser/browser_window.h" | 16 #include "chrome/browser/browser_window.h" |
| 17 #include "chrome/browser/chrome_thread.h" |
| 18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 19 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
| 20 | 20 |
| 21 SSLClientAuthHandler::SSLClientAuthHandler( | 21 SSLClientAuthHandler::SSLClientAuthHandler( |
| 22 URLRequest* request, | 22 URLRequest* request, |
| 23 net::SSLCertRequestInfo* cert_request_info, | 23 net::SSLCertRequestInfo* cert_request_info) |
| 24 MessageLoop* io_loop, | |
| 25 MessageLoop* ui_loop) | |
| 26 : request_(request), | 24 : request_(request), |
| 27 cert_request_info_(cert_request_info), | 25 cert_request_info_(cert_request_info) { |
| 28 io_loop_(io_loop), | |
| 29 ui_loop_(ui_loop) { | |
| 30 // Keep us alive until a cert is selected. | 26 // Keep us alive until a cert is selected. |
| 31 AddRef(); | 27 AddRef(); |
| 32 } | 28 } |
| 33 | 29 |
| 34 SSLClientAuthHandler::~SSLClientAuthHandler() { | 30 SSLClientAuthHandler::~SSLClientAuthHandler() { |
| 35 } | 31 } |
| 36 | 32 |
| 37 void SSLClientAuthHandler::OnRequestCancelled() { | 33 void SSLClientAuthHandler::OnRequestCancelled() { |
| 38 request_ = NULL; | 34 request_ = NULL; |
| 39 } | 35 } |
| 40 | 36 |
| 41 void SSLClientAuthHandler::SelectCertificate() { | 37 void SSLClientAuthHandler::SelectCertificate() { |
| 42 // Let's move the request to the UI thread. | 38 // Let's move the request to the UI thread. |
| 43 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 39 ChromeThread::PostTask( |
| 44 &SSLClientAuthHandler::DoSelectCertificate)); | 40 ChromeThread::UI, FROM_HERE, |
| 41 NewRunnableMethod(this, &SSLClientAuthHandler::DoSelectCertificate)); |
| 45 } | 42 } |
| 46 | 43 |
| 47 void SSLClientAuthHandler::DoSelectCertificate() { | 44 void SSLClientAuthHandler::DoSelectCertificate() { |
| 48 net::X509Certificate* cert = NULL; | 45 net::X509Certificate* cert = NULL; |
| 49 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
| 50 // TODO(jcampan): replace this with our own cert selection dialog. | 47 // TODO(jcampan): replace this with our own cert selection dialog. |
| 51 // CryptUIDlgSelectCertificateFromStore is blocking (but still processes | 48 // CryptUIDlgSelectCertificateFromStore is blocking (but still processes |
| 52 // Windows messages), which is scary. | 49 // Windows messages), which is scary. |
| 53 HCERTSTORE client_certs = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, | 50 HCERTSTORE client_certs = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, |
| 54 0, NULL); | 51 0, NULL); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 78 net::X509Certificate::SOURCE_LONE_CERT_IMPORT); | 75 net::X509Certificate::SOURCE_LONE_CERT_IMPORT); |
| 79 } | 76 } |
| 80 | 77 |
| 81 ok = CertCloseStore(client_certs, CERT_CLOSE_STORE_CHECK_FLAG); | 78 ok = CertCloseStore(client_certs, CERT_CLOSE_STORE_CHECK_FLAG); |
| 82 DCHECK(ok); | 79 DCHECK(ok); |
| 83 #else | 80 #else |
| 84 NOTIMPLEMENTED(); | 81 NOTIMPLEMENTED(); |
| 85 #endif | 82 #endif |
| 86 | 83 |
| 87 // Notify the IO thread that we have selected a cert. | 84 // Notify the IO thread that we have selected a cert. |
| 88 io_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 85 ChromeThread::PostTask( |
| 89 &SSLClientAuthHandler::CertificateSelected, cert)); | 86 ChromeThread::IO, FROM_HERE, |
| 87 NewRunnableMethod( |
| 88 this, &SSLClientAuthHandler::CertificateSelected, cert)); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void SSLClientAuthHandler::CertificateSelected(net::X509Certificate* cert) { | 91 void SSLClientAuthHandler::CertificateSelected(net::X509Certificate* cert) { |
| 93 // request_ could have been NULLed if the request was cancelled while the user | 92 // request_ could have been NULLed if the request was cancelled while the user |
| 94 // was choosing a cert. | 93 // was choosing a cert. |
| 95 if (request_) | 94 if (request_) |
| 96 request_->ContinueWithCertificate(cert); | 95 request_->ContinueWithCertificate(cert); |
| 97 | 96 |
| 98 // We are done. | 97 // We are done. |
| 99 Release(); | 98 Release(); |
| 100 } | 99 } |
| OLD | NEW |