| 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/autofill/autofill_dialog_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 | 691 |
| 692 // TODO(estade): don't show the dialog if the site didn't specify the right | 692 // TODO(estade): don't show the dialog if the site didn't specify the right |
| 693 // fields. First we must figure out what the "right" fields are. | 693 // fields. First we must figure out what the "right" fields are. |
| 694 view_.reset(CreateView()); | 694 view_.reset(CreateView()); |
| 695 view_->Show(); | 695 view_->Show(); |
| 696 GetManager()->AddObserver(this); | 696 GetManager()->AddObserver(this); |
| 697 | 697 |
| 698 // Try to see if the user is already signed-in. If signed-in, fetch the user's | 698 // Try to see if the user is already signed-in. If signed-in, fetch the user's |
| 699 // Wallet data. Otherwise, see if the user could be signed in passively. | 699 // Wallet data. Otherwise, see if the user could be signed in passively. |
| 700 // TODO(aruslan): UMA metrics for sign-in. | 700 // TODO(aruslan): UMA metrics for sign-in. |
| 701 signin_helper_.reset(new wallet::WalletSigninHelper( | 701 FetchWalletCookieAndUserName(); |
| 702 this, profile_->GetRequestContext())); | |
| 703 signin_helper_->StartWalletCookieValueFetch(); | |
| 704 | 702 |
| 705 if (!account_chooser_model_.WalletIsSelected()) | 703 if (!account_chooser_model_.WalletIsSelected()) { |
| 706 LogDialogLatencyToShow(); | 704 LogDialogLatencyToShow(); |
| 705 } |
| 707 } | 706 } |
| 708 | 707 |
| 709 void AutofillDialogControllerImpl::Hide() { | 708 void AutofillDialogControllerImpl::Hide() { |
| 710 if (view_) | 709 if (view_) |
| 711 view_->Hide(); | 710 view_->Hide(); |
| 712 } | 711 } |
| 713 | 712 |
| 714 void AutofillDialogControllerImpl::TabActivated() { | 713 void AutofillDialogControllerImpl::TabActivated() { |
| 715 // If the user switched away from this tab and then switched back, reload the | 714 // If the user switched away from this tab and then switched back, reload the |
| 716 // Wallet items, in case they've changed. | 715 // Wallet items, in case they've changed. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 signin_registrar_.RemoveAll(); | 970 signin_registrar_.RemoveAll(); |
| 972 view_->HideSignIn(); | 971 view_->HideSignIn(); |
| 973 view_->UpdateAccountChooser(); | 972 view_->UpdateAccountChooser(); |
| 974 } | 973 } |
| 975 | 974 |
| 976 AutofillDialogControllerImpl::DialogSignedInState | 975 AutofillDialogControllerImpl::DialogSignedInState |
| 977 AutofillDialogControllerImpl::SignedInState() const { | 976 AutofillDialogControllerImpl::SignedInState() const { |
| 978 if (wallet_error_notification_) | 977 if (wallet_error_notification_) |
| 979 return SIGN_IN_DISABLED; | 978 return SIGN_IN_DISABLED; |
| 980 | 979 |
| 981 if (signin_helper_ || !wallet_items_) | 980 if (signin_helper_ || username_fetcher_ || !wallet_items_) |
| 982 return REQUIRES_RESPONSE; | 981 return REQUIRES_RESPONSE; |
| 983 | 982 |
| 984 if (wallet_items_->HasRequiredAction(wallet::GAIA_AUTH)) | 983 if (wallet_items_->HasRequiredAction(wallet::GAIA_AUTH)) |
| 985 return REQUIRES_SIGN_IN; | 984 return REQUIRES_SIGN_IN; |
| 986 | 985 |
| 987 if (wallet_items_->HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) | 986 if (wallet_items_->HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) |
| 988 return REQUIRES_PASSIVE_SIGN_IN; | 987 return REQUIRES_PASSIVE_SIGN_IN; |
| 989 | 988 |
| 990 return SIGNED_IN; | 989 return SIGNED_IN; |
| 991 } | 990 } |
| 992 | 991 |
| 993 void AutofillDialogControllerImpl::SignedInStateUpdated() { | 992 void AutofillDialogControllerImpl::SignedInStateUpdated() { |
| 994 switch (SignedInState()) { | 993 switch (SignedInState()) { |
| 995 case SIGNED_IN: | 994 case SIGNED_IN: |
| 996 // Start fetching the user name if we don't know it yet. | 995 // Start fetching the user name if we don't know it yet. |
| 997 if (account_chooser_model_.active_wallet_account_name().empty()) { | 996 if (account_chooser_model_.active_wallet_account_name().empty()) { |
| 998 signin_helper_.reset(new wallet::WalletSigninHelper( | 997 username_fetcher_.reset(new wallet::WalletSigninHelper( |
| 999 this, profile_->GetRequestContext())); | 998 this, profile_->GetRequestContext())); |
| 1000 signin_helper_->StartUserNameFetch(); | 999 username_fetcher_->StartUserNameFetch(); |
| 1001 } else { | 1000 } else { |
| 1002 LogDialogLatencyToShow(); | 1001 LogDialogLatencyToShow(); |
| 1003 } | 1002 } |
| 1004 break; | 1003 break; |
| 1005 | 1004 |
| 1006 case REQUIRES_SIGN_IN: | 1005 case REQUIRES_SIGN_IN: |
| 1007 case SIGN_IN_DISABLED: | 1006 case SIGN_IN_DISABLED: |
| 1008 // Switch to the local account and refresh the dialog. | 1007 // Switch to the local account and refresh the dialog. |
| 1009 OnWalletSigninError(); | 1008 OnWalletSigninError(); |
| 1010 break; | 1009 break; |
| 1011 | 1010 |
| 1012 case REQUIRES_PASSIVE_SIGN_IN: | 1011 case REQUIRES_PASSIVE_SIGN_IN: |
| 1012 // Cancel any pending username fetch and clear any stale username data. |
| 1013 username_fetcher_.reset(); |
| 1014 account_chooser_model_.ClearActiveWalletAccountName(); |
| 1015 |
| 1013 // Attempt to passively sign in the user. | 1016 // Attempt to passively sign in the user. |
| 1014 DCHECK(!signin_helper_); | 1017 DCHECK(!signin_helper_); |
| 1015 account_chooser_model_.ClearActiveWalletAccountName(); | |
| 1016 signin_helper_.reset(new wallet::WalletSigninHelper( | 1018 signin_helper_.reset(new wallet::WalletSigninHelper( |
| 1017 this, | 1019 this, |
| 1018 profile_->GetRequestContext())); | 1020 profile_->GetRequestContext())); |
| 1019 signin_helper_->StartPassiveSignin(); | 1021 signin_helper_->StartPassiveSignin(); |
| 1020 break; | 1022 break; |
| 1021 | 1023 |
| 1022 case REQUIRES_RESPONSE: | 1024 case REQUIRES_RESPONSE: |
| 1023 break; | 1025 break; |
| 1024 } | 1026 } |
| 1025 } | 1027 } |
| (...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2100 void AutofillDialogControllerImpl::Observe( | 2102 void AutofillDialogControllerImpl::Observe( |
| 2101 int type, | 2103 int type, |
| 2102 const content::NotificationSource& source, | 2104 const content::NotificationSource& source, |
| 2103 const content::NotificationDetails& details) { | 2105 const content::NotificationDetails& details) { |
| 2104 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); | 2106 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); |
| 2105 content::LoadCommittedDetails* load_details = | 2107 content::LoadCommittedDetails* load_details = |
| 2106 content::Details<content::LoadCommittedDetails>(details).ptr(); | 2108 content::Details<content::LoadCommittedDetails>(details).ptr(); |
| 2107 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { | 2109 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { |
| 2108 should_show_wallet_promo_ = false; | 2110 should_show_wallet_promo_ = false; |
| 2109 account_chooser_model_.SelectActiveWalletAccount(); | 2111 account_chooser_model_.SelectActiveWalletAccount(); |
| 2110 signin_helper_.reset(new wallet::WalletSigninHelper( | 2112 FetchWalletCookieAndUserName(); |
| 2111 this, profile_->GetRequestContext())); | |
| 2112 signin_helper_->StartWalletCookieValueFetch(); | |
| 2113 HideSignIn(); | 2113 HideSignIn(); |
| 2114 } | 2114 } |
| 2115 } | 2115 } |
| 2116 | 2116 |
| 2117 //////////////////////////////////////////////////////////////////////////////// | 2117 //////////////////////////////////////////////////////////////////////////////// |
| 2118 // SuggestionsMenuModelDelegate implementation. | 2118 // SuggestionsMenuModelDelegate implementation. |
| 2119 | 2119 |
| 2120 void AutofillDialogControllerImpl::SuggestionItemSelected( | 2120 void AutofillDialogControllerImpl::SuggestionItemSelected( |
| 2121 SuggestionsMenuModel* model, | 2121 SuggestionsMenuModel* model, |
| 2122 size_t index) { | 2122 size_t index) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2226 const std::string& username) { | 2226 const std::string& username) { |
| 2227 const string16 username16 = UTF8ToUTF16(username); | 2227 const string16 username16 = UTF8ToUTF16(username); |
| 2228 signin_helper_->StartWalletCookieValueFetch(); | 2228 signin_helper_->StartWalletCookieValueFetch(); |
| 2229 account_chooser_model_.SetActiveWalletAccountName(username16); | 2229 account_chooser_model_.SetActiveWalletAccountName(username16); |
| 2230 } | 2230 } |
| 2231 | 2231 |
| 2232 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( | 2232 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( |
| 2233 const std::string& username) { | 2233 const std::string& username) { |
| 2234 ScopedViewUpdates updates(view_.get()); | 2234 ScopedViewUpdates updates(view_.get()); |
| 2235 const string16 username16 = UTF8ToUTF16(username); | 2235 const string16 username16 = UTF8ToUTF16(username); |
| 2236 signin_helper_.reset(); | 2236 username_fetcher_.reset(); |
| 2237 account_chooser_model_.SetActiveWalletAccountName(username16); | 2237 account_chooser_model_.SetActiveWalletAccountName(username16); |
| 2238 OnWalletOrSigninUpdate(); | 2238 OnWalletOrSigninUpdate(); |
| 2239 } | 2239 } |
| 2240 | 2240 |
| 2241 void AutofillDialogControllerImpl::OnPassiveSigninFailure( | 2241 void AutofillDialogControllerImpl::OnPassiveSigninFailure( |
| 2242 const GoogleServiceAuthError& error) { | 2242 const GoogleServiceAuthError& error) { |
| 2243 // TODO(aruslan): report an error. | 2243 // TODO(aruslan): report an error. |
| 2244 LOG(ERROR) << "failed to passively sign in: " << error.ToString(); | 2244 LOG(ERROR) << "failed to passively sign in: " << error.ToString(); |
| 2245 signin_helper_.reset(); |
| 2245 OnWalletSigninError(); | 2246 OnWalletSigninError(); |
| 2246 } | 2247 } |
| 2247 | 2248 |
| 2248 void AutofillDialogControllerImpl::OnUserNameFetchFailure( | 2249 void AutofillDialogControllerImpl::OnUserNameFetchFailure( |
| 2249 const GoogleServiceAuthError& error) { | 2250 const GoogleServiceAuthError& error) { |
| 2250 // TODO(aruslan): report an error. | 2251 // TODO(aruslan): report an error. |
| 2251 LOG(ERROR) << "failed to fetch the user account name: " << error.ToString(); | 2252 LOG(ERROR) << "failed to fetch the user account name: " << error.ToString(); |
| 2252 OnWalletSigninError(); | 2253 username_fetcher_.reset(); |
| 2254 // Only treat the failed fetch as an error if the user is known to already be |
| 2255 // signed in. Attempting to fetch the username prior to loading the |
| 2256 // |wallet_items_| is purely a performance optimization that shouldn't be |
| 2257 // treated as an error if it fails. |
| 2258 if (wallet_items_) |
| 2259 OnWalletSigninError(); |
| 2253 } | 2260 } |
| 2254 | 2261 |
| 2255 void AutofillDialogControllerImpl::OnDidFetchWalletCookieValue( | 2262 void AutofillDialogControllerImpl::OnDidFetchWalletCookieValue( |
| 2256 const std::string& cookie_value) { | 2263 const std::string& cookie_value) { |
| 2257 wallet_cookie_value_ = cookie_value; | 2264 wallet_cookie_value_ = cookie_value; |
| 2258 signin_helper_.reset(); | 2265 signin_helper_.reset(); |
| 2259 GetWalletItems(); | 2266 GetWalletItems(); |
| 2260 } | 2267 } |
| 2261 | 2268 |
| 2262 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 2269 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2481 } | 2488 } |
| 2482 | 2489 |
| 2483 bool AutofillDialogControllerImpl::IsManuallyEditingSection( | 2490 bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
| 2484 DialogSection section) const { | 2491 DialogSection section) const { |
| 2485 return IsEditingExistingData(section) || | 2492 return IsEditingExistingData(section) || |
| 2486 SuggestionsMenuModelForSection(section)-> | 2493 SuggestionsMenuModelForSection(section)-> |
| 2487 GetItemKeyForCheckedItem() == kAddNewItemKey; | 2494 GetItemKeyForCheckedItem() == kAddNewItemKey; |
| 2488 } | 2495 } |
| 2489 | 2496 |
| 2490 void AutofillDialogControllerImpl::OnWalletSigninError() { | 2497 void AutofillDialogControllerImpl::OnWalletSigninError() { |
| 2491 signin_helper_.reset(); | |
| 2492 account_chooser_model_.SetHadWalletSigninError(); | 2498 account_chooser_model_.SetHadWalletSigninError(); |
| 2493 GetWalletClient()->CancelRequests(); | 2499 GetWalletClient()->CancelRequests(); |
| 2494 LogDialogLatencyToShow(); | 2500 LogDialogLatencyToShow(); |
| 2495 } | 2501 } |
| 2496 | 2502 |
| 2497 void AutofillDialogControllerImpl::DisableWallet( | 2503 void AutofillDialogControllerImpl::DisableWallet( |
| 2498 wallet::WalletClient::ErrorType error_type) { | 2504 wallet::WalletClient::ErrorType error_type) { |
| 2499 signin_helper_.reset(); | 2505 signin_helper_.reset(); |
| 2506 username_fetcher_.reset(); |
| 2500 wallet_items_.reset(); | 2507 wallet_items_.reset(); |
| 2501 wallet_errors_.clear(); | 2508 wallet_errors_.clear(); |
| 2502 GetWalletClient()->CancelRequests(); | 2509 GetWalletClient()->CancelRequests(); |
| 2503 SetIsSubmitting(false); | 2510 SetIsSubmitting(false); |
| 2504 wallet_error_notification_ = GetWalletError(error_type); | 2511 wallet_error_notification_ = GetWalletError(error_type); |
| 2505 account_chooser_model_.SetHadWalletError(); | 2512 account_chooser_model_.SetHadWalletError(); |
| 2506 } | 2513 } |
| 2507 | 2514 |
| 2508 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 2515 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
| 2509 ScopedViewUpdates updates(view_.get()); | 2516 ScopedViewUpdates updates(view_.get()); |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3416 #endif | 3423 #endif |
| 3417 } | 3424 } |
| 3418 | 3425 |
| 3419 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { | 3426 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { |
| 3420 if (!view_) | 3427 if (!view_) |
| 3421 return; | 3428 return; |
| 3422 ScopedViewUpdates updates(view_.get()); | 3429 ScopedViewUpdates updates(view_.get()); |
| 3423 view_->UpdateButtonStrip(); | 3430 view_->UpdateButtonStrip(); |
| 3424 } | 3431 } |
| 3425 | 3432 |
| 3433 void AutofillDialogControllerImpl::FetchWalletCookieAndUserName() { |
| 3434 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 3435 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 3436 signin_helper_->StartWalletCookieValueFetch(); |
| 3437 |
| 3438 username_fetcher_.reset( |
| 3439 new wallet::WalletSigninHelper(this, request_context)); |
| 3440 username_fetcher_->StartUserNameFetch(); |
| 3441 } |
| 3442 |
| 3426 } // namespace autofill | 3443 } // namespace autofill |
| OLD | NEW |