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

Side by Side Diff: chrome/browser/ui/webui/signin/inline_login_handler_impl.cc

Issue 130963006: Reimplement inline signin with iframe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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/signin/inline_login_handler_impl.h" 5 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h"
6 6
7 #include "base/atomic_sequence_num.h"
8 #include "base/bind.h" 7 #include "base/bind.h"
9 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
12 #include "base/values.h" 11 #include "base/values.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/signin/signin_global_error.h" 13 #include "chrome/browser/signin/signin_global_error.h"
15 #include "chrome/browser/signin/signin_oauth_helper.h" 14 #include "chrome/browser/signin/signin_oauth_helper.h"
16 #include "chrome/browser/signin/signin_promo.h" 15 #include "chrome/browser/signin/signin_promo.h"
17 #include "chrome/browser/sync/profile_sync_service.h" 16 #include "chrome/browser/sync/profile_sync_service.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h" 17 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/browser/ui/browser_finder.h" 18 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 19 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h"
23 #include "content/public/browser/storage_partition.h" 23 #include "content/public/browser/storage_partition.h"
24 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_ui.h" 25 #include "content/public/browser/web_ui.h"
26 #include "google_apis/gaia/gaia_auth_fetcher.h" 26 #include "google_apis/gaia/gaia_auth_fetcher.h"
27 #include "google_apis/gaia/gaia_constants.h" 27 #include "google_apis/gaia/gaia_constants.h"
28 #include "google_apis/gaia/gaia_urls.h" 28 #include "google_apis/gaia/gaia_urls.h"
29 #include "net/base/url_util.h" 29 #include "net/base/url_util.h"
30 30
31 namespace { 31 namespace {
32 32
33 // Global SequenceNumber used for generating unique webview partition IDs.
34 base::StaticAtomicSequenceNumber next_partition_id;
35
36 } // empty namespace 33 } // empty namespace
37 34
38 InlineLoginHandlerImpl::InlineLoginHandlerImpl() 35 InlineLoginHandlerImpl::InlineLoginHandlerImpl()
39 : weak_factory_(this), choose_what_to_sync_(false), partition_id_("") { 36 : weak_factory_(this), choose_what_to_sync_(false) {
40 } 37 }
41 38
42 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} 39 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {}
43 40
44 void InlineLoginHandlerImpl::RegisterMessages() { 41 void InlineLoginHandlerImpl::RegisterMessages() {
45 InlineLoginHandler::RegisterMessages(); 42 InlineLoginHandler::RegisterMessages();
46 43
47 web_ui()->RegisterMessageCallback("switchToFullTab", 44 web_ui()->RegisterMessageCallback("switchToFullTab",
48 base::Bind(&InlineLoginHandlerImpl::HandleSwitchToFullTabMessage, 45 base::Bind(&InlineLoginHandlerImpl::HandleSwitchToFullTabMessage,
49 base::Unretained(this))); 46 base::Unretained(this)));
50 } 47 }
51 48
52 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { 49 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) {
53 params.SetInteger("authMode", InlineLoginHandler::kInlineAuthMode); 50 params.SetInteger("authMode", InlineLoginHandler::kDesktopAuthMode);
54 51
55 const GURL& current_url = web_ui()->GetWebContents()->GetURL(); 52 const GURL& current_url = web_ui()->GetWebContents()->GetURL();
56 signin::Source source = signin::GetSourceForPromoURL(current_url); 53 signin::Source source = signin::GetSourceForPromoURL(current_url);
57 DCHECK(source != signin::SOURCE_UNKNOWN); 54 DCHECK(source != signin::SOURCE_UNKNOWN);
58 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || 55 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT ||
59 source == signin::SOURCE_AVATAR_BUBBLE_SIGN_IN) { 56 source == signin::SOURCE_AVATAR_BUBBLE_SIGN_IN) {
60 // Drop the leading slash in the path. 57 // Drop the leading slash in the path.
61 params.SetString("gaiaPath", 58 params.SetString("gaiaPath",
62 GaiaUrls::GetInstance()->embedded_signin_url().path().substr(1)); 59 GaiaUrls::GetInstance()->embedded_signin_url().path().substr(1));
63 } 60 }
(...skipping 11 matching lines...) Expand all
75 72
76 std::string frame_url; 73 std::string frame_url;
77 net::GetValueForKeyInQuery(current_url, "frameUrl", &frame_url); 74 net::GetValueForKeyInQuery(current_url, "frameUrl", &frame_url);
78 if (!frame_url.empty()) 75 if (!frame_url.empty())
79 params.SetString("frameUrl", frame_url); 76 params.SetString("frameUrl", frame_url);
80 77
81 std::string is_constrained; 78 std::string is_constrained;
82 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); 79 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained);
83 if (!is_constrained.empty()) 80 if (!is_constrained.empty())
84 params.SetString("constrained", is_constrained); 81 params.SetString("constrained", is_constrained);
85
86 net::GetValueForKeyInQuery(current_url, "partitionId", &partition_id_);
87 if (partition_id_.empty()) {
88 partition_id_ =
89 "gaia-webview-" + base::IntToString(next_partition_id.GetNext());
90 }
91 params.SetString("partitionId", partition_id_);
92 } 82 }
93 83
94 84
95 void InlineLoginHandlerImpl::HandleSwitchToFullTabMessage( 85 void InlineLoginHandlerImpl::HandleSwitchToFullTabMessage(
96 const base::ListValue* args) { 86 const base::ListValue* args) {
97 base::string16 url_str; 87 base::string16 url_str;
98 CHECK(args->GetString(0, &url_str)); 88 CHECK(args->GetString(0, &url_str));
99 89
100 content::WebContents* web_contents = web_ui()->GetWebContents(); 90 content::WebContents* web_contents = web_ui()->GetWebContents();
101 GURL main_frame_url(web_contents->GetURL()); 91 GURL main_frame_url(web_contents->GetURL());
102 main_frame_url = net::AppendOrReplaceQueryParameter( 92 main_frame_url = net::AppendOrReplaceQueryParameter(
103 main_frame_url, "frameUrl", UTF16ToASCII(url_str)); 93 main_frame_url, "frameUrl", UTF16ToASCII(url_str));
104 main_frame_url = net::AppendOrReplaceQueryParameter(
105 main_frame_url, "partitionId", partition_id_);
106 chrome::NavigateParams params( 94 chrome::NavigateParams params(
107 Profile::FromWebUI(web_ui()), 95 Profile::FromWebUI(web_ui()),
108 net::AppendOrReplaceQueryParameter(main_frame_url, "constrained", "0"), 96 net::AppendOrReplaceQueryParameter(main_frame_url, "constrained", "0"),
109 content::PAGE_TRANSITION_AUTO_TOPLEVEL); 97 content::PAGE_TRANSITION_AUTO_TOPLEVEL);
110 chrome::Navigate(&params); 98 chrome::Navigate(&params);
111 99
112 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); 100 web_ui()->CallJavascriptFunction("inline.login.closeDialog");
113 } 101 }
114 102
115 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { 103 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) {
116 DCHECK(email_.empty() && password_.empty()); 104 DCHECK(email_.empty() && password_.empty() && session_index_.empty());
117 105
118 const base::DictionaryValue* dict = NULL; 106 const base::DictionaryValue* dict = NULL;
119 base::string16 email; 107 base::string16 email;
120 if (!args->GetDictionary(0, &dict) || !dict || 108 if (!args->GetDictionary(0, &dict) || !dict ||
121 !dict->GetString("email", &email)) { 109 !dict->GetString("email", &email)) {
122 // User cancelled the signin by clicking 'skip for now'. 110 // User cancelled the signin by clicking 'skip for now'.
123 bool skip_for_now = false; 111 bool skip_for_now = false;
124 DCHECK(dict->GetBoolean("skipForNow", &skip_for_now) && skip_for_now); 112 DCHECK(dict->GetBoolean("skipForNow", &skip_for_now) && skip_for_now);
125 113
126 signin::SetUserSkippedPromo(Profile::FromWebUI(web_ui())); 114 signin::SetUserSkippedPromo(Profile::FromWebUI(web_ui()));
127 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); 115 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE);
128 return; 116 return;
129 } 117 }
130 118
131 email_ = UTF16ToASCII(email); 119 email_ = UTF16ToASCII(email);
132 base::string16 password; 120 base::string16 password;
133 dict->GetString("password", &password); 121 dict->GetString("password", &password);
134 password_ = UTF16ToASCII(password); 122 password_ = UTF16ToASCII(password);
135 123
124 base::string16 session_index;
125 dict->GetString("sessionIndex", &session_index);
126 session_index_ = UTF16ToASCII(session_index);
127 DCHECK(!session_index_.empty());
136 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_); 128 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_);
137 129
138 content::WebContents* contents = web_ui()->GetWebContents(); 130 content::WebContents* contents = web_ui()->GetWebContents();
139 signin::Source source = signin::GetSourceForPromoURL(contents->GetURL()); 131 signin::Source source = signin::GetSourceForPromoURL(contents->GetURL());
140 OneClickSigninHelper::CanOfferFor can_offer = 132 OneClickSigninHelper::CanOfferFor can_offer =
141 source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT ? 133 source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT ?
142 OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT : 134 OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT :
143 OneClickSigninHelper::CAN_OFFER_FOR_ALL; 135 OneClickSigninHelper::CAN_OFFER_FOR_ALL;
144 std::string error_msg; 136 std::string error_msg;
145 OneClickSigninHelper::CanOffer( 137 OneClickSigninHelper::CanOffer(
146 contents, can_offer, email_, &error_msg); 138 contents, can_offer, email_, &error_msg);
147 if (!error_msg.empty()) { 139 if (!error_msg.empty()) {
148 HandleLoginError(error_msg); 140 HandleLoginError(error_msg);
149 return; 141 return;
150 } 142 }
151 143
152 content::StoragePartition* partition = 144 content::StoragePartition* partition =
153 content::BrowserContext::GetStoragePartitionForSite( 145 content::BrowserContext::GetStoragePartitionForSite(
154 contents->GetBrowserContext(), 146 contents->GetBrowserContext(),
155 GURL("chrome-guest://mfffpogegjflfpflabcdkioaeobkgjik/?" + 147 GURL(chrome::kChromeUIChromeSigninURL));
156 partition_id_));
157 148
158 auth_fetcher_.reset(new GaiaAuthFetcher(this, 149 auth_fetcher_.reset(new GaiaAuthFetcher(this,
159 GaiaConstants::kChromeSource, 150 GaiaConstants::kChromeSource,
160 partition->GetURLRequestContext())); 151 partition->GetURLRequestContext()));
161 auth_fetcher_->StartCookieForOAuthCodeExchange("0"); 152 auth_fetcher_->StartCookieForOAuthCodeExchange(session_index_);
162 } 153 }
163 154
164 void InlineLoginHandlerImpl::OnClientOAuthCodeSuccess( 155 void InlineLoginHandlerImpl::OnClientOAuthCodeSuccess(
165 const std::string& oauth_code) { 156 const std::string& oauth_code) {
166 DCHECK(!oauth_code.empty()); 157 DCHECK(!oauth_code.empty());
167 158
168 content::WebContents* contents = web_ui()->GetWebContents(); 159 content::WebContents* contents = web_ui()->GetWebContents();
169 Profile* profile = Profile::FromWebUI(web_ui()); 160 Profile* profile = Profile::FromWebUI(web_ui());
170 ProfileSyncService* sync_service = 161 ProfileSyncService* sync_service =
171 ProfileSyncServiceFactory::GetForProfile(profile); 162 ProfileSyncServiceFactory::GetForProfile(profile);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 email_, password_, oauth_code, 200 email_, password_, oauth_code,
210 start_mode, 201 start_mode,
211 contents, 202 contents,
212 confirmation_required, 203 confirmation_required,
213 sync_callback); 204 sync_callback);
214 } 205 }
215 } 206 }
216 207
217 email_.clear(); 208 email_.clear();
218 password_.clear(); 209 password_.clear();
210 session_index_.clear();
219 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); 211 web_ui()->CallJavascriptFunction("inline.login.closeDialog");
220 } 212 }
221 213
222 void InlineLoginHandlerImpl::OnClientOAuthCodeFailure( 214 void InlineLoginHandlerImpl::OnClientOAuthCodeFailure(
223 const GoogleServiceAuthError& error) { 215 const GoogleServiceAuthError& error) {
224 LOG(ERROR) << "InlineLoginUI::OnClientOAuthCodeFailure"; 216 LOG(ERROR) << "InlineLoginUI::OnClientOAuthCodeFailure";
225 HandleLoginError(error.ToString()); 217 HandleLoginError(error.ToString());
226 } 218 }
227 219
228 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg) { 220 void InlineLoginHandlerImpl::HandleLoginError(const std::string& error_msg) {
229 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); 221 SyncStarterCallback(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE);
230 222
231 Browser* browser = chrome::FindBrowserWithWebContents( 223 Browser* browser = chrome::FindBrowserWithWebContents(
232 web_ui()->GetWebContents()); 224 web_ui()->GetWebContents());
233 if (!browser) { 225 if (!browser) {
234 browser = chrome::FindLastActiveWithProfile( 226 browser = chrome::FindLastActiveWithProfile(
235 Profile::FromWebUI(web_ui()), chrome::GetActiveDesktop()); 227 Profile::FromWebUI(web_ui()), chrome::GetActiveDesktop());
236 } 228 }
237 if (browser) 229 if (browser)
238 OneClickSigninHelper::ShowSigninErrorBubble(browser, error_msg); 230 OneClickSigninHelper::ShowSigninErrorBubble(browser, error_msg);
239 231
240 email_.clear(); 232 email_.clear();
241 password_.clear(); 233 password_.clear();
234 session_index_.clear();
242 } 235 }
243 236
244 void InlineLoginHandlerImpl::SyncStarterCallback( 237 void InlineLoginHandlerImpl::SyncStarterCallback(
245 OneClickSigninSyncStarter::SyncSetupResult result) { 238 OneClickSigninSyncStarter::SyncSetupResult result) {
246 content::WebContents* contents = web_ui()->GetWebContents(); 239 content::WebContents* contents = web_ui()->GetWebContents();
247 const GURL& current_url = contents->GetURL(); 240 const GURL& current_url = contents->GetURL();
248 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); 241 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url);
249 if (auto_close) { 242 if (auto_close) {
250 base::MessageLoop::current()->PostTask( 243 base::MessageLoop::current()->PostTask(
251 FROM_HERE, 244 FROM_HERE,
(...skipping 13 matching lines...) Expand all
265 TabStripModel* tab_strip_model = browser->tab_strip_model(); 258 TabStripModel* tab_strip_model = browser->tab_strip_model();
266 if (tab_strip_model) { 259 if (tab_strip_model) {
267 int index = tab_strip_model->GetIndexOfWebContents(tab); 260 int index = tab_strip_model->GetIndexOfWebContents(tab);
268 if (index != TabStripModel::kNoTab) { 261 if (index != TabStripModel::kNoTab) {
269 tab_strip_model->ExecuteContextMenuCommand( 262 tab_strip_model->ExecuteContextMenuCommand(
270 index, TabStripModel::CommandCloseTab); 263 index, TabStripModel::CommandCloseTab);
271 } 264 }
272 } 265 }
273 } 266 }
274 } 267 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698