| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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_add_cert_handler.h" | 5 #include "chrome/browser/ssl/ssl_add_cert_handler.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/string_util.h" |
| 8 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
| 11 #include "chrome/browser/chrome_thread.h" | 12 #include "chrome/browser/chrome_thread.h" |
| 12 #include "chrome/browser/platform_util.h" | 13 #include "chrome/browser/platform_util.h" |
| 13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 14 #include "net/base/cert_database.h" | 15 #include "net/base/cert_database.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "net/base/x509_certificate.h" | 17 #include "net/base/x509_certificate.h" |
| 17 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 18 | 19 |
| 19 SSLAddCertHandler::SSLAddCertHandler(URLRequest* request, | 20 SSLAddCertHandler::SSLAddCertHandler(URLRequest* request, |
| 20 net::X509Certificate* cert) | 21 net::X509Certificate* cert) |
| 21 : cert_(cert) { | 22 : cert_(cert) { |
| 22 // Stay alive until the UI completes and Finished() is called. | 23 // Stay alive until the UI completes and Finished() is called. |
| 23 AddRef(); | 24 AddRef(); |
| 24 ChromeThread::PostTask( | 25 ChromeThread::PostTask( |
| 25 ChromeThread::UI, FROM_HERE, | 26 ChromeThread::UI, FROM_HERE, |
| 26 NewRunnableMethod(this, &SSLAddCertHandler::RunUI)); | 27 NewRunnableMethod(this, &SSLAddCertHandler::RunUI)); |
| 27 } | 28 } |
| 28 | 29 |
| 29 void SSLAddCertHandler::RunUI() { | 30 void SSLAddCertHandler::RunUI() { |
| 30 int cert_error; | 31 int cert_error; |
| 31 { | 32 { |
| 32 net::CertDatabase db; | 33 net::CertDatabase db; |
| 33 cert_error = db.CheckUserCert(cert_); | 34 cert_error = db.CheckUserCert(cert_); |
| 34 } | 35 } |
| 35 if (cert_error != net::OK) { | 36 if (cert_error != net::OK) { |
| 36 // TODO(snej): Map cert_error to a more specific error message. | 37 // TODO(snej): Map cert_error to a more specific error message. |
| 37 ShowError(l10n_util::GetStringUTF16(IDS_ADD_CERT_ERR_INVALID_CERT)); | 38 ShowError(l10n_util::GetStringFUTF16( |
| 39 IDS_ADD_CERT_ERR_INVALID_CERT, |
| 40 IntToString16(-cert_error), |
| 41 ASCIIToUTF16(net::ErrorToString(cert_error)))); |
| 38 Finished(false); | 42 Finished(false); |
| 39 return; | 43 return; |
| 40 } | 44 } |
| 41 AskToAddCert(); | 45 AskToAddCert(); |
| 42 } | 46 } |
| 43 | 47 |
| 44 #if !defined(OS_MACOSX) | 48 #if !defined(OS_MACOSX) |
| 45 void SSLAddCertHandler::AskToAddCert() { | 49 void SSLAddCertHandler::AskToAddCert() { |
| 46 // TODO(snej): Someone should add Windows and GTK implementations with UI. | 50 // TODO(snej): Someone should add Windows and GTK implementations with UI. |
| 47 Finished(true); | 51 Finished(true); |
| 48 } | 52 } |
| 49 #endif | 53 #endif |
| 50 | 54 |
| 51 void SSLAddCertHandler::Finished(bool add_cert) { | 55 void SSLAddCertHandler::Finished(bool add_cert) { |
| 52 if (add_cert) { | 56 if (add_cert) { |
| 53 net::CertDatabase db; | 57 net::CertDatabase db; |
| 54 int cert_error = db.AddUserCert(cert_); | 58 int cert_error = db.AddUserCert(cert_); |
| 55 if (cert_error != net::OK) { | 59 if (cert_error != net::OK) { |
| 56 // TODO(snej): Map cert_error to a more specific error message. | 60 // TODO(snej): Map cert_error to a more specific error message. |
| 57 ShowError(l10n_util::GetStringUTF16(IDS_ADD_CERT_ERR_FAILED)); | 61 ShowError(l10n_util::GetStringFUTF16( |
| 62 IDS_ADD_CERT_ERR_FAILED, |
| 63 IntToString16(-cert_error), |
| 64 ASCIIToUTF16(net::ErrorToString(cert_error)))); |
| 58 } | 65 } |
| 59 } | 66 } |
| 60 Release(); | 67 Release(); |
| 61 } | 68 } |
| 62 | 69 |
| 63 void SSLAddCertHandler::ShowError(const string16& error) { | 70 void SSLAddCertHandler::ShowError(const string16& error) { |
| 64 Browser* browser = BrowserList::GetLastActive(); | 71 Browser* browser = BrowserList::GetLastActive(); |
| 65 platform_util::SimpleErrorBox( | 72 platform_util::SimpleErrorBox( |
| 66 browser ? browser->window()->GetNativeHandle() : NULL, | 73 browser ? browser->window()->GetNativeHandle() : NULL, |
| 67 l10n_util::GetStringUTF16(IDS_ADD_CERT_FAILURE_TITLE), | 74 l10n_util::GetStringUTF16(IDS_ADD_CERT_FAILURE_TITLE), |
| 68 error); | 75 error); |
| 69 } | 76 } |
| OLD | NEW |