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

Side by Side Diff: chrome/browser/ui/webui/managed_user_passphrase_dialog_webui.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/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() {}
Bernhard Bauer 2013/01/07 14:20:22 Moar newlines plz :)
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)));
Bernhard Bauer 2013/01/07 14:20:22 base::Unretained makes me queasy. How do you know
43 }
44
45 void ManagedUserPassphraseDialogMessageHandler::CheckPassphrase(
46 const base::ListValue* args) {
47 const base::Value* passphrase_arg;
Bernhard Bauer 2013/01/07 14:20:22 Can you initialize this to null?
48 args->Get(0, &passphrase_arg);
49 std::string passphrase;
50 passphrase_arg->GetAsString(&passphrase);
51 std::string stored_passphrase_hash, encoded_passphrase_hash;
52 ManagedUserPassphrase::GenerateHashFromPassphrase(passphrase,
53 &encoded_passphrase_hash);
54 const PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
55 const PrefService::Preference* pref =
56 pref_service->FindPreference(prefs::kManagedModeLocalPassphrase);
57 if (!pref) {
58 NOTREACHED();
Bernhard Bauer 2013/01/07 14:20:22 DCHECK(pref);
59 }
60 if (!pref->GetValue()->GetAsString(&stored_passphrase_hash)) {
Bernhard Bauer 2013/01/07 14:20:22 bool success = ...; DCHECK(success);
61 NOTREACHED();
62 }
63 if (stored_passphrase_hash == encoded_passphrase_hash) {
64 web_ui()->CallJavascriptFunction("passphraseCorrect");
65 } else {
66 web_ui()->CallJavascriptFunction("passphraseIncorrect");
67 }
68 }
69
70 const int kDialogWidth = 400;
71 const int kDialogHeight = 310;
72
73 } // namespace
74
75 void ManagedUserPassphraseDialogWebUI::CreateManagedUserPassphraseDialog(
Bernhard Bauer 2013/01/07 14:20:22 I think you could get rid of the static factory me
76 content::WebContents* web_contents,
77 const base::Callback<void(void)>& callback) {
78 // this is deleted automatically when the user closes the dialog
Bernhard Bauer 2013/01/07 14:20:22 Capitalize please (also below).
79 new ManagedUserPassphraseDialogWebUI(web_contents, callback);
80 }
81
82 ui::ModalType ManagedUserPassphraseDialogWebUI::GetDialogModalType() const {
83 return ui::MODAL_TYPE_WINDOW;
84 }
85
86 string16 ManagedUserPassphraseDialogWebUI::GetDialogTitle() const {
87 return string16();
88 }
89
90 GURL ManagedUserPassphraseDialogWebUI::GetDialogContentURL() const {
91 return GURL(chrome::kChromeUIManagedUserPassphrasePageURL);
92 }
93
94 // this function is called by the constrained window delegate
95 void ManagedUserPassphraseDialogWebUI::GetWebUIMessageHandlers(
96 std::vector<content::WebUIMessageHandler*>* handlers) const {
97 DCHECK(handlers);
98 // the constrained window delegate takes care of registering the handler
99 // the handler is also deleted automatically
100 handlers->push_back(new ManagedUserPassphraseDialogMessageHandler());
101 }
102
103 void ManagedUserPassphraseDialogWebUI::GetDialogSize(gfx::Size* size) const {
104 size->SetSize(kDialogWidth, kDialogHeight);
105 }
106
107 std::string ManagedUserPassphraseDialogWebUI::GetDialogArgs() const {
108 return std::string();
109 }
110
111 void ManagedUserPassphraseDialogWebUI::OnDialogClosed(
112 const std::string& json_retval) {
113 if (closing_) {
Bernhard Bauer 2013/01/07 14:20:22 Single-line statements don't need braces. An empt
114 return;
115 }
116 closing_ = true;
117 if (!json_retval.empty()) {
118 callback_.Run();
Bernhard Bauer 2013/01/07 14:20:22 Hm, never running the callback when the user cance
119 }
120 }
121
122 void ManagedUserPassphraseDialogWebUI::OnCloseContents(
123 content::WebContents* source, bool* out_close_dialog) {}
124
125 bool ManagedUserPassphraseDialogWebUI::ShouldShowDialogTitle() const {
126 return false;
127 }
128
129 ManagedUserPassphraseDialogWebUI::ManagedUserPassphraseDialogWebUI(
130 content::WebContents* web_contents,
131 const base::Callback<void(void)>& callback) {
132 closing_ = false;
Bernhard Bauer 2013/01/07 14:20:22 You can initialize members directly.
133 callback_ = callback;
134 Profile* profile =
135 Profile::FromBrowserContext(web_contents->GetBrowserContext());
136 CreateDataSource(profile);
137 CreateConstrainedWebDialog(profile, this, NULL, web_contents);
138 }
139
140 ManagedUserPassphraseDialogWebUI::~ManagedUserPassphraseDialogWebUI() {}
141
142 void ManagedUserPassphraseDialogWebUI::CreateDataSource(Profile* profile) {
143 ChromeWebUIDataSource* data_source =
144 new ChromeWebUIDataSource(chrome::kChromeUIManagedUserPassphrasePageHost);
145 data_source->set_default_resource(IDR_MANAGED_USER_PASSPHRASE_DIALOG_HTML);
146 data_source->add_resource_path("managed_user_passphrase_dialog.js",
147 IDR_MANAGED_USER_PASSPHRASE_DIALOG_JS);
148 data_source->add_resource_path("managed_user_passphrase_dialog.css",
149 IDR_MANAGED_USER_PASSPHRASE_DIALOG_CSS);
150 data_source->add_resource_path("chrome_kid.png",
151 IDR_MANAGED_USER_PASSPHRASE_DIALOG_IMG);
152 data_source->AddLocalizedString("familyControlPassphrasePage",
153 IDS_PASSPHRASE_TITLE);
154 data_source->AddLocalizedString("forgot_passphrase", IDS_FORGOT_PASSPHRASE);
155 data_source->AddLocalizedString("unlock_passphrase_button",
156 IDS_UNLOCK_PASSPHRASE_BUTTON);
157 data_source->AddLocalizedString("passphrase_instruction",
158 IDS_PASSPHRASE_INSTRUCTION);
159 data_source->AddLocalizedString("incorrect_passphrase_warning",
160 IDS_INCORRECT_PASSPHRASE_WARNING);
161 data_source->AddLocalizedString("cancel_passphrase_button", IDS_CANCEL);
162 data_source->set_json_path("strings.js");
163 data_source->set_use_json_js_format_v2();
164 ChromeURLDataManager::AddDataSource(profile, data_source);
165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698