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/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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 | 180 |
| 181 bool AreUserNamesEqual(const string16& user1, const string16& user2) { | 181 bool AreUserNamesEqual(const string16& user1, const string16& user2) { |
| 182 return NormalizeUserName(user1) == NormalizeUserName(user2); | 182 return NormalizeUserName(user1) == NormalizeUserName(user2); |
| 183 } | 183 } |
| 184 | 184 |
| 185 bool IsKeystoreEncryptionEnabled() { | 185 bool IsKeystoreEncryptionEnabled() { |
| 186 return CommandLine::ForCurrentProcess()->HasSwitch( | 186 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 187 switches::kSyncKeystoreEncryption); | 187 switches::kSyncKeystoreEncryption); |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool UseWebBasedSigninFlow() { | |
| 191 return CommandLine::ForCurrentProcess()->HasSwitch( | |
| 192 switches::kUseWebBasedSigninFlow); | |
| 193 } | |
| 194 | |
| 195 void BringTabToFront(WebContents* web_contents) { | 190 void BringTabToFront(WebContents* web_contents) { |
| 196 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 191 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 197 if (browser) { | 192 if (browser) { |
| 198 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 193 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
| 199 if (tab_strip_model) { | 194 if (tab_strip_model) { |
| 200 int index = tab_strip_model->GetIndexOfWebContents(web_contents); | 195 int index = tab_strip_model->GetIndexOfWebContents(web_contents); |
| 201 if (index != TabStripModel::kNoTab) | 196 if (index != TabStripModel::kNoTab) |
| 202 tab_strip_model->ActivateTabAt(index, false); | 197 tab_strip_model->ActivateTabAt(index, false); |
| 203 } | 198 } |
| 204 } | 199 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_DATA)); | 490 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_DATA)); |
| 496 } | 491 } |
| 497 } else { | 492 } else { |
| 498 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); | 493 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); |
| 499 } | 494 } |
| 500 | 495 |
| 501 StringValue page("configure"); | 496 StringValue page("configure"); |
| 502 web_ui()->CallJavascriptFunction( | 497 web_ui()->CallJavascriptFunction( |
| 503 "SyncSetupOverlay.showSyncSetupPage", page, args); | 498 "SyncSetupOverlay.showSyncSetupPage", page, args); |
| 504 | 499 |
| 505 if (UseWebBasedSigninFlow()) { | 500 if (SyncPromoUI::UseWebBasedSigninFlow()) { |
| 506 // Make sure the tab used for the Gaia sign in does not cover the settings | 501 // Make sure the tab used for the Gaia sign in does not cover the settings |
| 507 // tab. | 502 // tab. |
| 508 FocusUI(); | 503 FocusUI(); |
| 509 } | 504 } |
| 510 } | 505 } |
| 511 | 506 |
| 512 void SyncSetupHandler::ConfigureSyncDone() { | 507 void SyncSetupHandler::ConfigureSyncDone() { |
| 513 StringValue page("done"); | 508 StringValue page("done"); |
| 514 web_ui()->CallJavascriptFunction( | 509 web_ui()->CallJavascriptFunction( |
| 515 "SyncSetupOverlay.showSyncSetupPage", page); | 510 "SyncSetupOverlay.showSyncSetupPage", page); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", | 571 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", |
| 577 base::Bind(&SyncSetupHandler::HandleStopSyncing, | 572 base::Bind(&SyncSetupHandler::HandleStopSyncing, |
| 578 base::Unretained(this))); | 573 base::Unretained(this))); |
| 579 } | 574 } |
| 580 | 575 |
| 581 SigninManager* SyncSetupHandler::GetSignin() const { | 576 SigninManager* SyncSetupHandler::GetSignin() const { |
| 582 return SigninManagerFactory::GetForProfile(GetProfile()); | 577 return SigninManagerFactory::GetForProfile(GetProfile()); |
| 583 } | 578 } |
| 584 | 579 |
| 585 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { | 580 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { |
| 586 if (UseWebBasedSigninFlow()) { | 581 if (SyncPromoUI::UseWebBasedSigninFlow()) { |
| 587 DCHECK(!active_gaia_signin_tab_); | |
| 588 | |
| 589 // Advanced options are no longer being configured if the login screen is | 582 // Advanced options are no longer being configured if the login screen is |
| 590 // visible. If the user exits the signin wizard after this without | 583 // visible. If the user exits the signin wizard after this without |
| 591 // configuring sync, CloseSyncSetup() will ensure they are logged out. | 584 // configuring sync, CloseSyncSetup() will ensure they are logged out. |
| 592 configuring_sync_ = false; | 585 configuring_sync_ = false; |
| 593 | 586 |
| 594 GURL url(SyncPromoUI::GetSyncPromoURL(GURL(), | 587 DisplayGaiaLoginInNewTab(); |
| 595 SyncPromoUI::SOURCE_SETTINGS, false)); | |
| 596 Browser* browser = chrome::FindBrowserWithWebContents( | |
| 597 web_ui()->GetWebContents()); | |
| 598 active_gaia_signin_tab_ = browser->OpenURL( | |
| 599 content::OpenURLParams(url, content::Referrer(), SINGLETON_TAB, | |
| 600 content::PAGE_TRANSITION_AUTO_BOOKMARK, | |
| 601 false)); | |
| 602 content::WebContentsObserver::Observe(active_gaia_signin_tab_); | |
| 603 signin_tracker_.reset( | 588 signin_tracker_.reset( |
| 604 new SigninTracker(GetProfile(), this, | 589 new SigninTracker(GetProfile(), this, |
| 605 SigninTracker::WAITING_FOR_GAIA_VALIDATION)); | 590 SigninTracker::WAITING_FOR_GAIA_VALIDATION)); |
| 606 } else { | 591 } else { |
| 607 retry_on_signin_failure_ = true; | 592 retry_on_signin_failure_ = true; |
| 608 DisplayGaiaLoginWithErrorMessage(string16(), fatal_error); | 593 DisplayGaiaLoginWithErrorMessage(string16(), fatal_error); |
| 609 } | 594 } |
| 610 } | 595 } |
| 611 | 596 |
| 597 void SyncSetupHandler::DisplayGaiaLoginInNewTab() { | |
| 598 DCHECK(!active_gaia_signin_tab_); | |
| 599 GURL url(SyncPromoUI::GetSyncPromoURL(GURL(), | |
| 600 SyncPromoUI::SOURCE_SETTINGS, false)); | |
| 601 Browser* browser = chrome::FindBrowserWithWebContents( | |
| 602 web_ui()->GetWebContents()); | |
| 603 active_gaia_signin_tab_ = browser->OpenURL( | |
| 604 content::OpenURLParams(url, content::Referrer(), SINGLETON_TAB, | |
| 605 content::PAGE_TRANSITION_AUTO_BOOKMARK, | |
| 606 false)); | |
| 607 content::WebContentsObserver::Observe(active_gaia_signin_tab_); | |
| 608 } | |
| 609 | |
| 612 void SyncSetupHandler::DisplayGaiaLoginWithErrorMessage( | 610 void SyncSetupHandler::DisplayGaiaLoginWithErrorMessage( |
| 613 const string16& error_message, bool fatal_error) { | 611 const string16& error_message, bool fatal_error) { |
| 614 // Advanced options are no longer being configured if the login screen is | 612 // Advanced options are no longer being configured if the login screen is |
| 615 // visible. If the user exits the signin wizard after this without | 613 // visible. If the user exits the signin wizard after this without |
| 616 // configuring sync, CloseSyncSetup() will ensure they are logged out. | 614 // configuring sync, CloseSyncSetup() will ensure they are logged out. |
| 617 configuring_sync_ = false; | 615 configuring_sync_ = false; |
| 618 | 616 |
| 619 string16 local_error_message(error_message); | 617 string16 local_error_message(error_message); |
| 620 | 618 |
| 621 // Setup args for the GAIA login screen: | 619 // Setup args for the GAIA login screen: |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 // By default, do nothing - subclasses can override. | 732 // By default, do nothing - subclasses can override. |
| 735 } | 733 } |
| 736 | 734 |
| 737 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { | 735 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { |
| 738 RecordSignin(); | 736 RecordSignin(); |
| 739 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); | 737 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); |
| 740 } | 738 } |
| 741 | 739 |
| 742 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { | 740 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { |
| 743 RecordSignin(); | 741 RecordSignin(); |
| 744 if (UseWebBasedSigninFlow()) | 742 if (SyncPromoUI::UseWebBasedSigninFlow()) |
| 745 CloseGaiaSigninPage(); | 743 CloseGaiaSigninPage(); |
| 746 | 744 |
| 747 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); | 745 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); |
| 748 } | 746 } |
| 749 | 747 |
| 750 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { | 748 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { |
| 751 CloseSyncSetup(); | 749 CloseSyncSetup(); |
| 752 } | 750 } |
| 753 | 751 |
| 754 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { | 752 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 } | 833 } |
| 836 | 834 |
| 837 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { | 835 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { |
| 838 // Stop a timer to handle timeout in waiting for checking network connection. | 836 // Stop a timer to handle timeout in waiting for checking network connection. |
| 839 backend_start_timer_.reset(); | 837 backend_start_timer_.reset(); |
| 840 | 838 |
| 841 last_signin_error_ = error; | 839 last_signin_error_ = error; |
| 842 | 840 |
| 843 // If using web-based sign in flow, don't show the gaia sign in page again | 841 // If using web-based sign in flow, don't show the gaia sign in page again |
| 844 // since there is no way to show the user an error message. | 842 // since there is no way to show the user an error message. |
| 845 if (UseWebBasedSigninFlow()) { | 843 if (SyncPromoUI::UseWebBasedSigninFlow()) { |
| 846 CloseSyncSetup(); | 844 CloseSyncSetup(); |
| 847 } else if (retry_on_signin_failure_) { | 845 } else if (retry_on_signin_failure_) { |
| 848 // Got a failed signin - this is either just a typical auth error, or a | 846 // Got a failed signin - this is either just a typical auth error, or a |
| 849 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). | 847 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). |
| 850 // On ChromeOS, this condition can happen when auth token is invalid and | 848 // On ChromeOS, this condition can happen when auth token is invalid and |
| 851 // cannot start sync backend. | 849 // cannot start sync backend. |
| 852 // If using web-based sign in flow, don't show the gaia sign in page again | 850 // If using web-based sign in flow, don't show the gaia sign in page again |
| 853 // since there is no way to show the user an error message. | 851 // since there is no way to show the user an error message. |
| 854 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); | 852 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); |
| 855 } else { | 853 } else { |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1108 // User is not logged in, or login has been specially requested - need to | 1106 // User is not logged in, or login has been specially requested - need to |
| 1109 // display login UI (cases 1-4). | 1107 // display login UI (cases 1-4). |
| 1110 DisplayGaiaLogin(false); | 1108 DisplayGaiaLogin(false); |
| 1111 } else { | 1109 } else { |
| 1112 // User is already logged in. They must have brought up the config wizard | 1110 // User is already logged in. They must have brought up the config wizard |
| 1113 // via the "Advanced..." button or through One-Click signin (cases 5/6), or | 1111 // via the "Advanced..." button or through One-Click signin (cases 5/6), or |
| 1114 // they are re-enabling sync on Chrome OS. | 1112 // they are re-enabling sync on Chrome OS. |
| 1115 DisplayConfigureSync(true, false); | 1113 DisplayConfigureSync(true, false); |
| 1116 } | 1114 } |
| 1117 | 1115 |
| 1118 if (!UseWebBasedSigninFlow()) | 1116 if (!SyncPromoUI::UseWebBasedSigninFlow()) |
| 1119 ShowSetupUI(); | 1117 ShowSetupUI(); |
| 1120 } | 1118 } |
| 1121 | 1119 |
| 1122 void SyncSetupHandler::OpenConfigureSync() { | 1120 void SyncSetupHandler::OpenConfigureSync() { |
| 1123 if (!PrepareSyncSetup()) | 1121 if (!PrepareSyncSetup()) |
| 1124 return; | 1122 return; |
| 1125 | 1123 |
| 1126 DisplayConfigureSync(true, false); | 1124 DisplayConfigureSync(true, false); |
| 1127 ShowSetupUI(); | 1125 ShowSetupUI(); |
| 1128 } | 1126 } |
| 1129 | 1127 |
| 1130 void SyncSetupHandler::FocusUI() { | 1128 void SyncSetupHandler::FocusUI() { |
| 1131 DCHECK(IsActiveLogin()); | 1129 DCHECK(IsActiveLogin()); |
| 1132 if (UseWebBasedSigninFlow() && signin_tracker_) { | 1130 if (SyncPromoUI::UseWebBasedSigninFlow() && signin_tracker_) { |
| 1133 BringTabToFront(active_gaia_signin_tab_); | 1131 BringTabToFront(active_gaia_signin_tab_); |
|
Andrew T Wilson (Slow)
2012/12/08 08:38:24
Wrong indent.
Roger Tawa OOO till Jul 10th
2012/12/08 14:42:16
Done.
| |
| 1134 } else { | 1132 } else { |
| 1135 WebContents* web_contents = web_ui()->GetWebContents(); | 1133 WebContents* web_contents = web_ui()->GetWebContents(); |
| 1136 web_contents->GetDelegate()->ActivateContents(web_contents); | 1134 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 1137 } | 1135 } |
| 1138 } | 1136 } |
| 1139 | 1137 |
| 1140 void SyncSetupHandler::CloseUI() { | 1138 void SyncSetupHandler::CloseUI() { |
| 1141 DCHECK(IsActiveLogin()); | 1139 DCHECK(IsActiveLogin()); |
| 1142 CloseOverlay(); | 1140 CloseOverlay(); |
| 1143 } | 1141 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1220 if (i != current_profile_index && AreUserNamesEqual( | 1218 if (i != current_profile_index && AreUserNamesEqual( |
| 1221 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 1219 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
| 1222 *error_message = l10n_util::GetStringUTF16( | 1220 *error_message = l10n_util::GetStringUTF16( |
| 1223 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 1221 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
| 1224 return false; | 1222 return false; |
| 1225 } | 1223 } |
| 1226 } | 1224 } |
| 1227 | 1225 |
| 1228 return true; | 1226 return true; |
| 1229 } | 1227 } |
| OLD | NEW |