Index: chrome/browser/ui/webui/sync_setup_handler.cc |
diff --git a/chrome/browser/ui/webui/sync_setup_handler.cc b/chrome/browser/ui/webui/sync_setup_handler.cc |
index 47cf1eb34c9816ad0a7162463fe108c3fda99ec9..77dcacf0316fdf1b972d21ee4d4ce9a08d7d8078 100644 |
--- a/chrome/browser/ui/webui/sync_setup_handler.cc |
+++ b/chrome/browser/ui/webui/sync_setup_handler.cc |
@@ -28,6 +28,7 @@ |
#include "chrome/browser/sync/profile_sync_service_factory.h" |
#include "chrome/browser/ui/browser_finder.h" |
#include "chrome/browser/ui/browser_navigator.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/browser/ui/webui/signin/login_ui_service.h" |
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
@@ -191,13 +192,28 @@ bool UseWebBasedSigninFlow() { |
switches::kUseWebBasedSigninFlow); |
} |
+void BringTabToFront(WebContents* web_contents) { |
+ Browser* browser = browser::FindBrowserWithWebContents(web_contents); |
Andrew T Wilson (Slow)
2012/11/30 16:40:12
We have FocusUI() to do the same thing - make this
Roger Tawa OOO till Jul 10th
2012/12/01 16:09:55
Done.
|
+ if (browser) { |
+ TabStripModel* tab_strip_model = browser->tab_strip_model(); |
+ if (tab_strip_model) { |
+ int index = tab_strip_model->GetIndexOfWebContents(web_contents); |
+ if (index != TabStripModel::kNoTab) |
+ tab_strip_model->ActivateTabAt(index, false); |
+ } |
+ } |
+} |
+ |
} // namespace |
+SyncSetupHandler* SyncSetupHandler::active_sync_setup_handler_ = NULL; |
+ |
SyncSetupHandler::SyncSetupHandler(ProfileManager* profile_manager) |
: configuring_sync_(false), |
profile_manager_(profile_manager), |
last_signin_error_(GoogleServiceAuthError::NONE), |
- retry_on_signin_failure_(true) { |
+ retry_on_signin_failure_(true), |
+ active_gaia_signin_tab_(NULL) { |
} |
SyncSetupHandler::~SyncSetupHandler() { |
@@ -489,6 +505,11 @@ void SyncSetupHandler::DisplayConfigureSync(bool show_advanced, |
StringValue page("configure"); |
web_ui()->CallJavascriptFunction( |
"SyncSetupOverlay.showSyncSetupPage", page, args); |
+ |
+ if (UseWebBasedSigninFlow()) { |
+ // Make sure the tab used for the Gaia sign in does not cover this tab. |
+ BringTabToFront(web_ui()->GetWebContents()); |
+ } |
} |
void SyncSetupHandler::ConfigureSyncDone() { |
@@ -513,10 +534,15 @@ void SyncSetupHandler::ConfigureSyncDone() { |
} |
bool SyncSetupHandler::IsActiveLogin() const { |
- // LoginUIService can be NULL if page is brought up in incognito mode |
- // (i.e. if the user is running in guest mode in cros and brings up settings). |
- LoginUIService* service = GetLoginUIService(); |
- return service && (service->current_login_ui() == this); |
+ if (UseWebBasedSigninFlow()) { |
+ return active_sync_setup_handler_ == this; |
Andrew T Wilson (Slow)
2012/11/30 16:40:12
I'm not sure I understand why we need different lo
Roger Tawa OOO till Jul 10th
2012/12/01 16:09:55
Done.
|
+ } else { |
+ // LoginUIService can be NULL if page is brought up in incognito mode |
+ // (i.e. if the user is running in guest mode in cros and brings up |
+ // settings). |
+ LoginUIService* service = GetLoginUIService(); |
+ return service && (service->current_login_ui() == this); |
+ } |
} |
void SyncSetupHandler::RegisterMessages() { |
@@ -566,13 +592,21 @@ SigninManager* SyncSetupHandler::GetSignin() const { |
void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { |
if (UseWebBasedSigninFlow()) { |
+ DCHECK_EQ(active_sync_setup_handler_, this); |
+ DCHECK(!active_gaia_signin_tab_); |
+ |
GURL url(SyncPromoUI::GetSyncPromoURL(GURL(), |
SyncPromoUI::SOURCE_SETTINGS, false)); |
Browser* browser = browser::FindBrowserWithWebContents( |
web_ui()->GetWebContents()); |
- browser->OpenURL( |
+ active_gaia_signin_tab_ = browser->OpenURL( |
content::OpenURLParams(url, content::Referrer(), SINGLETON_TAB, |
- content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); |
+ content::PAGE_TRANSITION_AUTO_BOOKMARK, |
+ false)); |
+ content::WebContentsObserver::Observe(active_gaia_signin_tab_); |
+ signin_tracker_.reset( |
+ new SigninTracker(GetProfile(), this, |
+ SigninTracker::WAITING_FOR_GAIA_VALIDATION)); |
} else { |
retry_on_signin_failure_ = true; |
DisplayGaiaLoginWithErrorMessage(string16(), fatal_error); |
@@ -662,7 +696,10 @@ bool SyncSetupHandler::PrepareSyncSetup() { |
return false; |
} |
- if (!UseWebBasedSigninFlow()) { |
+ if (UseWebBasedSigninFlow()) { |
+ DCHECK(!active_sync_setup_handler_); |
+ active_sync_setup_handler_ = this; |
+ } else { |
// Notify services that login UI is now active. |
GetLoginUIService()->SetLoginUI(this); |
service->SetSetupInProgress(true); |
@@ -1013,8 +1050,13 @@ void SyncSetupHandler::CloseSyncSetup() { |
ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); |
} |
} |
+ |
// Let the various services know that we're no longer active. |
- GetLoginUIService()->LoginUIClosed(this); |
+ if (UseWebBasedSigninFlow()) { |
+ CloseGaiaSigninPage(); |
Andrew T Wilson (Slow)
2012/11/30 16:40:12
Should we not also call LoginUIClosed() here?
Roger Tawa OOO till Jul 10th
2012/12/01 16:09:55
Done.
|
+ } else { |
+ GetLoginUIService()->LoginUIClosed(this); |
+ } |
} |
if (sync_service) { |
@@ -1098,13 +1140,34 @@ void SyncSetupHandler::CloseUI() { |
CloseOverlay(); |
} |
+void SyncSetupHandler::WebContentsDestroyed( |
+ content::WebContents* web_contents) { |
+ DCHECK_EQ(active_sync_setup_handler_, this); |
+ DCHECK(active_gaia_signin_tab_); |
+ |
+ content::WebContentsObserver::Observe(NULL); |
+ active_sync_setup_handler_ = NULL; |
+ active_gaia_signin_tab_ = NULL; |
Andrew T Wilson (Slow)
2012/11/30 16:40:12
Should we call CloseSyncSetup here? Seems like we
Roger Tawa OOO till Jul 10th
2012/12/01 16:09:55
Done.
|
+} |
+ |
// Private member functions. |
bool SyncSetupHandler::FocusExistingWizardIfPresent() { |
- LoginUIService* service = GetLoginUIService(); |
- if (!service->current_login_ui()) |
- return false; |
- service->current_login_ui()->FocusUI(); |
+ if (UseWebBasedSigninFlow()) { |
+ if (active_sync_setup_handler_ == NULL) |
+ return false; |
+ |
+ // |configuring_sync_| true means we are focusing to bring the configure |
+ // popup window to the top, not the Gaia sign in page. Therefore don't |
+ // bring Gaia to the front. |
+ if (!configuring_sync_) |
+ BringTabToFront(active_sync_setup_handler_->active_gaia_signin_tab_); |
+ } else { |
+ LoginUIService* service = GetLoginUIService(); |
+ if (!service->current_login_ui()) |
+ return false; |
+ service->current_login_ui()->FocusUI(); |
+ } |
return true; |
} |
@@ -1120,6 +1183,23 @@ void SyncSetupHandler::CloseOverlay() { |
web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); |
} |
+void SyncSetupHandler::CloseGaiaSigninPage() { |
+ if (active_sync_setup_handler_ == this && active_gaia_signin_tab_) { |
+ content::WebContentsObserver::Observe(NULL); |
+ |
+ Browser* browser = browser::FindBrowserWithWebContents( |
+ active_sync_setup_handler_->active_gaia_signin_tab_); |
+ TabStripModel* tab_strip_model = browser->tab_strip_model(); |
+ int index = tab_strip_model->GetIndexOfWebContents( |
+ active_sync_setup_handler_->active_gaia_signin_tab_); |
+ tab_strip_model->ExecuteContextMenuCommand( |
+ index, TabStripModel::CommandCloseTab); |
+ } |
+ |
+ active_gaia_signin_tab_ = NULL; |
+ active_sync_setup_handler_ = NULL; |
+} |
+ |
bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, |
string16* error_message) { |
if (username.empty()) |