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_user_passphrase.h" | |
11 #include "chrome/browser/prefs/pref_service.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/browser/ui/webui/managed_user_passphrase_dialog_webui.h" | |
14 #include "chrome/common/pref_names.h" | |
15 #include "content/public/browser/web_contents.h" | |
16 #include "content/public/browser/web_ui.h" | |
17 #include "grit/generated_resources.h" | |
18 | |
19 namespace options { | |
20 | |
21 ManagedUserPassphraseHandler::ManagedUserPassphraseHandler() { | |
22 } | |
23 | |
24 ManagedUserPassphraseHandler::~ManagedUserPassphraseHandler() { | |
25 } | |
26 | |
27 void ManagedUserPassphraseHandler::InitializeHandler() { | |
28 Profile* profile = Profile::FromWebUI(web_ui()); | |
29 PrefService* prefs = profile->GetPrefs(); | |
30 | |
31 base::Closure callback = base::Bind( | |
32 &ManagedUserPassphraseHandler::OnPreferenceChanged, | |
33 base::Unretained(this)); | |
34 | |
35 registrar_.Init(prefs); | |
36 registrar_.Add(prefs::kChildLockDisabled, callback); | |
37 } | |
38 | |
39 void ManagedUserPassphraseHandler::RegisterMessages() { | |
40 web_ui()->RegisterMessageCallback("setPassphrase", | |
41 base::Bind(&ManagedUserPassphraseHandler::SetLocalPassphrase, | |
42 base::Unretained(this))); | |
43 web_ui()->RegisterMessageCallback("displayPassphraseDialog", | |
44 base::Bind(&ManagedUserPassphraseHandler::DisplayPassphraseDialog, | |
45 base::Unretained(this))); | |
46 } | |
47 | |
48 void ManagedUserPassphraseHandler::GetLocalizedValues( | |
49 base::DictionaryValue* localized_strings) { | |
50 DCHECK(localized_strings); | |
51 | |
52 static OptionsStringResource resources[] = { | |
53 { "confirmPassphrase", IDS_CONFIRM_PASSPHRASE_LABEL }, | |
54 { "enterPassphrase", IDS_ENTER_PASSPHRASE_LABEL }, | |
55 { "savePassphrase", IDS_SAVE_PASSPHRASE_BUTTON }, | |
56 { "setPassphraseInstructions", IDS_SET_PASSPHRASE_INSTRUCTIONS }, | |
57 }; | |
58 | |
59 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
60 RegisterTitle(localized_strings, "setPassphraseTitle", | |
61 IDS_SET_PASSPHRASE_TITLE); | |
62 } | |
63 | |
64 void ManagedUserPassphraseHandler::CorrectPassphraseEntered() { | |
65 web_ui()->CallJavascriptFunction(callback_function_name_); | |
66 } | |
67 | |
68 void ManagedUserPassphraseHandler::DisplayPassphraseDialog( | |
69 const base::ListValue* args) { | |
70 // store the name of the callback function | |
71 const base::Value* callbackArg; | |
Bernhard Bauer
2013/01/07 14:39:22
Style guide says hacker_style for variables.
| |
72 args->Get(0, &callbackArg); | |
73 callbackArg->GetAsString(&callback_function_name_); | |
74 LOG(INFO) << callback_function_name_; | |
Bernhard Bauer
2013/01/07 14:39:22
At least DLOG?
| |
75 content::WebContents *web_contents = web_ui()->GetWebContents(); | |
Bernhard Bauer
2013/01/07 14:39:22
Asterisk comes left.
| |
76 ManagedUserPassphraseDialogWebUI::CreateManagedUserPassphraseDialog( | |
77 web_contents, | |
78 base::Bind(&ManagedUserPassphraseHandler::CorrectPassphraseEntered, | |
79 base::Unretained(this))); | |
Bernhard Bauer
2013/01/07 14:39:22
Again, might want to use weak pointers.
| |
80 } | |
81 | |
82 void ManagedUserPassphraseHandler::SetLocalPassphrase( | |
83 const base::ListValue* args) { | |
84 const base::Value *passphraseArg; | |
85 args->Get(0, &passphraseArg); | |
86 std::string passphrase; | |
87 passphraseArg->GetAsString(&passphrase); | |
88 ManagedUserPassphrase passphrase_key_generator(""); | |
Bernhard Bauer
2013/01/07 14:39:22
Using the empty std::string() constructor instead
| |
89 std::string encoded_passphrase_hash; | |
90 passphrase_key_generator.GenerateHashFromPassphrase(passphrase, | |
91 &encoded_passphrase_hash); | |
92 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
93 pref_service->SetString(prefs::kManagedModeLocalPassphrase, | |
94 encoded_passphrase_hash); | |
95 pref_service->SetString(prefs::kManagedModeLocalSalt, | |
96 passphrase_key_generator.GetSalt()); | |
97 } | |
98 | |
99 // was used for testing | |
100 void ManagedUserPassphraseHandler::OnPreferenceChanged() { | |
101 LOG(INFO) << "Child passphrase pref changed"; | |
102 } | |
103 | |
104 } // namespace options | |
OLD | NEW |