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 |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 CertificateManagerModel::OrgGroupingMap map; | 1035 CertificateManagerModel::OrgGroupingMap map; |
1036 | 1036 |
1037 certificate_manager_model_->FilterAndBuildOrgGroupingMap(type, &map); | 1037 certificate_manager_model_->FilterAndBuildOrgGroupingMap(type, &map); |
1038 | 1038 |
1039 { | 1039 { |
1040 std::unique_ptr<base::ListValue> nodes = | 1040 std::unique_ptr<base::ListValue> nodes = |
1041 base::WrapUnique(new base::ListValue()); | 1041 base::WrapUnique(new base::ListValue()); |
1042 for (CertificateManagerModel::OrgGroupingMap::iterator i = map.begin(); | 1042 for (CertificateManagerModel::OrgGroupingMap::iterator i = map.begin(); |
1043 i != map.end(); ++i) { | 1043 i != map.end(); ++i) { |
1044 // Populate first level (org name). | 1044 // Populate first level (org name). |
1045 base::DictionaryValue* dict = new base::DictionaryValue; | 1045 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
1046 dict->SetString(kKeyField, OrgNameToId(i->first)); | 1046 dict->SetString(kKeyField, OrgNameToId(i->first)); |
1047 dict->SetString(kNameField, i->first); | 1047 dict->SetString(kNameField, i->first); |
1048 | 1048 |
1049 // Populate second level (certs). | 1049 // Populate second level (certs). |
1050 base::ListValue* subnodes = new base::ListValue; | 1050 base::ListValue* subnodes = new base::ListValue; |
1051 for (net::CertificateList::const_iterator org_cert_it = i->second.begin(); | 1051 for (net::CertificateList::const_iterator org_cert_it = i->second.begin(); |
1052 org_cert_it != i->second.end(); ++org_cert_it) { | 1052 org_cert_it != i->second.end(); ++org_cert_it) { |
1053 base::DictionaryValue* cert_dict = new base::DictionaryValue; | 1053 std::unique_ptr<base::DictionaryValue> cert_dict( |
| 1054 new base::DictionaryValue); |
1054 net::X509Certificate* cert = org_cert_it->get(); | 1055 net::X509Certificate* cert = org_cert_it->get(); |
1055 cert_dict->SetString(kKeyField, cert_id_map_->CertToId(cert)); | 1056 cert_dict->SetString(kKeyField, cert_id_map_->CertToId(cert)); |
1056 cert_dict->SetString( | 1057 cert_dict->SetString( |
1057 kNameField, certificate_manager_model_->GetColumnText( | 1058 kNameField, certificate_manager_model_->GetColumnText( |
1058 *cert, CertificateManagerModel::COL_SUBJECT_NAME)); | 1059 *cert, CertificateManagerModel::COL_SUBJECT_NAME)); |
1059 cert_dict->SetBoolean( | 1060 cert_dict->SetBoolean( |
1060 kReadonlyField, | 1061 kReadonlyField, |
1061 certificate_manager_model_->cert_db()->IsReadOnly(cert)); | 1062 certificate_manager_model_->cert_db()->IsReadOnly(cert)); |
1062 // Policy-installed certificates with web trust are trusted. | 1063 // Policy-installed certificates with web trust are trusted. |
1063 bool policy_trusted = | 1064 bool policy_trusted = |
1064 IsPolicyInstalledWithWebTrust(web_trust_certs, cert); | 1065 IsPolicyInstalledWithWebTrust(web_trust_certs, cert); |
1065 cert_dict->SetBoolean( | 1066 cert_dict->SetBoolean( |
1066 kUntrustedField, | 1067 kUntrustedField, |
1067 !policy_trusted && | 1068 !policy_trusted && |
1068 certificate_manager_model_->cert_db()->IsUntrusted(cert)); | 1069 certificate_manager_model_->cert_db()->IsUntrusted(cert)); |
1069 cert_dict->SetBoolean(kPolicyField, policy_trusted); | 1070 cert_dict->SetBoolean(kPolicyField, policy_trusted); |
1070 // TODO(hshi): This should be determined by testing for PKCS #11 | 1071 // TODO(hshi): This should be determined by testing for PKCS #11 |
1071 // CKA_EXTRACTABLE attribute. We may need to use the NSS function | 1072 // CKA_EXTRACTABLE attribute. We may need to use the NSS function |
1072 // PK11_ReadRawAttribute to do that. | 1073 // PK11_ReadRawAttribute to do that. |
1073 cert_dict->SetBoolean( | 1074 cert_dict->SetBoolean( |
1074 kExtractableField, | 1075 kExtractableField, |
1075 !certificate_manager_model_->IsHardwareBacked(cert)); | 1076 !certificate_manager_model_->IsHardwareBacked(cert)); |
1076 // TODO(mattm): Other columns. | 1077 // TODO(mattm): Other columns. |
1077 subnodes->Append(cert_dict); | 1078 subnodes->Append(std::move(cert_dict)); |
1078 } | 1079 } |
1079 std::sort(subnodes->begin(), subnodes->end(), comparator); | 1080 std::sort(subnodes->begin(), subnodes->end(), comparator); |
1080 | 1081 |
1081 dict->Set(kSubnodesField, subnodes); | 1082 dict->Set(kSubnodesField, subnodes); |
1082 nodes->Append(dict); | 1083 nodes->Append(std::move(dict)); |
1083 } | 1084 } |
1084 std::sort(nodes->begin(), nodes->end(), comparator); | 1085 std::sort(nodes->begin(), nodes->end(), comparator); |
1085 | 1086 |
1086 CallJavascriptFunction("cr.webUIListenerCallback", | 1087 CallJavascriptFunction("cr.webUIListenerCallback", |
1087 base::StringValue("certificates-changed"), | 1088 base::StringValue("certificates-changed"), |
1088 base::StringValue(tab_name), *nodes); | 1089 base::StringValue(tab_name), *nodes); |
1089 } | 1090 } |
1090 } | 1091 } |
1091 | 1092 |
1092 void CertificatesHandler::ResolveCallback(const base::Value& response) { | 1093 void CertificatesHandler::ResolveCallback(const base::Value& response) { |
(...skipping 27 matching lines...) Expand all Loading... |
1120 error = l10n_util::GetStringUTF8( | 1121 error = l10n_util::GetStringUTF8( |
1121 IDS_SETTINGS_CERTIFICATE_MANAGER_IMPORT_ALL_NOT_IMPORTED); | 1122 IDS_SETTINGS_CERTIFICATE_MANAGER_IMPORT_ALL_NOT_IMPORTED); |
1122 else | 1123 else |
1123 error = l10n_util::GetStringUTF8( | 1124 error = l10n_util::GetStringUTF8( |
1124 IDS_SETTINGS_CERTIFICATE_MANAGER_IMPORT_SOME_NOT_IMPORTED); | 1125 IDS_SETTINGS_CERTIFICATE_MANAGER_IMPORT_SOME_NOT_IMPORTED); |
1125 | 1126 |
1126 std::unique_ptr<base::ListValue> cert_error_list = | 1127 std::unique_ptr<base::ListValue> cert_error_list = |
1127 base::WrapUnique(new base::ListValue()); | 1128 base::WrapUnique(new base::ListValue()); |
1128 for (size_t i = 0; i < not_imported.size(); ++i) { | 1129 for (size_t i = 0; i < not_imported.size(); ++i) { |
1129 const net::NSSCertDatabase::ImportCertFailure& failure = not_imported[i]; | 1130 const net::NSSCertDatabase::ImportCertFailure& failure = not_imported[i]; |
1130 base::DictionaryValue* dict = new base::DictionaryValue; | 1131 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
1131 dict->SetString(kNameField, | 1132 dict->SetString(kNameField, |
1132 failure.certificate->subject().GetDisplayName()); | 1133 failure.certificate->subject().GetDisplayName()); |
1133 dict->SetString(kErrorField, NetErrorToString(failure.net_error)); | 1134 dict->SetString(kErrorField, NetErrorToString(failure.net_error)); |
1134 cert_error_list->Append(dict); | 1135 cert_error_list->Append(std::move(dict)); |
1135 } | 1136 } |
1136 | 1137 |
1137 std::unique_ptr<base::DictionaryValue> error_info(new base::DictionaryValue); | 1138 std::unique_ptr<base::DictionaryValue> error_info(new base::DictionaryValue); |
1138 error_info->SetString(kErrorTitle, title); | 1139 error_info->SetString(kErrorTitle, title); |
1139 error_info->SetString(kErrorDescription, error); | 1140 error_info->SetString(kErrorDescription, error); |
1140 error_info->Set(kCertificateErrors, | 1141 error_info->Set(kCertificateErrors, |
1141 base::WrapUnique(cert_error_list.release())); | 1142 base::WrapUnique(cert_error_list.release())); |
1142 RejectCallback(*error_info); | 1143 RejectCallback(*error_info); |
1143 } | 1144 } |
1144 | 1145 |
1145 gfx::NativeWindow CertificatesHandler::GetParentWindow() const { | 1146 gfx::NativeWindow CertificatesHandler::GetParentWindow() const { |
1146 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); | 1147 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); |
1147 } | 1148 } |
1148 | 1149 |
1149 } // namespace settings | 1150 } // namespace settings |
OLD | NEW |