OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const char kJsApiUserManagerGetRemoveWarningDialogMessage[] = | 96 const char kJsApiUserManagerGetRemoveWarningDialogMessage[] = |
97 "getRemoveWarningDialogMessage"; | 97 "getRemoveWarningDialogMessage"; |
98 const size_t kAvatarIconSize = 180; | 98 const size_t kAvatarIconSize = 180; |
99 const int kMaxOAuthRetries = 3; | 99 const int kMaxOAuthRetries = 3; |
100 | 100 |
101 void HandleAndDoNothing(const base::ListValue* args) { | 101 void HandleAndDoNothing(const base::ListValue* args) { |
102 } | 102 } |
103 | 103 |
104 // This callback is run if the only profile has been deleted, and a new | 104 // This callback is run if the only profile has been deleted, and a new |
105 // profile has been created to replace it. | 105 // profile has been created to replace it. |
106 void OpenNewWindowForProfile( | 106 void OpenNewWindowForProfile(Profile* profile, Profile::CreateStatus status) { |
107 chrome::HostDesktopType desktop_type, | |
108 Profile* profile, | |
109 Profile::CreateStatus status) { | |
110 if (status != Profile::CREATE_STATUS_INITIALIZED) | 107 if (status != Profile::CREATE_STATUS_INITIALIZED) |
111 return; | 108 return; |
112 profiles::FindOrCreateNewWindowForProfile( | 109 profiles::FindOrCreateNewWindowForProfile( |
113 profile, | 110 profile, chrome::startup::IS_PROCESS_STARTUP, |
114 chrome::startup::IS_PROCESS_STARTUP, | 111 chrome::startup::IS_FIRST_RUN, false); |
115 chrome::startup::IS_FIRST_RUN, | |
116 desktop_type, | |
117 false); | |
118 } | 112 } |
119 | 113 |
120 std::string GetAvatarImageAtIndex( | 114 std::string GetAvatarImageAtIndex( |
121 size_t index, ProfileInfoCache* info_cache) { | 115 size_t index, ProfileInfoCache* info_cache) { |
122 bool is_gaia_picture = | 116 bool is_gaia_picture = |
123 info_cache->IsUsingGAIAPictureOfProfileAtIndex(index) && | 117 info_cache->IsUsingGAIAPictureOfProfileAtIndex(index) && |
124 info_cache->GetGAIAPictureOfProfileAtIndex(index); | 118 info_cache->GetGAIAPictureOfProfileAtIndex(index); |
125 | 119 |
126 // If the avatar is too small (i.e. the old-style low resolution avatar), | 120 // If the avatar is too small (i.e. the old-style low resolution avatar), |
127 // it will be pixelated when displayed in the User Manager, so we should | 121 // it will be pixelated when displayed in the User Manager, so we should |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 ~UrlHashHelper() override; | 162 ~UrlHashHelper() override; |
169 | 163 |
170 void ExecuteUrlHash(); | 164 void ExecuteUrlHash(); |
171 | 165 |
172 // chrome::BrowserListObserver overrides: | 166 // chrome::BrowserListObserver overrides: |
173 void OnBrowserRemoved(Browser* browser) override; | 167 void OnBrowserRemoved(Browser* browser) override; |
174 | 168 |
175 private: | 169 private: |
176 Browser* browser_; | 170 Browser* browser_; |
177 Profile* profile_; | 171 Profile* profile_; |
178 chrome::HostDesktopType desktop_type_; | |
179 std::string hash_; | 172 std::string hash_; |
180 | 173 |
181 DISALLOW_COPY_AND_ASSIGN(UrlHashHelper); | 174 DISALLOW_COPY_AND_ASSIGN(UrlHashHelper); |
182 }; | 175 }; |
183 | 176 |
184 UrlHashHelper::UrlHashHelper(Browser* browser, const std::string& hash) | 177 UrlHashHelper::UrlHashHelper(Browser* browser, const std::string& hash) |
185 : browser_(browser), | 178 : browser_(browser), |
186 profile_(browser->profile()), | 179 profile_(browser->profile()), |
187 desktop_type_(browser->host_desktop_type()), | |
188 hash_(hash) { | 180 hash_(hash) { |
189 BrowserList::AddObserver(this); | 181 BrowserList::AddObserver(this); |
190 } | 182 } |
191 | 183 |
192 UrlHashHelper::~UrlHashHelper() { | 184 UrlHashHelper::~UrlHashHelper() { |
193 BrowserList::RemoveObserver(this); | 185 BrowserList::RemoveObserver(this); |
194 } | 186 } |
195 | 187 |
196 void UrlHashHelper::OnBrowserRemoved(Browser* browser) { | 188 void UrlHashHelper::OnBrowserRemoved(Browser* browser) { |
197 if (browser == browser_) | 189 if (browser == browser_) |
198 browser_ = nullptr; | 190 browser_ = nullptr; |
199 } | 191 } |
200 | 192 |
201 void UrlHashHelper::ExecuteUrlHash() { | 193 void UrlHashHelper::ExecuteUrlHash() { |
202 if (hash_ == profiles::kUserManagerSelectProfileAppLauncher) { | 194 if (hash_ == profiles::kUserManagerSelectProfileAppLauncher) { |
203 AppListService* app_list_service = AppListService::Get(desktop_type_); | 195 AppListService* app_list_service = |
| 196 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE); |
204 app_list_service->ShowForProfile(profile_); | 197 app_list_service->ShowForProfile(profile_); |
205 return; | 198 return; |
206 } | 199 } |
207 | 200 |
208 Browser* target_browser = browser_; | 201 Browser* target_browser = browser_; |
209 if (!target_browser) { | 202 if (!target_browser) { |
210 target_browser = chrome::FindLastActiveWithProfile(profile_); | 203 target_browser = chrome::FindLastActiveWithProfile(profile_); |
211 if (!target_browser) | 204 if (!target_browser) |
212 return; | 205 return; |
213 } | 206 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 287 |
295 ProfileManager* profile_manager_; | 288 ProfileManager* profile_manager_; |
296 | 289 |
297 UserManagerScreenHandler* user_manager_handler_; // Weak; owns us. | 290 UserManagerScreenHandler* user_manager_handler_; // Weak; owns us. |
298 | 291 |
299 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver); | 292 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver); |
300 }; | 293 }; |
301 | 294 |
302 // UserManagerScreenHandler --------------------------------------------------- | 295 // UserManagerScreenHandler --------------------------------------------------- |
303 | 296 |
304 UserManagerScreenHandler::UserManagerScreenHandler() | 297 UserManagerScreenHandler::UserManagerScreenHandler() : weak_ptr_factory_(this) { |
305 : desktop_type_(chrome::GetActiveDesktop()), | |
306 weak_ptr_factory_(this) { | |
307 profileInfoCacheObserver_.reset( | 298 profileInfoCacheObserver_.reset( |
308 new UserManagerScreenHandler::ProfileUpdateObserver( | 299 new UserManagerScreenHandler::ProfileUpdateObserver( |
309 g_browser_process->profile_manager(), this)); | 300 g_browser_process->profile_manager(), this)); |
310 } | 301 } |
311 | 302 |
312 UserManagerScreenHandler::~UserManagerScreenHandler() { | 303 UserManagerScreenHandler::~UserManagerScreenHandler() { |
313 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); | 304 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); |
314 } | 305 } |
315 | 306 |
316 void UserManagerScreenHandler::ShowBannerMessage( | 307 void UserManagerScreenHandler::ShowBannerMessage( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 } | 378 } |
388 | 379 |
389 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { | 380 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { |
390 // If the URL has a hash parameter, store it for later. | 381 // If the URL has a hash parameter, store it for later. |
391 args->GetString(0, &url_hash_); | 382 args->GetString(0, &url_hash_); |
392 | 383 |
393 SendUserList(); | 384 SendUserList(); |
394 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", | 385 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", |
395 base::FundamentalValue(IsGuestModeEnabled()), | 386 base::FundamentalValue(IsGuestModeEnabled()), |
396 base::FundamentalValue(IsAddPersonEnabled())); | 387 base::FundamentalValue(IsAddPersonEnabled())); |
397 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( | |
398 web_ui()->GetWebContents()->GetNativeView()); | |
399 | 388 |
400 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(this); | 389 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(this); |
401 } | 390 } |
402 | 391 |
403 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { | 392 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { |
404 if (!IsAddPersonEnabled()) { | 393 if (!IsAddPersonEnabled()) { |
405 // The 'Add User' UI should not be showing. | 394 // The 'Add User' UI should not be showing. |
406 NOTREACHED(); | 395 NOTREACHED(); |
407 return; | 396 return; |
408 } | 397 } |
409 profiles::CreateAndSwitchToNewProfile( | 398 profiles::CreateAndSwitchToNewProfile( |
410 desktop_type_, | |
411 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 399 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
412 weak_ptr_factory_.GetWeakPtr()), | 400 weak_ptr_factory_.GetWeakPtr()), |
413 ProfileMetrics::ADD_NEW_USER_MANAGER); | 401 ProfileMetrics::ADD_NEW_USER_MANAGER); |
414 } | 402 } |
415 | 403 |
416 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( | 404 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( |
417 const base::ListValue* args) { | 405 const base::ListValue* args) { |
418 const base::Value* profile_path_value; | 406 const base::Value* profile_path_value; |
419 if (!args->Get(0, &profile_path_value)) | 407 if (!args->Get(0, &profile_path_value)) |
420 return; | 408 return; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 NOTREACHED(); | 476 NOTREACHED(); |
489 return; | 477 return; |
490 } | 478 } |
491 | 479 |
492 if (!profiles::IsMultipleProfilesEnabled()) { | 480 if (!profiles::IsMultipleProfilesEnabled()) { |
493 NOTREACHED(); | 481 NOTREACHED(); |
494 return; | 482 return; |
495 } | 483 } |
496 | 484 |
497 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 485 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
498 profile_path, | 486 profile_path, base::Bind(&OpenNewWindowForProfile)); |
499 base::Bind(&OpenNewWindowForProfile, desktop_type_)); | |
500 ProfileMetrics::LogProfileDeleteUser( | 487 ProfileMetrics::LogProfileDeleteUser( |
501 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); | 488 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); |
502 } | 489 } |
503 | 490 |
504 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { | 491 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { |
505 if (IsGuestModeEnabled()) { | 492 if (IsGuestModeEnabled()) { |
506 profiles::SwitchToGuestProfile( | 493 profiles::SwitchToGuestProfile( |
507 desktop_type_, | |
508 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 494 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
509 weak_ptr_factory_.GetWeakPtr())); | 495 weak_ptr_factory_.GetWeakPtr())); |
510 } else { | 496 } else { |
511 // The UI should have prevented the user from allowing the selection of | 497 // The UI should have prevented the user from allowing the selection of |
512 // guest mode. | 498 // guest mode. |
513 NOTREACHED(); | 499 NOTREACHED(); |
514 } | 500 } |
515 } | 501 } |
516 | 502 |
517 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 503 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
(...skipping 17 matching lines...) Expand all Loading... |
535 // It's possible that a user breaks into the user-manager page using the | 521 // It's possible that a user breaks into the user-manager page using the |
536 // JavaScript Inspector and causes a "locked" profile to call this | 522 // JavaScript Inspector and causes a "locked" profile to call this |
537 // unauthenticated version of "launch" instead of the proper one. Thus, | 523 // unauthenticated version of "launch" instead of the proper one. Thus, |
538 // we have to validate in (secure) C++ code that it really is a profile | 524 // we have to validate in (secure) C++ code that it really is a profile |
539 // not needing authentication. If it is, just ignore the "launch" request. | 525 // not needing authentication. If it is, just ignore the "launch" request. |
540 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) | 526 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) |
541 return; | 527 return; |
542 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); | 528 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); |
543 | 529 |
544 profiles::SwitchToProfile( | 530 profiles::SwitchToProfile( |
545 profile_path, | 531 profile_path, false, /* reuse any existing windows */ |
546 desktop_type_, | |
547 false, /* reuse any existing windows */ | |
548 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 532 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
549 weak_ptr_factory_.GetWeakPtr()), | 533 weak_ptr_factory_.GetWeakPtr()), |
550 ProfileMetrics::SWITCH_PROFILE_MANAGER); | 534 ProfileMetrics::SWITCH_PROFILE_MANAGER); |
551 } | 535 } |
552 | 536 |
553 void UserManagerScreenHandler::HandleAttemptUnlock( | 537 void UserManagerScreenHandler::HandleAttemptUnlock( |
554 const base::ListValue* args) { | 538 const base::ListValue* args) { |
555 std::string email; | 539 std::string email; |
556 CHECK(args->GetString(0, &email)); | 540 CHECK(args->GetString(0, &email)); |
557 GetScreenlockRouter(email) | 541 GetScreenlockRouter(email) |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 } | 923 } |
940 | 924 |
941 void UserManagerScreenHandler::ReportAuthenticationResult( | 925 void UserManagerScreenHandler::ReportAuthenticationResult( |
942 bool success, | 926 bool success, |
943 ProfileMetrics::ProfileAuth auth) { | 927 ProfileMetrics::ProfileAuth auth) { |
944 ProfileMetrics::LogProfileAuthResult(auth); | 928 ProfileMetrics::LogProfileAuthResult(auth); |
945 email_address_.clear(); | 929 email_address_.clear(); |
946 | 930 |
947 if (success) { | 931 if (success) { |
948 profiles::SwitchToProfile( | 932 profiles::SwitchToProfile( |
949 authenticating_profile_path_, | 933 authenticating_profile_path_, true, |
950 desktop_type_, | |
951 true, | |
952 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 934 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
953 weak_ptr_factory_.GetWeakPtr()), | 935 weak_ptr_factory_.GetWeakPtr()), |
954 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 936 ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
955 } else { | 937 } else { |
956 web_ui()->CallJavascriptFunction( | 938 web_ui()->CallJavascriptFunction( |
957 "cr.ui.Oobe.showSignInError", | 939 "cr.ui.Oobe.showSignInError", |
958 base::FundamentalValue(0), | 940 base::FundamentalValue(0), |
959 base::StringValue(l10n_util::GetStringUTF8( | 941 base::StringValue(l10n_util::GetStringUTF8( |
960 auth == ProfileMetrics::AUTH_FAILED_OFFLINE ? | 942 auth == ProfileMetrics::AUTH_FAILED_OFFLINE ? |
961 IDS_LOGIN_ERROR_AUTHENTICATING_OFFLINE : | 943 IDS_LOGIN_ERROR_AUTHENTICATING_OFFLINE : |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 Profile* profile, Profile::CreateStatus profile_create_status) { | 998 Profile* profile, Profile::CreateStatus profile_create_status) { |
1017 Browser* browser = chrome::FindAnyBrowser(profile, false); | 999 Browser* browser = chrome::FindAnyBrowser(profile, false); |
1018 if (browser && browser->window()) { | 1000 if (browser && browser->window()) { |
1019 OnBrowserWindowReady(browser); | 1001 OnBrowserWindowReady(browser); |
1020 } else { | 1002 } else { |
1021 registrar_.Add(this, | 1003 registrar_.Add(this, |
1022 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 1004 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
1023 content::NotificationService::AllSources()); | 1005 content::NotificationService::AllSources()); |
1024 } | 1006 } |
1025 } | 1007 } |
OLD | NEW |