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/tabs/tab_strip_model.h" | |
31 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 32 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
32 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 33 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
33 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 34 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
34 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
35 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
36 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
37 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
38 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
39 #include "content/public/browser/web_contents_delegate.h" | 40 #include "content/public/browser/web_contents_delegate.h" |
40 #include "google_apis/gaia/gaia_constants.h" | 41 #include "google_apis/gaia/gaia_constants.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 bool IsKeystoreEncryptionEnabled() { | 185 bool IsKeystoreEncryptionEnabled() { |
185 return CommandLine::ForCurrentProcess()->HasSwitch( | 186 return CommandLine::ForCurrentProcess()->HasSwitch( |
186 switches::kSyncKeystoreEncryption); | 187 switches::kSyncKeystoreEncryption); |
187 } | 188 } |
188 | 189 |
189 bool UseWebBasedSigninFlow() { | 190 bool UseWebBasedSigninFlow() { |
190 return CommandLine::ForCurrentProcess()->HasSwitch( | 191 return CommandLine::ForCurrentProcess()->HasSwitch( |
191 switches::kUseWebBasedSigninFlow); | 192 switches::kUseWebBasedSigninFlow); |
192 } | 193 } |
193 | 194 |
195 void BringTabToFront(WebContents* web_contents) { | |
196 Browser* browser = browser::FindBrowserWithWebContents(web_contents); | |
197 TabStripModel* tab_strip_model = browser->tab_strip_model(); | |
198 int index = tab_strip_model->GetIndexOfWebContents(web_contents); | |
199 tab_strip_model->ActivateTabAt(index, false); | |
200 } | |
201 | |
194 } // namespace | 202 } // namespace |
195 | 203 |
204 SyncSetupHandler* SyncSetupHandler::active_sync_setup_handler_ = NULL; | |
205 | |
196 SyncSetupHandler::SyncSetupHandler(ProfileManager* profile_manager) | 206 SyncSetupHandler::SyncSetupHandler(ProfileManager* profile_manager) |
197 : configuring_sync_(false), | 207 : configuring_sync_(false), |
198 profile_manager_(profile_manager), | 208 profile_manager_(profile_manager), |
199 last_signin_error_(GoogleServiceAuthError::NONE), | 209 last_signin_error_(GoogleServiceAuthError::NONE), |
200 retry_on_signin_failure_(true) { | 210 retry_on_signin_failure_(true), |
211 active_gaia_signin_tab_(NULL) { | |
201 } | 212 } |
202 | 213 |
203 SyncSetupHandler::~SyncSetupHandler() { | 214 SyncSetupHandler::~SyncSetupHandler() { |
204 // Just exit if running unit tests (no actual WebUI is attached). | 215 // Just exit if running unit tests (no actual WebUI is attached). |
205 if (!web_ui()) | 216 if (!web_ui()) |
206 return; | 217 return; |
207 | 218 |
208 // This case is hit when the user performs a back navigation. | 219 // This case is hit when the user performs a back navigation. |
209 CloseSyncSetup(); | 220 CloseSyncSetup(); |
210 } | 221 } |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 "fullEncryptionBody", | 493 "fullEncryptionBody", |
483 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_DATA)); | 494 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_DATA)); |
484 } | 495 } |
485 } else { | 496 } else { |
486 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); | 497 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); |
487 } | 498 } |
488 | 499 |
489 StringValue page("configure"); | 500 StringValue page("configure"); |
490 web_ui()->CallJavascriptFunction( | 501 web_ui()->CallJavascriptFunction( |
491 "SyncSetupOverlay.showSyncSetupPage", page, args); | 502 "SyncSetupOverlay.showSyncSetupPage", page, args); |
503 | |
504 if (UseWebBasedSigninFlow()) { | |
505 // Make sure the tab used for the Gaia sign in does not cover this tab. | |
tim (not reviewing)
2012/11/29 06:39:07
They're separate tabs?
Roger Tawa OOO till Jul 10th
2012/11/29 20:20:56
yes
| |
506 BringTabToFront(web_ui()->GetWebContents()); | |
507 } | |
492 } | 508 } |
493 | 509 |
494 void SyncSetupHandler::ConfigureSyncDone() { | 510 void SyncSetupHandler::ConfigureSyncDone() { |
495 StringValue page("done"); | 511 StringValue page("done"); |
496 web_ui()->CallJavascriptFunction( | 512 web_ui()->CallJavascriptFunction( |
497 "SyncSetupOverlay.showSyncSetupPage", page); | 513 "SyncSetupOverlay.showSyncSetupPage", page); |
498 | 514 |
499 // Suppress the sync promo once the user signs into sync. This way the user | 515 // Suppress the sync promo once the user signs into sync. This way the user |
500 // doesn't see the sync promo even if they sign out of sync later on. | 516 // doesn't see the sync promo even if they sign out of sync later on. |
501 SyncPromoUI::SetUserSkippedSyncPromo(GetProfile()); | 517 SyncPromoUI::SetUserSkippedSyncPromo(GetProfile()); |
502 | 518 |
503 ProfileSyncService* service = GetSyncService(); | 519 ProfileSyncService* service = GetSyncService(); |
504 if (!service->HasSyncSetupCompleted()) { | 520 if (!service->HasSyncSetupCompleted()) { |
505 // This is the first time configuring sync, so log it. | 521 // This is the first time configuring sync, so log it. |
506 FilePath profile_file_path = GetProfile()->GetPath(); | 522 FilePath profile_file_path = GetProfile()->GetPath(); |
507 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); | 523 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); |
508 | 524 |
509 // We're done configuring, so notify ProfileSyncService that it is OK to | 525 // We're done configuring, so notify ProfileSyncService that it is OK to |
510 // start syncing. | 526 // start syncing. |
511 service->SetSyncSetupCompleted(); | 527 service->SetSyncSetupCompleted(); |
512 } | 528 } |
513 } | 529 } |
514 | 530 |
515 bool SyncSetupHandler::IsActiveLogin() const { | 531 bool SyncSetupHandler::IsActiveLogin() const { |
516 // LoginUIService can be NULL if page is brought up in incognito mode | 532 if (UseWebBasedSigninFlow()) { |
517 // (i.e. if the user is running in guest mode in cros and brings up settings). | 533 return active_sync_setup_handler_ == this; |
518 LoginUIService* service = GetLoginUIService(); | 534 } else { |
519 return service && (service->current_login_ui() == this); | 535 // LoginUIService can be NULL if page is brought up in incognito mode |
536 // (i.e. if the user is running in guest mode in cros and brings up | |
537 // settings). | |
538 LoginUIService* service = GetLoginUIService(); | |
539 return service && (service->current_login_ui() == this); | |
540 } | |
520 } | 541 } |
521 | 542 |
522 void SyncSetupHandler::RegisterMessages() { | 543 void SyncSetupHandler::RegisterMessages() { |
523 web_ui()->RegisterMessageCallback( | 544 web_ui()->RegisterMessageCallback( |
524 "SyncSetupDidClosePage", | 545 "SyncSetupDidClosePage", |
525 base::Bind(&SyncSetupHandler::OnDidClosePage, | 546 base::Bind(&SyncSetupHandler::OnDidClosePage, |
526 base::Unretained(this))); | 547 base::Unretained(this))); |
527 web_ui()->RegisterMessageCallback( | 548 web_ui()->RegisterMessageCallback( |
528 "SyncSetupSubmitAuth", | 549 "SyncSetupSubmitAuth", |
529 base::Bind(&SyncSetupHandler::HandleSubmitAuth, | 550 base::Bind(&SyncSetupHandler::HandleSubmitAuth, |
(...skipping 29 matching lines...) Expand all Loading... | |
559 base::Bind(&SyncSetupHandler::HandleStopSyncing, | 580 base::Bind(&SyncSetupHandler::HandleStopSyncing, |
560 base::Unretained(this))); | 581 base::Unretained(this))); |
561 } | 582 } |
562 | 583 |
563 SigninManager* SyncSetupHandler::GetSignin() const { | 584 SigninManager* SyncSetupHandler::GetSignin() const { |
564 return SigninManagerFactory::GetForProfile(GetProfile()); | 585 return SigninManagerFactory::GetForProfile(GetProfile()); |
565 } | 586 } |
566 | 587 |
567 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { | 588 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { |
568 if (UseWebBasedSigninFlow()) { | 589 if (UseWebBasedSigninFlow()) { |
590 DCHECK(active_sync_setup_handler_ == this); | |
591 DCHECK(!active_gaia_signin_tab_); | |
592 | |
569 GURL url(SyncPromoUI::GetSyncPromoURL(GURL(), | 593 GURL url(SyncPromoUI::GetSyncPromoURL(GURL(), |
570 SyncPromoUI::SOURCE_SETTINGS, false)); | 594 SyncPromoUI::SOURCE_SETTINGS, false)); |
571 Browser* browser = browser::FindBrowserWithWebContents( | 595 Browser* browser = browser::FindBrowserWithWebContents( |
572 web_ui()->GetWebContents()); | 596 web_ui()->GetWebContents()); |
573 browser->OpenURL( | 597 active_gaia_signin_tab_ = browser->OpenURL( |
574 content::OpenURLParams(url, content::Referrer(), SINGLETON_TAB, | 598 content::OpenURLParams(url, content::Referrer(), SINGLETON_TAB, |
575 content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); | 599 content::PAGE_TRANSITION_AUTO_BOOKMARK, |
600 false)); | |
601 content::WebContentsObserver::Observe(active_gaia_signin_tab_); | |
602 signin_tracker_.reset( | |
603 new SigninTracker(GetProfile(), this, | |
604 SigninTracker::WAITING_FOR_GAIA_VALIDATION)); | |
576 } else { | 605 } else { |
577 retry_on_signin_failure_ = true; | 606 retry_on_signin_failure_ = true; |
578 DisplayGaiaLoginWithErrorMessage(string16(), fatal_error); | 607 DisplayGaiaLoginWithErrorMessage(string16(), fatal_error); |
579 } | 608 } |
580 } | 609 } |
581 | 610 |
582 void SyncSetupHandler::DisplayGaiaLoginWithErrorMessage( | 611 void SyncSetupHandler::DisplayGaiaLoginWithErrorMessage( |
583 const string16& error_message, bool fatal_error) { | 612 const string16& error_message, bool fatal_error) { |
584 // We are no longer configuring sync if the login screen is visible. | 613 // We are no longer configuring sync if the login screen is visible. |
585 // If the user exits the signin wizard after this without configuring sync, | 614 // If the user exits the signin wizard after this without configuring sync, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 return false; | 684 return false; |
656 } | 685 } |
657 | 686 |
658 // If the wizard is already visible, just focus that one. | 687 // If the wizard is already visible, just focus that one. |
659 if (FocusExistingWizardIfPresent()) { | 688 if (FocusExistingWizardIfPresent()) { |
660 if (!IsActiveLogin()) | 689 if (!IsActiveLogin()) |
661 CloseOverlay(); | 690 CloseOverlay(); |
662 return false; | 691 return false; |
663 } | 692 } |
664 | 693 |
665 if (!UseWebBasedSigninFlow()) { | 694 if (UseWebBasedSigninFlow()) { |
695 DCHECK(active_sync_setup_handler_ == NULL); | |
tim (not reviewing)
2012/11/29 06:39:07
DCHECK_EQ, here and elsewhere
Roger Tawa OOO till Jul 10th
2012/11/29 20:20:56
Done.
| |
696 active_sync_setup_handler_ = this; | |
697 } else { | |
666 // Notify services that login UI is now active. | 698 // Notify services that login UI is now active. |
667 GetLoginUIService()->SetLoginUI(this); | 699 GetLoginUIService()->SetLoginUI(this); |
668 service->SetSetupInProgress(true); | 700 service->SetSetupInProgress(true); |
669 } | 701 } |
670 | 702 |
671 return true; | 703 return true; |
672 } | 704 } |
673 | 705 |
674 void SyncSetupHandler::DisplaySpinner() { | 706 void SyncSetupHandler::DisplaySpinner() { |
675 configuring_sync_ = true; | 707 configuring_sync_ = true; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1006 ProfileSyncService::SyncEvent( | 1038 ProfileSyncService::SyncEvent( |
1007 ProfileSyncService::CANCEL_DURING_SIGNON); | 1039 ProfileSyncService::CANCEL_DURING_SIGNON); |
1008 } else if (configuring_sync_) { | 1040 } else if (configuring_sync_) { |
1009 ProfileSyncService::SyncEvent( | 1041 ProfileSyncService::SyncEvent( |
1010 ProfileSyncService::CANCEL_DURING_CONFIGURE); | 1042 ProfileSyncService::CANCEL_DURING_CONFIGURE); |
1011 } else { | 1043 } else { |
1012 ProfileSyncService::SyncEvent( | 1044 ProfileSyncService::SyncEvent( |
1013 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); | 1045 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); |
1014 } | 1046 } |
1015 } | 1047 } |
1048 | |
1016 // Let the various services know that we're no longer active. | 1049 // Let the various services know that we're no longer active. |
1017 GetLoginUIService()->LoginUIClosed(this); | 1050 if (UseWebBasedSigninFlow()) { |
1051 CloseGaiaSigninPage(); | |
1052 } else { | |
1053 GetLoginUIService()->LoginUIClosed(this); | |
1054 } | |
1018 } | 1055 } |
1019 | 1056 |
1020 if (sync_service) { | 1057 if (sync_service) { |
1021 sync_service->SetSetupInProgress(false); | 1058 sync_service->SetSetupInProgress(false); |
1022 | 1059 |
1023 // 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 |
1024 // 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 |
1025 // and shut down sync. | 1062 // and shut down sync. |
1026 if (!sync_service->HasSyncSetupCompleted()) { | 1063 if (!sync_service->HasSyncSetupCompleted()) { |
1027 DVLOG(1) << "Signin aborted by user action"; | 1064 DVLOG(1) << "Signin aborted by user action"; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1091 DCHECK(IsActiveLogin()); | 1128 DCHECK(IsActiveLogin()); |
1092 WebContents* web_contents = web_ui()->GetWebContents(); | 1129 WebContents* web_contents = web_ui()->GetWebContents(); |
1093 web_contents->GetDelegate()->ActivateContents(web_contents); | 1130 web_contents->GetDelegate()->ActivateContents(web_contents); |
1094 } | 1131 } |
1095 | 1132 |
1096 void SyncSetupHandler::CloseUI() { | 1133 void SyncSetupHandler::CloseUI() { |
1097 DCHECK(IsActiveLogin()); | 1134 DCHECK(IsActiveLogin()); |
1098 CloseOverlay(); | 1135 CloseOverlay(); |
1099 } | 1136 } |
1100 | 1137 |
1138 void SyncSetupHandler::WebContentsDestroyed( | |
1139 content::WebContents* web_contents) { | |
1140 DCHECK(active_sync_setup_handler_ == this); | |
1141 DCHECK(active_gaia_signin_tab_); | |
1142 | |
1143 content::WebContentsObserver::Observe(NULL); | |
1144 active_sync_setup_handler_ = NULL; | |
1145 active_gaia_signin_tab_ = NULL; | |
1146 } | |
1147 | |
1101 // Private member functions. | 1148 // Private member functions. |
1102 | 1149 |
1103 bool SyncSetupHandler::FocusExistingWizardIfPresent() { | 1150 bool SyncSetupHandler::FocusExistingWizardIfPresent() { |
1104 LoginUIService* service = GetLoginUIService(); | 1151 if (UseWebBasedSigninFlow()) { |
1105 if (!service->current_login_ui()) | 1152 if (active_sync_setup_handler_ == NULL) |
1106 return false; | 1153 return false; |
1107 service->current_login_ui()->FocusUI(); | 1154 |
1155 // |configuring_sync_| true means we are focusing to bring the configure | |
1156 // popup window to the top, not the Gaia sign in page. Therefore don't | |
1157 // bring Gaia to the front. | |
1158 if (!configuring_sync_) | |
1159 BringTabToFront(active_sync_setup_handler_->active_gaia_signin_tab_); | |
tim (not reviewing)
2012/11/29 06:39:07
There can be multiple active_sync_setup_handler_'s
Roger Tawa OOO till Jul 10th
2012/11/29 20:20:56
No, there can be only one. However, if you open a
| |
1160 } else { | |
1161 LoginUIService* service = GetLoginUIService(); | |
1162 if (!service->current_login_ui()) | |
1163 return false; | |
1164 service->current_login_ui()->FocusUI(); | |
1165 } | |
1108 return true; | 1166 return true; |
1109 } | 1167 } |
1110 | 1168 |
1111 LoginUIService* SyncSetupHandler::GetLoginUIService() const { | 1169 LoginUIService* SyncSetupHandler::GetLoginUIService() const { |
1112 return LoginUIServiceFactory::GetForProfile(GetProfile()); | 1170 return LoginUIServiceFactory::GetForProfile(GetProfile()); |
1113 } | 1171 } |
1114 | 1172 |
1115 void SyncSetupHandler::CloseOverlay() { | 1173 void SyncSetupHandler::CloseOverlay() { |
1116 // Stop a timer to handle timeout in waiting for sync setup. | 1174 // Stop a timer to handle timeout in waiting for sync setup. |
1117 backend_start_timer_.reset(); | 1175 backend_start_timer_.reset(); |
1118 | 1176 |
1119 CloseSyncSetup(); | 1177 CloseSyncSetup(); |
1120 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); | 1178 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); |
1121 } | 1179 } |
1122 | 1180 |
1181 void SyncSetupHandler::CloseGaiaSigninPage() { | |
1182 if (active_sync_setup_handler_ == this && active_gaia_signin_tab_) { | |
1183 content::WebContentsObserver::Observe(NULL); | |
1184 | |
1185 Browser* browser = browser::FindBrowserWithWebContents( | |
1186 active_sync_setup_handler_->active_gaia_signin_tab_); | |
1187 TabStripModel* tab_strip_model = browser->tab_strip_model(); | |
1188 int index = tab_strip_model->GetIndexOfWebContents( | |
1189 active_sync_setup_handler_->active_gaia_signin_tab_); | |
1190 tab_strip_model->CloseTabContentsAt(index, TabStripModel::CLOSE_NONE); | |
1191 } | |
1192 | |
1193 active_gaia_signin_tab_ = NULL; | |
1194 active_sync_setup_handler_ = NULL; | |
1195 } | |
1196 | |
1123 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, | 1197 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, |
1124 string16* error_message) { | 1198 string16* error_message) { |
1125 if (username.empty()) | 1199 if (username.empty()) |
1126 return true; | 1200 return true; |
1127 | 1201 |
1128 // Can be null during some unit tests. | 1202 // Can be null during some unit tests. |
1129 if (!web_ui()) | 1203 if (!web_ui()) |
1130 return true; | 1204 return true; |
1131 | 1205 |
1132 if (!GetSignin()->IsAllowedUsername(username)) { | 1206 if (!GetSignin()->IsAllowedUsername(username)) { |
(...skipping 15 matching lines...) Expand all Loading... | |
1148 if (i != current_profile_index && AreUserNamesEqual( | 1222 if (i != current_profile_index && AreUserNamesEqual( |
1149 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 1223 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
1150 *error_message = l10n_util::GetStringUTF16( | 1224 *error_message = l10n_util::GetStringUTF16( |
1151 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 1225 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
1152 return false; | 1226 return false; |
1153 } | 1227 } |
1154 } | 1228 } |
1155 | 1229 |
1156 return true; | 1230 return true; |
1157 } | 1231 } |
OLD | NEW |