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

Side by Side Diff: chrome/browser/ui/webui/options/managed_user_passphrase_handler.cc

Issue 13119011: Enable WebContents elevation for managed users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 7 years, 9 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options/managed_user_passphrase_handler.h" 5 #include "chrome/browser/ui/webui/options/managed_user_passphrase_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
11 #include "chrome/browser/managed_mode/managed_user_passphrase.h" 12 #include "chrome/browser/managed_mode/managed_user_passphrase.h"
12 #include "chrome/browser/managed_mode/managed_user_service.h" 13 #include "chrome/browser/managed_mode/managed_user_service.h"
13 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 14 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_ui.h" 18 #include "content/public/browser/web_ui.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 20
20 namespace options { 21 namespace options {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 { "passphraseMismatch", IDS_PASSPHRASE_MISMATCH }, 61 { "passphraseMismatch", IDS_PASSPHRASE_MISMATCH },
61 }; 62 };
62 RegisterStrings(localized_strings, resources, arraysize(resources)); 63 RegisterStrings(localized_strings, resources, arraysize(resources));
63 64
64 RegisterTitle(localized_strings, 65 RegisterTitle(localized_strings,
65 "setPassphraseTitle", 66 "setPassphraseTitle",
66 IDS_SET_PASSPHRASE_TITLE); 67 IDS_SET_PASSPHRASE_TITLE);
67 } 68 }
68 69
69 void ManagedUserPassphraseHandler::PassphraseDialogCallback(bool success) { 70 void ManagedUserPassphraseHandler::PassphraseDialogCallback(bool success) {
70 ManagedUserService* managed_user_service = 71 ManagedModeNavigationObserver::FromWebContents(
71 ManagedUserServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); 72 web_ui()->GetWebContents())->set_elevated(success);
72 managed_user_service->SetElevated(true);
73 base::FundamentalValue unlock_success(success); 73 base::FundamentalValue unlock_success(success);
74 web_ui()->CallJavascriptFunction("ManagedUserSettings.isAuthenticated", 74 web_ui()->CallJavascriptFunction("ManagedUserSettings.isAuthenticated",
75 unlock_success); 75 unlock_success);
76 } 76 }
77 77
78 void ManagedUserPassphraseHandler::SetElevated( 78 void ManagedUserPassphraseHandler::SetElevated(
79 const base::ListValue* args) { 79 const base::ListValue* args) {
80 bool elevated; 80 bool elevated;
81 bool success = args->GetBoolean(0, &elevated); 81 bool success = args->GetBoolean(0, &elevated);
82 DCHECK(success); 82 DCHECK(success);
83 83
84 Profile* profile = Profile::FromWebUI(web_ui()); 84 Profile* profile = Profile::FromWebUI(web_ui());
85 ManagedUserService* managed_user_service = 85 ManagedUserService* managed_user_service =
86 ManagedUserServiceFactory::GetForProfile(profile); 86 ManagedUserServiceFactory::GetForProfile(profile);
87 if (!elevated) { 87 if (!elevated) {
88 managed_user_service->SetElevated(false); 88 ManagedModeNavigationObserver::FromWebContents(
89 web_ui()->GetWebContents())->set_elevated(false);
89 return; 90 return;
90 } 91 }
91 managed_user_service->RequestAuthorization( 92 managed_user_service->RequestAuthorization(
92 web_ui()->GetWebContents(), 93 web_ui()->GetWebContents(),
93 base::Bind(&ManagedUserPassphraseHandler::PassphraseDialogCallback, 94 base::Bind(&ManagedUserPassphraseHandler::PassphraseDialogCallback,
94 weak_ptr_factory_.GetWeakPtr())); 95 weak_ptr_factory_.GetWeakPtr()));
95 } 96 }
96 97
97 void ManagedUserPassphraseHandler::IsPassphraseSet( 98 void ManagedUserPassphraseHandler::IsPassphraseSet(
98 const base::ListValue* args) { 99 const base::ListValue* args) {
(...skipping 10 matching lines...) Expand all
109 void ManagedUserPassphraseHandler::ResetPassphrase( 110 void ManagedUserPassphraseHandler::ResetPassphrase(
110 const base::ListValue* args) { 111 const base::ListValue* args) {
111 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 112 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
112 pref_service->SetString(prefs::kManagedModeLocalPassphrase, ""); 113 pref_service->SetString(prefs::kManagedModeLocalPassphrase, "");
113 pref_service->SetString(prefs::kManagedModeLocalSalt, ""); 114 pref_service->SetString(prefs::kManagedModeLocalSalt, "");
114 } 115 }
115 116
116 void ManagedUserPassphraseHandler::SetLocalPassphrase( 117 void ManagedUserPassphraseHandler::SetLocalPassphrase(
117 const base::ListValue* args) { 118 const base::ListValue* args) {
118 // Only change the passphrase if the custodian is authenticated. 119 // Only change the passphrase if the custodian is authenticated.
119 Profile* profile = Profile::FromWebUI(web_ui()); 120 if (!ManagedModeNavigationObserver::FromWebContents(
120 ManagedUserService* managed_user_service = 121 web_ui()->GetWebContents())->is_elevated())
121 ManagedUserServiceFactory::GetForProfile(profile);
122 if (!managed_user_service->IsElevated())
123 return; 122 return;
124 123
125 std::string passphrase; 124 std::string passphrase;
126 args->GetString(0, &passphrase); 125 args->GetString(0, &passphrase);
127 ManagedUserPassphrase passphrase_key_generator((std::string())); 126 ManagedUserPassphrase passphrase_key_generator((std::string()));
128 std::string encoded_passphrase_hash; 127 std::string encoded_passphrase_hash;
129 bool success = passphrase_key_generator.GenerateHashFromPassphrase( 128 bool success = passphrase_key_generator.GenerateHashFromPassphrase(
130 passphrase, 129 passphrase,
131 &encoded_passphrase_hash); 130 &encoded_passphrase_hash);
132 if (success) { 131 if (success) {
133 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 132 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
134 pref_service->SetString(prefs::kManagedModeLocalPassphrase, 133 pref_service->SetString(prefs::kManagedModeLocalPassphrase,
135 encoded_passphrase_hash); 134 encoded_passphrase_hash);
136 pref_service->SetString(prefs::kManagedModeLocalSalt, 135 pref_service->SetString(prefs::kManagedModeLocalSalt,
137 passphrase_key_generator.GetSalt()); 136 passphrase_key_generator.GetSalt());
138 } 137 }
139 // TODO(akuegel): Give failure back to the UI. 138 // TODO(akuegel): Give failure back to the UI.
140 } 139 }
141 140
142 } // namespace options 141 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698