| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" |
| 12 #include "content/public/browser/web_ui.h" |
| 13 #include "crypto/nss_util.h" |
| 14 |
| 15 namespace chromeos { |
| 16 |
| 17 CryptohomeWebUIHandler::CryptohomeWebUIHandler() : weak_ptr_factory_(this) {} |
| 18 |
| 19 CryptohomeWebUIHandler::~CryptohomeWebUIHandler() {} |
| 20 |
| 21 void CryptohomeWebUIHandler::RegisterMessages() { |
| 22 web_ui()->RegisterMessageCallback( |
| 23 "pageLoaded", |
| 24 base::Bind(&CryptohomeWebUIHandler::OnPageLoaded, |
| 25 weak_ptr_factory_.GetWeakPtr())); |
| 26 } |
| 27 |
| 28 void CryptohomeWebUIHandler::OnPageLoaded(const base::ListValue* args) { |
| 29 CryptohomeClient* cryptohome_client = |
| 30 DBusThreadManager::Get()->GetCryptohomeClient(); |
| 31 CryptohomeLibrary* cryptohome_library = |
| 32 CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 33 |
| 34 base::FundamentalValue is_mounted(cryptohome_library->IsMounted()); |
| 35 SetCryptohomeProperty("is-mounted", is_mounted); |
| 36 cryptohome_client->TpmIsReady(GetCryptohomeBoolCallback("tpm-is-ready")); |
| 37 base::FundamentalValue tpm_is_enabled(cryptohome_library->TpmIsEnabled()); |
| 38 SetCryptohomeProperty("tpm-is-enabled", tpm_is_enabled); |
| 39 base::FundamentalValue tpm_is_owned(cryptohome_library->TpmIsOwned()); |
| 40 SetCryptohomeProperty("tpm-is-owned", tpm_is_owned); |
| 41 base::FundamentalValue tpm_is_being_owned( |
| 42 cryptohome_library->TpmIsBeingOwned()); |
| 43 SetCryptohomeProperty("tpm-is-being-owned", tpm_is_being_owned); |
| 44 cryptohome_client->Pkcs11IsTpmTokenReady( |
| 45 GetCryptohomeBoolCallback("pkcs11-is-tpm-token-ready")); |
| 46 base::FundamentalValue is_tpm_token_ready(crypto::IsTPMTokenReady()); |
| 47 SetCryptohomeProperty("is-tpm-token-ready", is_tpm_token_ready); |
| 48 |
| 49 if (crypto::IsTPMTokenReady()) { |
| 50 std::string token_name; |
| 51 std::string user_pin; |
| 52 crypto::GetTPMTokenInfo(&token_name, &user_pin); |
| 53 // Hide user_pin. |
| 54 user_pin = std::string(user_pin.length(), '*'); |
| 55 base::StringValue token_name_value(token_name); |
| 56 SetCryptohomeProperty("token-name", token_name_value); |
| 57 base::StringValue user_pin_value(user_pin); |
| 58 SetCryptohomeProperty("user-pin", user_pin_value); |
| 59 } |
| 60 } |
| 61 |
| 62 CryptohomeClient::BoolMethodCallback |
| 63 CryptohomeWebUIHandler::GetCryptohomeBoolCallback( |
| 64 const std::string& destination_id) { |
| 65 return base::Bind(&CryptohomeWebUIHandler::OnCryptohomeBoolProperty, |
| 66 weak_ptr_factory_.GetWeakPtr(), |
| 67 destination_id); |
| 68 } |
| 69 |
| 70 void CryptohomeWebUIHandler::OnCryptohomeBoolProperty( |
| 71 const std::string& destination_id, |
| 72 DBusMethodCallStatus call_status, |
| 73 bool value) { |
| 74 if (call_status != DBUS_METHOD_CALL_SUCCESS) |
| 75 value = false; |
| 76 base::FundamentalValue fundamental_value(value); |
| 77 SetCryptohomeProperty(destination_id, fundamental_value); |
| 78 } |
| 79 |
| 80 void CryptohomeWebUIHandler::SetCryptohomeProperty( |
| 81 const std::string& destination_id, |
| 82 const base::Value& value) { |
| 83 base::StringValue destination_id_value(destination_id); |
| 84 web_ui()->CallJavascriptFunction( |
| 85 "SetCryptohomeProperty", destination_id_value, value); |
| 86 } |
| 87 |
| 88 } // namespace chromeos |
| OLD | NEW |