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", | |
James Hawkins
2013/02/11 18:04:19
nit: Start of parameter rows must align on the sam
Adrian Kuegel
2013/02/11 18:34:46
Done.
| |
34 base::Bind(&ManagedUserPassphraseHandler::SetLocalPassphrase, | |
35 weak_ptr_factory_.GetWeakPtr())); | |
36 } | |
37 | |
38 void ManagedUserPassphraseHandler::GetLocalizedValues( | |
39 base::DictionaryValue* localized_strings) { | |
40 DCHECK(localized_strings); | |
41 | |
42 static OptionsStringResource resources[] = { | |
43 { "confirmPassphrase", IDS_CONFIRM_PASSPHRASE_LABEL }, | |
44 { "enterPassphrase", IDS_ENTER_PASSPHRASE_LABEL }, | |
45 { "savePassphrase", IDS_SAVE_PASSPHRASE_BUTTON }, | |
46 { "setPassphraseInstructions", IDS_SET_PASSPHRASE_INSTRUCTIONS }, | |
47 { "passphraseMismatch", IDS_PASSPHRASE_MISMATCH }, | |
48 }; | |
49 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
50 | |
51 RegisterTitle(localized_strings, | |
52 "setPassphraseTitle", | |
53 IDS_SET_PASSPHRASE_TITLE); | |
54 } | |
55 | |
56 void ManagedUserPassphraseHandler::SetLocalPassphrase( | |
57 const base::ListValue* args) { | |
58 std::string passphrase; | |
59 args->GetString(0, &passphrase); | |
60 ManagedUserPassphrase passphrase_key_generator((std::string())); | |
61 std::string encoded_passphrase_hash; | |
62 bool success = passphrase_key_generator.GenerateHashFromPassphrase( | |
63 passphrase, | |
64 &encoded_passphrase_hash); | |
65 if (success) { | |
66 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
67 pref_service->SetString(prefs::kManagedModeLocalPassphrase, | |
68 encoded_passphrase_hash); | |
69 pref_service->SetString(prefs::kManagedModeLocalSalt, | |
70 passphrase_key_generator.GetSalt()); | |
71 } | |
72 // TODO(akuegel): Give failure back to the UI. | |
73 } | |
74 | |
75 } // namespace options | |
OLD | NEW |