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