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

Side by Side Diff: chrome/browser/ui/webui/signin/user_manager_screen_handler.cc

Issue 564453003: Access to Chrome via the System Tray should go through the User Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify UserManager View/Mac Created 6 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/signin/user_manager_screen_handler.h" 5 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/value_conversions.h" 10 #include "base/value_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h" 14 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 16 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
16 #include "chrome/browser/profiles/profile_info_cache.h" 17 #include "chrome/browser/profiles/profile_info_cache.h"
17 #include "chrome/browser/profiles/profile_info_cache_observer.h" 18 #include "chrome/browser/profiles/profile_info_cache_observer.h"
18 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/profiles/profile_metrics.h" 20 #include "chrome/browser/profiles/profile_metrics.h"
20 #include "chrome/browser/profiles/profile_window.h" 21 #include "chrome/browser/profiles/profile_window.h"
21 #include "chrome/browser/profiles/profiles_state.h" 22 #include "chrome/browser/profiles/profiles_state.h"
22 #include "chrome/browser/signin/local_auth.h" 23 #include "chrome/browser/signin/local_auth.h"
23 #include "chrome/browser/ui/browser_dialogs.h" 24 #include "chrome/browser/ui/browser_dialogs.h"
24 #include "chrome/browser/ui/browser_finder.h" 25 #include "chrome/browser/ui/browser_finder.h"
26 #include "chrome/browser/ui/browser_list.h"
27 #include "chrome/browser/ui/chrome_pages.h"
25 #include "chrome/browser/ui/singleton_tabs.h" 28 #include "chrome/browser/ui/singleton_tabs.h"
29 #include "chrome/browser/ui/user_manager.h"
26 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
27 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
28 #include "chrome/grit/chromium_strings.h" 32 #include "chrome/grit/chromium_strings.h"
29 #include "chrome/grit/generated_resources.h" 33 #include "chrome/grit/generated_resources.h"
34 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
31 #include "content/public/browser/web_ui.h" 36 #include "content/public/browser/web_ui.h"
32 #include "google_apis/gaia/gaia_auth_fetcher.h" 37 #include "google_apis/gaia/gaia_auth_fetcher.h"
33 #include "google_apis/gaia/gaia_constants.h" 38 #include "google_apis/gaia/gaia_constants.h"
34 #include "third_party/skia/include/core/SkBitmap.h" 39 #include "third_party/skia/include/core/SkBitmap.h"
35 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
36 #include "ui/base/resource/resource_bundle.h" 41 #include "ui/base/resource/resource_bundle.h"
37 #include "ui/base/webui/web_ui_util.h" 42 #include "ui/base/webui/web_ui_util.h"
38 #include "ui/gfx/image/image.h" 43 #include "ui/gfx/image/image.h"
39 #include "ui/gfx/image/image_skia.h" 44 #include "ui/gfx/image/image_skia.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (status != Profile::CREATE_STATUS_INITIALIZED) 82 if (status != Profile::CREATE_STATUS_INITIALIZED)
78 return; 83 return;
79 profiles::FindOrCreateNewWindowForProfile( 84 profiles::FindOrCreateNewWindowForProfile(
80 profile, 85 profile,
81 chrome::startup::IS_PROCESS_STARTUP, 86 chrome::startup::IS_PROCESS_STARTUP,
82 chrome::startup::IS_FIRST_RUN, 87 chrome::startup::IS_FIRST_RUN,
83 desktop_type, 88 desktop_type,
84 false); 89 false);
85 } 90 }
86 91
87 // This callback is run after switching to a new profile has finished. This
88 // means either a new browser window has been opened, or an existing one
89 // has been found, which means we can safely close the User Manager without
90 // accidentally terminating the browser process. The task needs to be posted,
91 // as HideUserManager will end up destroying its WebContents, which will
92 // destruct the UserManagerScreenHandler as well.
93 void OnSwitchToProfileComplete() {
94 base::MessageLoop::current()->PostTask(
95 FROM_HERE,
96 base::Bind(&chrome::HideUserManager));
97 }
98
99 std::string GetAvatarImageAtIndex( 92 std::string GetAvatarImageAtIndex(
100 size_t index, const ProfileInfoCache& info_cache) { 93 size_t index, const ProfileInfoCache& info_cache) {
101 bool is_gaia_picture = 94 bool is_gaia_picture =
102 info_cache.IsUsingGAIAPictureOfProfileAtIndex(index) && 95 info_cache.IsUsingGAIAPictureOfProfileAtIndex(index) &&
103 info_cache.GetGAIAPictureOfProfileAtIndex(index); 96 info_cache.GetGAIAPictureOfProfileAtIndex(index);
104 97
105 // If the avatar is too small (i.e. the old-style low resolution avatar), 98 // If the avatar is too small (i.e. the old-style low resolution avatar),
106 // it will be pixelated when displayed in the User Manager, so we should 99 // it will be pixelated when displayed in the User Manager, so we should
107 // return the placeholder avatar instead. 100 // return the placeholder avatar instead.
108 gfx::Image avatar_image = info_cache.GetAvatarIconOfProfileAtIndex(index); 101 gfx::Image avatar_image = info_cache.GetAvatarIconOfProfileAtIndex(index);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 ProfileManager* profile_manager_; 203 ProfileManager* profile_manager_;
211 204
212 UserManagerScreenHandler* user_manager_handler_; // Weak; owns us. 205 UserManagerScreenHandler* user_manager_handler_; // Weak; owns us.
213 206
214 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver); 207 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver);
215 }; 208 };
216 209
217 // UserManagerScreenHandler --------------------------------------------------- 210 // UserManagerScreenHandler ---------------------------------------------------
218 211
219 UserManagerScreenHandler::UserManagerScreenHandler() 212 UserManagerScreenHandler::UserManagerScreenHandler()
220 : desktop_type_(chrome::GetActiveDesktop()) { 213 : desktop_type_(chrome::GetActiveDesktop()),
214 weak_ptr_factory_(this) {
221 profileInfoCacheObserver_.reset( 215 profileInfoCacheObserver_.reset(
222 new UserManagerScreenHandler::ProfileUpdateObserver( 216 new UserManagerScreenHandler::ProfileUpdateObserver(
223 g_browser_process->profile_manager(), this)); 217 g_browser_process->profile_manager(), this));
224 } 218 }
225 219
226 UserManagerScreenHandler::~UserManagerScreenHandler() { 220 UserManagerScreenHandler::~UserManagerScreenHandler() {
227 ScreenlockBridge::Get()->SetLockHandler(NULL); 221 ScreenlockBridge::Get()->SetLockHandler(NULL);
228 } 222 }
229 223
230 void UserManagerScreenHandler::ShowBannerMessage( 224 void UserManagerScreenHandler::ShowBannerMessage(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 g_browser_process->profile_manager()->GetProfileInfoCache(); 280 g_browser_process->profile_manager()->GetProfileInfoCache();
287 const size_t profile_index = GetIndexOfProfileWithEmailAndName( 281 const size_t profile_index = GetIndexOfProfileWithEmailAndName(
288 info_cache, base::UTF8ToUTF16(user_email), base::string16()); 282 info_cache, base::UTF8ToUTF16(user_email), base::string16());
289 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); 283 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles());
290 284
291 authenticating_profile_index_ = profile_index; 285 authenticating_profile_index_ = profile_index;
292 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); 286 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL);
293 } 287 }
294 288
295 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { 289 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) {
290 // If the URL has a hash parameter, store it for later.
291 args->GetString(0, &url_hash_);
292
296 SendUserList(); 293 SendUserList();
297 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", 294 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen",
298 base::FundamentalValue(IsGuestModeEnabled()), 295 base::FundamentalValue(IsGuestModeEnabled()),
299 base::FundamentalValue(IsAddPersonEnabled())); 296 base::FundamentalValue(IsAddPersonEnabled()));
300 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( 297 desktop_type_ = chrome::GetHostDesktopTypeForNativeView(
301 web_ui()->GetWebContents()->GetNativeView()); 298 web_ui()->GetWebContents()->GetNativeView());
302 299
303 ScreenlockBridge::Get()->SetLockHandler(this); 300 ScreenlockBridge::Get()->SetLockHandler(this);
304 } 301 }
305 302
306 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { 303 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) {
307 if (!IsAddPersonEnabled()) { 304 if (!IsAddPersonEnabled()) {
308 // The 'Add User' UI should not be showing. 305 // The 'Add User' UI should not be showing.
309 NOTREACHED(); 306 NOTREACHED();
310 return; 307 return;
311 } 308 }
312 profiles::CreateAndSwitchToNewProfile( 309 profiles::CreateAndSwitchToNewProfile(
313 desktop_type_, 310 desktop_type_,
314 base::Bind(&OnSwitchToProfileComplete), 311 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete,
312 weak_ptr_factory_.GetWeakPtr()),
315 ProfileMetrics::ADD_NEW_USER_MANAGER); 313 ProfileMetrics::ADD_NEW_USER_MANAGER);
316 } 314 }
317 315
318 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( 316 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser(
319 const base::ListValue* args) { 317 const base::ListValue* args) {
320 base::string16 email_address; 318 base::string16 email_address;
321 if (!args->GetString(0, &email_address)) 319 if (!args->GetString(0, &email_address))
322 return; 320 return;
323 321
324 base::string16 display_name; 322 base::string16 display_name;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 382
385 g_browser_process->profile_manager()->ScheduleProfileForDeletion( 383 g_browser_process->profile_manager()->ScheduleProfileForDeletion(
386 profile_path, 384 profile_path,
387 base::Bind(&OpenNewWindowForProfile, desktop_type_)); 385 base::Bind(&OpenNewWindowForProfile, desktop_type_));
388 ProfileMetrics::LogProfileDeleteUser( 386 ProfileMetrics::LogProfileDeleteUser(
389 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); 387 ProfileMetrics::DELETE_PROFILE_USER_MANAGER);
390 } 388 }
391 389
392 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { 390 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) {
393 if (IsGuestModeEnabled()) { 391 if (IsGuestModeEnabled()) {
394 profiles::SwitchToGuestProfile(desktop_type_,
395 base::Bind(&OnSwitchToProfileComplete));
396 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); 392 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST);
393 profiles::SwitchToGuestProfile(
394 desktop_type_,
395 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete,
396 weak_ptr_factory_.GetWeakPtr()));
397 } else { 397 } else {
398 // The UI should have prevented the user from allowing the selection of 398 // The UI should have prevented the user from allowing the selection of
399 // guest mode. 399 // guest mode.
400 NOTREACHED(); 400 NOTREACHED();
401 } 401 }
402 } 402 }
403 403
404 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { 404 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) {
405 base::string16 email_address; 405 base::string16 email_address;
406 base::string16 display_name; 406 base::string16 display_name;
(...skipping 17 matching lines...) Expand all
424 // It's possible that a user breaks into the user-manager page using the 424 // It's possible that a user breaks into the user-manager page using the
425 // JavaScript Inspector and causes a "locked" profile to call this 425 // JavaScript Inspector and causes a "locked" profile to call this
426 // unauthenticated version of "launch" instead of the proper one. Thus, 426 // unauthenticated version of "launch" instead of the proper one. Thus,
427 // we have to validate in (secure) C++ code that it really is a profile 427 // we have to validate in (secure) C++ code that it really is a profile
428 // not needing authentication. If it is, just ignore the "launch" request. 428 // not needing authentication. If it is, just ignore the "launch" request.
429 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) 429 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index))
430 return; 430 return;
431 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); 431 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY);
432 432
433 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); 433 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index);
434 profiles::SwitchToProfile(path, 434 profiles::SwitchToProfile(
435 desktop_type_, 435 path,
436 false, /* reuse any existing windows */ 436 desktop_type_,
437 base::Bind(&OnSwitchToProfileComplete), 437 false, /* reuse any existing windows */
438 ProfileMetrics::SWITCH_PROFILE_MANAGER); 438 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete,
439 weak_ptr_factory_.GetWeakPtr()),
440 ProfileMetrics::SWITCH_PROFILE_MANAGER);
439 } 441 }
440 442
441 void UserManagerScreenHandler::HandleAttemptUnlock( 443 void UserManagerScreenHandler::HandleAttemptUnlock(
442 const base::ListValue* args) { 444 const base::ListValue* args) {
443 std::string email; 445 std::string email;
444 CHECK(args->GetString(0, &email)); 446 CHECK(args->GetString(0, &email));
445 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), ""); 447 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), "");
446 } 448 }
447 449
448 void UserManagerScreenHandler::HandleHardlockUserPod( 450 void UserManagerScreenHandler::HandleHardlockUserPod(
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 ProfileMetrics::LogProfileAuthResult(auth); 674 ProfileMetrics::LogProfileAuthResult(auth);
673 password_attempt_.clear(); 675 password_attempt_.clear();
674 676
675 if (success) { 677 if (success) {
676 ProfileInfoCache& info_cache = 678 ProfileInfoCache& info_cache =
677 g_browser_process->profile_manager()->GetProfileInfoCache(); 679 g_browser_process->profile_manager()->GetProfileInfoCache();
678 info_cache.SetProfileSigninRequiredAtIndex( 680 info_cache.SetProfileSigninRequiredAtIndex(
679 authenticating_profile_index_, false); 681 authenticating_profile_index_, false);
680 base::FilePath path = info_cache.GetPathOfProfileAtIndex( 682 base::FilePath path = info_cache.GetPathOfProfileAtIndex(
681 authenticating_profile_index_); 683 authenticating_profile_index_);
682 profiles::SwitchToProfile(path, desktop_type_, true, 684 profiles::SwitchToProfile(
683 base::Bind(&OnSwitchToProfileComplete), 685 path,
684 ProfileMetrics::SWITCH_PROFILE_UNLOCK); 686 desktop_type_,
687 true,
688 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete,
689 weak_ptr_factory_.GetWeakPtr()),
690 ProfileMetrics::SWITCH_PROFILE_UNLOCK);
685 } else { 691 } else {
686 web_ui()->CallJavascriptFunction( 692 web_ui()->CallJavascriptFunction(
687 "cr.ui.Oobe.showSignInError", 693 "cr.ui.Oobe.showSignInError",
688 base::FundamentalValue(0), 694 base::FundamentalValue(0),
689 base::StringValue( 695 base::StringValue(
690 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), 696 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)),
691 base::StringValue(""), 697 base::StringValue(""),
692 base::FundamentalValue(0)); 698 base::FundamentalValue(0));
693 } 699 }
694 } 700 }
701
702 void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) {
703 DCHECK(browser);
704 DCHECK(browser->window());
705 if (url_hash_ == profiles::kUserManagerSelectProfileTaskManager) {
706 base::MessageLoop::current()->PostTask(
707 FROM_HERE, base::Bind(&chrome::ShowTaskManager, browser));
708 } else if (url_hash_ == profiles::kUserManagerSelectProfileAboutChrome) {
709 base::MessageLoop::current()->PostTask(
710 FROM_HERE, base::Bind(&chrome::ShowAboutChrome, browser));
711 }
712
713 // This call is last as it deletes this object.
714 UserManager::Hide();
715 }
716
717 void UserManagerScreenHandler::Observe(
718 int type,
719 const content::NotificationSource& source,
720 const content::NotificationDetails& details) {
721 switch (type) {
722 case chrome::NOTIFICATION_BROWSER_WINDOW_READY:
723 // Only respond to one Browser Window Ready event.
724 registrar_.Remove(this,
725 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
726 content::NotificationService::AllSources());
727 OnBrowserWindowReady(content::Source<Browser>(source).ptr());
728 break;
729 default:
730 NOTREACHED();
731 }
732 }
733
734 // This callback is run after switching to a new profile has finished. This
735 // means either a new browser has been created (but not the window), or an
736 // existing one has been found. The HideUserManager task needs to be posted
737 // since closing the User Manager before the window is created can flakily
738 // cause Chrome to close.
739 void UserManagerScreenHandler::OnSwitchToProfileComplete(
740 Profile* profile, Profile::CreateStatus profile_create_status) {
741 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_);
742 if (browser && browser->window()) {
743 OnBrowserWindowReady(browser);
744 } else {
745 registrar_.Add(this,
746 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
747 content::NotificationService::AllSources());
748 }
749 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698