Chromium Code Reviews| Index: chrome/browser/ui/webui/options/managed_user_passphrase_handler.cc |
| diff --git a/chrome/browser/ui/webui/options/managed_user_passphrase_handler.cc b/chrome/browser/ui/webui/options/managed_user_passphrase_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..82c84594188992f52b578717e3d41fe3fdddb1a8 |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/options/managed_user_passphrase_handler.cc |
| @@ -0,0 +1,119 @@ |
| +// 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/options/managed_user_passphrase_handler.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/logging.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/managed_mode/managed_mode.h" |
| +#include "chrome/browser/managed_mode/managed_user_passphrase.h" |
| +#include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/webui/managed_user_passphrase_dialog.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_ui.h" |
| +#include "grit/generated_resources.h" |
| + |
| +namespace options { |
| + |
| +ManagedUserPassphraseHandler::ManagedUserPassphraseHandler() |
| + : weak_ptr_factory_(this) { |
| +} |
| + |
| +ManagedUserPassphraseHandler::~ManagedUserPassphraseHandler() { |
| +} |
| + |
| +void ManagedUserPassphraseHandler::InitializeHandler() { |
| +} |
| + |
| +void ManagedUserPassphraseHandler::RegisterMessages() { |
| + web_ui()->RegisterMessageCallback("setPassphrase", |
| + base::Bind(&ManagedUserPassphraseHandler::SetLocalPassphrase, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + web_ui()->RegisterMessageCallback("displayPassphraseDialog", |
| + base::Bind(&ManagedUserPassphraseHandler::DisplayPassphraseDialog, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + web_ui()->RegisterMessageCallback("endAuthentication", |
| + base::Bind(&ManagedUserPassphraseHandler::EndAuthentication, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + web_ui()->RegisterMessageCallback("isPassphraseSet", |
| + base::Bind(&ManagedUserPassphraseHandler::IsPassphraseSet, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void ManagedUserPassphraseHandler::GetLocalizedValues( |
| + base::DictionaryValue* localized_strings) { |
| + DCHECK(localized_strings); |
| + |
| + static OptionsStringResource resources[] = { |
| + { "confirmPassphrase", IDS_CONFIRM_PASSPHRASE_LABEL }, |
| + { "enterPassphrase", IDS_ENTER_PASSPHRASE_LABEL }, |
| + { "savePassphrase", IDS_SAVE_PASSPHRASE_BUTTON }, |
| + { "setPassphraseInstructions", IDS_SET_PASSPHRASE_INSTRUCTIONS }, |
| + { "passphraseMismatch", IDS_PASSPHRASE_MISMATCH }, |
| + }; |
| + RegisterStrings(localized_strings, resources, arraysize(resources)); |
| + |
| + RegisterTitle(localized_strings, |
| + "setPassphraseTitle", |
| + IDS_SET_PASSPHRASE_TITLE); |
| +} |
| + |
| +void ManagedUserPassphraseHandler::PassphraseDialogCallback(bool success) { |
| + base::FundamentalValue unlock_success(success); |
| + web_ui()->CallJavascriptFunction(callback_function_name_, unlock_success); |
| +} |
| + |
| +void ManagedUserPassphraseHandler::DisplayPassphraseDialog( |
| + const base::ListValue* args) { |
| + // Store the name of the callback function. |
| + args->GetString(0, &callback_function_name_); |
| + if (ManagedMode::IsCustodianAuthenticated()) { |
| + // If the custodian is already authenticated, skip the passphrase dialog. |
| + PassphraseDialogCallback(true); |
| + return; |
| + } |
| + // This is deleted automatically when the dialog is closed. |
| + new ManagedUserPassphraseDialog(web_ui()->GetWebContents(), |
| + base::Bind(&ManagedUserPassphraseHandler::PassphraseDialogCallback, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void ManagedUserPassphraseHandler::EndAuthentication( |
| + const base::ListValue* args) { |
| + ManagedMode::SetCustodianAuthenticated(false); |
| +} |
| + |
| +void ManagedUserPassphraseHandler::IsPassphraseSet( |
| + const base::ListValue* args) { |
| + PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| + base::FundamentalValue is_passphrase_empty(!pref_service->GetString( |
| + prefs::kManagedModeLocalPassphrase).empty()); |
| + web_ui()->CallJavascriptFunction( |
| + "ManagedUserSettings.isPassphraseSet", |
|
Pam (message me for reviews)
2013/01/14 15:37:50
Move onto previous line, then align next parameter
Adrian Kuegel
2013/01/19 01:21:32
Done.
|
| + is_passphrase_empty); |
| +} |
| + |
| +void ManagedUserPassphraseHandler::SetLocalPassphrase( |
| + const base::ListValue* args) { |
| + // Only change the passphrase if the custodian is authenticated. |
| + if (!ManagedMode::IsCustodianAuthenticated()) |
| + return; |
| + |
| + std::string passphrase; |
| + args->GetString(0, &passphrase); |
| + ManagedUserPassphrase passphrase_key_generator((std::string())); |
| + std::string encoded_passphrase_hash; |
| + passphrase_key_generator.GenerateHashFromPassphrase(passphrase, |
| + &encoded_passphrase_hash); |
| + PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| + pref_service->SetString(prefs::kManagedModeLocalPassphrase, |
| + encoded_passphrase_hash); |
| + pref_service->SetString(prefs::kManagedModeLocalSalt, |
| + passphrase_key_generator.GetSalt()); |
| +} |
| + |
| +} // namespace options |