| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <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" |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 icu::Locale(g_browser_process->GetApplicationLocale().c_str()), | 1135 icu::Locale(g_browser_process->GetApplicationLocale().c_str()), |
| 1135 error)); | 1136 error)); |
| 1136 if (U_FAILURE(error)) | 1137 if (U_FAILURE(error)) |
| 1137 collator.reset(NULL); | 1138 collator.reset(NULL); |
| 1138 DictionaryIdComparator comparator(collator.get()); | 1139 DictionaryIdComparator comparator(collator.get()); |
| 1139 CertificateManagerModel::OrgGroupingMap map; | 1140 CertificateManagerModel::OrgGroupingMap map; |
| 1140 | 1141 |
| 1141 certificate_manager_model_->FilterAndBuildOrgGroupingMap(type, &map); | 1142 certificate_manager_model_->FilterAndBuildOrgGroupingMap(type, &map); |
| 1142 | 1143 |
| 1143 { | 1144 { |
| 1144 base::ListValue* nodes = new base::ListValue; | 1145 std::unique_ptr<base::ListValue> nodes(new base::ListValue); |
| 1145 for (CertificateManagerModel::OrgGroupingMap::iterator i = map.begin(); | 1146 for (CertificateManagerModel::OrgGroupingMap::iterator i = map.begin(); |
| 1146 i != map.end(); ++i) { | 1147 i != map.end(); ++i) { |
| 1147 // Populate first level (org name). | 1148 // Populate first level (org name). |
| 1148 base::DictionaryValue* dict = new base::DictionaryValue; | 1149 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 1149 dict->SetString(kKeyId, OrgNameToId(i->first)); | 1150 dict->SetString(kKeyId, OrgNameToId(i->first)); |
| 1150 dict->SetString(kNameId, i->first); | 1151 dict->SetString(kNameId, i->first); |
| 1151 | 1152 |
| 1152 // Populate second level (certs). | 1153 // Populate second level (certs). |
| 1153 base::ListValue* subnodes = new base::ListValue; | 1154 base::ListValue* subnodes = new base::ListValue; |
| 1154 for (net::CertificateList::const_iterator org_cert_it = i->second.begin(); | 1155 for (net::CertificateList::const_iterator org_cert_it = i->second.begin(); |
| 1155 org_cert_it != i->second.end(); ++org_cert_it) { | 1156 org_cert_it != i->second.end(); ++org_cert_it) { |
| 1156 base::DictionaryValue* cert_dict = new base::DictionaryValue; | 1157 std::unique_ptr<base::DictionaryValue> cert_dict( |
| 1158 new base::DictionaryValue); |
| 1157 net::X509Certificate* cert = org_cert_it->get(); | 1159 net::X509Certificate* cert = org_cert_it->get(); |
| 1158 cert_dict->SetString(kKeyId, cert_id_map_->CertToId(cert)); | 1160 cert_dict->SetString(kKeyId, cert_id_map_->CertToId(cert)); |
| 1159 cert_dict->SetString(kNameId, certificate_manager_model_->GetColumnText( | 1161 cert_dict->SetString(kNameId, certificate_manager_model_->GetColumnText( |
| 1160 *cert, CertificateManagerModel::COL_SUBJECT_NAME)); | 1162 *cert, CertificateManagerModel::COL_SUBJECT_NAME)); |
| 1161 cert_dict->SetBoolean( | 1163 cert_dict->SetBoolean( |
| 1162 kReadOnlyId, | 1164 kReadOnlyId, |
| 1163 certificate_manager_model_->cert_db()->IsReadOnly(cert)); | 1165 certificate_manager_model_->cert_db()->IsReadOnly(cert)); |
| 1164 // Policy-installed certificates with web trust are trusted. | 1166 // Policy-installed certificates with web trust are trusted. |
| 1165 bool policy_trusted = | 1167 bool policy_trusted = |
| 1166 IsPolicyInstalledWithWebTrust(web_trust_certs, cert); | 1168 IsPolicyInstalledWithWebTrust(web_trust_certs, cert); |
| 1167 cert_dict->SetBoolean( | 1169 cert_dict->SetBoolean( |
| 1168 kUntrustedId, | 1170 kUntrustedId, |
| 1169 !policy_trusted && | 1171 !policy_trusted && |
| 1170 certificate_manager_model_->cert_db()->IsUntrusted(cert)); | 1172 certificate_manager_model_->cert_db()->IsUntrusted(cert)); |
| 1171 cert_dict->SetBoolean(kPolicyTrustedId, policy_trusted); | 1173 cert_dict->SetBoolean(kPolicyTrustedId, policy_trusted); |
| 1172 // TODO(hshi): This should be determined by testing for PKCS #11 | 1174 // TODO(hshi): This should be determined by testing for PKCS #11 |
| 1173 // CKA_EXTRACTABLE attribute. We may need to use the NSS function | 1175 // CKA_EXTRACTABLE attribute. We may need to use the NSS function |
| 1174 // PK11_ReadRawAttribute to do that. | 1176 // PK11_ReadRawAttribute to do that. |
| 1175 cert_dict->SetBoolean( | 1177 cert_dict->SetBoolean( |
| 1176 kExtractableId, | 1178 kExtractableId, |
| 1177 !certificate_manager_model_->IsHardwareBacked(cert)); | 1179 !certificate_manager_model_->IsHardwareBacked(cert)); |
| 1178 // TODO(mattm): Other columns. | 1180 // TODO(mattm): Other columns. |
| 1179 subnodes->Append(cert_dict); | 1181 subnodes->Append(std::move(cert_dict)); |
| 1180 } | 1182 } |
| 1181 std::sort(subnodes->begin(), subnodes->end(), comparator); | 1183 std::sort(subnodes->begin(), subnodes->end(), comparator); |
| 1182 | 1184 |
| 1183 dict->Set(kSubNodesId, subnodes); | 1185 dict->Set(kSubNodesId, subnodes); |
| 1184 nodes->Append(dict); | 1186 nodes->Append(std::move(dict)); |
| 1185 } | 1187 } |
| 1186 std::sort(nodes->begin(), nodes->end(), comparator); | 1188 std::sort(nodes->begin(), nodes->end(), comparator); |
| 1187 | 1189 |
| 1188 base::ListValue args; | 1190 base::ListValue args; |
| 1189 args.AppendString(tree_name); | 1191 args.AppendString(tree_name); |
| 1190 args.Append(nodes); | 1192 args.Append(std::move(nodes)); |
| 1191 web_ui()->CallJavascriptFunctionUnsafe("CertificateManager.onPopulateTree", | 1193 web_ui()->CallJavascriptFunctionUnsafe("CertificateManager.onPopulateTree", |
| 1192 args); | 1194 args); |
| 1193 } | 1195 } |
| 1194 } | 1196 } |
| 1195 | 1197 |
| 1196 void CertificateManagerHandler::ShowError(const std::string& title, | 1198 void CertificateManagerHandler::ShowError(const std::string& title, |
| 1197 const std::string& error) const { | 1199 const std::string& error) const { |
| 1198 ScopedVector<const base::Value> args; | 1200 ScopedVector<const base::Value> args; |
| 1199 args.push_back(new base::StringValue(title)); | 1201 args.push_back(new base::StringValue(title)); |
| 1200 args.push_back(new base::StringValue(error)); | 1202 args.push_back(new base::StringValue(error)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1213 error = l10n_util::GetStringUTF8( | 1215 error = l10n_util::GetStringUTF8( |
| 1214 IDS_CERT_MANAGER_IMPORT_SINGLE_NOT_IMPORTED); | 1216 IDS_CERT_MANAGER_IMPORT_SINGLE_NOT_IMPORTED); |
| 1215 else if (not_imported.size() == selected_cert_list_.size()) | 1217 else if (not_imported.size() == selected_cert_list_.size()) |
| 1216 error = l10n_util::GetStringUTF8(IDS_CERT_MANAGER_IMPORT_ALL_NOT_IMPORTED); | 1218 error = l10n_util::GetStringUTF8(IDS_CERT_MANAGER_IMPORT_ALL_NOT_IMPORTED); |
| 1217 else | 1219 else |
| 1218 error = l10n_util::GetStringUTF8(IDS_CERT_MANAGER_IMPORT_SOME_NOT_IMPORTED); | 1220 error = l10n_util::GetStringUTF8(IDS_CERT_MANAGER_IMPORT_SOME_NOT_IMPORTED); |
| 1219 | 1221 |
| 1220 base::ListValue cert_error_list; | 1222 base::ListValue cert_error_list; |
| 1221 for (size_t i = 0; i < not_imported.size(); ++i) { | 1223 for (size_t i = 0; i < not_imported.size(); ++i) { |
| 1222 const net::NSSCertDatabase::ImportCertFailure& failure = not_imported[i]; | 1224 const net::NSSCertDatabase::ImportCertFailure& failure = not_imported[i]; |
| 1223 base::DictionaryValue* dict = new base::DictionaryValue; | 1225 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 1224 dict->SetString(kNameId, failure.certificate->subject().GetDisplayName()); | 1226 dict->SetString(kNameId, failure.certificate->subject().GetDisplayName()); |
| 1225 dict->SetString(kErrorId, NetErrorToString(failure.net_error)); | 1227 dict->SetString(kErrorId, NetErrorToString(failure.net_error)); |
| 1226 cert_error_list.Append(dict); | 1228 cert_error_list.Append(std::move(dict)); |
| 1227 } | 1229 } |
| 1228 | 1230 |
| 1229 base::StringValue title_value(title); | 1231 base::StringValue title_value(title); |
| 1230 base::StringValue error_value(error); | 1232 base::StringValue error_value(error); |
| 1231 web_ui()->CallJavascriptFunctionUnsafe("CertificateImportErrorOverlay.show", | 1233 web_ui()->CallJavascriptFunctionUnsafe("CertificateImportErrorOverlay.show", |
| 1232 title_value, error_value, | 1234 title_value, error_value, |
| 1233 cert_error_list); | 1235 cert_error_list); |
| 1234 } | 1236 } |
| 1235 | 1237 |
| 1236 gfx::NativeWindow CertificateManagerHandler::GetParentWindow() const { | 1238 gfx::NativeWindow CertificateManagerHandler::GetParentWindow() const { |
| 1237 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); | 1239 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); |
| 1238 } | 1240 } |
| 1239 | 1241 |
| 1240 } // namespace options | 1242 } // namespace options |
| OLD | NEW |