Index: chrome/browser/ui/webui/options/managed_user_passphrase_handler.cc |
diff --git a/chrome/browser/ui/webui/options/managed_user_passphrase_handler.cc b/chrome/browser/ui/webui/options/managed_user_passphrase_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..50f2d2c8c8e3dc874344f46f3acd8257cb7834a5 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/options/managed_user_passphrase_handler.cc |
@@ -0,0 +1,102 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/options/managed_user_passphrase_handler.h" |
+ |
+#include "base/bind.h" |
+#include "base/logging.h" |
+#include "base/values.h" |
+#include "chrome/browser/managed_mode/managed_user_passphrase.h" |
+#include "chrome/browser/prefs/pref_service.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/webui/managed_user_passphrase_dialog_webui.h" |
+#include "chrome/common/pref_names.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/browser/web_ui.h" |
+#include "grit/generated_resources.h" |
+ |
+namespace options { |
+ |
+ManagedUserPassphraseHandler::ManagedUserPassphraseHandler() { |
+} |
+ |
+ManagedUserPassphraseHandler::~ManagedUserPassphraseHandler() { |
+} |
+ |
+void ManagedUserPassphraseHandler::InitializeHandler() { |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
+ PrefService* prefs = profile->GetPrefs(); |
+ |
+ base::Closure callback = base::Bind( |
+ &ManagedUserPassphraseHandler::OnPreferenceChanged, |
+ base::Unretained(this)); |
+ |
+ registrar_.Init(prefs); |
+ registrar_.Add(prefs::kChildLockDisabled, callback); |
+} |
+ |
+void ManagedUserPassphraseHandler::RegisterMessages() { |
+ web_ui()->RegisterMessageCallback("setPassphrase", |
+ base::Bind(&ManagedUserPassphraseHandler::SetLocalPassphrase, |
+ base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback("displayPassphraseDialog", |
+ base::Bind(&ManagedUserPassphraseHandler::DisplayPassphraseDialog, |
+ base::Unretained(this))); |
+} |
+ |
+void ManagedUserPassphraseHandler::GetLocalizedValues( |
+ base::DictionaryValue* localized_strings) { |
+ DCHECK(localized_strings); |
+ |
+ static OptionsStringResource resources[] = { |
+ { "confirmPassphrase", IDS_CONFIRM_PASSPHRASE_LABEL }, |
+ { "enterPassphrase", IDS_ENTER_PASSPHRASE_LABEL }, |
+ { "savePassphrase", IDS_SAVE_PASSPHRASE_BUTTON }, |
+ { "setPassphraseInstructions", IDS_SET_PASSPHRASE_INSTRUCTIONS }, |
+ }; |
+ |
+ RegisterStrings(localized_strings, resources, arraysize(resources)); |
Bernhard Bauer
2013/01/07 14:20:22
Could you switch this line with the empty one abov
|
+ RegisterTitle(localized_strings, "setPassphraseTitle", |
+ IDS_SET_PASSPHRASE_TITLE); |
+} |
+ |
+void ManagedUserPassphraseHandler::CorrectPassphraseEntered() { |
+ web_ui()->CallJavascriptFunction(callback_function_name_); |
+} |
+ |
+void ManagedUserPassphraseHandler::DisplayPassphraseDialog( |
+ const base::ListValue* args) { |
+ // 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).
|
+ const base::Value* callbackArg; |
+ args->Get(0, &callbackArg); |
+ callbackArg->GetAsString(&callback_function_name_); |
+ 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
|
+ content::WebContents *web_contents = web_ui()->GetWebContents(); |
+ ManagedUserPassphraseDialogWebUI::CreateManagedUserPassphraseDialog( |
+ web_contents, |
+ base::Bind(&ManagedUserPassphraseHandler::CorrectPassphraseEntered, |
+ base::Unretained(this))); |
+} |
+ |
+void ManagedUserPassphraseHandler::SetLocalPassphrase( |
+ const base::ListValue* args) { |
+ const base::Value *passphraseArg; |
+ args->Get(0, &passphraseArg); |
+ std::string passphrase; |
+ passphraseArg->GetAsString(&passphrase); |
+ PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
+ // store a passphrase hash which is derived from the real passphrase |
+ std::string encoded_passphrase_hash; |
+ ManagedUserPassphrase::GenerateHashFromPassphrase(passphrase, |
+ &encoded_passphrase_hash); |
+ pref_service->SetString(prefs::kManagedModeLocalPassphrase, |
+ encoded_passphrase_hash); |
+} |
+ |
+// was used for testing |
Bernhard Bauer
2013/01/07 14:20:22
Then remove please :)
|
+void ManagedUserPassphraseHandler::OnPreferenceChanged() { |
+ LOG(INFO) << "Child passphrase pref changed"; |
+} |
+ |
+} // namespace options |