Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / inline_login_handler_chromeos.cc
blob95fbf4ee8f29dc6c753943564a4a0a0c1b030eba
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h"
7 #include "chrome/browser/chromeos/login/oauth2_token_fetcher.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/signin/profile_oauth2_token_service.h"
10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
11 #include "content/public/browser/web_ui.h"
13 namespace chromeos {
15 class InlineLoginHandlerChromeOS::InlineLoginUIOAuth2Delegate
16 : public OAuth2TokenFetcher::Delegate {
17 public:
18 explicit InlineLoginUIOAuth2Delegate(content::WebUI* web_ui)
19 : web_ui_(web_ui) {}
20 virtual ~InlineLoginUIOAuth2Delegate() {}
22 // OAuth2TokenFetcher::Delegate overrides:
23 virtual void OnOAuth2TokensAvailable(
24 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE {
25 // Closes sign-in dialog before update token service. Token service update
26 // might trigger a permission dialog and if this dialog does not close,
27 // a DCHECK would be triggered because attempting to activate a window
28 // while there is a modal dialog.
29 web_ui_->CallJavascriptFunction("inline.login.closeDialog");
31 Profile* profile = Profile::FromWebUI(web_ui_);
32 ProfileOAuth2TokenService* token_service =
33 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
34 token_service->UpdateCredentials(token_service->GetPrimaryAccountId(),
35 oauth2_tokens.refresh_token);
38 virtual void OnOAuth2TokensFetchFailed() OVERRIDE {
39 LOG(ERROR) << "Failed to fetch oauth2 token with inline login.";
40 web_ui_->CallJavascriptFunction("inline.login.handleOAuth2TokenFailure");
43 private:
44 content::WebUI* web_ui_;
47 InlineLoginHandlerChromeOS::InlineLoginHandlerChromeOS() {}
49 InlineLoginHandlerChromeOS::~InlineLoginHandlerChromeOS() {}
51 void InlineLoginHandlerChromeOS::CompleteLogin(const base::ListValue* args) {
52 Profile* profile = Profile::FromWebUI(web_ui());
54 oauth2_delegate_.reset(new InlineLoginUIOAuth2Delegate(web_ui()));
55 oauth2_token_fetcher_.reset(new OAuth2TokenFetcher(
56 oauth2_delegate_.get(), profile->GetRequestContext()));
57 oauth2_token_fetcher_->StartExchangeFromCookies();
60 } // namespace chromeos