Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: chrome/browser/ui/webui/options/managed_user_passphrase_handler.cc

Issue 11783008: Add a lock to the managed user settings page and require authentication for unlocking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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));
Bernhard Bauer 2013/01/07 14:20:22 Could you switch this line with the empty one abov
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
Pam (message me for reviews) 2013/01/07 14:51:49 Capital letter and period please (also below).
71 const base::Value* callbackArg;
72 args->Get(0, &callbackArg);
73 callbackArg->GetAsString(&callback_function_name_);
74 LOG(INFO) << callback_function_name_;
Pam (message me for reviews) 2013/01/07 14:51:49 Please remove this, or change it to DLOG, or even
75 content::WebContents *web_contents = web_ui()->GetWebContents();
76 ManagedUserPassphraseDialogWebUI::CreateManagedUserPassphraseDialog(
77 web_contents,
78 base::Bind(&ManagedUserPassphraseHandler::CorrectPassphraseEntered,
79 base::Unretained(this)));
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 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
89 // store a passphrase hash which is derived from the real passphrase
90 std::string encoded_passphrase_hash;
91 ManagedUserPassphrase::GenerateHashFromPassphrase(passphrase,
92 &encoded_passphrase_hash);
93 pref_service->SetString(prefs::kManagedModeLocalPassphrase,
94 encoded_passphrase_hash);
95 }
96
97 // was used for testing
Bernhard Bauer 2013/01/07 14:20:22 Then remove please :)
98 void ManagedUserPassphraseHandler::OnPreferenceChanged() {
99 LOG(INFO) << "Child passphrase pref changed";
100 }
101
102 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698