| Index: chrome/browser/ui/webui/managed_user_passphrase_dialog_webui.cc
|
| diff --git a/chrome/browser/ui/webui/managed_user_passphrase_dialog_webui.cc b/chrome/browser/ui/webui/managed_user_passphrase_dialog_webui.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4890a05293e22f29c90e4e6bf16683ece3d8e02d
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/webui/managed_user_passphrase_dialog_webui.cc
|
| @@ -0,0 +1,173 @@
|
| +// 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/managed_user_passphrase_dialog_webui.h"
|
| +
|
| +#include <string>
|
| +#include <vector>
|
| +
|
| +#include "base/bind.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/chrome_url_data_manager.h"
|
| +#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
|
| +#include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
|
| +#include "chrome/common/pref_names.h"
|
| +#include "chrome/common/url_constants.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "content/public/browser/web_ui_message_handler.h"
|
| +#include "grit/browser_resources.h"
|
| +#include "grit/generated_resources.h"
|
| +#include "ui/gfx/size.h"
|
| +
|
| +namespace {
|
| +
|
| +class ManagedUserPassphraseDialogMessageHandler
|
| + : public content::WebUIMessageHandler {
|
| + public:
|
| + ManagedUserPassphraseDialogMessageHandler() {}
|
| + virtual ~ManagedUserPassphraseDialogMessageHandler() {}
|
| + virtual void RegisterMessages() OVERRIDE;
|
| + private:
|
| + void CheckPassphrase(const base::ListValue* args);
|
| + DISALLOW_COPY_AND_ASSIGN(ManagedUserPassphraseDialogMessageHandler);
|
| +};
|
| +
|
| +void ManagedUserPassphraseDialogMessageHandler::RegisterMessages() {
|
| + web_ui()->RegisterMessageCallback("checkPassphrase",
|
| + base::Bind(&ManagedUserPassphraseDialogMessageHandler::CheckPassphrase,
|
| + base::Unretained(this)));
|
| +}
|
| +
|
| +void ManagedUserPassphraseDialogMessageHandler::CheckPassphrase(
|
| + const base::ListValue* args) {
|
| + const base::Value* passphrase_arg;
|
| + args->Get(0, &passphrase_arg);
|
| + std::string passphrase;
|
| + passphrase_arg->GetAsString(&passphrase);
|
| + std::string salt, stored_passphrase_hash, encoded_passphrase_hash;
|
| + const PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
|
| + const PrefService::Preference* pref =
|
| + pref_service->FindPreference(prefs::kManagedModeLocalPassphrase);
|
| + if (!pref) {
|
| + NOTREACHED();
|
| + }
|
| + if (!pref->GetValue()->GetAsString(&stored_passphrase_hash)) {
|
| + NOTREACHED();
|
| + }
|
| + pref = pref_service->FindPreference(prefs::kManagedModeLocalSalt);
|
| + if (!pref) {
|
| + NOTREACHED();
|
| + }
|
| + if (!pref->GetValue()->GetAsString(&salt)) {
|
| + NOTREACHED();
|
| + }
|
| + ManagedUserPassphrase passphrase_key_generator(salt);
|
| + passphrase_key_generator.GenerateHashFromPassphrase(passphrase,
|
| + &encoded_passphrase_hash);
|
| + if (stored_passphrase_hash == encoded_passphrase_hash) {
|
| + web_ui()->CallJavascriptFunction("passphraseCorrect");
|
| + } else {
|
| + web_ui()->CallJavascriptFunction("passphraseIncorrect");
|
| + }
|
| +}
|
| +
|
| +const int kDialogWidth = 400;
|
| +const int kDialogHeight = 310;
|
| +
|
| +} // namespace
|
| +
|
| +void ManagedUserPassphraseDialogWebUI::CreateManagedUserPassphraseDialog(
|
| + content::WebContents* web_contents,
|
| + const base::Callback<void(void)>& callback) {
|
| + // this is deleted automatically when the user closes the dialog
|
| + new ManagedUserPassphraseDialogWebUI(web_contents, callback);
|
| +}
|
| +
|
| +ui::ModalType ManagedUserPassphraseDialogWebUI::GetDialogModalType() const {
|
| + return ui::MODAL_TYPE_WINDOW;
|
| +}
|
| +
|
| +string16 ManagedUserPassphraseDialogWebUI::GetDialogTitle() const {
|
| + return string16();
|
| +}
|
| +
|
| +GURL ManagedUserPassphraseDialogWebUI::GetDialogContentURL() const {
|
| + return GURL(chrome::kChromeUIManagedUserPassphrasePageURL);
|
| +}
|
| +
|
| +// this function is called by the constrained window delegate
|
| +void ManagedUserPassphraseDialogWebUI::GetWebUIMessageHandlers(
|
| + std::vector<content::WebUIMessageHandler*>* handlers) const {
|
| + DCHECK(handlers);
|
| + // the constrained window delegate takes care of registering the handler
|
| + // the handler is also deleted automatically
|
| + handlers->push_back(new ManagedUserPassphraseDialogMessageHandler());
|
| +}
|
| +
|
| +void ManagedUserPassphraseDialogWebUI::GetDialogSize(gfx::Size* size) const {
|
| + size->SetSize(kDialogWidth, kDialogHeight);
|
| +}
|
| +
|
| +std::string ManagedUserPassphraseDialogWebUI::GetDialogArgs() const {
|
| + return std::string();
|
| +}
|
| +
|
| +void ManagedUserPassphraseDialogWebUI::OnDialogClosed(
|
| + const std::string& json_retval) {
|
| + if (closing_) {
|
| + return;
|
| + }
|
| + closing_ = true;
|
| + if (!json_retval.empty()) {
|
| + callback_.Run();
|
| + }
|
| +}
|
| +
|
| +void ManagedUserPassphraseDialogWebUI::OnCloseContents(
|
| + content::WebContents* source, bool* out_close_dialog) {}
|
| +
|
| +bool ManagedUserPassphraseDialogWebUI::ShouldShowDialogTitle() const {
|
| + return false;
|
| +}
|
| +
|
| +ManagedUserPassphraseDialogWebUI::ManagedUserPassphraseDialogWebUI(
|
| + content::WebContents* web_contents,
|
| + const base::Callback<void(void)>& callback) {
|
| + closing_ = false;
|
| + callback_ = callback;
|
| + Profile* profile =
|
| + Profile::FromBrowserContext(web_contents->GetBrowserContext());
|
| + CreateDataSource(profile);
|
| + CreateConstrainedWebDialog(profile, this, NULL, web_contents);
|
| +}
|
| +
|
| +ManagedUserPassphraseDialogWebUI::~ManagedUserPassphraseDialogWebUI() {}
|
| +
|
| +void ManagedUserPassphraseDialogWebUI::CreateDataSource(Profile* profile) {
|
| + ChromeWebUIDataSource* data_source =
|
| + new ChromeWebUIDataSource(chrome::kChromeUIManagedUserPassphrasePageHost);
|
| + data_source->set_default_resource(IDR_MANAGED_USER_PASSPHRASE_DIALOG_HTML);
|
| + data_source->add_resource_path("managed_user_passphrase_dialog.js",
|
| + IDR_MANAGED_USER_PASSPHRASE_DIALOG_JS);
|
| + data_source->add_resource_path("managed_user_passphrase_dialog.css",
|
| + IDR_MANAGED_USER_PASSPHRASE_DIALOG_CSS);
|
| + data_source->add_resource_path("chrome_kid.png",
|
| + IDR_MANAGED_USER_PASSPHRASE_DIALOG_IMG);
|
| + data_source->AddLocalizedString("familyControlPassphrasePage",
|
| + IDS_PASSPHRASE_TITLE);
|
| + data_source->AddLocalizedString("forgot_passphrase", IDS_FORGOT_PASSPHRASE);
|
| + data_source->AddLocalizedString("unlock_passphrase_button",
|
| + IDS_UNLOCK_PASSPHRASE_BUTTON);
|
| + data_source->AddLocalizedString("passphrase_instruction",
|
| + IDS_PASSPHRASE_INSTRUCTION);
|
| + data_source->AddLocalizedString("incorrect_passphrase_warning",
|
| + IDS_INCORRECT_PASSPHRASE_WARNING);
|
| + data_source->AddLocalizedString("cancel_passphrase_button", IDS_CANCEL);
|
| + data_source->set_json_path("strings.js");
|
| + data_source->set_use_json_js_format_v2();
|
| + ChromeURLDataManager::AddDataSource(profile, data_source);
|
| +}
|
|
|