Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/signin_create_profile_handler.h" | 5 #include "chrome/browser/ui/webui/signin/signin_create_profile_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 24 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/profiles/profile_metrics.h" | 26 #include "chrome/browser/profiles/profile_metrics.h" |
| 27 #include "chrome/browser/profiles/profiles_state.h" | 27 #include "chrome/browser/profiles/profiles_state.h" |
| 28 #include "chrome/browser/signin/signin_error_controller_factory.h" | 28 #include "chrome/browser/signin/signin_error_controller_factory.h" |
| 29 #include "chrome/browser/signin/signin_manager_factory.h" | 29 #include "chrome/browser/signin/signin_manager_factory.h" |
| 30 #include "chrome/browser/sync/profile_sync_service_factory.h" | 30 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 31 #include "chrome/browser/ui/browser_finder.h" | 31 #include "chrome/browser/ui/browser_finder.h" |
| 32 #include "chrome/browser/ui/user_manager.h" | 32 #include "chrome/browser/ui/user_manager.h" |
| 33 #include "chrome/browser/ui/webui/profile_helper.h" | 33 #include "chrome/browser/ui/webui/profile_helper.h" |
| 34 #include "chrome/browser/ui/webui/signin/signin_utils.h" | |
| 34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
| 36 #include "chrome/grit/chromium_strings.h" | 37 #include "chrome/grit/chromium_strings.h" |
| 37 #include "chrome/grit/generated_resources.h" | 38 #include "chrome/grit/generated_resources.h" |
| 38 #include "components/browser_sync/profile_sync_service.h" | 39 #include "components/browser_sync/profile_sync_service.h" |
| 39 #include "components/prefs/pref_service.h" | 40 #include "components/prefs/pref_service.h" |
| 40 #include "components/signin/core/browser/signin_error_controller.h" | 41 #include "components/signin/core/browser/signin_error_controller.h" |
| 41 #include "components/strings/grit/components_strings.h" | 42 #include "components/strings/grit/components_strings.h" |
| 42 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 shortcut_manager->CreateProfileShortcut(profile->GetPath()); | 360 shortcut_manager->CreateProfileShortcut(profile->GetPath()); |
| 360 } | 361 } |
| 361 | 362 |
| 362 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); | 363 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); |
| 363 profile_path_being_created_.clear(); | 364 profile_path_being_created_.clear(); |
| 364 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 365 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
| 365 base::DictionaryValue dict; | 366 base::DictionaryValue dict; |
| 366 dict.SetString("name", profile->GetPrefs()->GetString(prefs::kProfileName)); | 367 dict.SetString("name", profile->GetPrefs()->GetString(prefs::kProfileName)); |
| 367 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); | 368 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); |
| 368 | 369 |
| 369 bool open_new_window = true; | 370 bool is_force_signin_enabled = signin::IsForceSigninEnabled(); |
| 371 bool open_new_window = !is_force_signin_enabled; | |
| 370 | 372 |
| 371 #if defined(ENABLE_SUPERVISED_USERS) | 373 #if defined(ENABLE_SUPERVISED_USERS) |
| 372 // If the new profile is a supervised user, instead of opening a new window | 374 // If the new profile is a supervised user, instead of opening a new window |
| 373 // right away, a confirmation page will be shown by JS from the creation | 375 // right away, a confirmation page will be shown by JS from the creation |
| 374 // dialog. If we are importing an existing supervised profile or creating a | 376 // dialog. If we are importing an existing supervised profile or creating a |
| 375 // new non-supervised user profile we don't show any confirmation, so open | 377 // new non-supervised user profile we don't show any confirmation, so open |
| 376 // the new window now. | 378 // the new window now. |
| 377 open_new_window = profile_creation_type_ != SUPERVISED_PROFILE_CREATION; | 379 |
| 378 dict.SetBoolean("showConfirmation", !open_new_window); | 380 open_new_window = |
| 381 open_new_window && profile_creation_type_ != SUPERVISED_PROFILE_CREATION; | |
| 382 | |
| 383 dict.SetBoolean("showConfirmation", | |
| 384 profile_creation_type_ == SUPERVISED_PROFILE_CREATION); | |
| 379 | 385 |
| 380 bool is_supervised = profile_creation_type_ == SUPERVISED_PROFILE_CREATION || | 386 bool is_supervised = profile_creation_type_ == SUPERVISED_PROFILE_CREATION || |
| 381 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; | 387 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; |
| 382 dict.SetBoolean("isSupervised", is_supervised); | 388 dict.SetBoolean("isSupervised", is_supervised); |
| 383 | 389 |
| 384 if (is_supervised) { | 390 if (is_supervised) { |
| 385 DCHECK(custodian_profile); | 391 DCHECK(custodian_profile); |
| 386 if (custodian_profile) { | 392 if (custodian_profile) { |
| 387 std::string custodian_username = custodian_profile->GetProfileUserName(); | 393 std::string custodian_username = custodian_profile->GetProfileUserName(); |
| 388 dict.SetString("custodianUsername", custodian_username); | 394 dict.SetString("custodianUsername", custodian_username); |
| 389 } | 395 } |
| 390 } | 396 } |
| 391 #endif | 397 #endif |
| 392 | 398 |
| 393 web_ui()->CallJavascriptFunctionUnsafe( | 399 web_ui()->CallJavascriptFunctionUnsafe( |
| 394 "cr.webUIListenerCallback", | 400 "cr.webUIListenerCallback", |
| 395 GetWebUIListenerName(PROFILE_CREATION_SUCCESS), dict); | 401 GetWebUIListenerName(PROFILE_CREATION_SUCCESS), dict); |
| 396 | 402 |
| 397 if (open_new_window) { | 403 if (open_new_window) { |
| 398 // Opening the new window must be the last action, after all callbacks | 404 // Opening the new window must be the last action, after all callbacks |
| 399 // have been run, to give them a chance to initialize the profile. | 405 // have been run, to give them a chance to initialize the profile. |
| 400 OpenNewWindowForProfile(profile, Profile::CREATE_STATUS_INITIALIZED); | 406 OpenNewWindowForProfile(profile, Profile::CREATE_STATUS_INITIALIZED); |
| 407 } else if (is_force_signin_enabled) { | |
| 408 OpenSigninDialogForProfile(profile); | |
| 401 } | 409 } |
| 402 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 410 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
| 403 } | 411 } |
| 404 | 412 |
| 405 void SigninCreateProfileHandler::OpenNewWindowForProfile( | 413 void SigninCreateProfileHandler::OpenNewWindowForProfile( |
| 406 Profile* profile, | 414 Profile* profile, |
| 407 Profile::CreateStatus status) { | 415 Profile::CreateStatus status) { |
| 408 profiles::OpenBrowserWindowForProfile( | 416 profiles::OpenBrowserWindowForProfile( |
| 409 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, | 417 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, |
| 410 weak_ptr_factory_.GetWeakPtr()), | 418 weak_ptr_factory_.GetWeakPtr()), |
| 411 false, // Don't create a window if one already exists. | 419 false, // Don't create a window if one already exists. |
| 412 true, // Create a first run window. | 420 true, // Create a first run window. |
| 413 profile, | 421 profile, |
| 414 status); | 422 status); |
| 415 } | 423 } |
| 416 | 424 |
| 425 void SigninCreateProfileHandler::OpenSigninDialogForProfile(Profile* profile) { | |
| 426 // TODO(zmin): Remove the swither once the UserManager API is finished on Mac. | |
|
anthonyvd
2016/09/30 17:30:15
nit: typo in "swither"
zmin
2016/09/30 17:41:48
Done.
| |
| 427 #if !defined(OS_MACOSX) | |
| 428 UserManager::ShowSigninDialog(web_ui()->GetWebContents()->GetBrowserContext(), | |
| 429 profile->GetPath()); | |
| 430 #endif | |
| 431 } | |
| 432 | |
| 417 void SigninCreateProfileHandler::ShowProfileCreationError( | 433 void SigninCreateProfileHandler::ShowProfileCreationError( |
| 418 Profile* profile, | 434 Profile* profile, |
| 419 const base::string16& error) { | 435 const base::string16& error) { |
| 420 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 436 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
| 421 web_ui()->CallJavascriptFunctionUnsafe( | 437 web_ui()->CallJavascriptFunctionUnsafe( |
| 422 "cr.webUIListenerCallback", GetWebUIListenerName(PROFILE_CREATION_ERROR), | 438 "cr.webUIListenerCallback", GetWebUIListenerName(PROFILE_CREATION_ERROR), |
| 423 base::StringValue(error)); | 439 base::StringValue(error)); |
| 424 // The ProfileManager calls us back with a NULL profile in some cases. | 440 // The ProfileManager calls us back with a NULL profile in some cases. |
| 425 if (profile) { | 441 if (profile) { |
| 426 webui::DeleteProfileAtPath(profile->GetPath(), | 442 webui::DeleteProfileAtPath(profile->GetPath(), |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 | 805 |
| 790 profiles::OpenBrowserWindowForProfile( | 806 profiles::OpenBrowserWindowForProfile( |
| 791 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, | 807 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, |
| 792 weak_ptr_factory_.GetWeakPtr()), | 808 weak_ptr_factory_.GetWeakPtr()), |
| 793 false, // Don't create a window if one already exists. | 809 false, // Don't create a window if one already exists. |
| 794 true, // Create a first run window. | 810 true, // Create a first run window. |
| 795 profile, | 811 profile, |
| 796 Profile::CREATE_STATUS_INITIALIZED); | 812 Profile::CREATE_STATUS_INITIALIZED); |
| 797 } | 813 } |
| 798 #endif | 814 #endif |
| OLD | NEW |