Chromium Code Reviews| 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/managed_user_passphrase_dialog_webui.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/bind.h" | |
| 11 #include "base/values.h" | |
| 12 #include "chrome/browser/managed_mode/managed_user_passphrase.h" | |
| 13 #include "chrome/browser/prefs/pref_service.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
| 16 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | |
| 17 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | |
| 18 #include "chrome/common/pref_names.h" | |
| 19 #include "chrome/common/url_constants.h" | |
| 20 #include "content/public/browser/web_contents.h" | |
| 21 #include "content/public/browser/web_ui_message_handler.h" | |
| 22 #include "grit/browser_resources.h" | |
| 23 #include "grit/generated_resources.h" | |
| 24 #include "ui/gfx/size.h" | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 class ManagedUserPassphraseDialogMessageHandler | |
| 29 : public content::WebUIMessageHandler { | |
| 30 public: | |
| 31 ManagedUserPassphraseDialogMessageHandler() {} | |
| 32 virtual ~ManagedUserPassphraseDialogMessageHandler() {} | |
| 33 virtual void RegisterMessages() OVERRIDE; | |
| 34 private: | |
| 35 void CheckPassphrase(const base::ListValue* args); | |
| 36 DISALLOW_COPY_AND_ASSIGN(ManagedUserPassphraseDialogMessageHandler); | |
| 37 }; | |
| 38 | |
| 39 void ManagedUserPassphraseDialogMessageHandler::RegisterMessages() { | |
| 40 web_ui()->RegisterMessageCallback("checkPassphrase", | |
| 41 base::Bind(&ManagedUserPassphraseDialogMessageHandler::CheckPassphrase, | |
| 42 base::Unretained(this))); | |
| 43 } | |
| 44 | |
| 45 void ManagedUserPassphraseDialogMessageHandler::CheckPassphrase( | |
| 46 const base::ListValue* args) { | |
| 47 const base::Value* passphrase_arg; | |
| 48 args->Get(0, &passphrase_arg); | |
| 49 std::string passphrase; | |
| 50 passphrase_arg->GetAsString(&passphrase); | |
| 51 std::string salt, stored_passphrase_hash, encoded_passphrase_hash; | |
|
Bernhard Bauer
2013/01/07 14:39:22
Please declare each variable separately.
| |
| 52 const PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | |
| 53 const PrefService::Preference* pref = | |
| 54 pref_service->FindPreference(prefs::kManagedModeLocalPassphrase); | |
| 55 if (!pref) { | |
| 56 NOTREACHED(); | |
| 57 } | |
| 58 if (!pref->GetValue()->GetAsString(&stored_passphrase_hash)) { | |
| 59 NOTREACHED(); | |
| 60 } | |
| 61 pref = pref_service->FindPreference(prefs::kManagedModeLocalSalt); | |
| 62 if (!pref) { | |
| 63 NOTREACHED(); | |
| 64 } | |
| 65 if (!pref->GetValue()->GetAsString(&salt)) { | |
| 66 NOTREACHED(); | |
| 67 } | |
| 68 ManagedUserPassphrase passphrase_key_generator(salt); | |
| 69 passphrase_key_generator.GenerateHashFromPassphrase(passphrase, | |
| 70 &encoded_passphrase_hash); | |
| 71 if (stored_passphrase_hash == encoded_passphrase_hash) { | |
| 72 web_ui()->CallJavascriptFunction("passphraseCorrect"); | |
| 73 } else { | |
| 74 web_ui()->CallJavascriptFunction("passphraseIncorrect"); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 const int kDialogWidth = 400; | |
| 79 const int kDialogHeight = 310; | |
| 80 | |
| 81 } // namespace | |
| 82 | |
| 83 void ManagedUserPassphraseDialogWebUI::CreateManagedUserPassphraseDialog( | |
| 84 content::WebContents* web_contents, | |
| 85 const base::Callback<void(void)>& callback) { | |
| 86 // this is deleted automatically when the user closes the dialog | |
| 87 new ManagedUserPassphraseDialogWebUI(web_contents, callback); | |
| 88 } | |
| 89 | |
| 90 ui::ModalType ManagedUserPassphraseDialogWebUI::GetDialogModalType() const { | |
| 91 return ui::MODAL_TYPE_WINDOW; | |
| 92 } | |
| 93 | |
| 94 string16 ManagedUserPassphraseDialogWebUI::GetDialogTitle() const { | |
| 95 return string16(); | |
| 96 } | |
| 97 | |
| 98 GURL ManagedUserPassphraseDialogWebUI::GetDialogContentURL() const { | |
| 99 return GURL(chrome::kChromeUIManagedUserPassphrasePageURL); | |
| 100 } | |
| 101 | |
| 102 // this function is called by the constrained window delegate | |
| 103 void ManagedUserPassphraseDialogWebUI::GetWebUIMessageHandlers( | |
| 104 std::vector<content::WebUIMessageHandler*>* handlers) const { | |
| 105 DCHECK(handlers); | |
| 106 // the constrained window delegate takes care of registering the handler | |
| 107 // the handler is also deleted automatically | |
| 108 handlers->push_back(new ManagedUserPassphraseDialogMessageHandler()); | |
| 109 } | |
| 110 | |
| 111 void ManagedUserPassphraseDialogWebUI::GetDialogSize(gfx::Size* size) const { | |
| 112 size->SetSize(kDialogWidth, kDialogHeight); | |
| 113 } | |
| 114 | |
| 115 std::string ManagedUserPassphraseDialogWebUI::GetDialogArgs() const { | |
| 116 return std::string(); | |
| 117 } | |
| 118 | |
| 119 void ManagedUserPassphraseDialogWebUI::OnDialogClosed( | |
| 120 const std::string& json_retval) { | |
| 121 if (closing_) { | |
| 122 return; | |
| 123 } | |
| 124 closing_ = true; | |
| 125 if (!json_retval.empty()) { | |
| 126 callback_.Run(); | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 void ManagedUserPassphraseDialogWebUI::OnCloseContents( | |
| 131 content::WebContents* source, bool* out_close_dialog) {} | |
| 132 | |
| 133 bool ManagedUserPassphraseDialogWebUI::ShouldShowDialogTitle() const { | |
| 134 return false; | |
| 135 } | |
| 136 | |
| 137 ManagedUserPassphraseDialogWebUI::ManagedUserPassphraseDialogWebUI( | |
| 138 content::WebContents* web_contents, | |
| 139 const base::Callback<void(void)>& callback) { | |
| 140 closing_ = false; | |
| 141 callback_ = callback; | |
| 142 Profile* profile = | |
| 143 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 144 CreateDataSource(profile); | |
| 145 CreateConstrainedWebDialog(profile, this, NULL, web_contents); | |
| 146 } | |
| 147 | |
| 148 ManagedUserPassphraseDialogWebUI::~ManagedUserPassphraseDialogWebUI() {} | |
| 149 | |
| 150 void ManagedUserPassphraseDialogWebUI::CreateDataSource(Profile* profile) { | |
| 151 ChromeWebUIDataSource* data_source = | |
| 152 new ChromeWebUIDataSource(chrome::kChromeUIManagedUserPassphrasePageHost); | |
| 153 data_source->set_default_resource(IDR_MANAGED_USER_PASSPHRASE_DIALOG_HTML); | |
| 154 data_source->add_resource_path("managed_user_passphrase_dialog.js", | |
| 155 IDR_MANAGED_USER_PASSPHRASE_DIALOG_JS); | |
| 156 data_source->add_resource_path("managed_user_passphrase_dialog.css", | |
| 157 IDR_MANAGED_USER_PASSPHRASE_DIALOG_CSS); | |
| 158 data_source->add_resource_path("chrome_kid.png", | |
| 159 IDR_MANAGED_USER_PASSPHRASE_DIALOG_IMG); | |
| 160 data_source->AddLocalizedString("familyControlPassphrasePage", | |
| 161 IDS_PASSPHRASE_TITLE); | |
| 162 data_source->AddLocalizedString("forgot_passphrase", IDS_FORGOT_PASSPHRASE); | |
| 163 data_source->AddLocalizedString("unlock_passphrase_button", | |
| 164 IDS_UNLOCK_PASSPHRASE_BUTTON); | |
| 165 data_source->AddLocalizedString("passphrase_instruction", | |
| 166 IDS_PASSPHRASE_INSTRUCTION); | |
| 167 data_source->AddLocalizedString("incorrect_passphrase_warning", | |
| 168 IDS_INCORRECT_PASSPHRASE_WARNING); | |
| 169 data_source->AddLocalizedString("cancel_passphrase_button", IDS_CANCEL); | |
| 170 data_source->set_json_path("strings.js"); | |
| 171 data_source->set_use_json_js_format_v2(); | |
| 172 ChromeURLDataManager::AddDataSource(profile, data_source); | |
| 173 } | |
| OLD | NEW |