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.
5 #include "chrome/browser/ui/webui/chromeos/cryptohome_web_ui_handler.h"
8 #include "base/values.h"
9 #include "chromeos/dbus/cryptohome_client.h"
10 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/web_ui.h"
13 #include "crypto/nss_util.h"
15 using content::BrowserThread
;
19 CryptohomeWebUIHandler::CryptohomeWebUIHandler() : weak_ptr_factory_(this) {}
21 CryptohomeWebUIHandler::~CryptohomeWebUIHandler() {}
23 void CryptohomeWebUIHandler::RegisterMessages() {
24 web_ui()->RegisterMessageCallback(
26 base::Bind(&CryptohomeWebUIHandler::OnPageLoaded
,
27 weak_ptr_factory_
.GetWeakPtr()));
30 void CryptohomeWebUIHandler::OnPageLoaded(const base::ListValue
* args
) {
31 CryptohomeClient
* cryptohome_client
=
32 DBusThreadManager::Get()->GetCryptohomeClient();
34 cryptohome_client
->IsMounted(GetCryptohomeBoolCallback("is-mounted"));
35 cryptohome_client
->TpmIsReady(GetCryptohomeBoolCallback("tpm-is-ready"));
36 cryptohome_client
->TpmIsEnabled(GetCryptohomeBoolCallback("tpm-is-enabled"));
37 cryptohome_client
->TpmIsOwned(GetCryptohomeBoolCallback("tpm-is-owned"));
38 cryptohome_client
->TpmIsBeingOwned(
39 GetCryptohomeBoolCallback("tpm-is-being-owned"));
40 cryptohome_client
->Pkcs11IsTpmTokenReady(
41 GetCryptohomeBoolCallback("pkcs11-is-tpm-token-ready"));
43 BrowserThread::PostTaskAndReplyWithResult(
46 base::Bind(&crypto::IsTPMTokenReady
, base::Closure()),
47 base::Bind(&CryptohomeWebUIHandler::DidGetNSSUtilInfoOnUIThread
,
48 weak_ptr_factory_
.GetWeakPtr()));
51 void CryptohomeWebUIHandler::DidGetNSSUtilInfoOnUIThread(
52 bool is_tpm_token_ready
) {
53 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
55 base::FundamentalValue
is_tpm_token_ready_value(is_tpm_token_ready
);
56 SetCryptohomeProperty("is-tpm-token-ready", is_tpm_token_ready_value
);
59 BoolDBusMethodCallback
CryptohomeWebUIHandler::GetCryptohomeBoolCallback(
60 const std::string
& destination_id
) {
61 return base::Bind(&CryptohomeWebUIHandler::OnCryptohomeBoolProperty
,
62 weak_ptr_factory_
.GetWeakPtr(),
66 void CryptohomeWebUIHandler::OnCryptohomeBoolProperty(
67 const std::string
& destination_id
,
68 DBusMethodCallStatus call_status
,
70 if (call_status
!= DBUS_METHOD_CALL_SUCCESS
)
72 base::FundamentalValue
fundamental_value(value
);
73 SetCryptohomeProperty(destination_id
, fundamental_value
);
76 void CryptohomeWebUIHandler::SetCryptohomeProperty(
77 const std::string
& destination_id
,
78 const base::Value
& value
) {
79 base::StringValue
destination_id_value(destination_id
);
80 web_ui()->CallJavascriptFunction(
81 "SetCryptohomeProperty", destination_id_value
, value
);
84 } // namespace chromeos