| 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/ui/webui/options/certificate_manager_handler.h" | 5 #include "chrome/browser/ui/webui/options/certificate_manager_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_util.h" // for FileAccessProvider | 9 #include "base/file_util.h" // for FileAccessProvider |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/safe_strerror_posix.h" | 11 #include "base/safe_strerror_posix.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/certificate_viewer.h" | 15 #include "chrome/browser/certificate_viewer.h" |
| 16 #include "chrome/browser/ui/certificate_dialogs.h" | 16 #include "chrome/browser/ui/certificate_dialogs.h" |
| 17 #include "chrome/browser/ui/crypto_module_password_dialog.h" | 17 #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/browser/tab_contents/tab_contents_view.h" | 19 #include "content/browser/tab_contents/tab_contents_view.h" |
| 20 #include "content/public/browser/browser_thread.h" // for FileAccessProvider | 20 #include "content/public/browser/browser_thread.h" // for FileAccessProvider |
| 21 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 22 #include "net/base/crypto_module.h" | 22 #include "net/base/crypto_module.h" |
| 23 #include "net/base/x509_certificate.h" | 23 #include "net/base/x509_certificate.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/l10n/l10n_util_collator.h" | 25 #include "ui/base/l10n/l10n_util_collator.h" |
| 26 | 26 |
| 27 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
| 28 #include "chrome/browser/chromeos/cros/cros_library.h" | 28 #include "chrome/browser/chromeos/cros/cros_library.h" |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 SelectFileDialog::FileTypeInfo file_type_info; | 559 SelectFileDialog::FileTypeInfo file_type_info; |
| 560 file_type_info.extensions.resize(1); | 560 file_type_info.extensions.resize(1); |
| 561 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("p12")); | 561 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("p12")); |
| 562 file_type_info.extension_description_overrides.push_back( | 562 file_type_info.extension_description_overrides.push_back( |
| 563 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_PKCS12_FILES)); | 563 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_PKCS12_FILES)); |
| 564 file_type_info.include_all_files = true; | 564 file_type_info.include_all_files = true; |
| 565 select_file_dialog_ = SelectFileDialog::Create(this); | 565 select_file_dialog_ = SelectFileDialog::Create(this); |
| 566 select_file_dialog_->SelectFile( | 566 select_file_dialog_->SelectFile( |
| 567 SelectFileDialog::SELECT_SAVEAS_FILE, string16(), | 567 SelectFileDialog::SELECT_SAVEAS_FILE, string16(), |
| 568 FilePath(), &file_type_info, 1, FILE_PATH_LITERAL("p12"), | 568 FilePath(), &file_type_info, 1, FILE_PATH_LITERAL("p12"), |
| 569 web_ui()->tab_contents(), GetParentWindow(), | 569 web_ui()->web_contents(), GetParentWindow(), |
| 570 reinterpret_cast<void*>(EXPORT_PERSONAL_FILE_SELECTED)); | 570 reinterpret_cast<void*>(EXPORT_PERSONAL_FILE_SELECTED)); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void CertificateManagerHandler::ExportAllPersonal(const ListValue* args) { | 573 void CertificateManagerHandler::ExportAllPersonal(const ListValue* args) { |
| 574 NOTIMPLEMENTED(); | 574 NOTIMPLEMENTED(); |
| 575 } | 575 } |
| 576 | 576 |
| 577 void CertificateManagerHandler::ExportPersonalFileSelected( | 577 void CertificateManagerHandler::ExportPersonalFileSelected( |
| 578 const FilePath& path) { | 578 const FilePath& path) { |
| 579 file_path_ = path; | 579 file_path_ = path; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 } | 646 } |
| 647 file_type_info.extensions.resize(1); | 647 file_type_info.extensions.resize(1); |
| 648 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("p12")); | 648 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("p12")); |
| 649 file_type_info.extension_description_overrides.push_back( | 649 file_type_info.extension_description_overrides.push_back( |
| 650 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_PKCS12_FILES)); | 650 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_PKCS12_FILES)); |
| 651 file_type_info.include_all_files = true; | 651 file_type_info.include_all_files = true; |
| 652 select_file_dialog_ = SelectFileDialog::Create(this); | 652 select_file_dialog_ = SelectFileDialog::Create(this); |
| 653 select_file_dialog_->SelectFile( | 653 select_file_dialog_->SelectFile( |
| 654 SelectFileDialog::SELECT_OPEN_FILE, string16(), | 654 SelectFileDialog::SELECT_OPEN_FILE, string16(), |
| 655 FilePath(), &file_type_info, 1, FILE_PATH_LITERAL("p12"), | 655 FilePath(), &file_type_info, 1, FILE_PATH_LITERAL("p12"), |
| 656 web_ui()->tab_contents(), GetParentWindow(), | 656 web_ui()->web_contents(), GetParentWindow(), |
| 657 reinterpret_cast<void*>(IMPORT_PERSONAL_FILE_SELECTED)); | 657 reinterpret_cast<void*>(IMPORT_PERSONAL_FILE_SELECTED)); |
| 658 } | 658 } |
| 659 | 659 |
| 660 void CertificateManagerHandler::ImportPersonalFileSelected( | 660 void CertificateManagerHandler::ImportPersonalFileSelected( |
| 661 const FilePath& path) { | 661 const FilePath& path) { |
| 662 file_path_ = path; | 662 file_path_ = path; |
| 663 web_ui()->CallJavascriptFunction( | 663 web_ui()->CallJavascriptFunction( |
| 664 "CertificateManager.importPersonalAskPassword"); | 664 "CertificateManager.importPersonalAskPassword"); |
| 665 } | 665 } |
| 666 | 666 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 select_file_dialog_->ListenerDestroyed(); | 763 select_file_dialog_->ListenerDestroyed(); |
| 764 select_file_dialog_ = NULL; | 764 select_file_dialog_ = NULL; |
| 765 } | 765 } |
| 766 | 766 |
| 767 void CertificateManagerHandler::ImportServer(const ListValue* args) { | 767 void CertificateManagerHandler::ImportServer(const ListValue* args) { |
| 768 select_file_dialog_ = SelectFileDialog::Create(this); | 768 select_file_dialog_ = SelectFileDialog::Create(this); |
| 769 ShowCertSelectFileDialog( | 769 ShowCertSelectFileDialog( |
| 770 select_file_dialog_.get(), | 770 select_file_dialog_.get(), |
| 771 SelectFileDialog::SELECT_OPEN_FILE, | 771 SelectFileDialog::SELECT_OPEN_FILE, |
| 772 FilePath(), | 772 FilePath(), |
| 773 web_ui()->tab_contents(), | 773 web_ui()->web_contents(), |
| 774 GetParentWindow(), | 774 GetParentWindow(), |
| 775 reinterpret_cast<void*>(IMPORT_SERVER_FILE_SELECTED)); | 775 reinterpret_cast<void*>(IMPORT_SERVER_FILE_SELECTED)); |
| 776 } | 776 } |
| 777 | 777 |
| 778 void CertificateManagerHandler::ImportServerFileSelected(const FilePath& path) { | 778 void CertificateManagerHandler::ImportServerFileSelected(const FilePath& path) { |
| 779 file_path_ = path; | 779 file_path_ = path; |
| 780 file_access_provider_->StartRead( | 780 file_access_provider_->StartRead( |
| 781 file_path_, &consumer_, | 781 file_path_, &consumer_, |
| 782 base::Bind(&CertificateManagerHandler::ImportServerFileRead, | 782 base::Bind(&CertificateManagerHandler::ImportServerFileRead, |
| 783 base::Unretained(this))); | 783 base::Unretained(this))); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 not_imported); | 818 not_imported); |
| 819 } | 819 } |
| 820 ImportExportCleanup(); | 820 ImportExportCleanup(); |
| 821 } | 821 } |
| 822 | 822 |
| 823 void CertificateManagerHandler::ImportCA(const ListValue* args) { | 823 void CertificateManagerHandler::ImportCA(const ListValue* args) { |
| 824 select_file_dialog_ = SelectFileDialog::Create(this); | 824 select_file_dialog_ = SelectFileDialog::Create(this); |
| 825 ShowCertSelectFileDialog(select_file_dialog_.get(), | 825 ShowCertSelectFileDialog(select_file_dialog_.get(), |
| 826 SelectFileDialog::SELECT_OPEN_FILE, | 826 SelectFileDialog::SELECT_OPEN_FILE, |
| 827 FilePath(), | 827 FilePath(), |
| 828 web_ui()->tab_contents(), | 828 web_ui()->web_contents(), |
| 829 GetParentWindow(), | 829 GetParentWindow(), |
| 830 reinterpret_cast<void*>(IMPORT_CA_FILE_SELECTED)); | 830 reinterpret_cast<void*>(IMPORT_CA_FILE_SELECTED)); |
| 831 } | 831 } |
| 832 | 832 |
| 833 void CertificateManagerHandler::ImportCAFileSelected(const FilePath& path) { | 833 void CertificateManagerHandler::ImportCAFileSelected(const FilePath& path) { |
| 834 file_path_ = path; | 834 file_path_ = path; |
| 835 file_access_provider_->StartRead( | 835 file_access_provider_->StartRead( |
| 836 file_path_, &consumer_, | 836 file_path_, &consumer_, |
| 837 base::Bind(&CertificateManagerHandler::ImportCAFileRead, | 837 base::Bind(&CertificateManagerHandler::ImportCAFileRead, |
| 838 base::Unretained(this))); | 838 base::Unretained(this))); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_CA_IMPORT_ERROR_TITLE), | 901 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_CA_IMPORT_ERROR_TITLE), |
| 902 not_imported); | 902 not_imported); |
| 903 } | 903 } |
| 904 ImportExportCleanup(); | 904 ImportExportCleanup(); |
| 905 } | 905 } |
| 906 | 906 |
| 907 void CertificateManagerHandler::Export(const ListValue* args) { | 907 void CertificateManagerHandler::Export(const ListValue* args) { |
| 908 net::X509Certificate* cert = CallbackArgsToCert(args); | 908 net::X509Certificate* cert = CallbackArgsToCert(args); |
| 909 if (!cert) | 909 if (!cert) |
| 910 return; | 910 return; |
| 911 ShowCertExportDialog(web_ui()->tab_contents(), GetParentWindow(), | 911 ShowCertExportDialog(web_ui()->web_contents(), GetParentWindow(), |
| 912 cert->os_cert_handle()); | 912 cert->os_cert_handle()); |
| 913 } | 913 } |
| 914 | 914 |
| 915 void CertificateManagerHandler::Delete(const ListValue* args) { | 915 void CertificateManagerHandler::Delete(const ListValue* args) { |
| 916 net::X509Certificate* cert = CallbackArgsToCert(args); | 916 net::X509Certificate* cert = CallbackArgsToCert(args); |
| 917 if (!cert) | 917 if (!cert) |
| 918 return; | 918 return; |
| 919 bool result = certificate_manager_model_->Delete(cert); | 919 bool result = certificate_manager_model_->Delete(cert); |
| 920 if (!result) { | 920 if (!result) { |
| 921 // TODO(mattm): better error messages? | 921 // TODO(mattm): better error messages? |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); | 1034 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 1035 | 1035 |
| 1036 // TODO(xiyuan): Use async way when underlying supports it. | 1036 // TODO(xiyuan): Use async way when underlying supports it. |
| 1037 base::FundamentalValue ready(cryptohome->Pkcs11IsTpmTokenReady()); | 1037 base::FundamentalValue ready(cryptohome->Pkcs11IsTpmTokenReady()); |
| 1038 web_ui()->CallJavascriptFunction("CertificateManager.onCheckTpmTokenReady", | 1038 web_ui()->CallJavascriptFunction("CertificateManager.onCheckTpmTokenReady", |
| 1039 ready); | 1039 ready); |
| 1040 } | 1040 } |
| 1041 #endif | 1041 #endif |
| 1042 | 1042 |
| 1043 gfx::NativeWindow CertificateManagerHandler::GetParentWindow() const { | 1043 gfx::NativeWindow CertificateManagerHandler::GetParentWindow() const { |
| 1044 return web_ui()->tab_contents()->GetView()->GetTopLevelNativeWindow(); | 1044 return web_ui()->web_contents()->GetView()->GetTopLevelNativeWindow(); |
| 1045 } | 1045 } |
| OLD | NEW |