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/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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 | 106 |
| 107 // This string is stored along with saved addresses and credit cards in the | 107 // This string is stored along with saved addresses and credit cards in the |
| 108 // WebDB, and hence should not be modified, so that it remains consistent over | 108 // WebDB, and hence should not be modified, so that it remains consistent over |
| 109 // time. | 109 // time. |
| 110 const char kAutofillDialogOrigin[] = "Chrome Autofill dialog"; | 110 const char kAutofillDialogOrigin[] = "Chrome Autofill dialog"; |
| 111 | 111 |
| 112 // HSL shift to gray out an image. | 112 // HSL shift to gray out an image. |
| 113 const color_utils::HSL kGrayImageShift = {-1, 0, 0.8}; | 113 const color_utils::HSL kGrayImageShift = {-1, 0, 0.8}; |
| 114 | 114 |
| 115 // Limit Wallet items refresh rate to at most once per minute. | 115 // Limit Wallet items refresh rate to at most once per minute. |
| 116 const int kWalletItemsRefreshRateSeconds = 60; | 116 const int64 kWalletItemsRefreshRateSeconds = 60; |
| 117 | 117 |
| 118 // The number of milliseconds to delay enabling the submit button after showing | 118 // The number of milliseconds to delay enabling the submit button after showing |
| 119 // the dialog. This delay prevents users from accidentally clicking the submit | 119 // the dialog. This delay prevents users from accidentally clicking the submit |
| 120 // button on startup. | 120 // button on startup. |
| 121 const int kSubmitButtonDelayMs = 1000; | 121 const int kSubmitButtonDelayMs = 1000; |
| 122 | 122 |
| 123 // A helper class to make sure an AutofillDialogView knows when a series of | 123 // A helper class to make sure an AutofillDialogView knows when a series of |
| 124 // updates is incoming. | 124 // updates is incoming. |
| 125 class ScopedViewUpdates { | 125 class ScopedViewUpdates { |
| 126 public: | 126 public: |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 694 | 694 |
| 695 // TODO(estade): don't show the dialog if the site didn't specify the right | 695 // TODO(estade): don't show the dialog if the site didn't specify the right |
| 696 // fields. First we must figure out what the "right" fields are. | 696 // fields. First we must figure out what the "right" fields are. |
| 697 view_.reset(CreateView()); | 697 view_.reset(CreateView()); |
| 698 view_->Show(); | 698 view_->Show(); |
| 699 GetManager()->AddObserver(this); | 699 GetManager()->AddObserver(this); |
| 700 | 700 |
| 701 // Try to see if the user is already signed-in. If signed-in, fetch the user's | 701 // Try to see if the user is already signed-in. If signed-in, fetch the user's |
| 702 // Wallet data. Otherwise, see if the user could be signed in passively. | 702 // Wallet data. Otherwise, see if the user could be signed in passively. |
| 703 // TODO(aruslan): UMA metrics for sign-in. | 703 // TODO(aruslan): UMA metrics for sign-in. |
| 704 signin_helper_.reset(new wallet::WalletSigninHelper( | 704 FetchWalletCookieAndUserName(); |
| 705 this, profile_->GetRequestContext())); | |
| 706 signin_helper_->StartWalletCookieValueFetch(); | |
| 707 | 705 |
| 708 if (!account_chooser_model_.WalletIsSelected()) | 706 if (!account_chooser_model_.WalletIsSelected()) |
| 709 LogDialogLatencyToShow(); | 707 LogDialogLatencyToShow(); |
| 710 } | 708 } |
| 711 | 709 |
| 712 void AutofillDialogControllerImpl::Hide() { | 710 void AutofillDialogControllerImpl::Hide() { |
| 713 if (view_) | 711 if (view_) |
| 714 view_->Hide(); | 712 view_->Hide(); |
| 715 } | 713 } |
| 716 | 714 |
| 717 void AutofillDialogControllerImpl::TabActivated() { | 715 void AutofillDialogControllerImpl::TabActivated() { |
| 718 // If the user switched away from this tab and then switched back, reload the | 716 // If the user switched away from this tab and then switched back, reload the |
| 719 // Wallet items, in case they've changed. | 717 // Wallet items, in case they've changed. |
| 720 int seconds_elapsed_since_last_refresh = | 718 int64 seconds_elapsed_since_last_refresh = |
| 721 (base::TimeTicks::Now() - last_wallet_items_fetch_timestamp_).InSeconds(); | 719 (base::TimeTicks::Now() - last_wallet_items_fetch_timestamp_).InSeconds(); |
| 722 if (IsPayingWithWallet() && wallet_items_ && | 720 if (IsPayingWithWallet() && wallet_items_ && |
| 723 seconds_elapsed_since_last_refresh >= kWalletItemsRefreshRateSeconds) { | 721 seconds_elapsed_since_last_refresh >= kWalletItemsRefreshRateSeconds) { |
| 724 GetWalletItems(); | 722 GetWalletItems(); |
| 725 } | 723 } |
| 726 } | 724 } |
| 727 | 725 |
| 728 TestableAutofillDialogView* AutofillDialogControllerImpl::GetTestableView() { | 726 TestableAutofillDialogView* AutofillDialogControllerImpl::GetTestableView() { |
| 729 return view_ ? view_->GetTestableView() : NULL; | 727 return view_ ? view_->GetTestableView() : NULL; |
| 730 } | 728 } |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 signin_registrar_.RemoveAll(); | 966 signin_registrar_.RemoveAll(); |
| 969 view_->HideSignIn(); | 967 view_->HideSignIn(); |
| 970 view_->UpdateAccountChooser(); | 968 view_->UpdateAccountChooser(); |
| 971 } | 969 } |
| 972 | 970 |
| 973 AutofillDialogControllerImpl::DialogSignedInState | 971 AutofillDialogControllerImpl::DialogSignedInState |
| 974 AutofillDialogControllerImpl::SignedInState() const { | 972 AutofillDialogControllerImpl::SignedInState() const { |
| 975 if (wallet_error_notification_) | 973 if (wallet_error_notification_) |
| 976 return SIGN_IN_DISABLED; | 974 return SIGN_IN_DISABLED; |
| 977 | 975 |
| 978 if (signin_helper_ || !wallet_items_) | 976 if (signin_helper_ || username_fetcher_ || !wallet_items_) |
| 979 return REQUIRES_RESPONSE; | 977 return REQUIRES_RESPONSE; |
| 980 | 978 |
| 981 if (wallet_items_->HasRequiredAction(wallet::GAIA_AUTH)) | 979 if (wallet_items_->HasRequiredAction(wallet::GAIA_AUTH)) |
| 982 return REQUIRES_SIGN_IN; | 980 return REQUIRES_SIGN_IN; |
| 983 | 981 |
| 984 if (wallet_items_->HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) | 982 if (wallet_items_->HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) |
| 985 return REQUIRES_PASSIVE_SIGN_IN; | 983 return REQUIRES_PASSIVE_SIGN_IN; |
| 986 | 984 |
| 987 return SIGNED_IN; | 985 return SIGNED_IN; |
| 988 } | 986 } |
| 989 | 987 |
| 990 void AutofillDialogControllerImpl::SignedInStateUpdated() { | 988 void AutofillDialogControllerImpl::SignedInStateUpdated() { |
| 991 switch (SignedInState()) { | 989 switch (SignedInState()) { |
| 992 case SIGNED_IN: | 990 case SIGNED_IN: |
| 993 // Start fetching the user name if we don't know it yet. | 991 // Start fetching the user name if we don't know it yet. |
| 994 if (account_chooser_model_.active_wallet_account_name().empty()) { | 992 if (account_chooser_model_.active_wallet_account_name().empty()) { |
| 995 signin_helper_.reset(new wallet::WalletSigninHelper( | 993 username_fetcher_.reset(new wallet::WalletSigninHelper( |
|
Evan Stade
2013/09/23 18:13:44
DCHECK(!username_fetcher_)
Ilya Sherman
2013/09/24 00:50:59
Done.
| |
| 996 this, profile_->GetRequestContext())); | 994 this, profile_->GetRequestContext())); |
| 997 signin_helper_->StartUserNameFetch(); | 995 username_fetcher_->StartUserNameFetch(); |
| 998 } else { | 996 } else { |
| 999 LogDialogLatencyToShow(); | 997 LogDialogLatencyToShow(); |
| 1000 } | 998 } |
| 1001 break; | 999 break; |
| 1002 | 1000 |
| 1003 case REQUIRES_SIGN_IN: | 1001 case REQUIRES_SIGN_IN: |
| 1004 case SIGN_IN_DISABLED: | 1002 case SIGN_IN_DISABLED: |
| 1005 // Switch to the local account and refresh the dialog. | 1003 // Switch to the local account and refresh the dialog. |
| 1006 OnWalletSigninError(); | 1004 OnWalletSigninError(); |
| 1007 break; | 1005 break; |
| 1008 | 1006 |
| 1009 case REQUIRES_PASSIVE_SIGN_IN: | 1007 case REQUIRES_PASSIVE_SIGN_IN: |
| 1008 // Cancel any pending username fetch and clear any stale username data. | |
| 1009 username_fetcher_.reset(); | |
|
Evan Stade
2013/09/23 18:13:44
I don't think username_fetcher_ can be non-null he
Ilya Sherman
2013/09/24 00:50:59
Oops, that was a bug in SignedInState(). It ought
| |
| 1010 account_chooser_model_.ClearActiveWalletAccountName(); | |
| 1011 | |
| 1010 // Attempt to passively sign in the user. | 1012 // Attempt to passively sign in the user. |
| 1011 DCHECK(!signin_helper_); | 1013 DCHECK(!signin_helper_); |
| 1012 account_chooser_model_.ClearActiveWalletAccountName(); | |
| 1013 signin_helper_.reset(new wallet::WalletSigninHelper( | 1014 signin_helper_.reset(new wallet::WalletSigninHelper( |
| 1014 this, | 1015 this, |
| 1015 profile_->GetRequestContext())); | 1016 profile_->GetRequestContext())); |
| 1016 signin_helper_->StartPassiveSignin(); | 1017 signin_helper_->StartPassiveSignin(); |
| 1017 break; | 1018 break; |
| 1018 | 1019 |
| 1019 case REQUIRES_RESPONSE: | 1020 case REQUIRES_RESPONSE: |
| 1020 break; | 1021 break; |
| 1021 } | 1022 } |
| 1022 } | 1023 } |
| (...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2089 | 2090 |
| 2090 void AutofillDialogControllerImpl::Observe( | 2091 void AutofillDialogControllerImpl::Observe( |
| 2091 int type, | 2092 int type, |
| 2092 const content::NotificationSource& source, | 2093 const content::NotificationSource& source, |
| 2093 const content::NotificationDetails& details) { | 2094 const content::NotificationDetails& details) { |
| 2094 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); | 2095 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); |
| 2095 content::LoadCommittedDetails* load_details = | 2096 content::LoadCommittedDetails* load_details = |
| 2096 content::Details<content::LoadCommittedDetails>(details).ptr(); | 2097 content::Details<content::LoadCommittedDetails>(details).ptr(); |
| 2097 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { | 2098 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { |
| 2098 account_chooser_model_.SelectActiveWalletAccount(); | 2099 account_chooser_model_.SelectActiveWalletAccount(); |
| 2099 signin_helper_.reset(new wallet::WalletSigninHelper( | 2100 FetchWalletCookieAndUserName(); |
| 2100 this, profile_->GetRequestContext())); | |
| 2101 signin_helper_->StartWalletCookieValueFetch(); | |
| 2102 HideSignIn(); | 2101 HideSignIn(); |
| 2103 } | 2102 } |
| 2104 } | 2103 } |
| 2105 | 2104 |
| 2106 //////////////////////////////////////////////////////////////////////////////// | 2105 //////////////////////////////////////////////////////////////////////////////// |
| 2107 // SuggestionsMenuModelDelegate implementation. | 2106 // SuggestionsMenuModelDelegate implementation. |
| 2108 | 2107 |
| 2109 void AutofillDialogControllerImpl::SuggestionItemSelected( | 2108 void AutofillDialogControllerImpl::SuggestionItemSelected( |
| 2110 SuggestionsMenuModel* model, | 2109 SuggestionsMenuModel* model, |
| 2111 size_t index) { | 2110 size_t index) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2216 const std::string& username) { | 2215 const std::string& username) { |
| 2217 const string16 username16 = UTF8ToUTF16(username); | 2216 const string16 username16 = UTF8ToUTF16(username); |
| 2218 signin_helper_->StartWalletCookieValueFetch(); | 2217 signin_helper_->StartWalletCookieValueFetch(); |
| 2219 account_chooser_model_.SetActiveWalletAccountName(username16); | 2218 account_chooser_model_.SetActiveWalletAccountName(username16); |
| 2220 } | 2219 } |
| 2221 | 2220 |
| 2222 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( | 2221 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( |
| 2223 const std::string& username) { | 2222 const std::string& username) { |
| 2224 ScopedViewUpdates updates(view_.get()); | 2223 ScopedViewUpdates updates(view_.get()); |
| 2225 const string16 username16 = UTF8ToUTF16(username); | 2224 const string16 username16 = UTF8ToUTF16(username); |
| 2226 signin_helper_.reset(); | 2225 username_fetcher_.reset(); |
| 2227 account_chooser_model_.SetActiveWalletAccountName(username16); | 2226 account_chooser_model_.SetActiveWalletAccountName(username16); |
| 2228 OnWalletOrSigninUpdate(); | 2227 OnWalletOrSigninUpdate(); |
| 2229 } | 2228 } |
| 2230 | 2229 |
| 2231 void AutofillDialogControllerImpl::OnPassiveSigninFailure( | 2230 void AutofillDialogControllerImpl::OnPassiveSigninFailure( |
| 2232 const GoogleServiceAuthError& error) { | 2231 const GoogleServiceAuthError& error) { |
| 2233 // TODO(aruslan): report an error. | 2232 // TODO(aruslan): report an error. |
| 2234 LOG(ERROR) << "failed to passively sign in: " << error.ToString(); | 2233 LOG(ERROR) << "failed to passively sign in: " << error.ToString(); |
| 2234 signin_helper_.reset(); | |
| 2235 OnWalletSigninError(); | 2235 OnWalletSigninError(); |
| 2236 } | 2236 } |
| 2237 | 2237 |
| 2238 void AutofillDialogControllerImpl::OnUserNameFetchFailure( | 2238 void AutofillDialogControllerImpl::OnUserNameFetchFailure( |
| 2239 const GoogleServiceAuthError& error) { | 2239 const GoogleServiceAuthError& error) { |
| 2240 // TODO(aruslan): report an error. | 2240 // TODO(aruslan): report an error. |
| 2241 LOG(ERROR) << "failed to fetch the user account name: " << error.ToString(); | 2241 LOG(ERROR) << "failed to fetch the user account name: " << error.ToString(); |
| 2242 OnWalletSigninError(); | 2242 username_fetcher_.reset(); |
| 2243 // Only treat the failed fetch as an error if the user is known to already be | |
| 2244 // signed in. Attempting to fetch the username prior to loading the | |
| 2245 // |wallet_items_| is purely a performance optimization that shouldn't be | |
| 2246 // treated as an error if it fails. | |
| 2247 if (wallet_items_) | |
| 2248 OnWalletSigninError(); | |
| 2243 } | 2249 } |
| 2244 | 2250 |
| 2245 void AutofillDialogControllerImpl::OnDidFetchWalletCookieValue( | 2251 void AutofillDialogControllerImpl::OnDidFetchWalletCookieValue( |
| 2246 const std::string& cookie_value) { | 2252 const std::string& cookie_value) { |
| 2247 wallet_cookie_value_ = cookie_value; | 2253 wallet_cookie_value_ = cookie_value; |
| 2248 signin_helper_.reset(); | 2254 signin_helper_.reset(); |
| 2249 GetWalletItems(); | 2255 GetWalletItems(); |
| 2250 } | 2256 } |
| 2251 | 2257 |
| 2252 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 2258 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2359 this, | 2365 this, |
| 2360 &AutofillDialogControllerImpl::OnSubmitButtonDelayEnd); | 2366 &AutofillDialogControllerImpl::OnSubmitButtonDelayEnd); |
| 2361 } | 2367 } |
| 2362 | 2368 |
| 2363 void AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting() { | 2369 void AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting() { |
| 2364 DCHECK(submit_button_delay_timer_.IsRunning()); | 2370 DCHECK(submit_button_delay_timer_.IsRunning()); |
| 2365 submit_button_delay_timer_.user_task().Run(); | 2371 submit_button_delay_timer_.user_task().Run(); |
| 2366 submit_button_delay_timer_.Stop(); | 2372 submit_button_delay_timer_.Stop(); |
| 2367 } | 2373 } |
| 2368 | 2374 |
| 2375 void AutofillDialogControllerImpl:: | |
| 2376 ClearLastWalletItemsFetchTimestampForTesting() { | |
| 2377 last_wallet_items_fetch_timestamp_ = base::TimeTicks(); | |
| 2378 } | |
| 2379 | |
| 2369 AutofillDialogControllerImpl::AutofillDialogControllerImpl( | 2380 AutofillDialogControllerImpl::AutofillDialogControllerImpl( |
| 2370 content::WebContents* contents, | 2381 content::WebContents* contents, |
| 2371 const FormData& form_structure, | 2382 const FormData& form_structure, |
| 2372 const GURL& source_url, | 2383 const GURL& source_url, |
| 2373 const base::Callback<void(const FormStructure*)>& callback) | 2384 const base::Callback<void(const FormStructure*)>& callback) |
| 2374 : WebContentsObserver(contents), | 2385 : WebContentsObserver(contents), |
| 2375 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2386 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
| 2376 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2387 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
| 2377 form_structure_(form_structure), | 2388 form_structure_(form_structure), |
| 2378 invoked_from_same_origin_(true), | 2389 invoked_from_same_origin_(true), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2468 } | 2479 } |
| 2469 | 2480 |
| 2470 bool AutofillDialogControllerImpl::IsManuallyEditingSection( | 2481 bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
| 2471 DialogSection section) const { | 2482 DialogSection section) const { |
| 2472 return IsEditingExistingData(section) || | 2483 return IsEditingExistingData(section) || |
| 2473 SuggestionsMenuModelForSection(section)-> | 2484 SuggestionsMenuModelForSection(section)-> |
| 2474 GetItemKeyForCheckedItem() == kAddNewItemKey; | 2485 GetItemKeyForCheckedItem() == kAddNewItemKey; |
| 2475 } | 2486 } |
| 2476 | 2487 |
| 2477 void AutofillDialogControllerImpl::OnWalletSigninError() { | 2488 void AutofillDialogControllerImpl::OnWalletSigninError() { |
| 2478 signin_helper_.reset(); | |
| 2479 account_chooser_model_.SetHadWalletSigninError(); | 2489 account_chooser_model_.SetHadWalletSigninError(); |
| 2480 GetWalletClient()->CancelRequests(); | 2490 GetWalletClient()->CancelRequests(); |
| 2481 LogDialogLatencyToShow(); | 2491 LogDialogLatencyToShow(); |
| 2482 } | 2492 } |
| 2483 | 2493 |
| 2484 void AutofillDialogControllerImpl::DisableWallet( | 2494 void AutofillDialogControllerImpl::DisableWallet( |
| 2485 wallet::WalletClient::ErrorType error_type) { | 2495 wallet::WalletClient::ErrorType error_type) { |
| 2486 signin_helper_.reset(); | 2496 signin_helper_.reset(); |
| 2497 username_fetcher_.reset(); | |
| 2487 wallet_items_.reset(); | 2498 wallet_items_.reset(); |
| 2488 wallet_errors_.clear(); | 2499 wallet_errors_.clear(); |
| 2489 GetWalletClient()->CancelRequests(); | 2500 GetWalletClient()->CancelRequests(); |
| 2490 SetIsSubmitting(false); | 2501 SetIsSubmitting(false); |
| 2491 wallet_error_notification_ = GetWalletError(error_type); | 2502 wallet_error_notification_ = GetWalletError(error_type); |
| 2492 account_chooser_model_.SetHadWalletError(); | 2503 account_chooser_model_.SetHadWalletError(); |
| 2493 } | 2504 } |
| 2494 | 2505 |
| 2495 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 2506 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
| 2496 ScopedViewUpdates updates(view_.get()); | 2507 ScopedViewUpdates updates(view_.get()); |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3403 #endif | 3414 #endif |
| 3404 } | 3415 } |
| 3405 | 3416 |
| 3406 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { | 3417 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { |
| 3407 if (!view_) | 3418 if (!view_) |
| 3408 return; | 3419 return; |
| 3409 ScopedViewUpdates updates(view_.get()); | 3420 ScopedViewUpdates updates(view_.get()); |
| 3410 view_->UpdateButtonStrip(); | 3421 view_->UpdateButtonStrip(); |
| 3411 } | 3422 } |
| 3412 | 3423 |
| 3424 void AutofillDialogControllerImpl::FetchWalletCookieAndUserName() { | |
| 3425 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | |
| 3426 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | |
| 3427 signin_helper_->StartWalletCookieValueFetch(); | |
| 3428 | |
| 3429 username_fetcher_.reset( | |
| 3430 new wallet::WalletSigninHelper(this, request_context)); | |
| 3431 username_fetcher_->StartUserNameFetch(); | |
| 3432 } | |
| 3433 | |
| 3413 } // namespace autofill | 3434 } // namespace autofill |
| OLD | NEW |