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

Side by Side Diff: chrome/browser/ui/views/profiles/user_manager_view.cc

Issue 2552473002: Display error message when user try to open a locked supervised user profile when force-sign-in is … (Closed)
Patch Set: refacotr Created 4 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/views/profiles/user_manager_view.h" 5 #include "chrome/browser/ui/views/profiles/user_manager_view.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 namespace { 49 namespace {
50 50
51 // An open User Manager window. There can only be one open at a time. This 51 // An open User Manager window. There can only be one open at a time. This
52 // is reset to NULL when the window is closed. 52 // is reset to NULL when the window is closed.
53 UserManagerView* instance_ = nullptr; 53 UserManagerView* instance_ = nullptr;
54 base::Closure* user_manager_shown_callback_for_testing_ = nullptr; 54 base::Closure* user_manager_shown_callback_for_testing_ = nullptr;
55 bool instance_under_construction_ = false; 55 bool instance_under_construction_ = false;
56 } // namespace 56 } // namespace
57 57
58 // ReauthDelegate--------------------------------------------------------------- 58 // Delegate---------------------------------------------------------------
59 59
60 ReauthDelegate::ReauthDelegate(UserManagerView* parent, 60 UserManagerDialogDelegate::UserManagerDialogDelegate(
61 views::WebView* web_view, 61 UserManagerView* parent,
62 const std::string& email_address, 62 views::WebView* web_view,
63 signin_metrics::Reason reason) 63 const std::string& email_address,
64 : parent_(parent), 64 const GURL& url)
65 web_view_(web_view), 65 : parent_(parent), web_view_(web_view), email_address_(email_address) {
66 email_address_(email_address) {
67 AddChildView(web_view_); 66 AddChildView(web_view_);
68 SetLayoutManager(new views::FillLayout()); 67 SetLayoutManager(new views::FillLayout());
69 68
70 web_view_->GetWebContents()->SetDelegate(this); 69 web_view_->GetWebContents()->SetDelegate(this);
71
72 // Load the re-auth URL, prepopulated with the user's email address.
73 // Add the index of the profile to the URL so that the inline login page
74 // knows which profile to load and update the credentials.
75 GURL url = signin::GetReauthURLWithEmail(
76 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason,
77 email_address_);
78 web_view_->LoadInitialURL(url); 70 web_view_->LoadInitialURL(url);
79 } 71 }
80 72
81 ReauthDelegate::~ReauthDelegate() {} 73 UserManagerDialogDelegate::~UserManagerDialogDelegate() {}
82 74
83 gfx::Size ReauthDelegate::GetPreferredSize() const { 75 gfx::Size UserManagerDialogDelegate::GetPreferredSize() const {
84 return switches::UsePasswordSeparatedSigninFlow() ? 76 return switches::UsePasswordSeparatedSigninFlow()
85 gfx::Size(UserManager::kReauthDialogWidth, 77 ? gfx::Size(UserManagerDialog::kDialogWidth,
86 UserManager::kReauthDialogHeight) : 78 UserManagerDialog::kDialogHeight)
87 gfx::Size(UserManager::kPasswordCombinedReauthDialogWidth, 79 : gfx::Size(UserManagerDialog::kPasswordCombinedDialogWidth,
88 UserManager::kPasswordCombinedReauthDialogHeight); 80 UserManagerDialog::kPasswordCombinedDialogHeight);
89 } 81 }
90 82
91 void ReauthDelegate::DisplayErrorMessage() { 83 void UserManagerDialogDelegate::DisplayErrorMessage() {
92 web_view_->LoadInitialURL(GURL(chrome::kChromeUISigninErrorURL)); 84 web_view_->LoadInitialURL(GURL(chrome::kChromeUISigninErrorURL));
93 } 85 }
94 86
95 bool ReauthDelegate::CanResize() const { 87 bool UserManagerDialogDelegate::CanResize() const {
96 return true; 88 return true;
97 } 89 }
98 90
99 bool ReauthDelegate::CanMaximize() const { 91 bool UserManagerDialogDelegate::CanMaximize() const {
100 return true; 92 return true;
101 } 93 }
102 94
103 bool ReauthDelegate::CanMinimize() const { 95 bool UserManagerDialogDelegate::CanMinimize() const {
104 return true; 96 return true;
105 } 97 }
106 98
107 bool ReauthDelegate::ShouldUseCustomFrame() const { 99 bool UserManagerDialogDelegate::ShouldUseCustomFrame() const {
108 return false; 100 return false;
109 } 101 }
110 102
111 ui::ModalType ReauthDelegate::GetModalType() const { 103 ui::ModalType UserManagerDialogDelegate::GetModalType() const {
112 return ui::MODAL_TYPE_WINDOW; 104 return ui::MODAL_TYPE_WINDOW;
113 } 105 }
114 106
115 void ReauthDelegate::DeleteDelegate() { 107 void UserManagerDialogDelegate::DeleteDelegate() {
116 OnReauthDialogDestroyed(); 108 OnDialogDestroyed();
117 delete this; 109 delete this;
118 } 110 }
119 111
120 base::string16 ReauthDelegate::GetWindowTitle() const { 112 base::string16 UserManagerDialogDelegate::GetWindowTitle() const {
121 return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE); 113 return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE);
122 } 114 }
123 115
124 int ReauthDelegate::GetDialogButtons() const { 116 int UserManagerDialogDelegate::GetDialogButtons() const {
125 return ui::DIALOG_BUTTON_NONE; 117 return ui::DIALOG_BUTTON_NONE;
126 } 118 }
127 119
128 views::View* ReauthDelegate::GetInitiallyFocusedView() { 120 views::View* UserManagerDialogDelegate::GetInitiallyFocusedView() {
129 return static_cast<views::View*>(web_view_); 121 return static_cast<views::View*>(web_view_);
130 } 122 }
131 123
132 void ReauthDelegate::CloseReauthDialog() { 124 void UserManagerDialogDelegate::CloseDialog() {
133 OnReauthDialogDestroyed(); 125 OnDialogDestroyed();
134 GetWidget()->Close(); 126 GetWidget()->Close();
135 } 127 }
136 128
137 void ReauthDelegate::OnReauthDialogDestroyed() { 129 void UserManagerDialogDelegate::OnDialogDestroyed() {
138 if (parent_) { 130 if (parent_) {
139 parent_->OnReauthDialogDestroyed(); 131 parent_->OnDialogDestroyed();
140 parent_ = nullptr; 132 parent_ = nullptr;
141 } 133 }
142 } 134 }
143 135
144 // UserManager ----------------------------------------------------------------- 136 // UserManager -----------------------------------------------------------------
145 137
146 // static 138 // static
147 void UserManager::Show( 139 void UserManager::Show(
148 const base::FilePath& profile_path_to_focus, 140 const base::FilePath& profile_path_to_focus,
149 profiles::UserManagerTutorialMode tutorial_mode, 141 profiles::UserManagerTutorialMode tutorial_mode,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (!user_manager_shown_callback_for_testing_->is_null()) 194 if (!user_manager_shown_callback_for_testing_->is_null())
203 user_manager_shown_callback_for_testing_->Run(); 195 user_manager_shown_callback_for_testing_->Run();
204 196
205 delete user_manager_shown_callback_for_testing_; 197 delete user_manager_shown_callback_for_testing_;
206 user_manager_shown_callback_for_testing_ = nullptr; 198 user_manager_shown_callback_for_testing_ = nullptr;
207 } 199 }
208 } 200 }
209 } 201 }
210 202
211 // static 203 // static
212 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context,
213 const std::string& email,
214 signin_metrics::Reason reason) {
215 // This method should only be called if the user manager is already showing.
216 if (!IsShowing())
217 return;
218 instance_->ShowReauthDialog(browser_context, email, reason);
219 }
220
221 // static
222 void UserManager::HideReauthDialog() {
223 // This method should only be called if the user manager is already showing.
224 if (instance_ && instance_->GetWidget()->IsVisible())
225 instance_->HideReauthDialog();
226 }
227
228 // static
229 void UserManager::AddOnUserManagerShownCallbackForTesting( 204 void UserManager::AddOnUserManagerShownCallbackForTesting(
230 const base::Closure& callback) { 205 const base::Closure& callback) {
231 DCHECK(!user_manager_shown_callback_for_testing_); 206 DCHECK(!user_manager_shown_callback_for_testing_);
232 user_manager_shown_callback_for_testing_ = new base::Closure(callback); 207 user_manager_shown_callback_for_testing_ = new base::Closure(callback);
233 } 208 }
234 209
235 // static 210 // static
236 void UserManager::ShowSigninDialog(content::BrowserContext* browser_context, 211 base::FilePath UserManager::GetSigninProfilePath() {
237 const base::FilePath& profile_path) { 212 return instance_->GetSigninProfilePath();
238 if (!IsShowing()) 213 }
214
215 // UserManagerDialog
216 // -------------------------------------------------------------
217
218 // static
219 void UserManagerDialog::ShowReauthDialog(
220 content::BrowserContext* browser_context,
221 const std::string& email,
222 signin_metrics::Reason reason) {
223 // This method should only be called if the user manager is already showing.
224 if (!UserManager::IsShowing())
239 return; 225 return;
240 instance_->SetSigninProfilePath(profile_path); 226 // Load the re-auth URL, prepopulated with the user's email address.
241 ShowReauthDialog(browser_context, std::string(), 227 // Add the index of the profile to the URL so that the inline login page
242 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT); 228 // knows which profile to load and update the credentials.
229 GURL url = signin::GetReauthURLWithEmail(
230 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason, email);
231 instance_->ShowDialog(browser_context, email, url);
243 } 232 }
244 233
245 // static 234 // static
246 void UserManager::DisplayErrorMessage() { 235 void UserManagerDialog::ShowSigninDialog(
236 content::BrowserContext* browser_context,
237 const base::FilePath& profile_path) {
238 if (!UserManager::IsShowing())
239 return;
240 instance_->SetSigninProfilePath(profile_path);
241 GURL url = signin::GetPromoURL(
242 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER,
243 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, true, true);
244 instance_->ShowDialog(browser_context, std::string(), url);
245 }
246
247 void UserManagerDialog::ShowDialogAndDisplayErrorMessage(
248 content::BrowserContext* browser_context) {
249 if (!UserManager::IsShowing())
250 return;
251 instance_->ShowDialog(browser_context, std::string(),
252 GURL(chrome::kChromeUISigninErrorURL));
253 }
254
255 // static
256 void UserManagerDialog::DisplayErrorMessage() {
247 // This method should only be called if the user manager is already showing. 257 // This method should only be called if the user manager is already showing.
248 DCHECK(instance_); 258 DCHECK(instance_);
249 instance_->DisplayErrorMessage(); 259 instance_->DisplayErrorMessage();
250 } 260 }
251 261
252 // static 262 // static
253 base::FilePath UserManager::GetSigninProfilePath() { 263 void UserManagerDialog::HideDialog() {
254 return instance_->GetSigninProfilePath(); 264 if (instance_ && instance_->GetWidget()->IsVisible())
265 instance_->HideDialog();
255 } 266 }
256 267
257 // UserManagerView ------------------------------------------------------------- 268 // UserManagerView -------------------------------------------------------------
258 269
259 UserManagerView::UserManagerView() 270 UserManagerView::UserManagerView()
260 : web_view_(nullptr), 271 : web_view_(nullptr),
261 delegate_(nullptr), 272 delegate_(nullptr),
262 user_manager_started_showing_(base::Time()) { 273 user_manager_started_showing_(base::Time()) {
263 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::USER_MANAGER_VIEW, 274 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::USER_MANAGER_VIEW,
264 KeepAliveRestartOption::DISABLED)); 275 KeepAliveRestartOption::DISABLED));
265 } 276 }
266 277
267 UserManagerView::~UserManagerView() { 278 UserManagerView::~UserManagerView() {
268 HideReauthDialog(); 279 HideDialog();
269 } 280 }
270 281
271 // static 282 // static
272 void UserManagerView::OnSystemProfileCreated( 283 void UserManagerView::OnSystemProfileCreated(
273 std::unique_ptr<UserManagerView> instance, 284 std::unique_ptr<UserManagerView> instance,
274 base::AutoReset<bool>* pending, 285 base::AutoReset<bool>* pending,
275 Profile* system_profile, 286 Profile* system_profile,
276 const std::string& url) { 287 const std::string& url) {
277 // If we are showing the User Manager after locking a profile, change the 288 // If we are showing the User Manager after locking a profile, change the
278 // active profile to Guest. 289 // active profile to Guest.
279 profiles::SetActiveProfileToGuestIfLocked(); 290 profiles::SetActiveProfileToGuestIfLocked();
280 291
281 DCHECK(!instance_); 292 DCHECK(!instance_);
282 instance_ = instance.release(); // |instance_| takes over ownership. 293 instance_ = instance.release(); // |instance_| takes over ownership.
283 instance_->Init(system_profile, GURL(url)); 294 instance_->Init(system_profile, GURL(url));
284 } 295 }
285 296
286 void UserManagerView::ShowReauthDialog(content::BrowserContext* browser_context, 297 void UserManagerView::ShowDialog(content::BrowserContext* browser_context,
287 const std::string& email, 298 const std::string& email,
288 signin_metrics::Reason reason) { 299 const GURL& url) {
289 HideReauthDialog(); 300 HideDialog();
290 // The dialog delegate will be deleted when the widget closes. The created 301 // The dialog delegate will be deleted when the widget closes. The created
291 // WebView's lifetime is managed by the delegate. 302 // WebView's lifetime is managed by the delegate.
292 delegate_ = new ReauthDelegate(this, 303 delegate_ = new UserManagerDialogDelegate(
293 new views::WebView(browser_context), 304 this, new views::WebView(browser_context), email, url);
294 email,
295 reason);
296 gfx::NativeView parent = instance_->GetWidget()->GetNativeView(); 305 gfx::NativeView parent = instance_->GetWidget()->GetNativeView();
297 views::DialogDelegate::CreateDialogWidget(delegate_, nullptr, parent); 306 views::DialogDelegate::CreateDialogWidget(delegate_, nullptr, parent);
298 delegate_->GetWidget()->Show(); 307 delegate_->GetWidget()->Show();
299 } 308 }
300 309
301 void UserManagerView::HideReauthDialog() { 310 void UserManagerView::HideDialog() {
302 if (delegate_) { 311 if (delegate_) {
303 delegate_->CloseReauthDialog(); 312 delegate_->CloseDialog();
304 DCHECK(!delegate_); 313 DCHECK(!delegate_);
305 } 314 }
306 } 315 }
307 316
308 void UserManagerView::OnReauthDialogDestroyed() { 317 void UserManagerView::OnDialogDestroyed() {
309 delegate_ = nullptr; 318 delegate_ = nullptr;
310 } 319 }
311 320
312 void UserManagerView::Init(Profile* system_profile, const GURL& url) { 321 void UserManagerView::Init(Profile* system_profile, const GURL& url) {
313 web_view_ = new views::WebView(system_profile); 322 web_view_ = new views::WebView(system_profile);
314 web_view_->set_allow_accelerators(true); 323 web_view_->set_allow_accelerators(true);
315 AddChildView(web_view_); 324 AddChildView(web_view_);
316 SetLayoutManager(new views::FillLayout); 325 SetLayoutManager(new views::FillLayout);
317 AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN)); 326 AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN));
318 AddAccelerator(ui::Accelerator(ui::VKEY_F4, ui::EF_ALT_DOWN)); 327 AddAccelerator(ui::Accelerator(ui::VKEY_F4, ui::EF_ALT_DOWN));
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 delegate_->DisplayErrorMessage(); 447 delegate_->DisplayErrorMessage();
439 } 448 }
440 449
441 void UserManagerView::SetSigninProfilePath(const base::FilePath& profile_path) { 450 void UserManagerView::SetSigninProfilePath(const base::FilePath& profile_path) {
442 signin_profile_path_ = profile_path; 451 signin_profile_path_ = profile_path;
443 } 452 }
444 453
445 base::FilePath UserManagerView::GetSigninProfilePath() { 454 base::FilePath UserManagerView::GetSigninProfilePath() {
446 return signin_profile_path_; 455 return signin_profile_path_;
447 } 456 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698