Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/options/sync_setup_handler.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 35 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 36 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
| 38 #include "chrome/grit/chromium_strings.h" | 38 #include "chrome/grit/chromium_strings.h" |
| 39 #include "chrome/grit/generated_resources.h" | 39 #include "chrome/grit/generated_resources.h" |
| 40 #include "chrome/grit/locale_settings.h" | 40 #include "chrome/grit/locale_settings.h" |
| 41 #include "components/browser_sync/browser/profile_sync_service.h" | 41 #include "components/browser_sync/browser/profile_sync_service.h" |
| 42 #include "components/google/core/browser/google_util.h" | 42 #include "components/google/core/browser/google_util.h" |
| 43 #include "components/signin/core/browser/signin_error_controller.h" | 43 #include "components/signin/core/browser/signin_error_controller.h" |
| 44 #include "components/signin/core/browser/signin_header_helper.h" | 44 #include "components/signin/core/browser/signin_header_helper.h" |
| 45 #include "components/signin/core/browser/signin_metrics.h" | |
| 46 #include "components/signin/core/common/profile_management_switches.h" | 45 #include "components/signin/core/common/profile_management_switches.h" |
| 47 #include "components/sync_driver/sync_prefs.h" | 46 #include "components/sync_driver/sync_prefs.h" |
| 48 #include "content/public/browser/render_view_host.h" | 47 #include "content/public/browser/render_view_host.h" |
| 49 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
| 50 #include "content/public/browser/web_contents_delegate.h" | 49 #include "content/public/browser/web_contents_delegate.h" |
| 51 #include "google_apis/gaia/gaia_auth_util.h" | 50 #include "google_apis/gaia/gaia_auth_util.h" |
| 52 #include "google_apis/gaia/gaia_constants.h" | 51 #include "google_apis/gaia/gaia_constants.h" |
| 53 #include "grit/components_strings.h" | 52 #include "grit/components_strings.h" |
| 54 #include "net/base/url_util.h" | 53 #include "net/base/url_util.h" |
| 55 #include "ui/base/l10n/l10n_util.h" | 54 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", | 327 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", |
| 329 base::Bind(&SyncSetupHandler::HandleStopSyncing, | 328 base::Bind(&SyncSetupHandler::HandleStopSyncing, |
| 330 base::Unretained(this))); | 329 base::Unretained(this))); |
| 331 web_ui()->RegisterMessageCallback("SyncSetupStartSignIn", | 330 web_ui()->RegisterMessageCallback("SyncSetupStartSignIn", |
| 332 base::Bind(&SyncSetupHandler::HandleStartSignin, | 331 base::Bind(&SyncSetupHandler::HandleStartSignin, |
| 333 base::Unretained(this))); | 332 base::Unretained(this))); |
| 334 #endif | 333 #endif |
| 335 } | 334 } |
| 336 | 335 |
| 337 #if !defined(OS_CHROMEOS) | 336 #if !defined(OS_CHROMEOS) |
| 338 void SyncSetupHandler::DisplayGaiaLogin() { | 337 void SyncSetupHandler::DisplayGaiaLogin( |
| 338 signin_metrics::AccessPoint access_point) { | |
| 339 DCHECK(!sync_startup_tracker_); | 339 DCHECK(!sync_startup_tracker_); |
| 340 // Advanced options are no longer being configured if the login screen is | 340 // Advanced options are no longer being configured if the login screen is |
| 341 // visible. If the user exits the signin wizard after this without | 341 // visible. If the user exits the signin wizard after this without |
| 342 // configuring sync, CloseSyncSetup() will ensure they are logged out. | 342 // configuring sync, CloseSyncSetup() will ensure they are logged out. |
| 343 configuring_sync_ = false; | 343 configuring_sync_ = false; |
| 344 DisplayGaiaLoginInNewTabOrWindow(); | 344 DisplayGaiaLoginInNewTabOrWindow(access_point); |
| 345 } | 345 } |
| 346 | 346 |
| 347 void SyncSetupHandler::DisplayGaiaLoginInNewTabOrWindow() { | 347 void SyncSetupHandler::DisplayGaiaLoginInNewTabOrWindow( |
| 348 signin_metrics::AccessPoint access_point) { | |
| 348 Browser* browser = chrome::FindBrowserWithWebContents( | 349 Browser* browser = chrome::FindBrowserWithWebContents( |
| 349 web_ui()->GetWebContents()); | 350 web_ui()->GetWebContents()); |
| 350 bool force_new_tab = false; | 351 bool force_new_tab = false; |
| 351 if (!browser) { | 352 if (!browser) { |
| 352 // Settings is not displayed in a browser window. Open a new window. | 353 // Settings is not displayed in a browser window. Open a new window. |
| 353 browser = new Browser(Browser::CreateParams( | 354 browser = new Browser(Browser::CreateParams( |
| 354 Browser::TYPE_TABBED, GetProfile(), chrome::GetActiveDesktop())); | 355 Browser::TYPE_TABBED, GetProfile(), chrome::GetActiveDesktop())); |
| 355 force_new_tab = true; | 356 force_new_tab = true; |
| 356 } | 357 } |
| 357 | 358 |
| 358 // If the signin manager already has an authenticated username, this is a | 359 // If the signin manager already has an authenticated username, this is a |
| 359 // re-auth scenario, and we need to ensure that the user signs in with the | 360 // re-auth scenario, and we need to ensure that the user signs in with the |
| 360 // same email address. | 361 // same email address. |
| 361 GURL url; | 362 GURL url; |
| 362 if (SigninManagerFactory::GetForProfile( | 363 if (SigninManagerFactory::GetForProfile( |
| 363 browser->profile())->IsAuthenticated()) { | 364 browser->profile())->IsAuthenticated()) { |
| 364 UMA_HISTOGRAM_ENUMERATION("Signin.Reauth", | 365 UMA_HISTOGRAM_ENUMERATION("Signin.Reauth", |
| 365 signin_metrics::HISTOGRAM_REAUTH_SHOWN, | 366 signin_metrics::HISTOGRAM_REAUTH_SHOWN, |
| 366 signin_metrics::HISTOGRAM_REAUTH_MAX); | 367 signin_metrics::HISTOGRAM_REAUTH_MAX); |
| 367 | 368 |
| 368 SigninErrorController* error_controller = | 369 SigninErrorController* error_controller = |
| 369 SigninErrorControllerFactory::GetForProfile(browser->profile()); | 370 SigninErrorControllerFactory::GetForProfile(browser->profile()); |
| 370 DCHECK(error_controller->HasError()); | 371 DCHECK(error_controller->HasError()); |
| 371 if (!force_new_tab) { | 372 if (!force_new_tab) { |
| 372 browser->window()->ShowAvatarBubbleFromAvatarButton( | 373 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 373 BrowserWindow::AVATAR_BUBBLE_MODE_REAUTH, | 374 BrowserWindow::AVATAR_BUBBLE_MODE_REAUTH, |
| 374 signin::ManageAccountsParams()); | 375 signin::ManageAccountsParams(), access_point); |
| 375 } else { | 376 } else { |
| 376 url = signin::GetReauthURL(browser->profile(), | 377 url = signin::GetReauthURL( |
| 377 error_controller->error_account_id()); | 378 access_point, signin_metrics::REASON_REAUTHENTICATION, |
| 379 browser->profile(), error_controller->error_account_id()); | |
| 378 } | 380 } |
| 379 } else { | 381 } else { |
| 380 signin_metrics::LogSigninSource(signin_metrics::SOURCE_SETTINGS); | |
| 381 if (!force_new_tab) { | 382 if (!force_new_tab) { |
| 382 browser->window()->ShowAvatarBubbleFromAvatarButton( | 383 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 383 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN, | 384 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN, |
| 384 signin::ManageAccountsParams()); | 385 signin::ManageAccountsParams(), access_point); |
| 385 } else { | 386 } else { |
| 386 url = signin::GetPromoURL(signin_metrics::SOURCE_SETTINGS, true); | 387 url = signin::GetPromoURL( |
| 388 access_point, signin_metrics::REASON_SIGNIN_PRIMARY_ACCOUNT, true); | |
| 387 } | 389 } |
| 388 } | 390 } |
| 389 | 391 |
| 390 if (url.is_valid()) | 392 if (url.is_valid()) |
| 391 chrome::ShowSingletonTab(browser, url); | 393 chrome::ShowSingletonTab(browser, url); |
| 392 } | 394 } |
| 393 #endif | 395 #endif |
| 394 | 396 |
| 395 bool SyncSetupHandler::PrepareSyncSetup() { | 397 bool SyncSetupHandler::PrepareSyncSetup() { |
| 396 // If the wizard is already visible, just focus that one. | 398 // If the wizard is already visible, just focus that one. |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 // blank setup overlay on this page by showing the "done" page. This can | 623 // blank setup overlay on this page by showing the "done" page. This can |
| 622 // happen if the user navigates to chrome://settings/syncSetup in more than | 624 // happen if the user navigates to chrome://settings/syncSetup in more than |
| 623 // one tab. See crbug.com/261566. | 625 // one tab. See crbug.com/261566. |
| 624 // Note: The following block will transfer focus to the existing wizard. | 626 // Note: The following block will transfer focus to the existing wizard. |
| 625 if (IsExistingWizardPresent() && !IsActiveLogin()) | 627 if (IsExistingWizardPresent() && !IsActiveLogin()) |
| 626 CloseUI(); | 628 CloseUI(); |
| 627 | 629 |
| 628 // If a setup wizard is present on this page or another, bring it to focus. | 630 // If a setup wizard is present on this page or another, bring it to focus. |
| 629 // Otherwise, display a new one on this page. | 631 // Otherwise, display a new one on this page. |
| 630 if (!FocusExistingWizardIfPresent()) | 632 if (!FocusExistingWizardIfPresent()) |
| 631 OpenSyncSetup(); | 633 OpenSyncSetup(args); |
| 632 } | 634 } |
| 633 | 635 |
| 634 #if defined(OS_CHROMEOS) | 636 #if defined(OS_CHROMEOS) |
| 635 // On ChromeOS, we need to sign out the user session to fix an auth error, so | 637 // On ChromeOS, we need to sign out the user session to fix an auth error, so |
| 636 // the user goes through the real signin flow to generate a new auth token. | 638 // the user goes through the real signin flow to generate a new auth token. |
| 637 void SyncSetupHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { | 639 void SyncSetupHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { |
| 638 DVLOG(1) << "Signing out the user to fix a sync error."; | 640 DVLOG(1) << "Signing out the user to fix a sync error."; |
| 639 chrome::AttemptUserExit(); | 641 chrome::AttemptUserExit(); |
| 640 } | 642 } |
| 641 #endif | 643 #endif |
| 642 | 644 |
| 643 #if !defined(OS_CHROMEOS) | 645 #if !defined(OS_CHROMEOS) |
| 644 void SyncSetupHandler::HandleStartSignin(const base::ListValue* args) { | 646 void SyncSetupHandler::HandleStartSignin(const base::ListValue* args) { |
| 645 // Should only be called if the user is not already signed in. | 647 // Should only be called if the user is not already signed in. |
| 646 DCHECK(!SigninManagerFactory::GetForProfile(GetProfile())-> | 648 DCHECK(!SigninManagerFactory::GetForProfile(GetProfile())-> |
| 647 IsAuthenticated()); | 649 IsAuthenticated()); |
| 648 OpenSyncSetup(); | 650 OpenSyncSetup(args); |
| 649 } | 651 } |
| 650 | 652 |
| 651 void SyncSetupHandler::HandleStopSyncing(const base::ListValue* args) { | 653 void SyncSetupHandler::HandleStopSyncing(const base::ListValue* args) { |
| 652 if (GetSyncService()) | 654 if (GetSyncService()) |
| 653 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); | 655 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); |
| 654 SigninManagerFactory::GetForProfile(GetProfile())->SignOut( | 656 SigninManagerFactory::GetForProfile(GetProfile())->SignOut( |
| 655 signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); | 657 signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); |
| 656 | 658 |
| 657 bool delete_profile = false; | 659 bool delete_profile = false; |
| 658 if (args->GetBoolean(0, &delete_profile) && delete_profile) { | 660 if (args->GetBoolean(0, &delete_profile) && delete_profile) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 | 712 |
| 711 // Alert the sync service anytime the sync setup dialog is closed. This can | 713 // Alert the sync service anytime the sync setup dialog is closed. This can |
| 712 // happen due to the user clicking the OK or Cancel button, or due to the | 714 // happen due to the user clicking the OK or Cancel button, or due to the |
| 713 // dialog being closed by virtue of sync being disabled in the background. | 715 // dialog being closed by virtue of sync being disabled in the background. |
| 714 if (sync_service) | 716 if (sync_service) |
| 715 sync_service->SetSetupInProgress(false); | 717 sync_service->SetSetupInProgress(false); |
| 716 | 718 |
| 717 configuring_sync_ = false; | 719 configuring_sync_ = false; |
| 718 } | 720 } |
| 719 | 721 |
| 720 void SyncSetupHandler::OpenSyncSetup() { | 722 void SyncSetupHandler::OpenSyncSetup(const base::ListValue* args) { |
| 721 if (!PrepareSyncSetup()) | 723 if (!PrepareSyncSetup()) |
| 722 return; | 724 return; |
| 723 | 725 |
| 724 // There are several different UI flows that can bring the user here: | 726 // There are several different UI flows that can bring the user here: |
| 725 // 1) Signin promo. | 727 // 1) Signin promo. |
| 726 // 2) Normal signin through settings page (IsAuthenticated() is false). | 728 // 2) Normal signin through settings page (IsAuthenticated() is false). |
| 727 // 3) Previously working credentials have expired. | 729 // 3) Previously working credentials have expired. |
| 728 // 4) User is signed in, but has stopped sync via the google dashboard, and | 730 // 4) User is signed in, but has stopped sync via the google dashboard, and |
| 729 // signout is prohibited by policy so we need to force a re-auth. | 731 // signout is prohibited by policy so we need to force a re-auth. |
| 730 // 5) User clicks [Advanced Settings] button on options page while already | 732 // 5) User clicks [Advanced Settings] button on options page while already |
| 731 // logged in. | 733 // logged in. |
| 732 // 6) One-click signin (credentials are already available, so should display | 734 // 6) One-click signin (credentials are already available, so should display |
| 733 // sync configure UI, not login UI). | 735 // sync configure UI, not login UI). |
| 734 // 7) User re-enables sync after disabling it via advanced settings. | 736 // 7) User re-enables sync after disabling it via advanced settings. |
| 735 #if !defined(OS_CHROMEOS) | 737 #if !defined(OS_CHROMEOS) |
| 736 SigninManagerBase* signin = | 738 SigninManagerBase* signin = |
| 737 SigninManagerFactory::GetForProfile(GetProfile()); | 739 SigninManagerFactory::GetForProfile(GetProfile()); |
| 738 | 740 |
| 739 if (!signin->IsAuthenticated() || | 741 if (!signin->IsAuthenticated() || |
| 740 SigninErrorControllerFactory::GetForProfile(GetProfile())->HasError()) { | 742 SigninErrorControllerFactory::GetForProfile(GetProfile())->HasError()) { |
| 741 // User is not logged in (cases 1-2), or login has been specially requested | 743 // User is not logged in (cases 1-2), or login has been specially requested |
| 742 // because previously working credentials have expired (case 3). Close sync | 744 // because previously working credentials have expired (case 3). Close sync |
| 743 // setup including any visible overlays, and display the gaia auth page. | 745 // setup including any visible overlays, and display the gaia auth page. |
| 744 // Control will be returned to the sync settings page once auth is complete. | 746 // Control will be returned to the sync settings page once auth is complete. |
| 745 CloseUI(); | 747 CloseUI(); |
| 746 DisplayGaiaLogin(); | 748 if (args != NULL) { |
|
Bernhard Bauer
2015/12/04 11:06:24
Just do `if (args)` directly.
gogerald1
2015/12/04 20:49:09
Done.
| |
| 749 std::string access_point = base::UTF16ToUTF8(ExtractStringValue(args)); | |
| 750 if (access_point == "access-point-supervised-user") { | |
| 751 DisplayGaiaLogin(signin_metrics::ACCESS_POINT_SUPERVISED_USER); | |
| 752 return; | |
| 753 } | |
| 754 } | |
| 755 DisplayGaiaLogin(signin_metrics::ACCESS_POINT_SETTINGS); | |
| 747 return; | 756 return; |
| 748 } | 757 } |
| 749 #endif | 758 #endif |
| 750 if (!GetSyncService()) { | 759 if (!GetSyncService()) { |
| 751 // This can happen if the user directly navigates to /settings/syncSetup. | 760 // This can happen if the user directly navigates to /settings/syncSetup. |
| 752 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; | 761 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; |
| 753 CloseUI(); | 762 CloseUI(); |
| 754 return; | 763 return; |
| 755 } | 764 } |
| 756 | 765 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 919 "SyncSetupOverlay.showSyncSetupPage", page, args); | 928 "SyncSetupOverlay.showSyncSetupPage", page, args); |
| 920 | 929 |
| 921 // Make sure the tab used for the Gaia sign in does not cover the settings | 930 // Make sure the tab used for the Gaia sign in does not cover the settings |
| 922 // tab. | 931 // tab. |
| 923 FocusUI(); | 932 FocusUI(); |
| 924 } | 933 } |
| 925 | 934 |
| 926 LoginUIService* SyncSetupHandler::GetLoginUIService() const { | 935 LoginUIService* SyncSetupHandler::GetLoginUIService() const { |
| 927 return LoginUIServiceFactory::GetForProfile(GetProfile()); | 936 return LoginUIServiceFactory::GetForProfile(GetProfile()); |
| 928 } | 937 } |
| OLD | NEW |