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/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_mode.h" | |
| 11 #include "chrome/browser/managed_mode/managed_user_passphrase.h" | |
| 12 #include "chrome/browser/prefs/pref_service.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/browser/ui/webui/managed_user_passphrase_dialog.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("displayPassphraseDialog", | |
| 37 base::Bind(&ManagedUserPassphraseHandler::DisplayPassphraseDialog, | |
| 38 weak_ptr_factory_.GetWeakPtr())); | |
| 39 web_ui()->RegisterMessageCallback("endAuthentication", | |
| 40 base::Bind(&ManagedUserPassphraseHandler::EndAuthentication, | |
| 41 weak_ptr_factory_.GetWeakPtr())); | |
| 42 web_ui()->RegisterMessageCallback("isPassphraseSet", | |
| 43 base::Bind(&ManagedUserPassphraseHandler::IsPassphraseSet, | |
| 44 weak_ptr_factory_.GetWeakPtr())); | |
| 45 } | |
| 46 | |
| 47 void ManagedUserPassphraseHandler::GetLocalizedValues( | |
| 48 base::DictionaryValue* localized_strings) { | |
| 49 DCHECK(localized_strings); | |
| 50 | |
| 51 static OptionsStringResource resources[] = { | |
| 52 { "confirmPassphrase", IDS_CONFIRM_PASSPHRASE_LABEL }, | |
| 53 { "enterPassphrase", IDS_ENTER_PASSPHRASE_LABEL }, | |
| 54 { "savePassphrase", IDS_SAVE_PASSPHRASE_BUTTON }, | |
| 55 { "setPassphraseInstructions", IDS_SET_PASSPHRASE_INSTRUCTIONS }, | |
| 56 { "passphraseMismatch", IDS_PASSPHRASE_MISMATCH }, | |
| 57 }; | |
| 58 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
| 59 | |
| 60 RegisterTitle(localized_strings, | |
| 61 "setPassphraseTitle", | |
| 62 IDS_SET_PASSPHRASE_TITLE); | |
| 63 } | |
| 64 | |
| 65 void ManagedUserPassphraseHandler::PassphraseDialogCallback(bool success) { | |
| 66 base::FundamentalValue unlock_success(success); | |
| 67 web_ui()->CallJavascriptFunction(callback_function_name_, unlock_success); | |
| 68 } | |
| 69 | |
| 70 void ManagedUserPassphraseHandler::DisplayPassphraseDialog( | |
| 71 const base::ListValue* args) { | |
| 72 // Store the name of the callback function. | |
| 73 args->GetString(0, &callback_function_name_); | |
| 74 if (ManagedMode::IsCustodianAuthenticated()) { | |
| 75 // If the custodian is already authenticated, skip the passphrase dialog. | |
| 76 PassphraseDialogCallback(true); | |
| 77 return; | |
| 78 } | |
| 79 // This is deleted automatically when the dialog is closed. | |
| 80 new ManagedUserPassphraseDialog(web_ui()->GetWebContents(), | |
| 81 base::Bind(&ManagedUserPassphraseHandler::PassphraseDialogCallback, | |
| 82 weak_ptr_factory_.GetWeakPtr())); | |
| 83 } | |
| 84 | |
| 85 void ManagedUserPassphraseHandler::EndAuthentication( | |
| 86 const base::ListValue* args) { | |
| 87 ManagedMode::SetCustodianAuthenticated(false); | |
| 88 } | |
| 89 | |
| 90 void ManagedUserPassphraseHandler::IsPassphraseSet( | |
| 91 const base::ListValue* args) { | |
| 92 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
| 93 base::FundamentalValue is_passphrase_empty(!pref_service->GetString( | |
| 94 prefs::kManagedModeLocalPassphrase).empty()); | |
| 95 web_ui()->CallJavascriptFunction( | |
| 96 "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.
| |
| 97 is_passphrase_empty); | |
| 98 } | |
| 99 | |
| 100 void ManagedUserPassphraseHandler::SetLocalPassphrase( | |
| 101 const base::ListValue* args) { | |
| 102 // Only change the passphrase if the custodian is authenticated. | |
| 103 if (!ManagedMode::IsCustodianAuthenticated()) | |
| 104 return; | |
| 105 | |
| 106 std::string passphrase; | |
| 107 args->GetString(0, &passphrase); | |
| 108 ManagedUserPassphrase passphrase_key_generator((std::string())); | |
| 109 std::string encoded_passphrase_hash; | |
| 110 passphrase_key_generator.GenerateHashFromPassphrase(passphrase, | |
| 111 &encoded_passphrase_hash); | |
| 112 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
| 113 pref_service->SetString(prefs::kManagedModeLocalPassphrase, | |
| 114 encoded_passphrase_hash); | |
| 115 pref_service->SetString(prefs::kManagedModeLocalSalt, | |
| 116 passphrase_key_generator.GetSalt()); | |
| 117 } | |
| 118 | |
| 119 } // namespace options | |
| OLD | NEW |