Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(800)

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.cc

Issue 256623002: Implemented inline login dialog for Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/chromeos/login/inline_login_handler_chromeos.h " 5 #include "chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h "
6 6
7 #include "base/strings/utf_string_conversions.h"
xiyuan 2014/04/24 21:22:10 Is this used?
dzhioev (left Google) 2014/04/24 22:06:20 No, removed it.
7 #include "chrome/browser/chromeos/login/oauth2_token_fetcher.h" 8 #include "chrome/browser/chromeos/login/oauth2_token_fetcher.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
10 #include "chrome/browser/signin/signin_manager_factory.h" 11 #include "chrome/browser/signin/signin_manager_factory.h"
12 #include "chrome/common/url_constants.h"
11 #include "components/signin/core/browser/profile_oauth2_token_service.h" 13 #include "components/signin/core/browser/profile_oauth2_token_service.h"
12 #include "components/signin/core/browser/signin_manager.h" 14 #include "components/signin/core/browser/signin_manager.h"
15 #include "content/public/browser/storage_partition.h"
16 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_ui.h" 17 #include "content/public/browser/web_ui.h"
18 #include "google_apis/gaia/gaia_urls.h"
19 #include "net/base/url_util.h"
14 20
15 namespace chromeos { 21 namespace chromeos {
16 22
17 class InlineLoginHandlerChromeOS::InlineLoginUIOAuth2Delegate 23 class InlineLoginHandlerChromeOS::InlineLoginUIOAuth2Delegate
18 : public OAuth2TokenFetcher::Delegate { 24 : public OAuth2TokenFetcher::Delegate {
19 public: 25 public:
20 explicit InlineLoginUIOAuth2Delegate(content::WebUI* web_ui) 26 explicit InlineLoginUIOAuth2Delegate(content::WebUI* web_ui,
21 : web_ui_(web_ui) {} 27 const std::string& account_id)
28 : web_ui_(web_ui), account_id_(account_id) {}
29
22 virtual ~InlineLoginUIOAuth2Delegate() {} 30 virtual ~InlineLoginUIOAuth2Delegate() {}
23 31
24 // OAuth2TokenFetcher::Delegate overrides: 32 // OAuth2TokenFetcher::Delegate overrides:
25 virtual void OnOAuth2TokensAvailable( 33 virtual void OnOAuth2TokensAvailable(
26 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE { 34 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE {
27 // Closes sign-in dialog before update token service. Token service update 35 // Closes sign-in dialog before update token service. Token service update
28 // might trigger a permission dialog and if this dialog does not close, 36 // might trigger a permission dialog and if this dialog does not close,
29 // a DCHECK would be triggered because attempting to activate a window 37 // a DCHECK would be triggered because attempting to activate a window
30 // while there is a modal dialog. 38 // while there is a modal dialog.
31 web_ui_->CallJavascriptFunction("inline.login.closeDialog"); 39 web_ui_->CallJavascriptFunction("inline.login.closeDialog");
32 40
33 Profile* profile = Profile::FromWebUI(web_ui_); 41 Profile* profile = Profile::FromWebUI(web_ui_);
34 ProfileOAuth2TokenService* token_service = 42 ProfileOAuth2TokenService* token_service =
35 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 43 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
36 SigninManagerBase* signin_manager = 44 token_service->UpdateCredentials(account_id_, oauth2_tokens.refresh_token);
37 SigninManagerFactory::GetForProfile(profile);
38 token_service->UpdateCredentials(
39 signin_manager->GetAuthenticatedAccountId(),
40 oauth2_tokens.refresh_token);
41 } 45 }
42 46
43 virtual void OnOAuth2TokensFetchFailed() OVERRIDE { 47 virtual void OnOAuth2TokensFetchFailed() OVERRIDE {
44 LOG(ERROR) << "Failed to fetch oauth2 token with inline login."; 48 LOG(ERROR) << "Failed to fetch oauth2 token with inline login.";
45 web_ui_->CallJavascriptFunction("inline.login.handleOAuth2TokenFailure"); 49 web_ui_->CallJavascriptFunction("inline.login.handleOAuth2TokenFailure");
46 } 50 }
47 51
48 private: 52 private:
49 content::WebUI* web_ui_; 53 content::WebUI* web_ui_;
54 std::string account_id_;
50 }; 55 };
xiyuan 2014/04/24 21:22:10 nit: DISALLOW_COPY_AND_ASSIGN since you are here.
dzhioev (left Google) 2014/04/24 22:06:20 Done.
51 56
52 InlineLoginHandlerChromeOS::InlineLoginHandlerChromeOS() {} 57 InlineLoginHandlerChromeOS::InlineLoginHandlerChromeOS() {}
53 58
54 InlineLoginHandlerChromeOS::~InlineLoginHandlerChromeOS() {} 59 InlineLoginHandlerChromeOS::~InlineLoginHandlerChromeOS() {}
55 60
61 void InlineLoginHandlerChromeOS::SetExtraInitParams(
62 base::DictionaryValue& params) {
63 const GURL& current_url = web_ui()->GetWebContents()->GetURL();
64 params.SetInteger("authMode", InlineLoginHandler::kDesktopAuthMode);
65
66 std::string frame_url;
67 net::GetValueForKeyInQuery(current_url, "frameUrl", &frame_url);
68 if (!frame_url.empty())
69 params.SetString("frameUrl", frame_url);
70
71 std::string is_constrained;
72 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained);
73 if (!is_constrained.empty())
74 params.SetString("constrained", is_constrained);
75
76 params.SetString(
77 "gaiaPath",
78 GaiaUrls::GetInstance()->embedded_signin_url().path().substr(1));
79 params.SetString(
80 "continueUrl",
81 "https://www.google.com/intl/en-US/chrome/blank.html?source=10");
xiyuan 2014/04/24 21:22:10 Should we get the url from GetLandingURL() in sign
dzhioev (left Google) 2014/04/24 22:06:20 Yes, sorry I forgot about it. Could you please exp
xiyuan 2014/04/24 22:31:51 It's the enum here: https://code.google.com/p/chro
dzhioev (left Google) 2014/04/24 23:05:47 Roger, should I add the new field?
dzhioev (left Google) 2014/04/29 12:23:58 Replaced with GetLandingURL. Roger said that it is
82 }
83
56 void InlineLoginHandlerChromeOS::CompleteLogin(const base::ListValue* args) { 84 void InlineLoginHandlerChromeOS::CompleteLogin(const base::ListValue* args) {
57 Profile* profile = Profile::FromWebUI(web_ui()); 85 Profile* profile = Profile::FromWebUI(web_ui());
58 86
59 oauth2_delegate_.reset(new InlineLoginUIOAuth2Delegate(web_ui())); 87 const base::DictionaryValue* dict = NULL;
60 oauth2_token_fetcher_.reset(new OAuth2TokenFetcher( 88 args->GetDictionary(0, &dict);
61 oauth2_delegate_.get(), profile->GetRequestContext())); 89
62 oauth2_token_fetcher_->StartExchangeFromCookies(); 90 std::string session_index;
91 dict->GetString("sessionIndex", &session_index);
92 CHECK(!session_index.empty()) << "Session index is empty.";
93
94 std::string account_id;
95 dict->GetString("email", &account_id);
96 CHECK(!account_id.empty()) << "Account ID is empty.";
97
98 oauth2_delegate_.reset(new InlineLoginUIOAuth2Delegate(web_ui(), account_id));
99 net::URLRequestContextGetter* request_context =
100 content::BrowserContext::GetStoragePartitionForSite(
101 profile, GURL(chrome::kChromeUIChromeSigninURL))
102 ->GetURLRequestContext();
103 oauth2_token_fetcher_.reset(
104 new OAuth2TokenFetcher(oauth2_delegate_.get(), request_context));
105 oauth2_token_fetcher_->StartExchangeFromCookies(session_index);
63 } 106 }
64 107
65 } // namespace chromeos 108 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698