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

Side by Side Diff: chrome/browser/ui/webui/managed_user_passphrase_dialog.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: Add a check if the passphrase is set before closing the settings. 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.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/bind.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/values.h"
13 #include "chrome/browser/managed_mode/managed_mode.h"
14 #include "chrome/browser/managed_mode/managed_user_passphrase.h"
15 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
18 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
19 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
20 #include "chrome/common/pref_names.h"
21 #include "chrome/common/url_constants.h"
22 #include "content/public/browser/web_contents.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
31 : public content::WebUIMessageHandler {
32
33 public:
34 ManagedUserPassphraseDialogMessageHandler();
35 virtual ~ManagedUserPassphraseDialogMessageHandler() {}
36 virtual void RegisterMessages() OVERRIDE;
37
38 private:
39 void CheckPassphrase(const base::ListValue* args) const;
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",
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;
59 args->Get(0, &passphrase_arg);
60 std::string passphrase;
61 passphrase_arg->GetAsString(&passphrase);
62 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
63 std::string stored_passphrase_hash =
64 pref_service->GetString(prefs::kManagedModeLocalPassphrase);
65 std::string salt = pref_service->GetString(prefs::kManagedModeLocalSalt);
66 ManagedUserPassphrase passphrase_key_generator(salt);
67 std::string encoded_passphrase_hash;
68 passphrase_key_generator.GenerateHashFromPassphrase(passphrase,
69 &encoded_passphrase_hash);
70 if (stored_passphrase_hash == encoded_passphrase_hash) {
71 ManagedMode::SetCustodianAuthenticated(true);
72 web_ui()->CallJavascriptFunction("passphraseCorrect");
73 } else {
74 ManagedMode::SetCustodianAuthenticated(false);
75 web_ui()->CallJavascriptFunction("passphraseIncorrect");
76 }
77 }
78
79 } // namespace
80
81 const int kDialogWidth = 400;
82 const int kDialogHeight = 310;
83
84 ManagedUserPassphraseDialog::ManagedUserPassphraseDialog(
85 content::WebContents* web_contents,
86 const base::Callback<void(bool)>& callback) : callback_(callback),
87 closing_(false) {
88 Profile* profile =
89 Profile::FromBrowserContext(web_contents->GetBrowserContext());
90 CreateDataSource(profile);
91 CreateConstrainedWebDialog(profile, this, NULL, web_contents);
92 }
93
94
95 ui::ModalType ManagedUserPassphraseDialog::GetDialogModalType() const {
96 return ui::MODAL_TYPE_WINDOW;
97 }
98
99 string16 ManagedUserPassphraseDialog::GetDialogTitle() const {
100 return string16();
101 }
102
103 GURL ManagedUserPassphraseDialog::GetDialogContentURL() const {
104 return GURL(chrome::kChromeUIManagedUserPassphrasePageURL);
105 }
106
107 // This function is called by the constrained window delegate.
108 void ManagedUserPassphraseDialog::GetWebUIMessageHandlers(
109 std::vector<content::WebUIMessageHandler*>* handlers) const {
110 DCHECK(handlers);
111 // The constrained window delegate takes care of registering the handler.
112 // The handler is also deleted automatically.
113 handlers->push_back(new ManagedUserPassphraseDialogMessageHandler());
114 }
115
116 void ManagedUserPassphraseDialog::GetDialogSize(gfx::Size* size) const {
117 size->SetSize(kDialogWidth, kDialogHeight);
118 }
119
120 std::string ManagedUserPassphraseDialog::GetDialogArgs() const {
121 return std::string();
122 }
123
124 void ManagedUserPassphraseDialog::OnDialogClosed(
125 const std::string& json_retval) {
126 if (closing_)
127 return;
128
129 closing_ = true;
130 callback_.Run(!json_retval.empty());
131 }
132
133 void ManagedUserPassphraseDialog::OnCloseContents(
134 content::WebContents* source, bool* out_close_dialog) {
135 }
136
137 bool ManagedUserPassphraseDialog::ShouldShowDialogTitle() const {
138 return false;
139 }
140
141 ManagedUserPassphraseDialog::~ManagedUserPassphraseDialog() {
142 }
143
144 void ManagedUserPassphraseDialog::CreateDataSource(Profile* profile) const {
145 ChromeWebUIDataSource* data_source =
146 new ChromeWebUIDataSource(chrome::kChromeUIManagedUserPassphrasePageHost);
147 data_source->set_default_resource(IDR_MANAGED_USER_PASSPHRASE_DIALOG_HTML);
148 data_source->add_resource_path("managed_user_passphrase_dialog.js",
149 IDR_MANAGED_USER_PASSPHRASE_DIALOG_JS);
150 data_source->add_resource_path("managed_user_passphrase_dialog.css",
151 IDR_MANAGED_USER_PASSPHRASE_DIALOG_CSS);
152 data_source->add_resource_path("managed_user.png",
153 IDR_MANAGED_USER_PASSPHRASE_DIALOG_IMG);
154 data_source->AddLocalizedString("managedModePassphrasePage",
155 IDS_PASSPHRASE_TITLE);
156 data_source->AddLocalizedString("forgot_passphrase", IDS_FORGOT_PASSPHRASE);
157 data_source->AddLocalizedString("unlock_passphrase_button",
158 IDS_UNLOCK_PASSPHRASE_BUTTON);
159 data_source->AddLocalizedString("passphrase_instruction",
160 IDS_PASSPHRASE_INSTRUCTION);
161 data_source->AddLocalizedString("incorrect_passphrase_warning",
162 IDS_INCORRECT_PASSPHRASE_WARNING);
163 data_source->AddLocalizedString("cancel_passphrase_button", IDS_CANCEL);
164 data_source->set_json_path("strings.js");
165 data_source->set_use_json_js_format_v2();
166 ChromeURLDataManager::AddDataSource(profile, data_source);
167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698