Commit 29125cfe authored by guohui@chromium.org's avatar guohui@chromium.org

Refactor inline_login_ui

BUG=

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242134 0039d316-1c4b-4281-b951-d872f2087c98
parent c7db8a3a
......@@ -32,7 +32,6 @@
#include "chrome/browser/ui/webui/help/help_ui.h"
#include "chrome/browser/ui/webui/history_ui.h"
#include "chrome/browser/ui/webui/identity_internals_ui.h"
#include "chrome/browser/ui/webui/inline_login_ui.h"
#include "chrome/browser/ui/webui/inspect_ui.h"
#include "chrome/browser/ui/webui/instant_ui.h"
#include "chrome/browser/ui/webui/memory_internals/memory_internals_ui.h"
......@@ -45,6 +44,7 @@
#include "chrome/browser/ui/webui/predictors/predictors_ui.h"
#include "chrome/browser/ui/webui/profiler_ui.h"
#include "chrome/browser/ui/webui/quota_internals/quota_internals_ui.h"
#include "chrome/browser/ui/webui/signin/inline_login_ui.h"
#include "chrome/browser/ui/webui/signin/profile_signin_confirmation_ui.h"
#include "chrome/browser/ui/webui/signin/user_manager_ui.h"
#include "chrome/browser/ui/webui/signin_internals_ui.h"
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h"
#include "chrome/browser/chromeos/login/oauth2_token_fetcher.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "content/public/browser/web_ui.h"
namespace chromeos {
class InlineLoginHandlerChromeOS::InlineLoginUIOAuth2Delegate
: public OAuth2TokenFetcher::Delegate {
public:
explicit InlineLoginUIOAuth2Delegate(content::WebUI* web_ui)
: web_ui_(web_ui) {}
virtual ~InlineLoginUIOAuth2Delegate() {}
// OAuth2TokenFetcher::Delegate overrides:
virtual void OnOAuth2TokensAvailable(
const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE {
// Closes sign-in dialog before update token service. Token service update
// might trigger a permission dialog and if this dialog does not close,
// a DCHECK would be triggered because attempting to activate a window
// while there is a modal dialog.
web_ui_->CallJavascriptFunction("inline.login.closeDialog");
Profile* profile = Profile::FromWebUI(web_ui_);
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
token_service->UpdateCredentials(token_service->GetPrimaryAccountId(),
oauth2_tokens.refresh_token);
}
virtual void OnOAuth2TokensFetchFailed() OVERRIDE {
LOG(ERROR) << "Failed to fetch oauth2 token with inline login.";
web_ui_->CallJavascriptFunction("inline.login.handleOAuth2TokenFailure");
}
private:
content::WebUI* web_ui_;
};
InlineLoginHandlerChromeOS::InlineLoginHandlerChromeOS() {}
InlineLoginHandlerChromeOS::~InlineLoginHandlerChromeOS() {}
void InlineLoginHandlerChromeOS::CompleteLogin(const base::ListValue* args) {
Profile* profile = Profile::FromWebUI(web_ui());
oauth2_delegate_.reset(new InlineLoginUIOAuth2Delegate(web_ui()));
oauth2_token_fetcher_.reset(new OAuth2TokenFetcher(
oauth2_delegate_.get(), profile->GetRequestContext()));
oauth2_token_fetcher_->StartExchangeFromCookies();
}
} // namespace chromeos
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_INLINE_LOGIN_HANDLER_CHROMEOS_H_
#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_INLINE_LOGIN_HANDLER_CHROMEOS_H_
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/webui/signin/inline_login_handler.h"
namespace chromeos {
class OAuth2TokenFetcher;
// Implementation for the inline login WebUI handler on ChromeOS.
class InlineLoginHandlerChromeOS : public ::InlineLoginHandler {
public:
InlineLoginHandlerChromeOS();
virtual ~InlineLoginHandlerChromeOS();
private:
class InlineLoginUIOAuth2Delegate;
// InlineLoginHandler overrides:
virtual void CompleteLogin(const base::ListValue* args) OVERRIDE;
scoped_ptr<InlineLoginUIOAuth2Delegate> oauth2_delegate_;
scoped_ptr<chromeos::OAuth2TokenFetcher> oauth2_token_fetcher_;
DISALLOW_COPY_AND_ASSIGN(InlineLoginHandlerChromeOS);
};
} // namespace chromeos
#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_INLINE_LOGIN_HANDLER_CHROMEOS_H_
bcwhite@chromium.org
guohui@chromium.org
noms@chromium.org
rogerta@chromium.org
xiyuan@chromium.org
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/signin/inline_login_handler.h"
#include "base/bind.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "content/public/browser/web_ui.h"
#include "google_apis/gaia/gaia_urls.h"
InlineLoginHandler::InlineLoginHandler() {}
InlineLoginHandler::~InlineLoginHandler() {}
void InlineLoginHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("initialize",
base::Bind(&InlineLoginHandler::HandleInitializeMessage,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("completeLogin",
base::Bind(&InlineLoginHandler::HandleCompleteLoginMessage,
base::Unretained(this)));
}
void InlineLoginHandler::HandleInitializeMessage(const base::ListValue* args) {
base::DictionaryValue params;
const std::string& app_locale = g_browser_process->GetApplicationLocale();
params.SetString("hl", app_locale);
GaiaUrls* gaiaUrls = GaiaUrls::GetInstance();
params.SetString("gaiaUrl", gaiaUrls->gaia_url().spec());
params.SetInteger("authMode", kDefaultAuthMode);
SetExtraInitParams(params);
web_ui()->CallJavascriptFunction("inline.login.loadAuthExtension", params);
}
void InlineLoginHandler::HandleCompleteLoginMessage(
const base::ListValue* args) {
CompleteLogin(args);
}
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_H_
#include "content/public/browser/web_ui_message_handler.h"
// The base class handler for the inline login WebUI.
class InlineLoginHandler : public content::WebUIMessageHandler {
public:
InlineLoginHandler();
virtual ~InlineLoginHandler();
// content::WebUIMessageHandler overrides:
virtual void RegisterMessages() OVERRIDE;
protected:
// Enum for gaia auth mode, must match AuthMode defined in
// chrome/browser/resources/gaia_auth_host/gaia_auth_host.js.
enum AuthMode {
kDefaultAuthMode = 0,
kOfflineAuthMode = 1,
kInlineAuthMode = 2
};
private:
// JS callback to initialize the gaia auth extension. It calls
// |SetExtraInitParams| to set extra init params.
void HandleInitializeMessage(const base::ListValue* args);
// JS callback to complete login. It calls |CompleteLogin| to do the real
// work.
void HandleCompleteLoginMessage(const base::ListValue* args);
virtual void SetExtraInitParams(base::DictionaryValue& params) {}
virtual void CompleteLogin(const base::ListValue* args) = 0;
DISALLOW_COPY_AND_ASSIGN(InlineLoginHandler);
};
#endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_H_
This diff is collapsed.
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_
#define CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
#include "chrome/browser/ui/webui/signin/inline_login_handler.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
class GaiaAuthFetcher;
// Implementation for the inline login WebUI handler on desktop Chrome. Once
// CrOS migrates to the same webview approach as desktop Chrome, much of the
// code in this class should move to its base class |InlineLoginHandler|.
class InlineLoginHandlerImpl : public GaiaAuthConsumer,
public InlineLoginHandler {
public:
InlineLoginHandlerImpl();
virtual ~InlineLoginHandlerImpl();
private:
// InlineLoginHandler overrides:
virtual void RegisterMessages() OVERRIDE;
virtual void SetExtraInitParams(base::DictionaryValue& params) OVERRIDE;
virtual void CompleteLogin(const base::ListValue* args) OVERRIDE;
// GaiaAuthConsumer override.
virtual void OnClientOAuthCodeSuccess(const std::string& oauth_code) OVERRIDE;
virtual void OnClientOAuthCodeFailure(
const GoogleServiceAuthError& error) OVERRIDE;
// JS callback to switch the UI from a constrainted dialog to a full tab.
void HandleSwitchToFullTabMessage(const base::ListValue* args);
void HandleLoginError(const std::string& error_msg);
void SyncStarterCallback(OneClickSigninSyncStarter::SyncSetupResult result);
void CloseTab();
base::WeakPtrFactory<InlineLoginHandlerImpl> weak_factory_;
scoped_ptr<GaiaAuthFetcher> auth_fetcher_;
std::string email_;
std::string password_;
bool choose_what_to_sync_;
// Partition id for the gaia webview;
std::string partition_id_;
DISALLOW_COPY_AND_ASSIGN(InlineLoginHandlerImpl);
};
#endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/signin/inline_login_ui.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "grit/browser_resources.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h"
#else
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h"
#endif
namespace {
content::WebUIDataSource* CreateWebUIDataSource() {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIChromeSigninHost);
source->SetUseJsonJSFormatV2();
source->SetJsonPath("strings.js");
source->SetDefaultResource(IDR_INLINE_LOGIN_HTML);
source->AddResourcePath("inline_login.css", IDR_INLINE_LOGIN_CSS);
source->AddResourcePath("inline_login.js", IDR_INLINE_LOGIN_JS);
return source;
};
} // empty namespace
InlineLoginUI::InlineLoginUI(content::WebUI* web_ui)
: WebDialogUI(web_ui),
auth_extension_(Profile::FromWebUI(web_ui)) {
Profile* profile = Profile::FromWebUI(web_ui);
content::WebUIDataSource::Add(profile, CreateWebUIDataSource());
#if defined(OS_CHROMEOS)
web_ui->AddMessageHandler(new chromeos::InlineLoginHandlerChromeOS());
#else
web_ui->AddMessageHandler(new InlineLoginHandlerImpl());
// Required for intercepting extension function calls when the page is loaded
// in a bubble (not a full tab, thus tab helpers are not registered
// automatically).
extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents());
#endif
}
InlineLoginUI::~InlineLoginUI() {}
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_INLINE_LOGIN_UI_H_
#define CHROME_BROWSER_UI_WEBUI_INLINE_LOGIN_UI_H_
#ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_UI_H_
#define CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_UI_H_
#include "chrome/browser/extensions/signin/scoped_gaia_auth_extension.h"
#include "ui/web_dialogs/web_dialog_ui.h"
......@@ -23,4 +23,4 @@ class InlineLoginUI : public ui::WebDialogUI {
DISALLOW_COPY_AND_ASSIGN(InlineLoginUI);
};
#endif // CHROME_BROWSER_UI_WEBUI_INLINE_LOGIN_UI_H_
#endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_UI_H_
......@@ -2221,6 +2221,8 @@
'browser/ui/webui/chromeos/login/eula_screen_handler.h',
'browser/ui/webui/chromeos/login/gaia_screen_handler.cc',
'browser/ui/webui/chromeos/login/gaia_screen_handler.h',
'browser/ui/webui/chromeos/login/inline_login_handler_chromeos.cc',
'browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h',
'browser/ui/webui/chromeos/login/kiosk_app_menu_handler.cc',
'browser/ui/webui/chromeos/login/kiosk_app_menu_handler.h',
'browser/ui/webui/chromeos/login/kiosk_autolaunch_screen_handler.cc',
......@@ -2339,8 +2341,6 @@
'browser/ui/webui/history_ui.h',
'browser/ui/webui/identity_internals_ui.cc',
'browser/ui/webui/identity_internals_ui.h',
'browser/ui/webui/inline_login_ui.cc',
'browser/ui/webui/inline_login_ui.h',
'browser/ui/webui/inspect_ui.cc',
'browser/ui/webui/inspect_ui.h',
'browser/ui/webui/instant_ui.cc',
......@@ -2535,6 +2535,12 @@
'browser/ui/webui/quota_internals/quota_internals_ui.h',
'browser/ui/webui/set_as_default_browser_ui.cc',
'browser/ui/webui/set_as_default_browser_ui.h',
'browser/ui/webui/signin/inline_login_handler.cc',
'browser/ui/webui/signin/inline_login_handler.h',
'browser/ui/webui/signin/inline_login_handler_impl.cc',
'browser/ui/webui/signin/inline_login_handler_impl.h',
'browser/ui/webui/signin/inline_login_ui.cc',
'browser/ui/webui/signin/inline_login_ui.h',
'browser/ui/webui/signin/login_ui_service.cc',
'browser/ui/webui/signin/login_ui_service.h',
'browser/ui/webui/signin/login_ui_service_factory.cc',
......@@ -2805,6 +2811,8 @@
'browser/ui/views/screen_capture_notification_ui_views.cc',
'browser/ui/webui/help/version_updater_basic.cc',
'browser/ui/webui/help/version_updater_basic.h',
'browser/ui/webui/signin/inline_login_handler_impl.cc',
'browser/ui/webui/signin/inline_login_handler_impl.h',
'browser/ui/webui/signin/user_manager_screen_handler.h',
'browser/ui/webui/signin/user_manager_screen_handler.cc',
'browser/ui/webui/signin/user_manager_ui.h',
......
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