OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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/options/managed_user_passphrase_handler.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/browser/managed_mode/managed_user_passphrase.h" |
| 11 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 12 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/pref_names.h" |
| 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_ui.h" |
| 18 #include "grit/generated_resources.h" |
| 19 |
| 20 namespace options { |
| 21 |
| 22 ManagedUserPassphraseHandler::ManagedUserPassphraseHandler() |
| 23 : weak_ptr_factory_(this) { |
| 24 } |
| 25 |
| 26 ManagedUserPassphraseHandler::~ManagedUserPassphraseHandler() { |
| 27 } |
| 28 |
| 29 void ManagedUserPassphraseHandler::InitializeHandler() { |
| 30 } |
| 31 |
| 32 void ManagedUserPassphraseHandler::RegisterMessages() { |
| 33 web_ui()->RegisterMessageCallback("setPassphrase", |
| 34 base::Bind(&ManagedUserPassphraseHandler::SetLocalPassphrase, |
| 35 weak_ptr_factory_.GetWeakPtr())); |
| 36 web_ui()->RegisterMessageCallback("isPassphraseSet", |
| 37 base::Bind(&ManagedUserPassphraseHandler::IsPassphraseSet, |
| 38 weak_ptr_factory_.GetWeakPtr())); |
| 39 web_ui()->RegisterMessageCallback("resetPassphrase", |
| 40 base::Bind(&ManagedUserPassphraseHandler::ResetPassphrase, |
| 41 weak_ptr_factory_.GetWeakPtr())); |
| 42 } |
| 43 |
| 44 void ManagedUserPassphraseHandler::GetLocalizedValues( |
| 45 base::DictionaryValue* localized_strings) { |
| 46 DCHECK(localized_strings); |
| 47 |
| 48 static OptionsStringResource resources[] = { |
| 49 { "confirmPassphrase", IDS_CONFIRM_PASSPHRASE_LABEL }, |
| 50 { "enterPassphrase", IDS_ENTER_PASSPHRASE_LABEL }, |
| 51 { "savePassphrase", IDS_SAVE_PASSPHRASE_BUTTON }, |
| 52 { "setPassphraseInstructions", IDS_SET_PASSPHRASE_INSTRUCTIONS }, |
| 53 { "passphraseMismatch", IDS_PASSPHRASE_MISMATCH }, |
| 54 }; |
| 55 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 56 |
| 57 RegisterTitle(localized_strings, |
| 58 "setPassphraseTitle", |
| 59 IDS_SET_PASSPHRASE_TITLE); |
| 60 } |
| 61 |
| 62 void ManagedUserPassphraseHandler::IsPassphraseSet( |
| 63 const base::ListValue* args) { |
| 64 // Get the name of the callback function. |
| 65 std::string callback_function_name; |
| 66 args->GetString(0, &callback_function_name); |
| 67 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 68 base::FundamentalValue is_passphrase_set(!pref_service->GetString( |
| 69 prefs::kManagedModeLocalPassphrase).empty()); |
| 70 web_ui()->CallJavascriptFunction(callback_function_name, |
| 71 is_passphrase_set); |
| 72 } |
| 73 |
| 74 void ManagedUserPassphraseHandler::ResetPassphrase( |
| 75 const base::ListValue* args) { |
| 76 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 77 pref_service->SetString(prefs::kManagedModeLocalPassphrase, ""); |
| 78 } |
| 79 |
| 80 void ManagedUserPassphraseHandler::SetLocalPassphrase( |
| 81 const base::ListValue* args) { |
| 82 // Only change the passphrase if the custodian is authenticated. |
| 83 Profile* profile = Profile::FromWebUI(web_ui()); |
| 84 ManagedUserService* managed_user_service = |
| 85 ManagedUserServiceFactory::GetForProfile(profile); |
| 86 if (!managed_user_service->IsElevated()) |
| 87 return; |
| 88 |
| 89 std::string passphrase; |
| 90 args->GetString(0, &passphrase); |
| 91 ManagedUserPassphrase passphrase_key_generator((std::string())); |
| 92 std::string encoded_passphrase_hash; |
| 93 passphrase_key_generator.GenerateHashFromPassphrase(passphrase, |
| 94 &encoded_passphrase_hash); |
| 95 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 96 pref_service->SetString(prefs::kManagedModeLocalPassphrase, |
| 97 encoded_passphrase_hash); |
| 98 pref_service->SetString(prefs::kManagedModeLocalSalt, |
| 99 passphrase_key_generator.GetSalt()); |
| 100 } |
| 101 |
| 102 } // namespace options |
OLD | NEW |