| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "content/public/browser/web_contents_view.h" | 28 #include "content/public/browser/web_contents_view.h" |
| 29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 30 #include "net/base/crypto_module.h" | 30 #include "net/base/crypto_module.h" |
| 31 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
| 32 #include "net/cert/x509_certificate.h" | 32 #include "net/cert/x509_certificate.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 34 | 34 |
| 35 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 36 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" | 36 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" |
| 37 #include "chrome/browser/chromeos/policy/user_network_configuration_updater_fact
ory.h" | 37 #include "chrome/browser/chromeos/policy/user_network_configuration_updater_fact
ory.h" |
| 38 #include "chromeos/dbus/cryptohome_client.h" | |
| 39 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 40 #endif | 38 #endif |
| 41 | 39 |
| 42 using content::BrowserThread; | 40 using content::BrowserThread; |
| 43 | 41 |
| 44 namespace { | 42 namespace { |
| 45 | 43 |
| 46 static const char kKeyId[] = "id"; | 44 static const char kKeyId[] = "id"; |
| 47 static const char kSubNodesId[] = "subnodes"; | 45 static const char kSubNodesId[] = "subnodes"; |
| 48 static const char kNameId[] = "name"; | 46 static const char kNameId[] = "name"; |
| 49 static const char kReadOnlyId[] = "readonly"; | 47 static const char kReadOnlyId[] = "readonly"; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 *saved_errno = *bytes_written >= 0 ? 0 : errno; | 281 *saved_errno = *bytes_written >= 0 ? 0 : errno; |
| 284 } | 282 } |
| 285 | 283 |
| 286 /////////////////////////////////////////////////////////////////////////////// | 284 /////////////////////////////////////////////////////////////////////////////// |
| 287 // CertificateManagerHandler | 285 // CertificateManagerHandler |
| 288 | 286 |
| 289 CertificateManagerHandler::CertificateManagerHandler() | 287 CertificateManagerHandler::CertificateManagerHandler() |
| 290 : use_hardware_backed_(false), | 288 : use_hardware_backed_(false), |
| 291 file_access_provider_(new FileAccessProvider()), | 289 file_access_provider_(new FileAccessProvider()), |
| 292 cert_id_map_(new CertIdMap), | 290 cert_id_map_(new CertIdMap), |
| 293 weak_ptr_factory_(this) { | 291 weak_ptr_factory_(this) {} |
| 294 certificate_manager_model_.reset(new CertificateManagerModel(this)); | |
| 295 } | |
| 296 | 292 |
| 297 CertificateManagerHandler::~CertificateManagerHandler() { | 293 CertificateManagerHandler::~CertificateManagerHandler() { |
| 298 } | 294 } |
| 299 | 295 |
| 300 void CertificateManagerHandler::GetLocalizedValues( | 296 void CertificateManagerHandler::GetLocalizedValues( |
| 301 DictionaryValue* localized_strings) { | 297 DictionaryValue* localized_strings) { |
| 302 DCHECK(localized_strings); | 298 DCHECK(localized_strings); |
| 303 | 299 |
| 304 RegisterTitle(localized_strings, "certificateManagerPage", | 300 RegisterTitle(localized_strings, "certificateManagerPage", |
| 305 IDS_CERTIFICATE_MANAGER_TITLE); | 301 IDS_CERTIFICATE_MANAGER_TITLE); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 462 |
| 467 web_ui()->RegisterMessageCallback( | 463 web_ui()->RegisterMessageCallback( |
| 468 "deleteCertificate", | 464 "deleteCertificate", |
| 469 base::Bind(&CertificateManagerHandler::Delete, | 465 base::Bind(&CertificateManagerHandler::Delete, |
| 470 base::Unretained(this))); | 466 base::Unretained(this))); |
| 471 | 467 |
| 472 web_ui()->RegisterMessageCallback( | 468 web_ui()->RegisterMessageCallback( |
| 473 "populateCertificateManager", | 469 "populateCertificateManager", |
| 474 base::Bind(&CertificateManagerHandler::Populate, | 470 base::Bind(&CertificateManagerHandler::Populate, |
| 475 base::Unretained(this))); | 471 base::Unretained(this))); |
| 472 } |
| 476 | 473 |
| 477 #if defined(OS_CHROMEOS) | 474 void CertificateManagerHandler::CertificateManagerModelReady() { |
| 478 web_ui()->RegisterMessageCallback( | 475 web_ui()->CallJavascriptFunction("CertificateManager.onModelReady"); |
| 479 "checkTpmTokenReady", | 476 certificate_manager_model_->Refresh(); |
| 480 base::Bind(&CertificateManagerHandler::CheckTpmTokenReady, | |
| 481 base::Unretained(this))); | |
| 482 #endif | |
| 483 } | 477 } |
| 484 | 478 |
| 485 void CertificateManagerHandler::CertificatesRefreshed() { | 479 void CertificateManagerHandler::CertificatesRefreshed() { |
| 486 net::CertificateList web_trusted_certs; | 480 net::CertificateList web_trusted_certs; |
| 487 #if defined(OS_CHROMEOS) | 481 #if defined(OS_CHROMEOS) |
| 488 policy::UserNetworkConfigurationUpdater* service = | 482 policy::UserNetworkConfigurationUpdater* service = |
| 489 policy::UserNetworkConfigurationUpdaterFactory::GetForProfile( | 483 policy::UserNetworkConfigurationUpdaterFactory::GetForProfile( |
| 490 Profile::FromWebUI(web_ui())); | 484 Profile::FromWebUI(web_ui())); |
| 491 if (service) | 485 if (service) |
| 492 service->GetWebTrustedCertificates(&web_trusted_certs); | 486 service->GetWebTrustedCertificates(&web_trusted_certs); |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 bool result = certificate_manager_model_->Delete(cert); | 972 bool result = certificate_manager_model_->Delete(cert); |
| 979 if (!result) { | 973 if (!result) { |
| 980 // TODO(mattm): better error messages? | 974 // TODO(mattm): better error messages? |
| 981 ShowError( | 975 ShowError( |
| 982 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_DELETE_CERT_ERROR_TITLE), | 976 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_DELETE_CERT_ERROR_TITLE), |
| 983 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_UNKNOWN_ERROR)); | 977 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_UNKNOWN_ERROR)); |
| 984 } | 978 } |
| 985 } | 979 } |
| 986 | 980 |
| 987 void CertificateManagerHandler::Populate(const ListValue* args) { | 981 void CertificateManagerHandler::Populate(const ListValue* args) { |
| 988 certificate_manager_model_->Refresh(); | 982 if (certificate_manager_model_) { |
| 983 if (certificate_manager_model_->is_ready()) { |
| 984 // Re-run the webui initialization. |
| 985 CertificateManagerModelReady(); |
| 986 } |
| 987 // else wait for CertificateManagerModelReady to be called through the |
| 988 // observer, as the init is still pending. |
| 989 } else { |
| 990 certificate_manager_model_.reset( |
| 991 new CertificateManagerModel(Profile::FromWebUI(web_ui()), this)); |
| 992 } |
| 989 } | 993 } |
| 990 | 994 |
| 991 void CertificateManagerHandler::PopulateTree( | 995 void CertificateManagerHandler::PopulateTree( |
| 992 const std::string& tab_name, | 996 const std::string& tab_name, |
| 993 net::CertType type, | 997 net::CertType type, |
| 994 const net::CertificateList& web_trust_certs) { | 998 const net::CertificateList& web_trust_certs) { |
| 995 const std::string tree_name = tab_name + "-tree"; | 999 const std::string tree_name = tab_name + "-tree"; |
| 996 | 1000 |
| 997 scoped_ptr<icu::Collator> collator; | 1001 scoped_ptr<icu::Collator> collator; |
| 998 UErrorCode error = U_ZERO_ERROR; | 1002 UErrorCode error = U_ZERO_ERROR; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 } | 1097 } |
| 1094 | 1098 |
| 1095 StringValue title_value(title); | 1099 StringValue title_value(title); |
| 1096 StringValue error_value(error); | 1100 StringValue error_value(error); |
| 1097 web_ui()->CallJavascriptFunction("CertificateImportErrorOverlay.show", | 1101 web_ui()->CallJavascriptFunction("CertificateImportErrorOverlay.show", |
| 1098 title_value, | 1102 title_value, |
| 1099 error_value, | 1103 error_value, |
| 1100 cert_error_list); | 1104 cert_error_list); |
| 1101 } | 1105 } |
| 1102 | 1106 |
| 1103 #if defined(OS_CHROMEOS) | |
| 1104 void CertificateManagerHandler::CheckTpmTokenReady(const ListValue* args) { | |
| 1105 chromeos::CryptohomeClient* cryptohome_client = | |
| 1106 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(); | |
| 1107 cryptohome_client->Pkcs11IsTpmTokenReady( | |
| 1108 base::Bind(&CertificateManagerHandler::CheckTpmTokenReadyInternal, | |
| 1109 weak_ptr_factory_.GetWeakPtr())); | |
| 1110 } | |
| 1111 | |
| 1112 void CertificateManagerHandler::CheckTpmTokenReadyInternal( | |
| 1113 chromeos::DBusMethodCallStatus call_status, | |
| 1114 bool is_tpm_token_ready) { | |
| 1115 base::FundamentalValue ready( | |
| 1116 call_status == chromeos::DBUS_METHOD_CALL_SUCCESS && is_tpm_token_ready); | |
| 1117 web_ui()->CallJavascriptFunction("CertificateManager.onCheckTpmTokenReady", | |
| 1118 ready); | |
| 1119 } | |
| 1120 #endif | |
| 1121 | |
| 1122 gfx::NativeWindow CertificateManagerHandler::GetParentWindow() const { | 1107 gfx::NativeWindow CertificateManagerHandler::GetParentWindow() const { |
| 1123 return web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(); | 1108 return web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(); |
| 1124 } | 1109 } |
| 1125 | 1110 |
| 1126 } // namespace options | 1111 } // namespace options |
| OLD | NEW |