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 : weak_ptr_factory_(this) { | |
23 } | |
24 | |
25 ManagedUserPassphraseHandler::~ManagedUserPassphraseHandler() { | |
26 } | |
27 | |
28 void ManagedUserPassphraseHandler::InitializeHandler() { | |
29 } | |
30 | |
31 void ManagedUserPassphraseHandler::RegisterMessages() { | |
32 web_ui()->RegisterMessageCallback("setPassphrase", | |
33 base::Bind(&ManagedUserPassphraseHandler::SetLocalPassphrase, | |
34 weak_ptr_factory_.GetWeakPtr())); | |
35 web_ui()->RegisterMessageCallback("displayPassphraseDialog", | |
36 base::Bind(&ManagedUserPassphraseHandler::DisplayPassphraseDialog, | |
37 weak_ptr_factory_.GetWeakPtr())); | |
38 } | |
39 | |
40 void ManagedUserPassphraseHandler::GetLocalizedValues( | |
41 base::DictionaryValue* localized_strings) { | |
42 DCHECK(localized_strings); | |
43 | |
44 static OptionsStringResource resources[] = { | |
45 { "confirmPassphrase", IDS_CONFIRM_PASSPHRASE_LABEL }, | |
46 { "enterPassphrase", IDS_ENTER_PASSPHRASE_LABEL }, | |
47 { "savePassphrase", IDS_SAVE_PASSPHRASE_BUTTON }, | |
48 { "setPassphraseInstructions", IDS_SET_PASSPHRASE_INSTRUCTIONS }, | |
49 { "passphraseMismatch", IDS_PASSPHRASE_MISMATCH }, | |
50 }; | |
51 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
52 | |
53 RegisterTitle(localized_strings, "setPassphraseTitle", | |
54 IDS_SET_PASSPHRASE_TITLE); | |
55 } | |
56 | |
57 void ManagedUserPassphraseHandler::PassphraseDialogCallback(bool success) { | |
58 if (success) | |
Bernhard Bauer
2013/01/08 17:43:14
I think I would actually plumb the success through
Adrian Kuegel
2013/01/09 12:10:05
Done.
| |
59 web_ui()->CallJavascriptFunction(callback_function_name_); | |
60 } | |
61 | |
62 void ManagedUserPassphraseHandler::DisplayPassphraseDialog( | |
63 const base::ListValue* args) { | |
64 // Store the name of the callback function. | |
65 const base::Value* callback_arg; | |
66 args->Get(0, &callback_arg); | |
Bernhard Bauer
2013/01/08 17:43:14
Here you can use ListValue::GetString().
Adrian Kuegel
2013/01/09 12:10:05
Done.
| |
67 callback_arg->GetAsString(&callback_function_name_); | |
68 content::WebContents* web_contents = web_ui()->GetWebContents(); | |
Bernhard Bauer
2013/01/08 17:43:14
You could probably inline this.
Adrian Kuegel
2013/01/09 12:10:05
Done.
| |
69 ManagedUserPassphraseDialogWebUI::CreateManagedUserPassphraseDialog( | |
70 web_contents, | |
71 base::Bind(&ManagedUserPassphraseHandler::PassphraseDialogCallback, | |
72 base::Unretained(this))); | |
73 } | |
74 | |
75 void ManagedUserPassphraseHandler::SetLocalPassphrase( | |
76 const base::ListValue* args) { | |
77 const base::Value *passphraseArg; | |
78 args->Get(0, &passphraseArg); | |
79 std::string passphrase; | |
80 passphraseArg->GetAsString(&passphrase); | |
81 ManagedUserPassphrase passphrase_key_generator((std::string())); | |
82 std::string encoded_passphrase_hash; | |
83 passphrase_key_generator.GenerateHashFromPassphrase(passphrase, | |
Bernhard Bauer
2013/01/08 17:43:14
Align the parameters please (here and below).
Adrian Kuegel
2013/01/09 12:10:05
Done.
| |
84 &encoded_passphrase_hash); | |
85 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
86 pref_service->SetString(prefs::kManagedModeLocalPassphrase, | |
87 encoded_passphrase_hash); | |
88 pref_service->SetString(prefs::kManagedModeLocalSalt, | |
89 passphrase_key_generator.GetSalt()); | |
90 } | |
91 | |
92 } // namespace options | |
OLD | NEW |