Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(644)

Unified Diff: chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.cc

Issue 10703162: chromeos: Remove CryptohomeLibrary::TpmGetPassword and TpmIsReady (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add cryptohome_web_ui_handler.cc/h Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.cc
diff --git a/chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.cc b/chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e561df44e9165c88eeb2dc935672f00349b1efa4
--- /dev/null
+++ b/chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.h"
+
+#include "base/bind.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/cros/cryptohome_library.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "content/public/browser/web_ui.h"
+#include "crypto/nss_util.h"
+
+namespace chromeos {
+
+CryptohomeWebUIHandler::CryptohomeWebUIHandler() : weak_ptr_factory_(this) {}
+
+CryptohomeWebUIHandler::~CryptohomeWebUIHandler() {}
+
+void CryptohomeWebUIHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "requestCryptohomeProperty",
+ base::Bind(&CryptohomeWebUIHandler::OnRequestCryptohomeProperty,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void CryptohomeWebUIHandler::OnRequestCryptohomeProperty(
+ const base::ListValue* args) {
+ std::string destination_id;
+ if (!args->GetString(0, &destination_id)) {
+ DLOG(ERROR) << "Invalid arguments.";
+ return;
+ }
+ CryptohomeClient* cryptohome_client =
+ DBusThreadManager::Get()->GetCryptohomeClient();
+ CryptohomeLibrary* cryptohome_library =
+ CrosLibrary::Get()->GetCryptohomeLibrary();
+ if (destination_id == "is-mounted") {
+ SetCryptohomeBoolProperty(destination_id,
+ cryptohome_library->IsMounted());
+ } else if (destination_id == "tpm-is-ready") {
+ cryptohome_client->TpmIsReady(GetCryptohomeBoolCallback(destination_id));
+ } else if (destination_id == "tpm-is-enabled") {
+ SetCryptohomeBoolProperty(destination_id,
+ cryptohome_library->TpmIsEnabled());
+ } else if (destination_id == "tpm-is-owned") {
+ SetCryptohomeBoolProperty(destination_id,
+ cryptohome_library->TpmIsOwned());
+ } else if (destination_id == "tpm-is-being-owned") {
+ SetCryptohomeBoolProperty(destination_id,
+ cryptohome_library->TpmIsBeingOwned());
+ } else if (destination_id == "pkcs11-is-tpm-token-ready") {
+ cryptohome_client->Pkcs11IsTpmTokenReady(
+ GetCryptohomeBoolCallback(destination_id));
+ } else if (destination_id == "is-tpm-token-ready") {
+ SetCryptohomeBoolProperty(destination_id, crypto::IsTPMTokenReady());
+ } else if (destination_id == "token-name") {
+ std::string token_name;
+ if (crypto::IsTPMTokenReady())
+ crypto::GetTPMTokenInfo(&token_name, NULL);
+ SetCryptohomeStringProperty(destination_id, token_name);
+ } else if (destination_id == "user-pin") {
+ std::string user_pin;
+ if (crypto::IsTPMTokenReady())
+ crypto::GetTPMTokenInfo(NULL, &user_pin);
+ user_pin = std::string(user_pin.length(), '*');
+ SetCryptohomeStringProperty(destination_id, user_pin);
+ } else {
+ NOTREACHED();
+ }
+}
+
+CryptohomeClient::BoolMethodCallback
+CryptohomeWebUIHandler::GetCryptohomeBoolCallback(
+ const std::string& destination_id) {
+ return base::Bind(&CryptohomeWebUIHandler::OnCryptohomeBoolProperty,
+ weak_ptr_factory_.GetWeakPtr(),
+ destination_id);
+}
+
+void CryptohomeWebUIHandler::OnCryptohomeBoolProperty(
+ const std::string& destination_id,
+ DBusMethodCallStatus call_status,
+ bool value) {
+ if (call_status != DBUS_METHOD_CALL_SUCCESS)
+ value = false;
+ SetCryptohomeBoolProperty(destination_id, value);
+}
+
+void CryptohomeWebUIHandler::SetCryptohomeBoolProperty(
+ const std::string& destination_id,
+ bool value) {
+ SetCryptohomeStringProperty(destination_id,
Evan Stade 2012/07/19 22:54:41 how about: void CryptohomeWebUIHandler::SetCrypto
hashimoto 2012/07/20 10:54:28 Done.
+ value ? "true" : "false");
+}
+
+void CryptohomeWebUIHandler::SetCryptohomeStringProperty(
+ const std::string& destination_id,
+ const std::string& value) {
+ base::StringValue destination_id_value(destination_id);
+ base::StringValue value_value(value);
+ web_ui()->CallJavascriptFunction(
+ "SetCryptohomeProperty", destination_id_value, value_value);
+}
+
+} // namespace chromeos
« no previous file with comments | « chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698