| 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 "base/string_number_conversions.h" |
| 9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
| 10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| 11 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
| 12 #include "chrome/browser/chrome_thread.h" | 12 #include "chrome/browser/chrome_thread.h" |
| 13 #include "chrome/browser/platform_util.h" | 13 #include "chrome/browser/platform_util.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "net/base/cert_database.h" | 15 #include "net/base/cert_database.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/base/x509_certificate.h" | 17 #include "net/base/x509_certificate.h" |
| 18 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 30 void SSLAddCertHandler::RunUI() { | 30 void SSLAddCertHandler::RunUI() { |
| 31 int cert_error; | 31 int cert_error; |
| 32 { | 32 { |
| 33 net::CertDatabase db; | 33 net::CertDatabase db; |
| 34 cert_error = db.CheckUserCert(cert_); | 34 cert_error = db.CheckUserCert(cert_); |
| 35 } | 35 } |
| 36 if (cert_error != net::OK) { | 36 if (cert_error != net::OK) { |
| 37 // TODO(snej): Map cert_error to a more specific error message. | 37 // TODO(snej): Map cert_error to a more specific error message. |
| 38 ShowError(l10n_util::GetStringFUTF16( | 38 ShowError(l10n_util::GetStringFUTF16( |
| 39 IDS_ADD_CERT_ERR_INVALID_CERT, | 39 IDS_ADD_CERT_ERR_INVALID_CERT, |
| 40 IntToString16(-cert_error), | 40 base::IntToString16(-cert_error), |
| 41 ASCIIToUTF16(net::ErrorToString(cert_error)))); | 41 ASCIIToUTF16(net::ErrorToString(cert_error)))); |
| 42 Finished(false); | 42 Finished(false); |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 AskToAddCert(); | 45 AskToAddCert(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 #if !defined(OS_MACOSX) | 48 #if !defined(OS_MACOSX) |
| 49 void SSLAddCertHandler::AskToAddCert() { | 49 void SSLAddCertHandler::AskToAddCert() { |
| 50 // TODO(snej): Someone should add Windows and GTK implementations with UI. | 50 // TODO(snej): Someone should add Windows and GTK implementations with UI. |
| 51 Finished(true); | 51 Finished(true); |
| 52 } | 52 } |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 void SSLAddCertHandler::Finished(bool add_cert) { | 55 void SSLAddCertHandler::Finished(bool add_cert) { |
| 56 if (add_cert) { | 56 if (add_cert) { |
| 57 net::CertDatabase db; | 57 net::CertDatabase db; |
| 58 int cert_error = db.AddUserCert(cert_); | 58 int cert_error = db.AddUserCert(cert_); |
| 59 if (cert_error != net::OK) { | 59 if (cert_error != net::OK) { |
| 60 // TODO(snej): Map cert_error to a more specific error message. | 60 // TODO(snej): Map cert_error to a more specific error message. |
| 61 ShowError(l10n_util::GetStringFUTF16( | 61 ShowError(l10n_util::GetStringFUTF16( |
| 62 IDS_ADD_CERT_ERR_FAILED, | 62 IDS_ADD_CERT_ERR_FAILED, |
| 63 IntToString16(-cert_error), | 63 base::IntToString16(-cert_error), |
| 64 ASCIIToUTF16(net::ErrorToString(cert_error)))); | 64 ASCIIToUTF16(net::ErrorToString(cert_error)))); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 Release(); | 67 Release(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void SSLAddCertHandler::ShowError(const string16& error) { | 70 void SSLAddCertHandler::ShowError(const string16& error) { |
| 71 Browser* browser = BrowserList::GetLastActive(); | 71 Browser* browser = BrowserList::GetLastActive(); |
| 72 platform_util::SimpleErrorBox( | 72 platform_util::SimpleErrorBox( |
| 73 browser ? browser->window()->GetNativeHandle() : NULL, | 73 browser ? browser->window()->GetNativeHandle() : NULL, |
| 74 l10n_util::GetStringUTF16(IDS_ADD_CERT_FAILURE_TITLE), | 74 l10n_util::GetStringUTF16(IDS_ADD_CERT_FAILURE_TITLE), |
| 75 error); | 75 error); |
| 76 } | 76 } |
| OLD | NEW |