| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/settings/certificates_handler.h" | 5 #include "chrome/browser/ui/webui/settings/certificates_handler.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 |
| 10 #include <algorithm> | 11 #include <algorithm> |
| 11 #include <map> | 12 #include <map> |
| 12 #include <utility> | 13 #include <utility> |
| 13 | 14 |
| 14 #include "base/bind.h" | 15 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 16 #include "base/files/file_util.h" // for FileAccessProvider | 17 #include "base/files/file_util.h" // for FileAccessProvider |
| 17 #include "base/i18n/string_compare.h" | 18 #include "base/i18n/string_compare.h" |
| 18 #include "base/id_map.h" | 19 #include "base/id_map.h" |
| 19 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/memory/ptr_util.h" |
| 20 #include "base/memory/scoped_vector.h" | 22 #include "base/memory/scoped_vector.h" |
| 21 #include "base/posix/safe_strerror.h" | 23 #include "base/posix/safe_strerror.h" |
| 22 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/values.h" | 26 #include "base/values.h" |
| 25 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 26 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/certificate_viewer.h" | 29 #include "chrome/browser/certificate_viewer.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/ui/certificate_dialogs.h" | 31 #include "chrome/browser/ui/certificate_dialogs.h" |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 CHECK_EQ(2U, args->GetSize()); | 489 CHECK_EQ(2U, args->GetSize()); |
| 488 AssignWebUICallbackId(args); | 490 AssignWebUICallbackId(args); |
| 489 std::string node_id; | 491 std::string node_id; |
| 490 CHECK(args->GetString(1, &node_id)); | 492 CHECK(args->GetString(1, &node_id)); |
| 491 | 493 |
| 492 net::X509Certificate* cert = cert_id_map_->IdToCert(node_id); | 494 net::X509Certificate* cert = cert_id_map_->IdToCert(node_id); |
| 493 CHECK(cert); | 495 CHECK(cert); |
| 494 | 496 |
| 495 net::NSSCertDatabase::TrustBits trust_bits = | 497 net::NSSCertDatabase::TrustBits trust_bits = |
| 496 certificate_manager_model_->cert_db()->GetCertTrust(cert, net::CA_CERT); | 498 certificate_manager_model_->cert_db()->GetCertTrust(cert, net::CA_CERT); |
| 497 scoped_ptr<base::DictionaryValue> ca_trust_info(new base::DictionaryValue); | 499 std::unique_ptr<base::DictionaryValue> ca_trust_info( |
| 500 new base::DictionaryValue); |
| 498 ca_trust_info->SetBoolean( | 501 ca_trust_info->SetBoolean( |
| 499 kSslField, | 502 kSslField, |
| 500 static_cast<bool>(trust_bits & net::NSSCertDatabase::TRUSTED_SSL)); | 503 static_cast<bool>(trust_bits & net::NSSCertDatabase::TRUSTED_SSL)); |
| 501 ca_trust_info->SetBoolean( | 504 ca_trust_info->SetBoolean( |
| 502 kEmailField, | 505 kEmailField, |
| 503 static_cast<bool>(trust_bits & net::NSSCertDatabase::TRUSTED_EMAIL)); | 506 static_cast<bool>(trust_bits & net::NSSCertDatabase::TRUSTED_EMAIL)); |
| 504 ca_trust_info->SetBoolean( | 507 ca_trust_info->SetBoolean( |
| 505 kObjSignField, | 508 kObjSignField, |
| 506 static_cast<bool>(trust_bits & net::NSSCertDatabase::TRUSTED_OBJ_SIGN)); | 509 static_cast<bool>(trust_bits & net::NSSCertDatabase::TRUSTED_OBJ_SIGN)); |
| 507 ResolveCallback(*ca_trust_info); | 510 ResolveCallback(*ca_trust_info); |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 l10n_util::GetStringUTF8( | 968 l10n_util::GetStringUTF8( |
| 966 IDS_SETTINGS_CERTIFICATE_MANAGER_DELETE_CERT_ERROR_TITLE), | 969 IDS_SETTINGS_CERTIFICATE_MANAGER_DELETE_CERT_ERROR_TITLE), |
| 967 l10n_util::GetStringUTF8( | 970 l10n_util::GetStringUTF8( |
| 968 IDS_SETTINGS_CERTIFICATE_MANAGER_UNKNOWN_ERROR)); | 971 IDS_SETTINGS_CERTIFICATE_MANAGER_UNKNOWN_ERROR)); |
| 969 } else { | 972 } else { |
| 970 ResolveCallback(*base::Value::CreateNullValue()); | 973 ResolveCallback(*base::Value::CreateNullValue()); |
| 971 } | 974 } |
| 972 } | 975 } |
| 973 | 976 |
| 974 void CertificatesHandler::OnCertificateManagerModelCreated( | 977 void CertificatesHandler::OnCertificateManagerModelCreated( |
| 975 scoped_ptr<CertificateManagerModel> model) { | 978 std::unique_ptr<CertificateManagerModel> model) { |
| 976 certificate_manager_model_ = std::move(model); | 979 certificate_manager_model_ = std::move(model); |
| 977 CertificateManagerModelReady(); | 980 CertificateManagerModelReady(); |
| 978 } | 981 } |
| 979 | 982 |
| 980 void CertificatesHandler::CertificateManagerModelReady() { | 983 void CertificatesHandler::CertificateManagerModelReady() { |
| 981 base::FundamentalValue user_db_available_value( | 984 base::FundamentalValue user_db_available_value( |
| 982 certificate_manager_model_->is_user_db_available()); | 985 certificate_manager_model_->is_user_db_available()); |
| 983 base::FundamentalValue tpm_available_value( | 986 base::FundamentalValue tpm_available_value( |
| 984 certificate_manager_model_->is_tpm_available()); | 987 certificate_manager_model_->is_tpm_available()); |
| 985 web_ui()->CallJavascriptFunction( | 988 web_ui()->CallJavascriptFunction( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1008 } | 1011 } |
| 1009 | 1012 |
| 1010 // We are already waiting for a CertificateManagerModel to be created, no need | 1013 // We are already waiting for a CertificateManagerModel to be created, no need |
| 1011 // to do anything. | 1014 // to do anything. |
| 1012 } | 1015 } |
| 1013 | 1016 |
| 1014 void CertificatesHandler::PopulateTree( | 1017 void CertificatesHandler::PopulateTree( |
| 1015 const std::string& tab_name, | 1018 const std::string& tab_name, |
| 1016 net::CertType type, | 1019 net::CertType type, |
| 1017 const net::CertificateList& web_trust_certs) { | 1020 const net::CertificateList& web_trust_certs) { |
| 1018 scoped_ptr<icu::Collator> collator; | 1021 std::unique_ptr<icu::Collator> collator; |
| 1019 UErrorCode error = U_ZERO_ERROR; | 1022 UErrorCode error = U_ZERO_ERROR; |
| 1020 collator.reset(icu::Collator::createInstance( | 1023 collator.reset(icu::Collator::createInstance( |
| 1021 icu::Locale(g_browser_process->GetApplicationLocale().c_str()), error)); | 1024 icu::Locale(g_browser_process->GetApplicationLocale().c_str()), error)); |
| 1022 if (U_FAILURE(error)) | 1025 if (U_FAILURE(error)) |
| 1023 collator.reset(NULL); | 1026 collator.reset(NULL); |
| 1024 DictionaryIdComparator comparator(collator.get()); | 1027 DictionaryIdComparator comparator(collator.get()); |
| 1025 CertificateManagerModel::OrgGroupingMap map; | 1028 CertificateManagerModel::OrgGroupingMap map; |
| 1026 | 1029 |
| 1027 certificate_manager_model_->FilterAndBuildOrgGroupingMap(type, &map); | 1030 certificate_manager_model_->FilterAndBuildOrgGroupingMap(type, &map); |
| 1028 | 1031 |
| 1029 { | 1032 { |
| 1030 scoped_ptr<base::ListValue> nodes = make_scoped_ptr(new base::ListValue()); | 1033 std::unique_ptr<base::ListValue> nodes = |
| 1034 base::WrapUnique(new base::ListValue()); |
| 1031 for (CertificateManagerModel::OrgGroupingMap::iterator i = map.begin(); | 1035 for (CertificateManagerModel::OrgGroupingMap::iterator i = map.begin(); |
| 1032 i != map.end(); ++i) { | 1036 i != map.end(); ++i) { |
| 1033 // Populate first level (org name). | 1037 // Populate first level (org name). |
| 1034 base::DictionaryValue* dict = new base::DictionaryValue; | 1038 base::DictionaryValue* dict = new base::DictionaryValue; |
| 1035 dict->SetString(kKeyField, OrgNameToId(i->first)); | 1039 dict->SetString(kKeyField, OrgNameToId(i->first)); |
| 1036 dict->SetString(kNameField, i->first); | 1040 dict->SetString(kNameField, i->first); |
| 1037 | 1041 |
| 1038 // Populate second level (certs). | 1042 // Populate second level (certs). |
| 1039 base::ListValue* subnodes = new base::ListValue; | 1043 base::ListValue* subnodes = new base::ListValue; |
| 1040 for (net::CertificateList::const_iterator org_cert_it = i->second.begin(); | 1044 for (net::CertificateList::const_iterator org_cert_it = i->second.begin(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 } | 1089 } |
| 1086 | 1090 |
| 1087 void CertificatesHandler::RejectCallback(const base::Value& response) { | 1091 void CertificatesHandler::RejectCallback(const base::Value& response) { |
| 1088 DCHECK(!webui_callback_id_.empty()); | 1092 DCHECK(!webui_callback_id_.empty()); |
| 1089 RejectJavascriptCallback(base::StringValue(webui_callback_id_), response); | 1093 RejectJavascriptCallback(base::StringValue(webui_callback_id_), response); |
| 1090 webui_callback_id_.clear(); | 1094 webui_callback_id_.clear(); |
| 1091 } | 1095 } |
| 1092 | 1096 |
| 1093 void CertificatesHandler::RejectCallbackWithError(const std::string& title, | 1097 void CertificatesHandler::RejectCallbackWithError(const std::string& title, |
| 1094 const std::string& error) { | 1098 const std::string& error) { |
| 1095 scoped_ptr<base::DictionaryValue> error_info(new base::DictionaryValue); | 1099 std::unique_ptr<base::DictionaryValue> error_info(new base::DictionaryValue); |
| 1096 error_info->SetString(kErrorTitle, title); | 1100 error_info->SetString(kErrorTitle, title); |
| 1097 error_info->SetString(kErrorDescription, error); | 1101 error_info->SetString(kErrorDescription, error); |
| 1098 RejectCallback(*error_info); | 1102 RejectCallback(*error_info); |
| 1099 } | 1103 } |
| 1100 | 1104 |
| 1101 void CertificatesHandler::RejectCallbackWithImportError( | 1105 void CertificatesHandler::RejectCallbackWithImportError( |
| 1102 const std::string& title, | 1106 const std::string& title, |
| 1103 const net::NSSCertDatabase::ImportCertFailureList& not_imported) { | 1107 const net::NSSCertDatabase::ImportCertFailureList& not_imported) { |
| 1104 std::string error; | 1108 std::string error; |
| 1105 if (selected_cert_list_.size() == 1) | 1109 if (selected_cert_list_.size() == 1) |
| 1106 error = l10n_util::GetStringUTF8( | 1110 error = l10n_util::GetStringUTF8( |
| 1107 IDS_SETTINGS_CERTIFICATE_MANAGER_IMPORT_SINGLE_NOT_IMPORTED); | 1111 IDS_SETTINGS_CERTIFICATE_MANAGER_IMPORT_SINGLE_NOT_IMPORTED); |
| 1108 else if (not_imported.size() == selected_cert_list_.size()) | 1112 else if (not_imported.size() == selected_cert_list_.size()) |
| 1109 error = l10n_util::GetStringUTF8( | 1113 error = l10n_util::GetStringUTF8( |
| 1110 IDS_SETTINGS_CERTIFICATE_MANAGER_IMPORT_ALL_NOT_IMPORTED); | 1114 IDS_SETTINGS_CERTIFICATE_MANAGER_IMPORT_ALL_NOT_IMPORTED); |
| 1111 else | 1115 else |
| 1112 error = l10n_util::GetStringUTF8( | 1116 error = l10n_util::GetStringUTF8( |
| 1113 IDS_SETTINGS_CERTIFICATE_MANAGER_IMPORT_SOME_NOT_IMPORTED); | 1117 IDS_SETTINGS_CERTIFICATE_MANAGER_IMPORT_SOME_NOT_IMPORTED); |
| 1114 | 1118 |
| 1115 scoped_ptr<base::ListValue> cert_error_list = | 1119 std::unique_ptr<base::ListValue> cert_error_list = |
| 1116 make_scoped_ptr(new base::ListValue()); | 1120 base::WrapUnique(new base::ListValue()); |
| 1117 for (size_t i = 0; i < not_imported.size(); ++i) { | 1121 for (size_t i = 0; i < not_imported.size(); ++i) { |
| 1118 const net::NSSCertDatabase::ImportCertFailure& failure = not_imported[i]; | 1122 const net::NSSCertDatabase::ImportCertFailure& failure = not_imported[i]; |
| 1119 base::DictionaryValue* dict = new base::DictionaryValue; | 1123 base::DictionaryValue* dict = new base::DictionaryValue; |
| 1120 dict->SetString(kNameField, | 1124 dict->SetString(kNameField, |
| 1121 failure.certificate->subject().GetDisplayName()); | 1125 failure.certificate->subject().GetDisplayName()); |
| 1122 dict->SetString(kErrorField, NetErrorToString(failure.net_error)); | 1126 dict->SetString(kErrorField, NetErrorToString(failure.net_error)); |
| 1123 cert_error_list->Append(dict); | 1127 cert_error_list->Append(dict); |
| 1124 } | 1128 } |
| 1125 | 1129 |
| 1126 scoped_ptr<base::DictionaryValue> error_info(new base::DictionaryValue); | 1130 std::unique_ptr<base::DictionaryValue> error_info(new base::DictionaryValue); |
| 1127 error_info->SetString(kErrorTitle, title); | 1131 error_info->SetString(kErrorTitle, title); |
| 1128 error_info->SetString(kErrorDescription, error); | 1132 error_info->SetString(kErrorDescription, error); |
| 1129 error_info->Set(kCertificateErrors, | 1133 error_info->Set(kCertificateErrors, |
| 1130 make_scoped_ptr(cert_error_list.release())); | 1134 base::WrapUnique(cert_error_list.release())); |
| 1131 RejectCallback(*error_info); | 1135 RejectCallback(*error_info); |
| 1132 } | 1136 } |
| 1133 | 1137 |
| 1134 gfx::NativeWindow CertificatesHandler::GetParentWindow() const { | 1138 gfx::NativeWindow CertificatesHandler::GetParentWindow() const { |
| 1135 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); | 1139 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); |
| 1136 } | 1140 } |
| 1137 | 1141 |
| 1138 } // namespace settings | 1142 } // namespace settings |
| OLD | NEW |