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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // WebDB, and hence should not be modified, so that it remains consistent over | 107 // WebDB, and hence should not be modified, so that it remains consistent over |
108 // time. | 108 // time. |
109 const char kAutofillDialogOrigin[] = "Chrome Autofill dialog"; | 109 const char kAutofillDialogOrigin[] = "Chrome Autofill dialog"; |
110 | 110 |
111 // HSL shift to gray out an image. | 111 // HSL shift to gray out an image. |
112 const color_utils::HSL kGrayImageShift = {-1, 0, 0.8}; | 112 const color_utils::HSL kGrayImageShift = {-1, 0, 0.8}; |
113 | 113 |
114 // Limit Wallet items refresh rate to at most once per minute. | 114 // Limit Wallet items refresh rate to at most once per minute. |
115 const int kWalletItemsRefreshRateSeconds = 60; | 115 const int kWalletItemsRefreshRateSeconds = 60; |
116 | 116 |
| 117 // The number of milliseconds to delay enabling the submit button after showing |
| 118 // the dialog. This delay prevents users from accidentally clicking the submit |
| 119 // button on startup. |
| 120 const int kSubmitButtonDelayMs = 1000; |
| 121 |
117 // A helper class to make sure an AutofillDialogView knows when a series of | 122 // A helper class to make sure an AutofillDialogView knows when a series of |
118 // updates is incoming. | 123 // updates is incoming. |
119 class ScopedViewUpdates { | 124 class ScopedViewUpdates { |
120 public: | 125 public: |
121 explicit ScopedViewUpdates(AutofillDialogView* view) : view_(view) { | 126 explicit ScopedViewUpdates(AutofillDialogView* view) : view_(view) { |
122 if (view_) | 127 if (view_) |
123 view_->UpdatesStarted(); | 128 view_->UpdatesStarted(); |
124 } | 129 } |
125 | 130 |
126 ~ScopedViewUpdates() { | 131 ~ScopedViewUpdates() { |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), | 626 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), |
622 &form_structure_); | 627 &form_structure_); |
623 | 628 |
624 SuggestionsUpdated(); | 629 SuggestionsUpdated(); |
625 | 630 |
626 int show_count = | 631 int show_count = |
627 profile_->GetPrefs()->GetInteger(::prefs::kAutofillDialogShowCount); | 632 profile_->GetPrefs()->GetInteger(::prefs::kAutofillDialogShowCount); |
628 profile_->GetPrefs()->SetInteger(::prefs::kAutofillDialogShowCount, | 633 profile_->GetPrefs()->SetInteger(::prefs::kAutofillDialogShowCount, |
629 show_count + 1); | 634 show_count + 1); |
630 | 635 |
| 636 SubmitButtonDelayBegin(); |
| 637 |
631 // TODO(estade): don't show the dialog if the site didn't specify the right | 638 // TODO(estade): don't show the dialog if the site didn't specify the right |
632 // fields. First we must figure out what the "right" fields are. | 639 // fields. First we must figure out what the "right" fields are. |
633 view_.reset(CreateView()); | 640 view_.reset(CreateView()); |
634 view_->Show(); | 641 view_->Show(); |
635 GetManager()->AddObserver(this); | 642 GetManager()->AddObserver(this); |
636 | 643 |
637 // Try to see if the user is already signed-in. If signed-in, fetch the user's | 644 // Try to see if the user is already signed-in. If signed-in, fetch the user's |
638 // Wallet data. Otherwise, see if the user could be signed in passively. | 645 // Wallet data. Otherwise, see if the user could be signed in passively. |
639 // TODO(aruslan): UMA metrics for sign-in. | 646 // TODO(aruslan): UMA metrics for sign-in. |
640 signin_helper_.reset(new wallet::WalletSigninHelper( | 647 signin_helper_.reset(new wallet::WalletSigninHelper( |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 755 |
749 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( | 756 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( |
750 ui::DialogButton button) const { | 757 ui::DialogButton button) const { |
751 if (button == ui::DIALOG_BUTTON_OK) { | 758 if (button == ui::DIALOG_BUTTON_OK) { |
752 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) | 759 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) |
753 return true; | 760 return true; |
754 | 761 |
755 if (ShouldShowSpinner() || is_submitting_) | 762 if (ShouldShowSpinner() || is_submitting_) |
756 return false; | 763 return false; |
757 | 764 |
| 765 if (submit_button_delay_timer_.IsRunning()) |
| 766 return false; |
| 767 |
758 return true; | 768 return true; |
759 } | 769 } |
760 | 770 |
761 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); | 771 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); |
762 return !is_submitting_ || IsSubmitPausedOn(wallet::VERIFY_CVV); | 772 return !is_submitting_ || IsSubmitPausedOn(wallet::VERIFY_CVV); |
763 } | 773 } |
764 | 774 |
765 DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() const { | 775 DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() const { |
766 bool show_wallet_interstitial = IsPayingWithWallet() && is_submitting_ && | 776 bool show_wallet_interstitial = IsPayingWithWallet() && is_submitting_ && |
767 !IsSubmitPausedOn(wallet::VERIFY_CVV); | 777 !IsSubmitPausedOn(wallet::VERIFY_CVV); |
(...skipping 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2219 void AutofillDialogControllerImpl::ShowNewCreditCardBubble( | 2229 void AutofillDialogControllerImpl::ShowNewCreditCardBubble( |
2220 scoped_ptr<CreditCard> new_card, | 2230 scoped_ptr<CreditCard> new_card, |
2221 scoped_ptr<AutofillProfile> billing_profile) { | 2231 scoped_ptr<AutofillProfile> billing_profile) { |
2222 #if !defined(OS_ANDROID) | 2232 #if !defined(OS_ANDROID) |
2223 NewCreditCardBubbleController::Show(profile(), | 2233 NewCreditCardBubbleController::Show(profile(), |
2224 new_card.Pass(), | 2234 new_card.Pass(), |
2225 billing_profile.Pass()); | 2235 billing_profile.Pass()); |
2226 #endif | 2236 #endif |
2227 } | 2237 } |
2228 | 2238 |
| 2239 void AutofillDialogControllerImpl::SubmitButtonDelayBegin() { |
| 2240 submit_button_delay_timer_.Start( |
| 2241 FROM_HERE, |
| 2242 base::TimeDelta::FromMilliseconds(kSubmitButtonDelayMs), |
| 2243 this, |
| 2244 &AutofillDialogControllerImpl::OnSubmitButtonDelayEnd); |
| 2245 } |
| 2246 |
| 2247 void AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting() { |
| 2248 DCHECK(submit_button_delay_timer_.IsRunning()); |
| 2249 submit_button_delay_timer_.user_task().Run(); |
| 2250 submit_button_delay_timer_.Stop(); |
| 2251 } |
| 2252 |
2229 AutofillDialogControllerImpl::AutofillDialogControllerImpl( | 2253 AutofillDialogControllerImpl::AutofillDialogControllerImpl( |
2230 content::WebContents* contents, | 2254 content::WebContents* contents, |
2231 const FormData& form_structure, | 2255 const FormData& form_structure, |
2232 const GURL& source_url, | 2256 const GURL& source_url, |
2233 const base::Callback<void(const FormStructure*, | 2257 const base::Callback<void(const FormStructure*, |
2234 const std::string&)>& callback) | 2258 const std::string&)>& callback) |
2235 : WebContentsObserver(contents), | 2259 : WebContentsObserver(contents), |
2236 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2260 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
2237 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2261 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
2238 form_structure_(form_structure), | 2262 form_structure_(form_structure), |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3333 backing_last_four = card.TypeAndLastFourDigits(); | 3357 backing_last_four = card.TypeAndLastFourDigits(); |
3334 } | 3358 } |
3335 #if !defined(OS_ANDROID) | 3359 #if !defined(OS_ANDROID) |
3336 GeneratedCreditCardBubbleController::Show( | 3360 GeneratedCreditCardBubbleController::Show( |
3337 web_contents(), | 3361 web_contents(), |
3338 full_wallet_->TypeAndLastFourDigits(), | 3362 full_wallet_->TypeAndLastFourDigits(), |
3339 backing_last_four); | 3363 backing_last_four); |
3340 #endif | 3364 #endif |
3341 } | 3365 } |
3342 | 3366 |
| 3367 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { |
| 3368 if (!view_) |
| 3369 return; |
| 3370 ScopedViewUpdates updates(view_.get()); |
| 3371 view_->UpdateButtonStrip(); |
| 3372 } |
| 3373 |
3343 } // namespace autofill | 3374 } // namespace autofill |
OLD | NEW |