Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 #include "components/signin/core/browser/about_signin_internals.h" | 46 #include "components/signin/core/browser/about_signin_internals.h" |
| 47 #include "components/signin/core/browser/account_tracker_service.h" | 47 #include "components/signin/core/browser/account_tracker_service.h" |
| 48 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 48 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 49 #include "components/signin/core/browser/signin_error_controller.h" | 49 #include "components/signin/core/browser/signin_error_controller.h" |
| 50 #include "components/signin/core/browser/signin_header_helper.h" | 50 #include "components/signin/core/browser/signin_header_helper.h" |
| 51 #include "components/signin/core/browser/signin_metrics.h" | 51 #include "components/signin/core/browser/signin_metrics.h" |
| 52 #include "components/signin/core/common/profile_management_switches.h" | 52 #include "components/signin/core/common/profile_management_switches.h" |
| 53 #include "components/signin/core/common/signin_pref_names.h" | 53 #include "components/signin/core/common/signin_pref_names.h" |
| 54 #include "content/public/browser/storage_partition.h" | 54 #include "content/public/browser/storage_partition.h" |
| 55 #include "content/public/browser/web_ui.h" | 55 #include "content/public/browser/web_ui.h" |
| 56 #include "google_apis/gaia/gaia_auth_consumer.h" | |
| 57 #include "google_apis/gaia/gaia_auth_fetcher.h" | 56 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 58 #include "google_apis/gaia/gaia_auth_util.h" | 57 #include "google_apis/gaia/gaia_auth_util.h" |
| 59 #include "google_apis/gaia/gaia_constants.h" | 58 #include "google_apis/gaia/gaia_constants.h" |
| 60 #include "google_apis/gaia/gaia_urls.h" | 59 #include "google_apis/gaia/gaia_urls.h" |
| 61 #include "grit/components_strings.h" | 60 #include "grit/components_strings.h" |
| 62 #include "net/base/url_util.h" | 61 #include "net/base/url_util.h" |
| 63 #include "ui/base/l10n/l10n_util.h" | 62 #include "ui/base/l10n/l10n_util.h" |
| 64 | 63 |
| 65 namespace { | 64 namespace { |
| 66 | 65 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 95 } | 94 } |
| 96 | 95 |
| 97 void RedirectToNtpOrAppsPageIfNecessary(content::WebContents* contents, | 96 void RedirectToNtpOrAppsPageIfNecessary(content::WebContents* contents, |
| 98 signin_metrics::Source source) { | 97 signin_metrics::Source source) { |
| 99 if (source != signin_metrics::SOURCE_SETTINGS) | 98 if (source != signin_metrics::SOURCE_SETTINGS) |
| 100 RedirectToNtpOrAppsPage(contents, source); | 99 RedirectToNtpOrAppsPage(contents, source); |
| 101 } | 100 } |
| 102 | 101 |
| 103 class ConfirmEmailDialogDelegate : public TabModalConfirmDialogDelegate { | 102 class ConfirmEmailDialogDelegate : public TabModalConfirmDialogDelegate { |
| 104 public: | 103 public: |
| 105 enum Action { | |
| 106 CREATE_NEW_USER, | |
| 107 START_SYNC, | |
| 108 CLOSE | |
| 109 }; | |
| 110 | |
| 111 // Callback indicating action performed by the user. | 104 // Callback indicating action performed by the user. |
| 112 typedef base::Callback<void(Action)> Callback; | 105 typedef base::Callback<void(InlineSigninHelper::Action)> Callback; |
| 113 | 106 |
| 114 // Ask the user for confirmation before starting to sync. | 107 // Ask the user for confirmation before starting to sync. |
| 115 static void AskForConfirmation(content::WebContents* contents, | 108 static void AskForConfirmation(content::WebContents* contents, |
| 116 const std::string& last_email, | 109 const std::string& last_email, |
| 117 const std::string& email, | 110 const std::string& email, |
| 118 Callback callback); | 111 Callback callback); |
| 119 | 112 |
| 120 private: | 113 private: |
| 121 ConfirmEmailDialogDelegate(content::WebContents* contents, | 114 ConfirmEmailDialogDelegate(content::WebContents* contents, |
| 122 const std::string& last_email, | 115 const std::string& last_email, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 base::string16 ConfirmEmailDialogDelegate::GetCancelButtonTitle() { | 183 base::string16 ConfirmEmailDialogDelegate::GetCancelButtonTitle() { |
| 191 return l10n_util::GetStringUTF16( | 184 return l10n_util::GetStringUTF16( |
| 192 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); | 185 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); |
| 193 } | 186 } |
| 194 | 187 |
| 195 base::string16 ConfirmEmailDialogDelegate::GetLinkText() const { | 188 base::string16 ConfirmEmailDialogDelegate::GetLinkText() const { |
| 196 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 189 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 197 } | 190 } |
| 198 | 191 |
| 199 void ConfirmEmailDialogDelegate::OnAccepted() { | 192 void ConfirmEmailDialogDelegate::OnAccepted() { |
| 200 base::ResetAndReturn(&callback_).Run(CREATE_NEW_USER); | 193 base::ResetAndReturn(&callback_).Run(InlineSigninHelper::CREATE_NEW_USER); |
| 201 } | 194 } |
| 202 | 195 |
| 203 void ConfirmEmailDialogDelegate::OnCanceled() { | 196 void ConfirmEmailDialogDelegate::OnCanceled() { |
| 204 base::ResetAndReturn(&callback_).Run(START_SYNC); | 197 base::ResetAndReturn(&callback_).Run(InlineSigninHelper::START_SYNC); |
| 205 } | 198 } |
| 206 | 199 |
| 207 void ConfirmEmailDialogDelegate::OnClosed() { | 200 void ConfirmEmailDialogDelegate::OnClosed() { |
| 208 base::ResetAndReturn(&callback_).Run(CLOSE); | 201 base::ResetAndReturn(&callback_).Run(InlineSigninHelper::CLOSE); |
| 209 } | 202 } |
| 210 | 203 |
| 211 void ConfirmEmailDialogDelegate::OnLinkClicked( | 204 void ConfirmEmailDialogDelegate::OnLinkClicked( |
| 212 WindowOpenDisposition disposition) { | 205 WindowOpenDisposition disposition) { |
| 213 content::OpenURLParams params( | 206 content::OpenURLParams params( |
| 214 GURL(chrome::kChromeSyncMergeTroubleshootingURL), | 207 GURL(chrome::kChromeSyncMergeTroubleshootingURL), |
| 215 content::Referrer(), | 208 content::Referrer(), |
| 216 NEW_POPUP, | 209 NEW_POPUP, |
| 217 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 210 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 218 false); | 211 false); |
| 219 // It is guaranteed that |web_contents_| is valid here because when it's | 212 // It is guaranteed that |web_contents_| is valid here because when it's |
| 220 // deleted, the dialog is immediately closed and no further action can be | 213 // deleted, the dialog is immediately closed and no further action can be |
| 221 // performed. | 214 // performed. |
| 222 web_contents_->OpenURL(params); | 215 web_contents_->OpenURL(params); |
| 223 } | 216 } |
| 224 | 217 |
| 225 class InlineSigninHelper : public GaiaAuthConsumer { | 218 } // namespace |
| 226 public: | |
| 227 InlineSigninHelper( | |
| 228 base::WeakPtr<InlineLoginHandlerImpl> handler, | |
| 229 net::URLRequestContextGetter* getter, | |
| 230 Profile* profile, | |
| 231 const GURL& current_url, | |
| 232 const std::string& email, | |
| 233 const std::string& gaia_id, | |
| 234 const std::string& password, | |
| 235 const std::string& session_index, | |
| 236 const std::string& signin_scoped_device_id, | |
| 237 bool choose_what_to_sync, | |
| 238 bool confirm_untrusted_signin); | |
| 239 | |
| 240 private: | |
| 241 // Handles cross account sign in error. If the supplied |email| does not match | |
| 242 // the last signed in email of the current profile, then Chrome will show a | |
| 243 // confirmation dialog before starting sync. It returns true if there is a | |
| 244 // cross account error, and false otherwise. | |
| 245 bool HandleCrossAccountError( | |
| 246 const std::string& refresh_token, | |
| 247 signin_metrics::Source source, | |
| 248 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, | |
| 249 OneClickSigninSyncStarter::StartSyncMode start_mode); | |
| 250 | |
| 251 // Callback used with ConfirmEmailDialogDelegate. | |
| 252 void ConfirmEmailAction( | |
| 253 content::WebContents* web_contents, | |
| 254 const std::string& refresh_token, | |
| 255 signin_metrics::Source source, | |
| 256 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, | |
| 257 OneClickSigninSyncStarter::StartSyncMode start_mode, | |
| 258 ConfirmEmailDialogDelegate::Action action); | |
| 259 | |
| 260 // Overridden from GaiaAuthConsumer. | |
| 261 void OnClientOAuthSuccess(const ClientOAuthResult& result) override; | |
| 262 void OnClientOAuthFailure(const GoogleServiceAuthError& error) | |
| 263 override; | |
| 264 | |
| 265 GaiaAuthFetcher gaia_auth_fetcher_; | |
| 266 base::WeakPtr<InlineLoginHandlerImpl> handler_; | |
| 267 Profile* profile_; | |
| 268 GURL current_url_; | |
| 269 std::string email_; | |
| 270 std::string gaia_id_; | |
| 271 std::string password_; | |
| 272 std::string session_index_; | |
| 273 bool choose_what_to_sync_; | |
| 274 bool confirm_untrusted_signin_; | |
| 275 | |
| 276 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper); | |
| 277 }; | |
| 278 | 219 |
| 279 InlineSigninHelper::InlineSigninHelper( | 220 InlineSigninHelper::InlineSigninHelper( |
| 280 base::WeakPtr<InlineLoginHandlerImpl> handler, | 221 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 281 net::URLRequestContextGetter* getter, | 222 net::URLRequestContextGetter* getter, |
| 282 Profile* profile, | 223 Profile* profile, |
| 283 const GURL& current_url, | 224 const GURL& current_url, |
| 284 const std::string& email, | 225 const std::string& email, |
| 285 const std::string& gaia_id, | 226 const std::string& gaia_id, |
| 286 const std::string& password, | 227 const std::string& password, |
| 287 const std::string& session_index, | 228 const std::string& session_index, |
| 229 const std::string& auth_code, | |
| 288 const std::string& signin_scoped_device_id, | 230 const std::string& signin_scoped_device_id, |
| 289 bool choose_what_to_sync, | 231 bool choose_what_to_sync, |
| 290 bool confirm_untrusted_signin) | 232 bool confirm_untrusted_signin) |
| 291 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter), | 233 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter), |
| 292 handler_(handler), | 234 handler_(handler), |
| 293 profile_(profile), | 235 profile_(profile), |
| 294 current_url_(current_url), | 236 current_url_(current_url), |
| 295 email_(email), | 237 email_(email), |
| 296 gaia_id_(gaia_id), | 238 gaia_id_(gaia_id), |
| 297 password_(password), | 239 password_(password), |
| 298 session_index_(session_index), | 240 session_index_(session_index), |
| 241 auth_code_(auth_code), | |
| 299 choose_what_to_sync_(choose_what_to_sync), | 242 choose_what_to_sync_(choose_what_to_sync), |
| 300 confirm_untrusted_signin_(confirm_untrusted_signin) { | 243 confirm_untrusted_signin_(confirm_untrusted_signin) { |
| 301 DCHECK(profile_); | 244 DCHECK(profile_); |
| 302 DCHECK(!email_.empty()); | 245 DCHECK(!email_.empty()); |
| 303 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId( | 246 if (!auth_code_.empty()) { |
| 304 session_index, signin_scoped_device_id); | 247 gaia_auth_fetcher_.StartAuthCodeForOAuth2TokenExchangeWithDeviceId( |
| 248 auth_code, signin_scoped_device_id); | |
| 249 } else { | |
| 250 DCHECK(!session_index_.empty()); | |
| 251 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId( | |
| 252 session_index_, signin_scoped_device_id); | |
| 253 } | |
| 305 } | 254 } |
| 306 | 255 |
| 256 InlineSigninHelper::~InlineSigninHelper() {} | |
| 257 | |
| 307 void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { | 258 void InlineSigninHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { |
| 308 content::WebContents* contents = NULL; | 259 content::WebContents* contents = NULL; |
| 309 Browser* browser = NULL; | 260 Browser* browser = NULL; |
| 310 if (handler_) { | 261 if (handler_) { |
| 311 contents = handler_->web_ui()->GetWebContents(); | 262 contents = handler_->web_ui()->GetWebContents(); |
| 312 browser = handler_->GetDesktopBrowser(); | 263 browser = handler_->GetDesktopBrowser(); |
| 313 } | 264 } |
| 314 | 265 |
| 315 AboutSigninInternals* about_signin_internals = | 266 AboutSigninInternals* about_signin_internals = |
| 316 AboutSigninInternalsFactory::GetForProfile(profile_); | 267 AboutSigninInternalsFactory::GetForProfile(profile_); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 confirmation_required = | 334 confirmation_required = |
| 384 source == signin_metrics::SOURCE_SETTINGS || | 335 source == signin_metrics::SOURCE_SETTINGS || |
| 385 choose_what_to_sync_ ? | 336 choose_what_to_sync_ ? |
| 386 OneClickSigninSyncStarter::NO_CONFIRMATION : | 337 OneClickSigninSyncStarter::NO_CONFIRMATION : |
| 387 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; | 338 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; |
| 388 } | 339 } |
| 389 | 340 |
| 390 bool start_signin = !HandleCrossAccountError(result.refresh_token, source, | 341 bool start_signin = !HandleCrossAccountError(result.refresh_token, source, |
| 391 confirmation_required, start_mode); | 342 confirmation_required, start_mode); |
| 392 if (start_signin) { | 343 if (start_signin) { |
| 393 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. | 344 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. |
|
achuithb
2015/10/02 21:51:06
This comment should go in the header file I think
Roger Tawa OOO till Jul 10th
2015/10/05 12:18:59
Done.
| |
| 394 // OneClickSigninSyncStarter will delete itself once the job is done. | 345 // OneClickSigninSyncStarter will delete itself once the job is done. |
|
achuithb
2015/10/02 21:51:06
This comment should go right before you create a n
Roger Tawa OOO till Jul 10th
2015/10/05 12:18:59
Done.
| |
| 395 new OneClickSigninSyncStarter( | 346 CreateSyncStarter(browser, |
| 396 profile_, browser, | 347 contents, |
| 397 gaia_id_, email_, password_, result.refresh_token, | 348 signin::GetNextPageURLForPromoURL(current_url_), |
| 398 start_mode, | 349 result.refresh_token, |
| 399 contents, | 350 start_mode, |
| 400 confirmation_required, | 351 confirmation_required); |
| 401 signin::GetNextPageURLForPromoURL(current_url_), | |
| 402 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); | |
| 403 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 352 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 404 } | 353 } |
| 405 } | 354 } |
| 406 } | 355 } |
| 407 | 356 |
| 357 void InlineSigninHelper::CreateSyncStarter( | |
| 358 Browser* browser, | |
| 359 content::WebContents* contents, | |
| 360 const GURL& url, | |
| 361 const std::string& refresh_token, | |
| 362 OneClickSigninSyncStarter::StartSyncMode start_mode, | |
| 363 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required) { | |
| 364 new OneClickSigninSyncStarter( | |
| 365 profile_, browser, | |
| 366 gaia_id_, email_, password_, refresh_token, | |
| 367 start_mode, | |
| 368 contents, | |
| 369 confirmation_required, | |
| 370 url, | |
| 371 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); | |
| 372 } | |
| 373 | |
| 408 bool InlineSigninHelper::HandleCrossAccountError( | 374 bool InlineSigninHelper::HandleCrossAccountError( |
| 409 const std::string& refresh_token, | 375 const std::string& refresh_token, |
| 410 signin_metrics::Source source, | 376 signin_metrics::Source source, |
| 411 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, | 377 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, |
| 412 OneClickSigninSyncStarter::StartSyncMode start_mode) { | 378 OneClickSigninSyncStarter::StartSyncMode start_mode) { |
| 413 std::string last_email = | 379 std::string last_email = |
| 414 profile_->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 380 profile_->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
| 415 | 381 |
| 416 if (last_email.empty() || gaia::AreEmailsSame(last_email, email_)) | 382 if (last_email.empty() || gaia::AreEmailsSame(last_email, email_)) |
| 417 return false; | 383 return false; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 434 start_mode)); | 400 start_mode)); |
| 435 return true; | 401 return true; |
| 436 } | 402 } |
| 437 | 403 |
| 438 void InlineSigninHelper::ConfirmEmailAction( | 404 void InlineSigninHelper::ConfirmEmailAction( |
| 439 content::WebContents* web_contents, | 405 content::WebContents* web_contents, |
| 440 const std::string& refresh_token, | 406 const std::string& refresh_token, |
| 441 signin_metrics::Source source, | 407 signin_metrics::Source source, |
| 442 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, | 408 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, |
| 443 OneClickSigninSyncStarter::StartSyncMode start_mode, | 409 OneClickSigninSyncStarter::StartSyncMode start_mode, |
| 444 ConfirmEmailDialogDelegate::Action action) { | 410 InlineSigninHelper::Action action) { |
| 445 Browser* browser = chrome::FindLastActiveWithProfile( | 411 Browser* browser = chrome::FindLastActiveWithProfile( |
| 446 profile_, chrome::GetActiveDesktop()); | 412 profile_, chrome::GetActiveDesktop()); |
| 447 switch (action) { | 413 switch (action) { |
| 448 case ConfirmEmailDialogDelegate::CREATE_NEW_USER: | 414 case InlineSigninHelper::CREATE_NEW_USER: |
| 449 if (handler_) { | 415 if (handler_) { |
| 450 handler_->SyncStarterCallback( | 416 handler_->SyncStarterCallback( |
| 451 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); | 417 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); |
| 452 } | 418 } |
| 453 chrome::ShowSettingsSubPage(browser, | 419 chrome::ShowSettingsSubPage(browser, |
| 454 std::string(chrome::kCreateProfileSubPage)); | 420 std::string(chrome::kCreateProfileSubPage)); |
| 455 break; | 421 break; |
| 456 case ConfirmEmailDialogDelegate::START_SYNC: | 422 case InlineSigninHelper::START_SYNC: |
| 457 new OneClickSigninSyncStarter( | 423 CreateSyncStarter(browser, web_contents, GURL(), refresh_token, |
| 458 profile_, browser, gaia_id_, email_, password_, refresh_token, | 424 start_mode, confirmation_required); |
| 459 start_mode, web_contents, confirmation_required, GURL(), | |
| 460 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); | |
| 461 break; | 425 break; |
| 462 case ConfirmEmailDialogDelegate::CLOSE: | 426 case InlineSigninHelper::CLOSE: |
| 463 if (handler_) { | 427 if (handler_) { |
| 464 handler_->SyncStarterCallback( | 428 handler_->SyncStarterCallback( |
| 465 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); | 429 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); |
| 466 } | 430 } |
| 467 break; | 431 break; |
| 468 default: | 432 default: |
| 469 DCHECK(false) << "Invalid action"; | 433 DCHECK(false) << "Invalid action"; |
| 470 } | 434 } |
| 471 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 435 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 472 } | 436 } |
| 473 | 437 |
| 474 void InlineSigninHelper::OnClientOAuthFailure( | 438 void InlineSigninHelper::OnClientOAuthFailure( |
| 475 const GoogleServiceAuthError& error) { | 439 const GoogleServiceAuthError& error) { |
| 476 if (handler_) | 440 if (handler_) |
| 477 handler_->HandleLoginError(error.ToString()); | 441 handler_->HandleLoginError(error.ToString()); |
| 478 | 442 |
| 479 AboutSigninInternals* about_signin_internals = | 443 AboutSigninInternals* about_signin_internals = |
| 480 AboutSigninInternalsFactory::GetForProfile(profile_); | 444 AboutSigninInternalsFactory::GetForProfile(profile_); |
| 481 about_signin_internals->OnRefreshTokenReceived("Failure"); | 445 about_signin_internals->OnRefreshTokenReceived("Failure"); |
| 482 | 446 |
| 483 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 447 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 484 } | 448 } |
| 485 | 449 |
| 486 } // namespace | |
| 487 | |
| 488 InlineLoginHandlerImpl::InlineLoginHandlerImpl() | 450 InlineLoginHandlerImpl::InlineLoginHandlerImpl() |
| 489 : confirm_untrusted_signin_(false), | 451 : confirm_untrusted_signin_(false), |
| 490 weak_factory_(this) { | 452 weak_factory_(this) { |
| 491 } | 453 } |
| 492 | 454 |
| 493 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} | 455 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} |
| 494 | 456 |
| 495 // This method is not called with webview sign in enabled. | 457 // This method is not called with webview sign in enabled. |
| 496 void InlineLoginHandlerImpl::DidCommitProvisionalLoadForFrame( | 458 void InlineLoginHandlerImpl::DidCommitProvisionalLoadForFrame( |
| 497 content::RenderFrameHost* render_frame_host, | 459 content::RenderFrameHost* render_frame_host, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { | 566 void InlineLoginHandlerImpl::SetExtraInitParams(base::DictionaryValue& params) { |
| 605 params.SetString("service", "chromiumsync"); | 567 params.SetString("service", "chromiumsync"); |
| 606 | 568 |
| 607 // If this was called from the user manager to reauthenticate the profile, | 569 // If this was called from the user manager to reauthenticate the profile, |
| 608 // make sure the webui is aware. | 570 // make sure the webui is aware. |
| 609 Profile* profile = Profile::FromWebUI(web_ui()); | 571 Profile* profile = Profile::FromWebUI(web_ui()); |
| 610 if (IsSystemProfile(profile)) | 572 if (IsSystemProfile(profile)) |
| 611 params.SetBoolean("dontResizeNonEmbeddedPages", true); | 573 params.SetBoolean("dontResizeNonEmbeddedPages", true); |
| 612 | 574 |
| 613 content::WebContents* contents = web_ui()->GetWebContents(); | 575 content::WebContents* contents = web_ui()->GetWebContents(); |
| 576 const GURL& current_url = contents->GetURL(); | |
| 577 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); | |
| 578 | |
| 579 std::string is_constrained; | |
| 580 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); | |
| 581 | |
| 582 // Use new embedded flow if in constrained window. | |
| 583 if (is_constrained == "1") { | |
| 584 const bool is_new_gaia_flow = switches::UsePasswordSeparatedSigninFlow(); | |
| 585 const GURL url = is_new_gaia_flow | |
|
achuithb
2015/10/02 21:51:06
const GURL&, you don't need to copy
Roger Tawa OOO till Jul 10th
2015/10/05 12:18:59
Done.
| |
| 586 ? GaiaUrls::GetInstance()->embedded_signin_url() | |
| 587 : GaiaUrls::GetInstance()->password_combined_embedded_signin_url(); | |
| 588 params.SetBoolean("isNewGaiaFlow", is_new_gaia_flow); | |
| 589 params.SetString("clientId", | |
| 590 GaiaUrls::GetInstance()->oauth2_chrome_client_id()); | |
| 591 params.SetString("gaiaPath", url.path().substr(1)); | |
| 592 | |
| 593 std::string flow; | |
| 594 switch (source) { | |
| 595 case signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT: | |
| 596 flow = "addaccount"; | |
| 597 break; | |
| 598 case signin_metrics::SOURCE_REAUTH: | |
| 599 flow = "reauth"; | |
| 600 break; | |
| 601 default: | |
| 602 flow = "signin"; | |
| 603 break; | |
| 604 } | |
| 605 params.SetString("flow", flow); | |
| 606 } | |
| 607 | |
| 614 content::WebContentsObserver::Observe(contents); | 608 content::WebContentsObserver::Observe(contents); |
| 615 LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN); | 609 LogHistogramValue(signin_metrics::HISTOGRAM_SHOWN); |
| 616 } | 610 } |
| 617 | 611 |
| 618 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { | 612 void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) { |
| 619 content::WebContents* contents = web_ui()->GetWebContents(); | 613 content::WebContents* contents = web_ui()->GetWebContents(); |
| 620 const GURL& current_url = contents->GetURL(); | 614 const GURL& current_url = contents->GetURL(); |
| 621 | 615 |
| 622 const base::DictionaryValue* dict = NULL; | 616 const base::DictionaryValue* dict = NULL; |
| 623 args->GetDictionary(0, &dict); | 617 args->GetDictionary(0, &dict); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 642 | 636 |
| 643 base::string16 password_string16; | 637 base::string16 password_string16; |
| 644 dict->GetString("password", &password_string16); | 638 dict->GetString("password", &password_string16); |
| 645 std::string password(base::UTF16ToASCII(password_string16)); | 639 std::string password(base::UTF16ToASCII(password_string16)); |
| 646 | 640 |
| 647 base::string16 gaia_id_string16; | 641 base::string16 gaia_id_string16; |
| 648 dict->GetString("gaiaId", &gaia_id_string16); | 642 dict->GetString("gaiaId", &gaia_id_string16); |
| 649 DCHECK(!gaia_id_string16.empty()); | 643 DCHECK(!gaia_id_string16.empty()); |
| 650 std::string gaia_id = base::UTF16ToASCII(gaia_id_string16); | 644 std::string gaia_id = base::UTF16ToASCII(gaia_id_string16); |
| 651 | 645 |
| 646 std::string is_constrained; | |
| 647 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); | |
| 648 const bool is_password_separated_signin_flow = is_constrained == "1" && | |
| 649 switches::UsePasswordSeparatedSigninFlow(); | |
| 650 | |
| 652 base::string16 session_index_string16; | 651 base::string16 session_index_string16; |
| 653 dict->GetString("sessionIndex", &session_index_string16); | 652 dict->GetString("sessionIndex", &session_index_string16); |
| 654 std::string session_index = base::UTF16ToASCII(session_index_string16); | 653 std::string session_index = base::UTF16ToASCII(session_index_string16); |
| 655 DCHECK(!session_index.empty()); | 654 DCHECK(is_password_separated_signin_flow || !session_index.empty()); |
| 655 | |
| 656 base::string16 auth_code_string16; | |
| 657 dict->GetString("authCode", &auth_code_string16); | |
| 658 std::string auth_code = base::UTF16ToASCII(auth_code_string16); | |
| 659 DCHECK(!is_password_separated_signin_flow || !auth_code.empty()); | |
| 656 | 660 |
| 657 bool choose_what_to_sync = false; | 661 bool choose_what_to_sync = false; |
| 658 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); | 662 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync); |
| 659 | 663 |
| 660 content::StoragePartition* partition = | 664 content::StoragePartition* partition = |
| 661 content::BrowserContext::GetStoragePartitionForSite( | 665 content::BrowserContext::GetStoragePartitionForSite( |
| 662 contents->GetBrowserContext(), signin::GetSigninPartitionURL()); | 666 contents->GetBrowserContext(), signin::GetSigninPartitionURL()); |
| 663 | 667 |
| 664 // If this was called from the user manager to reauthenticate the profile, | 668 // If this was called from the user manager to reauthenticate the profile, |
| 665 // the current profile is the system profile. In this case, use the email to | 669 // the current profile is the system profile. In this case, use the email to |
| 666 // find the right profile to reauthenticate. Otherwise the profile can be | 670 // find the right profile to reauthenticate. Otherwise the profile can be |
| 667 // taken from web_ui(). | 671 // taken from web_ui(). |
| 668 Profile* profile = Profile::FromWebUI(web_ui()); | 672 Profile* profile = Profile::FromWebUI(web_ui()); |
| 669 if (IsSystemProfile(profile)) { | 673 if (IsSystemProfile(profile)) { |
| 670 // Switch to the profile and finish the login. Don't pass a handler pointer | 674 // Switch to the profile and finish the login. Don't pass a handler pointer |
| 671 // since it will be destroyed before the callback runs. | 675 // since it will be destroyed before the callback runs. |
| 672 ProfileManager* manager = g_browser_process->profile_manager(); | 676 ProfileManager* manager = g_browser_process->profile_manager(); |
| 673 base::FilePath path = profiles::GetPathOfProfileWithEmail(manager, email); | 677 base::FilePath path = profiles::GetPathOfProfileWithEmail(manager, email); |
| 674 if (!path.empty()) { | 678 if (!path.empty()) { |
| 675 FinishCompleteLoginParams params(nullptr, partition, current_url, path, | 679 FinishCompleteLoginParams params(nullptr, partition, current_url, path, |
| 676 confirm_untrusted_signin_, email, | 680 confirm_untrusted_signin_, email, |
| 677 gaia_id, password, session_index, | 681 gaia_id, password, session_index, |
| 678 choose_what_to_sync); | 682 auth_code, choose_what_to_sync); |
| 679 ProfileManager::CreateCallback callback = base::Bind( | 683 ProfileManager::CreateCallback callback = base::Bind( |
| 680 &InlineLoginHandlerImpl::FinishCompleteLogin, params); | 684 &InlineLoginHandlerImpl::FinishCompleteLogin, params); |
| 681 profiles::SwitchToProfile(path, chrome::GetActiveDesktop(), true, | 685 profiles::SwitchToProfile(path, chrome::GetActiveDesktop(), true, |
| 682 callback, ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 686 callback, ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
| 683 } | 687 } |
| 684 } else { | 688 } else { |
| 685 FinishCompleteLogin( | 689 FinishCompleteLogin( |
| 686 FinishCompleteLoginParams(this, partition, current_url, | 690 FinishCompleteLoginParams(this, partition, current_url, |
| 687 base::FilePath(), confirm_untrusted_signin_, | 691 base::FilePath(), confirm_untrusted_signin_, |
| 688 email, gaia_id, password, session_index, | 692 email, gaia_id, password, session_index, |
| 689 choose_what_to_sync), | 693 auth_code, choose_what_to_sync), |
| 690 profile, | 694 profile, |
| 691 Profile::CREATE_STATUS_CREATED); | 695 Profile::CREATE_STATUS_CREATED); |
| 692 } | 696 } |
| 693 } | 697 } |
| 694 | 698 |
| 695 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams( | 699 InlineLoginHandlerImpl::FinishCompleteLoginParams::FinishCompleteLoginParams( |
| 696 InlineLoginHandlerImpl* handler, | 700 InlineLoginHandlerImpl* handler, |
| 697 content::StoragePartition* partition, | 701 content::StoragePartition* partition, |
| 698 const GURL& url, | 702 const GURL& url, |
| 699 const base::FilePath& profile_path, | 703 const base::FilePath& profile_path, |
| 700 bool confirm_untrusted_signin, | 704 bool confirm_untrusted_signin, |
| 701 const std::string& email, | 705 const std::string& email, |
| 702 const std::string& gaia_id, | 706 const std::string& gaia_id, |
| 703 const std::string& password, | 707 const std::string& password, |
| 704 const std::string& session_index, | 708 const std::string& session_index, |
| 709 const std::string& auth_code, | |
| 705 bool choose_what_to_sync) | 710 bool choose_what_to_sync) |
| 706 : handler(handler), | 711 : handler(handler), |
| 707 partition(partition), | 712 partition(partition), |
| 708 url(url), | 713 url(url), |
| 709 profile_path(profile_path), | 714 profile_path(profile_path), |
| 710 confirm_untrusted_signin(confirm_untrusted_signin), | 715 confirm_untrusted_signin(confirm_untrusted_signin), |
| 711 email(email), | 716 email(email), |
| 712 gaia_id(gaia_id), | 717 gaia_id(gaia_id), |
| 713 password(password), | 718 password(password), |
| 714 session_index(session_index), | 719 session_index(session_index), |
| 720 auth_code(auth_code), | |
| 715 choose_what_to_sync(choose_what_to_sync) {} | 721 choose_what_to_sync(choose_what_to_sync) {} |
| 716 | 722 |
| 717 InlineLoginHandlerImpl:: | 723 InlineLoginHandlerImpl:: |
| 718 FinishCompleteLoginParams::~FinishCompleteLoginParams() {} | 724 FinishCompleteLoginParams::~FinishCompleteLoginParams() {} |
| 719 | 725 |
| 720 // static | 726 // static |
| 721 void InlineLoginHandlerImpl::FinishCompleteLogin( | 727 void InlineLoginHandlerImpl::FinishCompleteLogin( |
| 722 const FinishCompleteLoginParams& params, | 728 const FinishCompleteLoginParams& params, |
| 723 Profile* profile, | 729 Profile* profile, |
| 724 Profile::CreateStatus status) { | 730 Profile::CreateStatus status) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 signin_client->GetSigninScopedDeviceId(); | 794 signin_client->GetSigninScopedDeviceId(); |
| 789 base::WeakPtr<InlineLoginHandlerImpl> handler_weak_ptr; | 795 base::WeakPtr<InlineLoginHandlerImpl> handler_weak_ptr; |
| 790 if (params.handler) | 796 if (params.handler) |
| 791 handler_weak_ptr = params.handler->GetWeakPtr(); | 797 handler_weak_ptr = params.handler->GetWeakPtr(); |
| 792 | 798 |
| 793 // InlineSigninHelper will delete itself. | 799 // InlineSigninHelper will delete itself. |
| 794 new InlineSigninHelper(handler_weak_ptr, | 800 new InlineSigninHelper(handler_weak_ptr, |
| 795 params.partition->GetURLRequestContext(), profile, | 801 params.partition->GetURLRequestContext(), profile, |
| 796 params.url, | 802 params.url, |
| 797 params.email, params.gaia_id, params.password, | 803 params.email, params.gaia_id, params.password, |
| 798 params.session_index, signin_scoped_device_id, | 804 params.session_index, params.auth_code, |
| 805 signin_scoped_device_id, | |
| 799 params.choose_what_to_sync, | 806 params.choose_what_to_sync, |
| 800 params.confirm_untrusted_signin); | 807 params.confirm_untrusted_signin); |
| 801 | 808 |
| 802 // If opened from user manager to reauthenticate, make sure the user manager | 809 // If opened from user manager to reauthenticate, make sure the user manager |
| 803 // is closed and that the profile is marked as unlocked. | 810 // is closed and that the profile is marked as unlocked. |
| 804 if (!params.profile_path.empty()) { | 811 if (!params.profile_path.empty()) { |
| 805 UserManager::Hide(); | 812 UserManager::Hide(); |
| 806 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 813 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 807 if (profile_manager) { | 814 if (profile_manager) { |
| 808 ProfileAttributesEntry* entry; | 815 ProfileAttributesEntry* entry; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 879 } | 886 } |
| 880 } | 887 } |
| 881 | 888 |
| 882 if (show_account_management) { | 889 if (show_account_management) { |
| 883 browser->window()->ShowAvatarBubbleFromAvatarButton( | 890 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 884 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, | 891 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, |
| 885 signin::ManageAccountsParams()); | 892 signin::ManageAccountsParams()); |
| 886 } | 893 } |
| 887 } | 894 } |
| 888 } | 895 } |
| OLD | NEW |