Chromium Code Reviews| 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 "requestCryptohomeProperty", | |
| 24 base::Bind(&CryptohomeWebUIHandler::OnRequestCryptohomeProperty, | |
| 25 weak_ptr_factory_.GetWeakPtr())); | |
| 26 } | |
| 27 | |
| 28 void CryptohomeWebUIHandler::OnRequestCryptohomeProperty( | |
| 29 const base::ListValue* args) { | |
| 30 std::string destination_id; | |
| 31 if (!args->GetString(0, &destination_id)) { | |
| 32 DLOG(ERROR) << "Invalid arguments."; | |
| 33 return; | |
| 34 } | |
| 35 CryptohomeClient* cryptohome_client = | |
| 36 DBusThreadManager::Get()->GetCryptohomeClient(); | |
| 37 CryptohomeLibrary* cryptohome_library = | |
| 38 CrosLibrary::Get()->GetCryptohomeLibrary(); | |
| 39 if (destination_id == "is-mounted") { | |
| 40 SetCryptohomeBoolProperty(destination_id, | |
| 41 cryptohome_library->IsMounted()); | |
| 42 } else if (destination_id == "tpm-is-ready") { | |
| 43 cryptohome_client->TpmIsReady(GetCryptohomeBoolCallback(destination_id)); | |
| 44 } else if (destination_id == "tpm-is-enabled") { | |
| 45 SetCryptohomeBoolProperty(destination_id, | |
| 46 cryptohome_library->TpmIsEnabled()); | |
| 47 } else if (destination_id == "tpm-is-owned") { | |
| 48 SetCryptohomeBoolProperty(destination_id, | |
| 49 cryptohome_library->TpmIsOwned()); | |
| 50 } else if (destination_id == "tpm-is-being-owned") { | |
| 51 SetCryptohomeBoolProperty(destination_id, | |
| 52 cryptohome_library->TpmIsBeingOwned()); | |
| 53 } else if (destination_id == "pkcs11-is-tpm-token-ready") { | |
| 54 cryptohome_client->Pkcs11IsTpmTokenReady( | |
| 55 GetCryptohomeBoolCallback(destination_id)); | |
| 56 } else if (destination_id == "is-tpm-token-ready") { | |
| 57 SetCryptohomeBoolProperty(destination_id, crypto::IsTPMTokenReady()); | |
| 58 } else if (destination_id == "token-name") { | |
| 59 std::string token_name; | |
| 60 if (crypto::IsTPMTokenReady()) | |
| 61 crypto::GetTPMTokenInfo(&token_name, NULL); | |
| 62 SetCryptohomeStringProperty(destination_id, token_name); | |
| 63 } else if (destination_id == "user-pin") { | |
| 64 std::string user_pin; | |
| 65 if (crypto::IsTPMTokenReady()) | |
| 66 crypto::GetTPMTokenInfo(NULL, &user_pin); | |
| 67 user_pin = std::string(user_pin.length(), '*'); | |
| 68 SetCryptohomeStringProperty(destination_id, user_pin); | |
| 69 } else { | |
| 70 NOTREACHED(); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 CryptohomeClient::BoolMethodCallback | |
| 75 CryptohomeWebUIHandler::GetCryptohomeBoolCallback( | |
| 76 const std::string& destination_id) { | |
| 77 return base::Bind(&CryptohomeWebUIHandler::OnCryptohomeBoolProperty, | |
| 78 weak_ptr_factory_.GetWeakPtr(), | |
| 79 destination_id); | |
| 80 } | |
| 81 | |
| 82 void CryptohomeWebUIHandler::OnCryptohomeBoolProperty( | |
| 83 const std::string& destination_id, | |
| 84 DBusMethodCallStatus call_status, | |
| 85 bool value) { | |
| 86 if (call_status != DBUS_METHOD_CALL_SUCCESS) | |
| 87 value = false; | |
| 88 SetCryptohomeBoolProperty(destination_id, value); | |
| 89 } | |
| 90 | |
| 91 void CryptohomeWebUIHandler::SetCryptohomeBoolProperty( | |
| 92 const std::string& destination_id, | |
| 93 bool value) { | |
| 94 SetCryptohomeStringProperty(destination_id, | |
|
Evan Stade
2012/07/19 22:54:41
how about:
void CryptohomeWebUIHandler::SetCrypto
hashimoto
2012/07/20 10:54:28
Done.
| |
| 95 value ? "true" : "false"); | |
| 96 } | |
| 97 | |
| 98 void CryptohomeWebUIHandler::SetCryptohomeStringProperty( | |
| 99 const std::string& destination_id, | |
| 100 const std::string& value) { | |
| 101 base::StringValue destination_id_value(destination_id); | |
| 102 base::StringValue value_value(value); | |
| 103 web_ui()->CallJavascriptFunction( | |
| 104 "SetCryptohomeProperty", destination_id_value, value_value); | |
| 105 } | |
| 106 | |
| 107 } // namespace chromeos | |
| OLD | NEW |