| 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/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/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 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/profiles/profile_info_cache.h" | 21 #include "chrome/browser/profiles/profile_info_cache.h" |
| 22 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/browser/profiles/profile_metrics.h" | 23 #include "chrome/browser/profiles/profile_metrics.h" |
| 24 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
| 25 #include "chrome/browser/signin/signin_manager.h" | 25 #include "chrome/browser/signin/signin_manager.h" |
| 26 #include "chrome/browser/signin/signin_manager_factory.h" | 26 #include "chrome/browser/signin/signin_manager_factory.h" |
| 27 #include "chrome/browser/sync/profile_sync_service.h" | 27 #include "chrome/browser/sync/profile_sync_service.h" |
| 28 #include "chrome/browser/sync/profile_sync_service_factory.h" | 28 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 29 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
| 30 #include "chrome/browser/ui/browser_navigator.h" | 30 #include "chrome/browser/ui/browser_navigator.h" |
| 31 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| 31 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 32 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 33 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 33 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 34 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 34 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 35 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
| 35 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 36 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 37 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 38 #include "content/public/browser/render_view_host.h" | 39 #include "content/public/browser/render_view_host.h" |
| 39 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 40 #include "content/public/browser/web_contents_delegate.h" | 41 #include "content/public/browser/web_contents_delegate.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 181 |
| 181 bool AreUserNamesEqual(const string16& user1, const string16& user2) { | 182 bool AreUserNamesEqual(const string16& user1, const string16& user2) { |
| 182 return NormalizeUserName(user1) == NormalizeUserName(user2); | 183 return NormalizeUserName(user1) == NormalizeUserName(user2); |
| 183 } | 184 } |
| 184 | 185 |
| 185 bool IsKeystoreEncryptionEnabled() { | 186 bool IsKeystoreEncryptionEnabled() { |
| 186 return CommandLine::ForCurrentProcess()->HasSwitch( | 187 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 187 switches::kSyncKeystoreEncryption); | 188 switches::kSyncKeystoreEncryption); |
| 188 } | 189 } |
| 189 | 190 |
| 190 bool UseWebBasedSigninFlow() { | |
| 191 return CommandLine::ForCurrentProcess()->HasSwitch( | |
| 192 switches::kUseWebBasedSigninFlow); | |
| 193 } | |
| 194 | |
| 195 void BringTabToFront(WebContents* web_contents) { | 191 void BringTabToFront(WebContents* web_contents) { |
| 196 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 192 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 197 if (browser) { | 193 if (browser) { |
| 198 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 194 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
| 199 if (tab_strip_model) { | 195 if (tab_strip_model) { |
| 200 int index = tab_strip_model->GetIndexOfWebContents(web_contents); | 196 int index = tab_strip_model->GetIndexOfWebContents(web_contents); |
| 201 if (index != TabStripModel::kNoTab) | 197 if (index != TabStripModel::kNoTab) |
| 202 tab_strip_model->ActivateTabAt(index, false); | 198 tab_strip_model->ActivateTabAt(index, false); |
| 203 } | 199 } |
| 204 } | 200 } |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_DATA)); | 493 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_DATA)); |
| 498 } | 494 } |
| 499 } else { | 495 } else { |
| 500 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); | 496 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); |
| 501 } | 497 } |
| 502 | 498 |
| 503 StringValue page("configure"); | 499 StringValue page("configure"); |
| 504 web_ui()->CallJavascriptFunction( | 500 web_ui()->CallJavascriptFunction( |
| 505 "SyncSetupOverlay.showSyncSetupPage", page, args); | 501 "SyncSetupOverlay.showSyncSetupPage", page, args); |
| 506 | 502 |
| 507 if (UseWebBasedSigninFlow()) { | 503 if (OneClickSigninHelper::UseWebBasedSigninFlow()) { |
| 508 // Make sure the tab used for the Gaia sign in does not cover this tab. | 504 // Make sure the tab used for the Gaia sign in does not cover this tab. |
| 509 FocusUI(); | 505 FocusUI(); |
| 510 } | 506 } |
| 511 } | 507 } |
| 512 | 508 |
| 513 void SyncSetupHandler::ConfigureSyncDone() { | 509 void SyncSetupHandler::ConfigureSyncDone() { |
| 514 StringValue page("done"); | 510 StringValue page("done"); |
| 515 web_ui()->CallJavascriptFunction( | 511 web_ui()->CallJavascriptFunction( |
| 516 "SyncSetupOverlay.showSyncSetupPage", page); | 512 "SyncSetupOverlay.showSyncSetupPage", page); |
| 517 | 513 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", | 574 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", |
| 579 base::Bind(&SyncSetupHandler::HandleStopSyncing, | 575 base::Bind(&SyncSetupHandler::HandleStopSyncing, |
| 580 base::Unretained(this))); | 576 base::Unretained(this))); |
| 581 } | 577 } |
| 582 | 578 |
| 583 SigninManager* SyncSetupHandler::GetSignin() const { | 579 SigninManager* SyncSetupHandler::GetSignin() const { |
| 584 return SigninManagerFactory::GetForProfile(GetProfile()); | 580 return SigninManagerFactory::GetForProfile(GetProfile()); |
| 585 } | 581 } |
| 586 | 582 |
| 587 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { | 583 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { |
| 588 if (UseWebBasedSigninFlow()) { | 584 if (OneClickSigninHelper::UseWebBasedSigninFlow()) { |
| 589 DCHECK(!active_gaia_signin_tab_); | 585 DCHECK(!active_gaia_signin_tab_); |
| 590 | 586 |
| 591 // We are no longer configuring sync if the login screen is visible. | 587 // We are no longer configuring sync if the login screen is visible. |
| 592 // If the user exits the signin wizard after this without configuring sync, | 588 // If the user exits the signin wizard after this without configuring sync, |
| 593 // CloseSyncSetup() will ensure they are logged out. | 589 // CloseSyncSetup() will ensure they are logged out. |
| 594 configuring_sync_ = false; | 590 configuring_sync_ = false; |
| 595 | 591 |
| 596 GURL url(SyncPromoUI::GetSyncPromoURL(GURL(), | 592 GURL url(SyncPromoUI::GetSyncPromoURL(GURL(), |
| 597 SyncPromoUI::SOURCE_SETTINGS, false)); | 593 SyncPromoUI::SOURCE_SETTINGS, false)); |
| 598 Browser* browser = chrome::FindBrowserWithWebContents( | 594 Browser* browser = chrome::FindBrowserWithWebContents( |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 } | 830 } |
| 835 | 831 |
| 836 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { | 832 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { |
| 837 // Stop a timer to handle timeout in waiting for checking network connection. | 833 // Stop a timer to handle timeout in waiting for checking network connection. |
| 838 backend_start_timer_.reset(); | 834 backend_start_timer_.reset(); |
| 839 | 835 |
| 840 last_signin_error_ = error; | 836 last_signin_error_ = error; |
| 841 | 837 |
| 842 // If using web-based sign in flow, don't show the gaia sign in page again | 838 // If using web-based sign in flow, don't show the gaia sign in page again |
| 843 // since there is no way to show the user an error message. | 839 // since there is no way to show the user an error message. |
| 844 if (UseWebBasedSigninFlow()) { | 840 if (OneClickSigninHelper::UseWebBasedSigninFlow()) { |
| 845 CloseSyncSetup(); | 841 CloseSyncSetup(); |
| 846 } else { | 842 } else { |
| 847 // Got a failed signin - this is either just a typical auth error, or a | 843 // Got a failed signin - this is either just a typical auth error, or a |
| 848 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). | 844 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). |
| 849 // On ChromeOS, this condition can happen when auth token is invalid and | 845 // On ChromeOS, this condition can happen when auth token is invalid and |
| 850 // cannot start sync backend. | 846 // cannot start sync backend. |
| 851 // If using web-based sign in flow, don't show the gaia sign in page again | 847 // If using web-based sign in flow, don't show the gaia sign in page again |
| 852 // since there is no way to show the user an error message. | 848 // since there is no way to show the user an error message. |
| 853 if (retry_on_signin_failure_) { | 849 if (retry_on_signin_failure_) { |
| 854 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); | 850 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 } else if (configuring_sync_) { | 1043 } else if (configuring_sync_) { |
| 1048 ProfileSyncService::SyncEvent( | 1044 ProfileSyncService::SyncEvent( |
| 1049 ProfileSyncService::CANCEL_DURING_CONFIGURE); | 1045 ProfileSyncService::CANCEL_DURING_CONFIGURE); |
| 1050 } else { | 1046 } else { |
| 1051 ProfileSyncService::SyncEvent( | 1047 ProfileSyncService::SyncEvent( |
| 1052 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); | 1048 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); |
| 1053 } | 1049 } |
| 1054 } | 1050 } |
| 1055 | 1051 |
| 1056 // Let the various services know that we're no longer active. | 1052 // Let the various services know that we're no longer active. |
| 1057 if (UseWebBasedSigninFlow()) | 1053 if (OneClickSigninHelper::UseWebBasedSigninFlow()) |
| 1058 CloseGaiaSigninPage(); | 1054 CloseGaiaSigninPage(); |
| 1059 | 1055 |
| 1060 GetLoginUIService()->LoginUIClosed(this); | 1056 GetLoginUIService()->LoginUIClosed(this); |
| 1061 } | 1057 } |
| 1062 | 1058 |
| 1063 if (sync_service) { | 1059 if (sync_service) { |
| 1064 // Make sure user isn't left half-logged-in (signed in, but without sync | 1060 // Make sure user isn't left half-logged-in (signed in, but without sync |
| 1065 // started up). If the user hasn't finished setting up sync, then sign out | 1061 // started up). If the user hasn't finished setting up sync, then sign out |
| 1066 // and shut down sync. | 1062 // and shut down sync. |
| 1067 if (!sync_service->HasSyncSetupCompleted()) { | 1063 if (!sync_service->HasSyncSetupCompleted()) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 // User is not logged in, or login has been specially requested - need to | 1108 // User is not logged in, or login has been specially requested - need to |
| 1113 // display login UI (cases 1-4). | 1109 // display login UI (cases 1-4). |
| 1114 DisplayGaiaLogin(false); | 1110 DisplayGaiaLogin(false); |
| 1115 } else { | 1111 } else { |
| 1116 // User is already logged in. They must have brought up the config wizard | 1112 // User is already logged in. They must have brought up the config wizard |
| 1117 // via the "Advanced..." button or through One-Click signin (cases 5/6), or | 1113 // via the "Advanced..." button or through One-Click signin (cases 5/6), or |
| 1118 // they are re-enabling sync on Chrome OS. | 1114 // they are re-enabling sync on Chrome OS. |
| 1119 DisplayConfigureSync(true, false); | 1115 DisplayConfigureSync(true, false); |
| 1120 } | 1116 } |
| 1121 | 1117 |
| 1122 if (!UseWebBasedSigninFlow()) | 1118 if (!OneClickSigninHelper::UseWebBasedSigninFlow()) |
| 1123 ShowSetupUI(); | 1119 ShowSetupUI(); |
| 1124 } | 1120 } |
| 1125 | 1121 |
| 1126 void SyncSetupHandler::OpenConfigureSync() { | 1122 void SyncSetupHandler::OpenConfigureSync() { |
| 1127 if (!PrepareSyncSetup()) | 1123 if (!PrepareSyncSetup()) |
| 1128 return; | 1124 return; |
| 1129 | 1125 |
| 1130 DisplayConfigureSync(true, false); | 1126 DisplayConfigureSync(true, false); |
| 1131 ShowSetupUI(); | 1127 ShowSetupUI(); |
| 1132 } | 1128 } |
| 1133 | 1129 |
| 1134 void SyncSetupHandler::FocusUI() { | 1130 void SyncSetupHandler::FocusUI() { |
| 1135 DCHECK(IsActiveLogin()); | 1131 DCHECK(IsActiveLogin()); |
| 1136 // In the case of the web-based sign in flow, |configuring_sync_| true means | 1132 // In the case of the web-based sign in flow, |configuring_sync_| true means |
| 1137 // we are focusing to bring the configure popup window to the top, not the | 1133 // we are focusing to bring the configure popup window to the top, not the |
| 1138 // Gaia sign in page. | 1134 // Gaia sign in page. |
| 1139 if (UseWebBasedSigninFlow() && !configuring_sync_) { | 1135 if (OneClickSigninHelper::UseWebBasedSigninFlow() && !configuring_sync_) { |
| 1140 BringTabToFront(active_gaia_signin_tab_); | 1136 BringTabToFront(active_gaia_signin_tab_); |
| 1141 } else { | 1137 } else { |
| 1142 WebContents* web_contents = web_ui()->GetWebContents(); | 1138 WebContents* web_contents = web_ui()->GetWebContents(); |
| 1143 web_contents->GetDelegate()->ActivateContents(web_contents); | 1139 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 1144 } | 1140 } |
| 1145 } | 1141 } |
| 1146 | 1142 |
| 1147 void SyncSetupHandler::CloseUI() { | 1143 void SyncSetupHandler::CloseUI() { |
| 1148 DCHECK(IsActiveLogin()); | 1144 DCHECK(IsActiveLogin()); |
| 1149 CloseOverlay(); | 1145 CloseOverlay(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 if (i != current_profile_index && AreUserNamesEqual( | 1223 if (i != current_profile_index && AreUserNamesEqual( |
| 1228 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 1224 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
| 1229 *error_message = l10n_util::GetStringUTF16( | 1225 *error_message = l10n_util::GetStringUTF16( |
| 1230 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 1226 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
| 1231 return false; | 1227 return false; |
| 1232 } | 1228 } |
| 1233 } | 1229 } |
| 1234 | 1230 |
| 1235 return true; | 1231 return true; |
| 1236 } | 1232 } |
| OLD | NEW |