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

Side by Side Diff: chrome/browser/ui/webui/managed_user_passphrase_dialog.cc

Issue 12218118: Add a passphrase dialog for managed user accounts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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) 2013 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.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/bind.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/prefs/pref_service.h"
13 #include "base/values.h"
James Hawkins 2013/02/12 18:57:16 Where is this used?
Adrian Kuegel 2013/02/13 10:53:36 For the CheckPassphrase method, which is called fr
14 #include "chrome/browser/managed_mode/managed_user_passphrase.h"
15 #include "chrome/browser/managed_mode/managed_user_service.h"
16 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
19 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h"
21 #include "content/public/browser/web_contents.h"
22 #include "content/public/browser/web_ui_data_source.h"
23 #include "content/public/browser/web_ui_message_handler.h"
24 #include "grit/browser_resources.h"
25 #include "grit/generated_resources.h"
26 #include "ui/gfx/size.h"
27
28 namespace {
29
30 class ManagedUserPassphraseDialogMessageHandler
James Hawkins 2013/02/12 18:57:16 nit: Document class.
Adrian Kuegel 2013/02/13 10:53:36 Done.
31 : public content::WebUIMessageHandler {
32
33 public:
34 ManagedUserPassphraseDialogMessageHandler();
35 virtual ~ManagedUserPassphraseDialogMessageHandler() {}
36 virtual void RegisterMessages() OVERRIDE;
James Hawkins 2013/02/12 18:57:16 // content::WebUIMessageHandler implementation.
Adrian Kuegel 2013/02/13 10:53:36 Done.
37
38 private:
39 void CheckPassphrase(const base::ListValue* args) const;
James Hawkins 2013/02/12 18:57:16 nit: Document method.
Adrian Kuegel 2013/02/13 10:53:36 Done.
40
41 base::WeakPtrFactory<ManagedUserPassphraseDialogMessageHandler> weak_factory_;
42
43 DISALLOW_COPY_AND_ASSIGN(ManagedUserPassphraseDialogMessageHandler);
44 };
45
46 ManagedUserPassphraseDialogMessageHandler
47 ::ManagedUserPassphraseDialogMessageHandler() : weak_factory_(this) {
48 }
49
50 void ManagedUserPassphraseDialogMessageHandler::RegisterMessages() {
51 web_ui()->RegisterMessageCallback("checkPassphrase",
James Hawkins 2013/02/12 18:57:16 nit: The start of parameter rows must align on the
Adrian Kuegel 2013/02/13 10:53:36 Done.
52 base::Bind(&ManagedUserPassphraseDialogMessageHandler::CheckPassphrase,
53 weak_factory_.GetWeakPtr()));
54 }
55
56 void ManagedUserPassphraseDialogMessageHandler::CheckPassphrase(
57 const base::ListValue* args) const {
58 const base::Value* passphrase_arg = NULL;
James Hawkins 2013/02/12 18:57:16 This method could use some whitespace love and som
Adrian Kuegel 2013/02/13 10:53:36 Done.
59 args->Get(0, &passphrase_arg);
60 std::string passphrase;
61 passphrase_arg->GetAsString(&passphrase);
62 Profile* profile = Profile::FromWebUI(web_ui());
63 PrefService* pref_service = profile->GetPrefs();
64 std::string stored_passphrase_hash =
65 pref_service->GetString(prefs::kManagedModeLocalPassphrase);
66 std::string salt = pref_service->GetString(prefs::kManagedModeLocalSalt);
67 ManagedUserPassphrase passphrase_key_generator(salt);
68 std::string encoded_passphrase_hash;
69 passphrase_key_generator.GenerateHashFromPassphrase(passphrase,
70 &encoded_passphrase_hash);
71 ManagedUserService* managed_user_service =
72 ManagedUserServiceFactory::GetForProfile(profile);
73 if (stored_passphrase_hash == encoded_passphrase_hash) {
74 managed_user_service->SetElevated(true);
75 web_ui()->CallJavascriptFunction("passphraseCorrect");
76 } else {
77 managed_user_service->SetElevated(false);
78 web_ui()->CallJavascriptFunction("passphraseIncorrect");
79 }
80 }
81
82 } // namespace
83
84 const int kDialogWidth = 400;
James Hawkins 2013/02/12 18:57:16 These are in the global namespace, which is no bue
Adrian Kuegel 2013/02/13 10:53:36 Done.
85 const int kDialogHeight = 310;
86
87 ManagedUserPassphraseDialog::ManagedUserPassphraseDialog(
88 content::WebContents* web_contents,
89 const base::Callback<void(bool)>& callback) : callback_(callback),
90 closing_(false) {
91 Profile* profile =
92 Profile::FromBrowserContext(web_contents->GetBrowserContext());
93 CreateDataSource(profile);
94 CreateConstrainedWebDialog(profile, this, NULL, web_contents);
95 }
96
97
98 ui::ModalType ManagedUserPassphraseDialog::GetDialogModalType() const {
99 return ui::MODAL_TYPE_WINDOW;
100 }
101
102 string16 ManagedUserPassphraseDialog::GetDialogTitle() const {
103 return string16();
104 }
105
106 GURL ManagedUserPassphraseDialog::GetDialogContentURL() const {
107 return GURL(chrome::kChromeUIManagedUserPassphrasePageURL);
108 }
109
110 // This function is called by the constrained window delegate.
James Hawkins 2013/02/12 18:57:16 This comment is superfluous.
Adrian Kuegel 2013/02/13 10:53:36 Done.
111 void ManagedUserPassphraseDialog::GetWebUIMessageHandlers(
112 std::vector<content::WebUIMessageHandler*>* handlers) const {
113 DCHECK(handlers);
114 // The constrained window delegate takes care of registering the handler.
115 // The handler is also deleted automatically.
116 handlers->push_back(new ManagedUserPassphraseDialogMessageHandler());
117 }
118
119 void ManagedUserPassphraseDialog::GetDialogSize(gfx::Size* size) const {
120 size->SetSize(kDialogWidth, kDialogHeight);
121 }
122
123 std::string ManagedUserPassphraseDialog::GetDialogArgs() const {
124 return std::string();
125 }
126
127 void ManagedUserPassphraseDialog::OnDialogClosed(
128 const std::string& json_retval) {
129 if (closing_)
James Hawkins 2013/02/12 18:57:16 Why do you need |closing_|? Can't you reset the c
Adrian Kuegel 2013/02/13 10:53:36 True, I don't need |closing_|. I changed it like y
130 return;
131
132 closing_ = true;
133 callback_.Run(!json_retval.empty());
134 }
135
136 void ManagedUserPassphraseDialog::OnCloseContents(
137 content::WebContents* source, bool* out_close_dialog) {
138 }
139
140 bool ManagedUserPassphraseDialog::ShouldShowDialogTitle() const {
141 return false;
142 }
143
144 ManagedUserPassphraseDialog::~ManagedUserPassphraseDialog() {
145 }
146
147 void ManagedUserPassphraseDialog::CreateDataSource(Profile* profile) const {
148 content::WebUIDataSource* data_source = content::WebUIDataSource::Create(
149 chrome::kChromeUIManagedUserPassphrasePageHost);
150 data_source->SetDefaultResource(IDR_MANAGED_USER_PASSPHRASE_DIALOG_HTML);
151 data_source->AddResourcePath("managed_user_passphrase_dialog.js",
152 IDR_MANAGED_USER_PASSPHRASE_DIALOG_JS);
153 data_source->AddResourcePath("managed_user_passphrase_dialog.css",
154 IDR_MANAGED_USER_PASSPHRASE_DIALOG_CSS);
155 data_source->AddResourcePath("managed_user.png",
156 IDR_MANAGED_USER_PASSPHRASE_DIALOG_IMG);
157 data_source->AddLocalizedString("managedModePassphrasePage",
158 IDS_PASSPHRASE_TITLE);
159 data_source->AddLocalizedString("forgot_passphrase", IDS_FORGOT_PASSPHRASE);
160 data_source->AddLocalizedString("unlock_passphrase_button",
161 IDS_UNLOCK_PASSPHRASE_BUTTON);
162 data_source->AddLocalizedString("passphrase_instruction",
163 IDS_PASSPHRASE_INSTRUCTION);
164 data_source->AddLocalizedString("incorrect_passphrase_warning",
165 IDS_INCORRECT_PASSPHRASE_WARNING);
166 data_source->AddLocalizedString("cancel_passphrase_button", IDS_CANCEL);
167 data_source->SetJsonPath("strings.js");
168 data_source->SetUseJsonJSFormatV2();
169 content::WebUIDataSource::Add(profile, data_source);
170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698