Commit 58030de8 authored by guohui@chromium.org's avatar guohui@chromium.org

Add error handling to inline signin flow

BUG=318859

Review URL: https://codereview.chromium.org/99913004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238439 0039d316-1c4b-4281-b951-d872f2087c98
parent 4f99c556
...@@ -365,16 +365,6 @@ void RedirectToNtpOrAppsPageWithIds(int child_id, ...@@ -365,16 +365,6 @@ void RedirectToNtpOrAppsPageWithIds(int child_id,
RedirectToNtpOrAppsPage(web_contents, source); RedirectToNtpOrAppsPage(web_contents, source);
} }
// If the |source| is not settings page/webstore, redirects to
// the NTP/Apps page.
void RedirectToNtpOrAppsPageIfNecessary(content::WebContents* contents,
signin::Source source) {
if (source != signin::SOURCE_SETTINGS &&
source != signin::SOURCE_WEBSTORE_INSTALL) {
RedirectToNtpOrAppsPage(contents, source);
}
}
// Start syncing with the given user information. // Start syncing with the given user information.
void StartSync(const StartSyncArgs& args, void StartSync(const StartSyncArgs& args,
OneClickSigninSyncStarter::StartSyncMode start_mode) { OneClickSigninSyncStarter::StartSyncMode start_mode) {
...@@ -419,7 +409,8 @@ void StartExplicitSync(const StartSyncArgs& args, ...@@ -419,7 +409,8 @@ void StartExplicitSync(const StartSyncArgs& args,
ConfirmEmailDialogDelegate::Action action) { ConfirmEmailDialogDelegate::Action action) {
if (action == ConfirmEmailDialogDelegate::START_SYNC) { if (action == ConfirmEmailDialogDelegate::START_SYNC) {
StartSync(args, start_mode); StartSync(args, start_mode);
RedirectToNtpOrAppsPageIfNecessary(contents, args.source); OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary(
contents, args.source);
} else { } else {
// Perform a redirection to the NTP/Apps page to hide the blank page when // Perform a redirection to the NTP/Apps page to hide the blank page when
// the action is CLOSE or CREATE_NEW_USER. The redirection is useful when // the action is CLOSE or CREATE_NEW_USER. The redirection is useful when
...@@ -1028,6 +1019,7 @@ void OneClickSigninHelper::RemoveSigninRedirectURLHistoryItem( ...@@ -1028,6 +1019,7 @@ void OneClickSigninHelper::RemoveSigninRedirectURLHistoryItem(
} }
} }
// static
void OneClickSigninHelper::ShowSigninErrorBubble(Browser* browser, void OneClickSigninHelper::ShowSigninErrorBubble(Browser* browser,
const std::string& error) { const std::string& error) {
DCHECK(!error.empty()); DCHECK(!error.empty());
...@@ -1042,6 +1034,15 @@ void OneClickSigninHelper::ShowSigninErrorBubble(Browser* browser, ...@@ -1042,6 +1034,15 @@ void OneClickSigninHelper::ShowSigninErrorBubble(Browser* browser,
BrowserWindow::StartSyncCallback()); BrowserWindow::StartSyncCallback());
} }
// static
void OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary(
content::WebContents* contents, signin::Source source) {
if (source != signin::SOURCE_SETTINGS &&
source != signin::SOURCE_WEBSTORE_INSTALL) {
RedirectToNtpOrAppsPage(contents, source);
}
}
void OneClickSigninHelper::RedirectToSignin() { void OneClickSigninHelper::RedirectToSignin() {
VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; VLOG(1) << "OneClickSigninHelper::RedirectToSignin";
......
...@@ -120,6 +120,13 @@ class OneClickSigninHelper ...@@ -120,6 +120,13 @@ class OneClickSigninHelper
int child_id, int child_id,
int route_id); int route_id);
// If the |source| is not settings page/webstore, redirects to
// the NTP/Apps page.
static void RedirectToNtpOrAppsPageIfNecessary(
content::WebContents* contents, signin::Source source);
static void ShowSigninErrorBubble(Browser* browser, const std::string& error);
// Remove the item currently at the top of the history list if it's // Remove the item currently at the top of the history list if it's
// the Gaia redirect URL. Due to limitations of the NavigationController // the Gaia redirect URL. Due to limitations of the NavigationController
// this cannot be done until a new page becomes "current". // this cannot be done until a new page becomes "current".
...@@ -208,7 +215,6 @@ class OneClickSigninHelper ...@@ -208,7 +215,6 @@ class OneClickSigninHelper
int route_id); int route_id);
void RedirectToSignin(); void RedirectToSignin();
void ShowSigninErrorBubble(Browser* browser, const std::string& error);
// Clear all data member of the helper, except for the error. // Clear all data member of the helper, except for the error.
void CleanTransientState(); void CleanTransientState();
......
...@@ -254,8 +254,6 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, ...@@ -254,8 +254,6 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<FlagsUI>; return &NewWebUI<FlagsUI>;
if (url.host() == chrome::kChromeUIHistoryFrameHost) if (url.host() == chrome::kChromeUIHistoryFrameHost)
return &NewWebUI<HistoryUI>; return &NewWebUI<HistoryUI>;
if (url.host() == chrome::kChromeUIChromeSigninHost)
return &NewWebUI<InlineLoginUI>;
if (url.host() == chrome::kChromeUIInstantHost) if (url.host() == chrome::kChromeUIInstantHost)
return &NewWebUI<InstantUI>; return &NewWebUI<InstantUI>;
if (url.host() == chrome::kChromeUIManagedUserPassphrasePageHost) if (url.host() == chrome::kChromeUIManagedUserPassphrasePageHost)
...@@ -407,6 +405,10 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, ...@@ -407,6 +405,10 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
if (url.host() == chrome::kChromeUINetworkHost) if (url.host() == chrome::kChromeUINetworkHost)
return &NewWebUI<chromeos::NetworkUI>; return &NewWebUI<chromeos::NetworkUI>;
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if !defined(OS_ANDROID) && !defined(OS_IOS)
if (url.host() == chrome::kChromeUIChromeSigninHost)
return &NewWebUI<InlineLoginUI>;
#endif
/**************************************************************************** /****************************************************************************
* Other #defines and special logics. * Other #defines and special logics.
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/sync/one_click_signin_helper.h"
#include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
...@@ -90,10 +91,10 @@ class InlineLoginUIOAuth2Delegate ...@@ -90,10 +91,10 @@ class InlineLoginUIOAuth2Delegate
private: private:
content::WebUI* web_ui_; content::WebUI* web_ui_;
}; };
#elif !defined(OS_ANDROID) #else
// Global SequenceNumber used for generating unique webview partition IDs. // Global SequenceNumber used for generating unique webview partition IDs.
base::StaticAtomicSequenceNumber next_partition_id; base::StaticAtomicSequenceNumber next_partition_id;
#endif #endif // OS_CHROMEOS
class InlineLoginUIHandler : public content::WebUIMessageHandler { class InlineLoginUIHandler : public content::WebUIMessageHandler {
public: public:
...@@ -136,7 +137,7 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler { ...@@ -136,7 +137,7 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler {
enable_inline ? kInlineAuthMode : kDefaultAuthMode); enable_inline ? kInlineAuthMode : kDefaultAuthMode);
// Set parameters specific for inline signin flow. // Set parameters specific for inline signin flow.
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) #if !defined(OS_CHROMEOS)
if (enable_inline) { if (enable_inline) {
// Set continueUrl param for the inline sign in flow. It should point to // Set continueUrl param for the inline sign in flow. It should point to
// the oauth2 auth code URL so that later we can grab the auth code from // the oauth2 auth code URL so that later we can grab the auth code from
...@@ -176,7 +177,7 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler { ...@@ -176,7 +177,7 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler {
"gaia-webview-" + base::IntToString(next_partition_id.GetNext()); "gaia-webview-" + base::IntToString(next_partition_id.GetNext());
params.SetString("partitionId", partition_id_); params.SetString("partitionId", partition_id_);
} }
#endif #endif // OS_CHROMEOS
web_ui()->CallJavascriptFunction("inline.login.loadAuthExtension", params); web_ui()->CallJavascriptFunction("inline.login.loadAuthExtension", params);
} }
...@@ -194,7 +195,7 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler { ...@@ -194,7 +195,7 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler {
oauth2_token_fetcher_.reset(new chromeos::OAuth2TokenFetcher( oauth2_token_fetcher_.reset(new chromeos::OAuth2TokenFetcher(
oauth2_delegate_.get(), profile_->GetRequestContext())); oauth2_delegate_.get(), profile_->GetRequestContext()));
oauth2_token_fetcher_->StartExchangeFromCookies(); oauth2_token_fetcher_->StartExchangeFromCookies();
#elif !defined(OS_ANDROID) #else
const base::DictionaryValue* dict = NULL; const base::DictionaryValue* dict = NULL;
string16 email; string16 email;
string16 password; string16 password;
...@@ -207,6 +208,18 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler { ...@@ -207,6 +208,18 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler {
dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_); dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_);
content::WebContents* web_contents = web_ui()->GetWebContents(); content::WebContents* web_contents = web_ui()->GetWebContents();
std::string error_msg;
OneClickSigninHelper::CanOffer(
web_contents, OneClickSigninHelper::CAN_OFFER_FOR_ALL,
UTF16ToASCII(email), &error_msg);
if (!error_msg.empty()) {
SyncStarterCallback(
OneClickSigninSyncStarter::SYNC_SETUP_FAILURE);
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
OneClickSigninHelper::ShowSigninErrorBubble(browser, error_msg);
return;
}
content::StoragePartition* partition = content::StoragePartition* partition =
content::BrowserContext::GetStoragePartitionForSite( content::BrowserContext::GetStoragePartitionForSite(
web_contents->GetBrowserContext(), web_contents->GetBrowserContext(),
...@@ -219,7 +232,7 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler { ...@@ -219,7 +232,7 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler {
GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url()), GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url()),
base::Bind(&InlineLoginUIHandler::OnGaiaCookiesFetched, base::Bind(&InlineLoginUIHandler::OnGaiaCookiesFetched,
weak_factory_.GetWeakPtr(), email, password)); weak_factory_.GetWeakPtr(), email, password));
#endif #endif // OS_CHROMEOS
} }
void OnGaiaCookiesFetched( void OnGaiaCookiesFetched(
...@@ -285,21 +298,10 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler { ...@@ -285,21 +298,10 @@ class InlineLoginUIHandler : public content::WebUIMessageHandler {
FROM_HERE, FROM_HERE,
base::Bind( base::Bind(
&InlineLoginUIHandler::CloseTab, weak_factory_.GetWeakPtr())); &InlineLoginUIHandler::CloseTab, weak_factory_.GetWeakPtr()));
} else if (source != signin::SOURCE_UNKNOWN && return;
source != signin::SOURCE_SETTINGS &&
source != signin::SOURCE_WEBSTORE_INSTALL) {
// Redirect to NTP/Apps page and display a confirmation bubble.
// TODO(guohui): should redirect to the given continue url for webstore
// install flows.
GURL url(source == signin::SOURCE_APPS_PAGE_LINK ?
chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL);
content::OpenURLParams params(url,
content::Referrer(),
CURRENT_TAB,
content::PAGE_TRANSITION_AUTO_TOPLEVEL,
false);
contents->OpenURL(params);
} }
OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary(contents, source);
} }
void CloseTab() { void CloseTab() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment