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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 // WebDB, and hence should not be modified, so that it remains consistent over | 105 // WebDB, and hence should not be modified, so that it remains consistent over |
106 // time. | 106 // time. |
107 const char kAutofillDialogOrigin[] = "Chrome Autofill dialog"; | 107 const char kAutofillDialogOrigin[] = "Chrome Autofill dialog"; |
108 | 108 |
109 // HSL shift to gray out an image. | 109 // HSL shift to gray out an image. |
110 const color_utils::HSL kGrayImageShift = {-1, 0, 0.8}; | 110 const color_utils::HSL kGrayImageShift = {-1, 0, 0.8}; |
111 | 111 |
112 // Limit Wallet items refresh rate to at most once per minute. | 112 // Limit Wallet items refresh rate to at most once per minute. |
113 const int kWalletItemsRefreshRateSeconds = 60; | 113 const int kWalletItemsRefreshRateSeconds = 60; |
114 | 114 |
115 // The number of seconds to delay enabling the submit button after showing the | |
116 // dialog. This delay prevents users from accidentally clicking the submit | |
117 // button on startup. | |
118 const int kSubmitButtonDelaySeconds = 1; | |
119 | |
115 // A helper class to make sure an AutofillDialogView knows when a series of | 120 // A helper class to make sure an AutofillDialogView knows when a series of |
116 // updates is incoming. | 121 // updates is incoming. |
117 class ScopedViewUpdates { | 122 class ScopedViewUpdates { |
118 public: | 123 public: |
119 explicit ScopedViewUpdates(AutofillDialogView* view) : view_(view) { | 124 explicit ScopedViewUpdates(AutofillDialogView* view) : view_(view) { |
120 if (view_) | 125 if (view_) |
121 view_->UpdatesStarted(); | 126 view_->UpdatesStarted(); |
122 } | 127 } |
123 | 128 |
124 ~ScopedViewUpdates() { | 129 ~ScopedViewUpdates() { |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 | 637 |
633 // Try to see if the user is already signed-in. If signed-in, fetch the user's | 638 // Try to see if the user is already signed-in. If signed-in, fetch the user's |
634 // Wallet data. Otherwise, see if the user could be signed in passively. | 639 // Wallet data. Otherwise, see if the user could be signed in passively. |
635 // TODO(aruslan): UMA metrics for sign-in. | 640 // TODO(aruslan): UMA metrics for sign-in. |
636 signin_helper_.reset(new wallet::WalletSigninHelper( | 641 signin_helper_.reset(new wallet::WalletSigninHelper( |
637 this, profile_->GetRequestContext())); | 642 this, profile_->GetRequestContext())); |
638 signin_helper_->StartWalletCookieValueFetch(); | 643 signin_helper_->StartWalletCookieValueFetch(); |
639 | 644 |
640 if (!account_chooser_model_.WalletIsSelected()) | 645 if (!account_chooser_model_.WalletIsSelected()) |
641 LogDialogLatencyToShow(); | 646 LogDialogLatencyToShow(); |
647 | |
648 SubmitButtonDelayBegin(); | |
642 } | 649 } |
643 | 650 |
644 void AutofillDialogControllerImpl::Hide() { | 651 void AutofillDialogControllerImpl::Hide() { |
645 if (view_) | 652 if (view_) |
646 view_->Hide(); | 653 view_->Hide(); |
647 } | 654 } |
648 | 655 |
649 void AutofillDialogControllerImpl::TabActivated() { | 656 void AutofillDialogControllerImpl::TabActivated() { |
650 // If the user switched away from this tab and then switched back, reload the | 657 // If the user switched away from this tab and then switched back, reload the |
651 // Wallet items, in case they've changed. | 658 // Wallet items, in case they've changed. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
752 | 759 |
753 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( | 760 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( |
754 ui::DialogButton button) const { | 761 ui::DialogButton button) const { |
755 if (button == ui::DIALOG_BUTTON_OK) { | 762 if (button == ui::DIALOG_BUTTON_OK) { |
756 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) | 763 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) |
757 return true; | 764 return true; |
758 | 765 |
759 if (ShouldShowSpinner() || is_submitting_) | 766 if (ShouldShowSpinner() || is_submitting_) |
760 return false; | 767 return false; |
761 | 768 |
769 if (is_submit_button_delayed_) | |
770 return false; | |
771 | |
762 return true; | 772 return true; |
763 } | 773 } |
764 | 774 |
765 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); | 775 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); |
766 return !is_submitting_ || IsSubmitPausedOn(wallet::VERIFY_CVV); | 776 return !is_submitting_ || IsSubmitPausedOn(wallet::VERIFY_CVV); |
767 } | 777 } |
768 | 778 |
769 DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() const { | 779 DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() const { |
770 bool show_wallet_interstitial = IsPayingWithWallet() && is_submitting_ && | 780 bool show_wallet_interstitial = IsPayingWithWallet() && is_submitting_ && |
771 !IsSubmitPausedOn(wallet::VERIFY_CVV) && | 781 !IsSubmitPausedOn(wallet::VERIFY_CVV) && |
(...skipping 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2222 void AutofillDialogControllerImpl::ShowNewCreditCardBubble( | 2232 void AutofillDialogControllerImpl::ShowNewCreditCardBubble( |
2223 scoped_ptr<CreditCard> new_card, | 2233 scoped_ptr<CreditCard> new_card, |
2224 scoped_ptr<AutofillProfile> billing_profile) { | 2234 scoped_ptr<AutofillProfile> billing_profile) { |
2225 #if !defined(OS_ANDROID) | 2235 #if !defined(OS_ANDROID) |
2226 NewCreditCardBubbleController::Show(profile(), | 2236 NewCreditCardBubbleController::Show(profile(), |
2227 new_card.Pass(), | 2237 new_card.Pass(), |
2228 billing_profile.Pass()); | 2238 billing_profile.Pass()); |
2229 #endif | 2239 #endif |
2230 } | 2240 } |
2231 | 2241 |
2242 void AutofillDialogControllerImpl::SubmitButtonDelayBegin() { | |
2243 is_submit_button_delayed_ = true; | |
Evan Stade
2013/09/04 02:36:28
I think this will be slightly cleaner if you use a
please use gerrit instead
2013/09/04 02:51:46
I can see using a Timer instead of PostDelayedTask
Evan Stade
2013/09/04 18:24:29
just because it was the first line of this fn (als
| |
2244 content::BrowserThread::PostDelayedTask( | |
2245 content::BrowserThread::UI, | |
2246 FROM_HERE, | |
2247 base::Bind(&AutofillDialogControllerImpl::OnSubmitButtonDelayEnd, | |
2248 weak_ptr_factory_.GetWeakPtr()), | |
2249 base::TimeDelta::FromSeconds(kSubmitButtonDelaySeconds)); | |
2250 } | |
2251 | |
2252 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { | |
2253 is_submit_button_delayed_ = false; | |
2254 if (view_) { | |
2255 ScopedViewUpdates updates(view_.get()); | |
2256 view_->UpdateButtonStrip(); | |
2257 } | |
2258 } | |
2259 | |
2232 AutofillDialogControllerImpl::AutofillDialogControllerImpl( | 2260 AutofillDialogControllerImpl::AutofillDialogControllerImpl( |
2233 content::WebContents* contents, | 2261 content::WebContents* contents, |
2234 const FormData& form_structure, | 2262 const FormData& form_structure, |
2235 const GURL& source_url, | 2263 const GURL& source_url, |
2236 const DialogType dialog_type, | 2264 const DialogType dialog_type, |
2237 const base::Callback<void(const FormStructure*, | 2265 const base::Callback<void(const FormStructure*, |
2238 const std::string&)>& callback) | 2266 const std::string&)>& callback) |
2239 : WebContentsObserver(contents), | 2267 : WebContentsObserver(contents), |
2240 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2268 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
2241 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2269 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
(...skipping 14 matching lines...) Expand all Loading... | |
2256 input_showing_popup_(NULL), | 2284 input_showing_popup_(NULL), |
2257 weak_ptr_factory_(this), | 2285 weak_ptr_factory_(this), |
2258 should_show_wallet_promo_(!profile_->GetPrefs()->GetBoolean( | 2286 should_show_wallet_promo_(!profile_->GetPrefs()->GetBoolean( |
2259 ::prefs::kAutofillDialogHasPaidWithWallet)), | 2287 ::prefs::kAutofillDialogHasPaidWithWallet)), |
2260 has_shown_wallet_usage_confirmation_(false), | 2288 has_shown_wallet_usage_confirmation_(false), |
2261 has_accepted_legal_documents_(false), | 2289 has_accepted_legal_documents_(false), |
2262 is_submitting_(false), | 2290 is_submitting_(false), |
2263 choose_another_instrument_or_address_(false), | 2291 choose_another_instrument_or_address_(false), |
2264 wallet_server_validation_recoverable_(true), | 2292 wallet_server_validation_recoverable_(true), |
2265 data_was_passed_back_(false), | 2293 data_was_passed_back_(false), |
2266 was_ui_latency_logged_(false) { | 2294 was_ui_latency_logged_(false), |
2295 is_submit_button_delayed_(false) { | |
2267 // TODO(estade): remove duplicates from |form_structure|? | 2296 // TODO(estade): remove duplicates from |form_structure|? |
2268 DCHECK(!callback_.is_null()); | 2297 DCHECK(!callback_.is_null()); |
2269 } | 2298 } |
2270 | 2299 |
2271 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { | 2300 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { |
2272 return AutofillDialogView::Create(this); | 2301 return AutofillDialogView::Create(this); |
2273 } | 2302 } |
2274 | 2303 |
2275 PersonalDataManager* AutofillDialogControllerImpl::GetManager() { | 2304 PersonalDataManager* AutofillDialogControllerImpl::GetManager() { |
2276 return PersonalDataManagerFactory::GetForProfile(profile_); | 2305 return PersonalDataManagerFactory::GetForProfile(profile_); |
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3340 } | 3369 } |
3341 #if !defined(OS_ANDROID) | 3370 #if !defined(OS_ANDROID) |
3342 GeneratedCreditCardBubbleController::Show( | 3371 GeneratedCreditCardBubbleController::Show( |
3343 web_contents(), | 3372 web_contents(), |
3344 full_wallet_->TypeAndLastFourDigits(), | 3373 full_wallet_->TypeAndLastFourDigits(), |
3345 backing_last_four); | 3374 backing_last_four); |
3346 #endif | 3375 #endif |
3347 } | 3376 } |
3348 | 3377 |
3349 } // namespace autofill | 3378 } // namespace autofill |
OLD | NEW |