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 base::TimeDelta::FromMilliseconds(kSubmitButtonDelayMs)); |
| 638 |
631 // TODO(estade): don't show the dialog if the site didn't specify the right | 639 // 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. | 640 // fields. First we must figure out what the "right" fields are. |
633 view_.reset(CreateView()); | 641 view_.reset(CreateView()); |
634 view_->Show(); | 642 view_->Show(); |
635 GetManager()->AddObserver(this); | 643 GetManager()->AddObserver(this); |
636 | 644 |
637 // Try to see if the user is already signed-in. If signed-in, fetch the user's | 645 // 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. | 646 // Wallet data. Otherwise, see if the user could be signed in passively. |
639 // TODO(aruslan): UMA metrics for sign-in. | 647 // TODO(aruslan): UMA metrics for sign-in. |
640 signin_helper_.reset(new wallet::WalletSigninHelper( | 648 signin_helper_.reset(new wallet::WalletSigninHelper( |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 756 |
749 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( | 757 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( |
750 ui::DialogButton button) const { | 758 ui::DialogButton button) const { |
751 if (button == ui::DIALOG_BUTTON_OK) { | 759 if (button == ui::DIALOG_BUTTON_OK) { |
752 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) | 760 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) |
753 return true; | 761 return true; |
754 | 762 |
755 if (ShouldShowSpinner() || is_submitting_) | 763 if (ShouldShowSpinner() || is_submitting_) |
756 return false; | 764 return false; |
757 | 765 |
| 766 if (submit_button_delay_timer_.IsRunning()) |
| 767 return false; |
| 768 |
758 return true; | 769 return true; |
759 } | 770 } |
760 | 771 |
761 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); | 772 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); |
762 return !is_submitting_ || IsSubmitPausedOn(wallet::VERIFY_CVV); | 773 return !is_submitting_ || IsSubmitPausedOn(wallet::VERIFY_CVV); |
763 } | 774 } |
764 | 775 |
765 DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() const { | 776 DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() const { |
766 bool show_wallet_interstitial = IsPayingWithWallet() && is_submitting_ && | 777 bool show_wallet_interstitial = IsPayingWithWallet() && is_submitting_ && |
767 !IsSubmitPausedOn(wallet::VERIFY_CVV); | 778 !IsSubmitPausedOn(wallet::VERIFY_CVV); |
(...skipping 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2219 void AutofillDialogControllerImpl::ShowNewCreditCardBubble( | 2230 void AutofillDialogControllerImpl::ShowNewCreditCardBubble( |
2220 scoped_ptr<CreditCard> new_card, | 2231 scoped_ptr<CreditCard> new_card, |
2221 scoped_ptr<AutofillProfile> billing_profile) { | 2232 scoped_ptr<AutofillProfile> billing_profile) { |
2222 #if !defined(OS_ANDROID) | 2233 #if !defined(OS_ANDROID) |
2223 NewCreditCardBubbleController::Show(profile(), | 2234 NewCreditCardBubbleController::Show(profile(), |
2224 new_card.Pass(), | 2235 new_card.Pass(), |
2225 billing_profile.Pass()); | 2236 billing_profile.Pass()); |
2226 #endif | 2237 #endif |
2227 } | 2238 } |
2228 | 2239 |
| 2240 void AutofillDialogControllerImpl::SubmitButtonDelayBegin( |
| 2241 base::TimeDelta delay) { |
| 2242 submit_button_delay_timer_.Start( |
| 2243 FROM_HERE, |
| 2244 delay, |
| 2245 this, |
| 2246 &AutofillDialogControllerImpl::OnSubmitButtonDelayEnd); |
| 2247 } |
| 2248 |
| 2249 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { |
| 2250 if (view_) { |
| 2251 ScopedViewUpdates updates(view_.get()); |
| 2252 view_->UpdateButtonStrip(); |
| 2253 } |
| 2254 } |
| 2255 |
| 2256 void AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting() { |
| 2257 if (submit_button_delay_timer_.IsRunning()) |
| 2258 submit_button_delay_timer_.Stop(); |
| 2259 OnSubmitButtonDelayEnd(); |
| 2260 } |
| 2261 |
2229 AutofillDialogControllerImpl::AutofillDialogControllerImpl( | 2262 AutofillDialogControllerImpl::AutofillDialogControllerImpl( |
2230 content::WebContents* contents, | 2263 content::WebContents* contents, |
2231 const FormData& form_structure, | 2264 const FormData& form_structure, |
2232 const GURL& source_url, | 2265 const GURL& source_url, |
2233 const base::Callback<void(const FormStructure*, | 2266 const base::Callback<void(const FormStructure*, |
2234 const std::string&)>& callback) | 2267 const std::string&)>& callback) |
2235 : WebContentsObserver(contents), | 2268 : WebContentsObserver(contents), |
2236 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2269 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
2237 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2270 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
2238 form_structure_(form_structure), | 2271 form_structure_(form_structure), |
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3334 } | 3367 } |
3335 #if !defined(OS_ANDROID) | 3368 #if !defined(OS_ANDROID) |
3336 GeneratedCreditCardBubbleController::Show( | 3369 GeneratedCreditCardBubbleController::Show( |
3337 web_contents(), | 3370 web_contents(), |
3338 full_wallet_->TypeAndLastFourDigits(), | 3371 full_wallet_->TypeAndLastFourDigits(), |
3339 backing_last_four); | 3372 backing_last_four); |
3340 #endif | 3373 #endif |
3341 } | 3374 } |
3342 | 3375 |
3343 } // namespace autofill | 3376 } // namespace autofill |
OLD | NEW |