Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 12893007: Implementing VERIFY_CVV required action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 CreditCard* card, 164 CreditCard* card,
165 string16* cvc, 165 string16* cvc,
166 AutofillProfile* profile) { 166 AutofillProfile* profile) {
167 for (DetailOutputMap::const_iterator it = output.begin(); 167 for (DetailOutputMap::const_iterator it = output.begin();
168 it != output.end(); ++it) { 168 it != output.end(); ++it) {
169 string16 trimmed; 169 string16 trimmed;
170 TrimWhitespace(it->second, TRIM_ALL, &trimmed); 170 TrimWhitespace(it->second, TRIM_ALL, &trimmed);
171 171
172 // Special case CVC as CreditCard just swallows it. 172 // Special case CVC as CreditCard just swallows it.
173 if (it->first->type == CREDIT_CARD_VERIFICATION_CODE) { 173 if (it->first->type == CREDIT_CARD_VERIFICATION_CODE) {
174 cvc->assign(trimmed); 174 if (cvc)
175 cvc->assign(trimmed);
175 } else { 176 } else {
176 // Copy the credit card name to |profile| in addition to |card| as 177 // Copy the credit card name to |profile| in addition to |card| as
177 // wallet::Instrument requires a recipient name for its billing address. 178 // wallet::Instrument requires a recipient name for its billing address.
178 if (it->first->type == CREDIT_CARD_NAME) 179 if (profile && it->first->type == CREDIT_CARD_NAME)
179 profile->SetRawInfo(NAME_FULL, trimmed); 180 profile->SetRawInfo(NAME_FULL, trimmed);
180 181
181 if (IsCreditCardType(it->first->type)) 182 if (IsCreditCardType(it->first->type)) {
182 card->SetRawInfo(it->first->type, trimmed); 183 if (card)
183 else 184 card->SetRawInfo(it->first->type, trimmed);
185 } else if (profile) {
184 profile->SetRawInfo(it->first->type, trimmed); 186 profile->SetRawInfo(it->first->type, trimmed);
187 }
185 } 188 }
186 } 189 }
187 } 190 }
188 191
189 // Returns the containing window for the given |web_contents|. The containing 192 // Returns the containing window for the given |web_contents|. The containing
190 // window might be a browser window for a Chrome tab, or it might be a shell 193 // window might be a browser window for a Chrome tab, or it might be a shell
191 // window for a platform app. 194 // window for a platform app.
192 BaseWindow* GetBaseWindowForWebContents( 195 BaseWindow* GetBaseWindowForWebContents(
193 const content::WebContents* web_contents) { 196 const content::WebContents* web_contents) {
194 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 197 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)), 244 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)),
242 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)), 245 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)),
243 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)), 246 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)),
244 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_billing_(this)), 247 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_billing_(this)),
245 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)), 248 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)),
246 section_showing_popup_(SECTION_BILLING), 249 section_showing_popup_(SECTION_BILLING),
247 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 250 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
248 metric_logger_(metric_logger), 251 metric_logger_(metric_logger),
249 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), 252 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN),
250 dialog_type_(dialog_type), 253 dialog_type_(dialog_type),
251 did_submit_(false), 254 is_submitting_(false),
252 autocheckout_is_running_(false), 255 autocheckout_is_running_(false),
253 had_autocheckout_error_(false) { 256 had_autocheckout_error_(false) {
254 // TODO(estade): remove duplicates from |form|? 257 // TODO(estade): remove duplicates from |form|?
255 } 258 }
256 259
257 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { 260 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() {
258 if (popup_controller_) 261 if (popup_controller_)
259 popup_controller_->Hide(); 262 popup_controller_->Hide();
260 263
261 metric_logger_.LogDialogInitialUserState(dialog_type_, initial_user_state_); 264 metric_logger_.LogDialogInitialUserState(dialog_type_, initial_user_state_);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 string16 AutofillDialogControllerImpl::UseBillingForShippingText() const { 423 string16 AutofillDialogControllerImpl::UseBillingForShippingText() const {
421 return l10n_util::GetStringUTF16( 424 return l10n_util::GetStringUTF16(
422 IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING); 425 IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING);
423 } 426 }
424 427
425 string16 AutofillDialogControllerImpl::CancelButtonText() const { 428 string16 AutofillDialogControllerImpl::CancelButtonText() const {
426 return l10n_util::GetStringUTF16(IDS_CANCEL); 429 return l10n_util::GetStringUTF16(IDS_CANCEL);
427 } 430 }
428 431
429 string16 AutofillDialogControllerImpl::ConfirmButtonText() const { 432 string16 AutofillDialogControllerImpl::ConfirmButtonText() const {
430 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON); 433 return l10n_util::GetStringUTF16(IsSubmitPausedOn(wallet::VERIFY_CVV) ?
434 IDS_AUTOFILL_DIALOG_VERIFY_BUTTON : IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON);
431 } 435 }
432 436
433 string16 AutofillDialogControllerImpl::CancelSignInText() const { 437 string16 AutofillDialogControllerImpl::CancelSignInText() const {
434 // TODO(abodenha): real strings and l10n. 438 // TODO(abodenha): real strings and l10n.
435 return ASCIIToUTF16("Don't sign in."); 439 return ASCIIToUTF16("Don't sign in.");
436 } 440 }
437 441
438 string16 AutofillDialogControllerImpl::SaveLocallyText() const { 442 string16 AutofillDialogControllerImpl::SaveLocallyText() const {
439 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); 443 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX);
440 } 444 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 return autocheckout_is_running_; 490 return autocheckout_is_running_;
487 } 491 }
488 492
489 bool AutofillDialogControllerImpl::HadAutocheckoutError() const { 493 bool AutofillDialogControllerImpl::HadAutocheckoutError() const {
490 return had_autocheckout_error_; 494 return had_autocheckout_error_;
491 } 495 }
492 496
493 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( 497 bool AutofillDialogControllerImpl::IsDialogButtonEnabled(
494 ui::DialogButton button) const { 498 ui::DialogButton button) const {
495 if (button == ui::DIALOG_BUTTON_OK) 499 if (button == ui::DIALOG_BUTTON_OK)
496 return !did_submit_; 500 return !is_submitting_ || IsSubmitPausedOn(wallet::VERIFY_CVV);
501
497 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); 502 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button);
498 // TODO(ahutter): Make it possible for the user to cancel out of the dialog 503 // TODO(ahutter): Make it possible for the user to cancel out of the dialog
499 // while Autocheckout is in progress. 504 // while Autocheckout is in progress.
500 return had_autocheckout_error_ || !did_submit_; 505 return had_autocheckout_error_ ||
506 dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE;
Ilya Sherman 2013/03/28 05:28:57 Hrm, I think you've just globally disabled the can
Dan Beam 2013/03/29 00:43:10 Added back !is_submitting_
501 } 507 }
502 508
503 bool AutofillDialogControllerImpl::SectionIsActive(DialogSection section) 509 bool AutofillDialogControllerImpl::SectionIsActive(DialogSection section)
504 const { 510 const {
511 if (IsSubmitPausedOn(wallet::VERIFY_CVV))
512 return section == SECTION_CC_BILLING;
513
505 if (IsPayingWithWallet()) 514 if (IsPayingWithWallet())
506 return section != SECTION_BILLING && section != SECTION_CC; 515 return section != SECTION_BILLING && section != SECTION_CC;
507 516
508 return section != SECTION_CC_BILLING; 517 return section != SECTION_CC_BILLING;
509 } 518 }
510 519
511 bool AutofillDialogControllerImpl::HasCompleteWallet() const { 520 bool AutofillDialogControllerImpl::HasCompleteWallet() const {
512 return wallet_items_.get() != NULL && 521 return wallet_items_.get() != NULL &&
513 !wallet_items_->instruments().empty() && 522 !wallet_items_->instruments().empty() &&
514 !wallet_items_->addresses().empty(); 523 !wallet_items_->addresses().empty();
515 } 524 }
516 525
526 bool AutofillDialogControllerImpl::IsSubmitPausedOn(
527 wallet::RequiredAction required_action) const {
528 return full_wallet_ && full_wallet_->HasRequiredAction(required_action);
529 }
530
517 void AutofillDialogControllerImpl::StartFetchingWalletItems() { 531 void AutofillDialogControllerImpl::StartFetchingWalletItems() {
518 DCHECK(IsPayingWithWallet()); 532 DCHECK(IsPayingWithWallet());
519 // TODO(dbeam): Add Risk capabilites once the UI supports risk challenges. 533 // TODO(dbeam): Add Risk capabilites once the UI supports risk challenges.
520 GetWalletClient()->GetWalletItems( 534 GetWalletClient()->GetWalletItems(
521 source_url_, 535 source_url_,
522 std::vector<wallet::WalletClient::RiskCapability>()); 536 std::vector<wallet::WalletClient::RiskCapability>());
523 } 537 }
524 538
525 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { 539 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() {
526 if (wallet_items_.get()) { 540 if (wallet_items_.get()) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 case SECTION_SHIPPING: 655 case SECTION_SHIPPING:
642 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); 656 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING);
643 default: 657 default:
644 NOTREACHED(); 658 NOTREACHED();
645 return string16(); 659 return string16();
646 } 660 }
647 } 661 }
648 662
649 string16 AutofillDialogControllerImpl::SuggestionTextForSection( 663 string16 AutofillDialogControllerImpl::SuggestionTextForSection(
650 DialogSection section) { 664 DialogSection section) {
665 string16 action_text = RequiredActionSuggestionTextForSection(section);
666 if (!action_text.empty())
667 return action_text;
668
651 // When the user has clicked 'edit', don't show a suggestion (even though 669 // When the user has clicked 'edit', don't show a suggestion (even though
652 // there is a profile selected in the model). 670 // there is a profile selected in the model).
653 if (section_editing_state_[section]) 671 if (section_editing_state_[section])
654 return string16(); 672 return string16();
655 673
656 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 674 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
657 std::string item_key = model->GetItemKeyForCheckedItem(); 675 std::string item_key = model->GetItemKeyForCheckedItem();
658 if (item_key.empty()) 676 if (item_key.empty())
659 return string16(); 677 return string16();
660 678
661 if (section == SECTION_EMAIL) 679 if (section == SECTION_EMAIL)
662 return model->GetLabelAt(model->checked_item()); 680 return model->GetLabelAt(model->checked_item());
663 681
664 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 682 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
665 return wrapper->GetDisplayText(); 683 return wrapper->GetDisplayText();
666 } 684 }
667 685
686 string16 AutofillDialogControllerImpl::RequiredActionSuggestionTextForSection(
687 DialogSection section) {
688 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) {
689 const wallet::WalletItems::MaskedInstrument* current_instrument =
690 wallet_items_->GetInstrumentById(active_instrument_id_);
691 if (current_instrument)
692 return current_instrument->TypeAndLastFourDigits();
693
694 DetailOutputMap output;
695 view_->GetUserInput(section, &output);
696 CreditCard card;
697 GetBillingInfoFromOutputs(output, &card, NULL, NULL);
698 return card.TypeAndLastFourDigits();
699 }
700
701 return string16();
702 }
703
668 scoped_ptr<DataModelWrapper> AutofillDialogControllerImpl::CreateWrapper( 704 scoped_ptr<DataModelWrapper> AutofillDialogControllerImpl::CreateWrapper(
669 DialogSection section) { 705 DialogSection section) {
670 if (IsPayingWithWallet() && full_wallet_) { 706 if (IsPayingWithWallet() && full_wallet_ &&
707 !IsSubmitPausedOn(wallet::VERIFY_CVV)) {
671 if (section == SECTION_CC_BILLING) { 708 if (section == SECTION_CC_BILLING) {
672 return scoped_ptr<DataModelWrapper>( 709 return scoped_ptr<DataModelWrapper>(
673 new FullWalletBillingWrapper(full_wallet_.get())); 710 new FullWalletBillingWrapper(full_wallet_.get()));
674 } 711 }
675 if (section == SECTION_SHIPPING) { 712 if (section == SECTION_SHIPPING) {
676 return scoped_ptr<DataModelWrapper>( 713 return scoped_ptr<DataModelWrapper>(
677 new FullWalletShippingWrapper(full_wallet_.get())); 714 new FullWalletShippingWrapper(full_wallet_.get()));
678 } 715 }
679 } 716 }
680 717
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 std::vector<DialogNotification> 1011 std::vector<DialogNotification>
975 AutofillDialogControllerImpl::CurrentNotifications() const { 1012 AutofillDialogControllerImpl::CurrentNotifications() const {
976 std::vector<DialogNotification> notifications; 1013 std::vector<DialogNotification> notifications;
977 1014
978 if (IsPayingWithWallet()) { 1015 if (IsPayingWithWallet()) {
979 // TODO(dbeam): what about REQUIRES_PASSIVE_SIGN_IN? 1016 // TODO(dbeam): what about REQUIRES_PASSIVE_SIGN_IN?
980 if (SignedInState() == SIGNED_IN) { 1017 if (SignedInState() == SIGNED_IN) {
981 // On first run with a complete wallet profile, show a notification 1018 // On first run with a complete wallet profile, show a notification
982 // explaining where this data came from. 1019 // explaining where this data came from.
983 if (IsFirstRun() && HasCompleteWallet()) { 1020 if (IsFirstRun() && HasCompleteWallet()) {
984 notifications.push_back( 1021 notifications.push_back(DialogNotification(
985 DialogNotification( 1022 DialogNotification::EXPLANATORY_MESSAGE,
986 DialogNotification::EXPLANATORY_MESSAGE, 1023 l10n_util::GetStringUTF16(
987 l10n_util::GetStringUTF16( 1024 IDS_AUTOFILL_DIALOG_DETAILS_FROM_WALLET)));
988 IDS_AUTOFILL_DIALOG_DETAILS_FROM_WALLET)));
989 } else { 1025 } else {
990 notifications.push_back( 1026 notifications.push_back(DialogNotification(
991 DialogNotification( 1027 DialogNotification::WALLET_PROMO,
992 DialogNotification::WALLET_PROMO, 1028 l10n_util::GetStringUTF16(
993 l10n_util::GetStringUTF16( 1029 IDS_AUTOFILL_DIALOG_SAVE_DETAILS_IN_WALLET)));
994 IDS_AUTOFILL_DIALOG_SAVE_DETAILS_IN_WALLET)));
995 } 1030 }
996 } else if (IsFirstRun()) { 1031 } else if (IsFirstRun()) {
997 // If the user is not signed in, show an upsell notification on first run. 1032 // If the user is not signed in, show an upsell notification on first run.
998 notifications.push_back( 1033 notifications.push_back(DialogNotification(
999 DialogNotification( 1034 DialogNotification::WALLET_PROMO,
1000 DialogNotification::WALLET_PROMO, 1035 l10n_util::GetStringUTF16(
1001 l10n_util::GetStringUTF16( 1036 IDS_AUTOFILL_DIALOG_SIGN_IN_AND_SAVE_DETAILS)));
1002 IDS_AUTOFILL_DIALOG_SIGN_IN_AND_SAVE_DETAILS)));
1003 } 1037 }
1004 } 1038 }
1005 1039
1006 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) { 1040 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) {
1007 notifications.push_back( 1041 notifications.push_back(DialogNotification(
1008 DialogNotification( 1042 DialogNotification::SECURITY_WARNING,
1009 DialogNotification::SECURITY_WARNING, 1043 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)));
1010 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)));
1011 } 1044 }
1012 1045
1013 if (!invoked_from_same_origin_) { 1046 if (!invoked_from_same_origin_) {
1014 notifications.push_back( 1047 notifications.push_back(DialogNotification(
1015 DialogNotification( 1048 DialogNotification::SECURITY_WARNING,
1016 DialogNotification::SECURITY_WARNING, 1049 l10n_util::GetStringFUTF16(IDS_AUTOFILL_DIALOG_SITE_WARNING,
1017 l10n_util::GetStringFUTF16( 1050 UTF8ToUTF16(source_url_.host()))));
1018 IDS_AUTOFILL_DIALOG_SITE_WARNING, 1051 }
1019 UTF8ToUTF16(source_url_.host())))); 1052
1053 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1054 notifications.push_back(DialogNotification(
1055 DialogNotification::REQUIRED_ACTION,
1056 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV)));
1020 } 1057 }
1021 1058
1022 if (had_autocheckout_error_) { 1059 if (had_autocheckout_error_) {
1023 notifications.push_back( 1060 notifications.push_back(DialogNotification(
1024 DialogNotification( 1061 DialogNotification::AUTOCHECKOUT_ERROR,
1025 DialogNotification::AUTOCHECKOUT_ERROR, 1062 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_ERROR)));
1026 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_ERROR)));
1027 } 1063 }
1028 1064
1029 if (account_chooser_model_.had_wallet_error()) { 1065 if (account_chooser_model_.had_wallet_error()) {
1030 // TODO(dbeam): pass along the Wallet error or remove from the translation. 1066 // TODO(dbeam): pass along the Wallet error or remove from the translation.
1031 // TODO(dbeam): figure out a way to dismiss this error after a while. 1067 // TODO(dbeam): figure out a way to dismiss this error after a while.
1032 notifications.push_back(DialogNotification( 1068 notifications.push_back(DialogNotification(
1033 DialogNotification::WALLET_ERROR, 1069 DialogNotification::WALLET_ERROR,
1034 l10n_util::GetStringFUTF16( 1070 l10n_util::GetStringFUTF16(
1035 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET, 1071 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET,
1036 ASCIIToUTF16("Oops, [Wallet-Error].")))); 1072 ASCIIToUTF16("Oops, [Wallet-Error]."))));
1037 } 1073 }
1038 1074
1039 return notifications; 1075 return notifications;
1040 } 1076 }
1041 1077
1042 void AutofillDialogControllerImpl::StartSignInFlow() { 1078 void AutofillDialogControllerImpl::StartSignInFlow() {
1043 DCHECK(registrar_.IsEmpty()); 1079 DCHECK(registrar_.IsEmpty());
1044 1080
1045 content::Source<content::NavigationController> source(view_->ShowSignIn()); 1081 content::Source<content::NavigationController> source(view_->ShowSignIn());
1046 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); 1082 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source);
1047 } 1083 }
1048 1084
1049 void AutofillDialogControllerImpl::EndSignInFlow() { 1085 void AutofillDialogControllerImpl::EndSignInFlow() {
1050 DCHECK(!registrar_.IsEmpty()); 1086 DCHECK(!registrar_.IsEmpty());
1051 registrar_.RemoveAll(); 1087 registrar_.RemoveAll();
1052 view_->HideSignIn(); 1088 view_->HideSignIn();
1053 } 1089 }
1054 1090
1055 void AutofillDialogControllerImpl::OnCancel() { 1091 void AutofillDialogControllerImpl::OnCancel() {
1056 if (!did_submit_) { 1092 if (!is_submitting_) {
Ilya Sherman 2013/03/28 05:28:57 I don't think this is desirable. The goal is to *
Dan Beam 2013/03/29 00:43:10 Changed to use callback_.is_null()
1057 metric_logger_.LogDialogUiDuration( 1093 metric_logger_.LogDialogUiDuration(
1058 base::Time::Now() - dialog_shown_timestamp_, 1094 base::Time::Now() - dialog_shown_timestamp_,
1059 dialog_type_, 1095 dialog_type_,
1060 AutofillMetrics::DIALOG_CANCELED); 1096 AutofillMetrics::DIALOG_CANCELED);
1061 } 1097 }
1062 1098
1063 // If Autocheckout has an error, it's possible that the dialog will be 1099 // If Autocheckout has an error, it's possible that the dialog will be
1064 // submitted to start the flow and then cancelled to close the dialog after 1100 // submitted to start the flow and then cancelled to close the dialog after
1065 // the error. 1101 // the error.
1066 if (!callback_.is_null()) { 1102 if (!callback_.is_null()) {
1067 callback_.Run(NULL); 1103 callback_.Run(NULL);
1068 callback_ = base::Callback<void(const FormStructure*)>(); 1104 callback_ = base::Callback<void(const FormStructure*)>();
1069 } 1105 }
1070 } 1106 }
1071 1107
1072 void AutofillDialogControllerImpl::OnSubmit() { 1108 void AutofillDialogControllerImpl::OnAccept() {
1073 did_submit_ = true; 1109 // Update the button strip after Autocheckout may have started.
1074 metric_logger_.LogDialogUiDuration( 1110 is_submitting_ = true;
1075 base::Time::Now() - dialog_shown_timestamp_, 1111 view_->UpdateButtonStrip();
1076 dialog_type_,
1077 AutofillMetrics::DIALOG_ACCEPTED);
1078 1112
1079 if (dialog_type_ == DIALOG_TYPE_AUTOCHECKOUT) { 1113 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1080 // Stop observing PersonalDataManager to avoid the dialog redrawing while 1114 DCHECK(!active_instrument_id_.empty());
1081 // in an Autocheckout flow. 1115 GetWalletClient()->AuthenticateInstrument(
1082 GetManager()->RemoveObserver(this); 1116 active_instrument_id_,
1083 autocheckout_is_running_ = true; 1117 UTF16ToUTF8(view_->GetCvc()),
1084 autocheckout_started_timestamp_ = base::Time::Now(); 1118 wallet_items_->obfuscated_gaia_id());
1085 view_->UpdateButtonStrip(); 1119 } else if (IsPayingWithWallet()) {
1120 SubmitWithWallet();
1121 } else {
1122 FinishSubmit();
1086 } 1123 }
1087
1088 if (IsPayingWithWallet())
1089 SubmitWithWallet();
1090 else
1091 FinishSubmit();
1092 } 1124 }
1093 1125
1094 Profile* AutofillDialogControllerImpl::profile() { 1126 Profile* AutofillDialogControllerImpl::profile() {
1095 return profile_; 1127 return profile_;
1096 } 1128 }
1097 1129
1098 content::WebContents* AutofillDialogControllerImpl::web_contents() { 1130 content::WebContents* AutofillDialogControllerImpl::web_contents() {
1099 return contents_; 1131 return contents_;
1100 } 1132 }
1101 1133
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) { 1229 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) {
1198 // TODO(dbeam): use the returned full wallet. b/8332329 1230 // TODO(dbeam): use the returned full wallet. b/8332329
1199 if (success) 1231 if (success)
1200 GetFullWallet(); 1232 GetFullWallet();
1201 else 1233 else
1202 DisableWallet(); 1234 DisableWallet();
1203 } 1235 }
1204 1236
1205 void AutofillDialogControllerImpl::OnDidGetFullWallet( 1237 void AutofillDialogControllerImpl::OnDidGetFullWallet(
1206 scoped_ptr<wallet::FullWallet> full_wallet) { 1238 scoped_ptr<wallet::FullWallet> full_wallet) {
1207 // TODO(dbeam): handle more required actions.
1208 full_wallet_ = full_wallet.Pass(); 1239 full_wallet_ = full_wallet.Pass();
1209 1240
1210 if (full_wallet_->HasRequiredAction(wallet::VERIFY_CVV)) 1241 if (full_wallet_->required_actions().empty()) {
1211 DisableWallet();
1212 else
1213 FinishSubmit(); 1242 FinishSubmit();
1243 return;
1244 }
1245
1246 GenerateSuggestionsModels();
1247 view_->ModelChanged();
1248 view_->UpdateNotificationArea();
1249 view_->UpdateButtonStrip();
1214 } 1250 }
1215 1251
1216 void AutofillDialogControllerImpl::OnPassiveSigninSuccess( 1252 void AutofillDialogControllerImpl::OnPassiveSigninSuccess(
1217 const std::string& username) { 1253 const std::string& username) {
1218 DCHECK(IsPayingWithWallet()); 1254 DCHECK(IsPayingWithWallet());
1219 current_username_ = username; 1255 current_username_ = username;
1220 signin_helper_.reset(); 1256 signin_helper_.reset();
1221 wallet_items_.reset(); 1257 wallet_items_.reset();
1222 StartFetchingWalletItems(); 1258 StartFetchingWalletItems();
1223 } 1259 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 1425
1390 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { 1426 bool AutofillDialogControllerImpl::IsPayingWithWallet() const {
1391 return account_chooser_model_.WalletIsSelected(); 1427 return account_chooser_model_.WalletIsSelected();
1392 } 1428 }
1393 1429
1394 void AutofillDialogControllerImpl::DisableWallet() { 1430 void AutofillDialogControllerImpl::DisableWallet() {
1395 signin_helper_.reset(); 1431 signin_helper_.reset();
1396 current_username_.clear(); 1432 current_username_.clear();
1397 account_chooser_model_.SetHadWalletError(); 1433 account_chooser_model_.SetHadWalletError();
1398 GetWalletClient()->CancelPendingRequests(); 1434 GetWalletClient()->CancelPendingRequests();
1435 full_wallet_.reset();
1399 } 1436 }
1400 1437
1401 void AutofillDialogControllerImpl::OnWalletSigninError() { 1438 void AutofillDialogControllerImpl::OnWalletSigninError() {
1402 signin_helper_.reset(); 1439 signin_helper_.reset();
1403 current_username_.clear(); 1440 current_username_.clear();
1404 account_chooser_model_.SetHadWalletSigninError(); 1441 account_chooser_model_.SetHadWalletSigninError();
1405 GetWalletClient()->CancelPendingRequests(); 1442 GetWalletClient()->CancelPendingRequests();
1406 } 1443 }
1407 1444
1408 bool AutofillDialogControllerImpl::IsFirstRun() const { 1445 bool AutofillDialogControllerImpl::IsFirstRun() const {
1409 PrefService* prefs = profile_->GetPrefs(); 1446 PrefService* prefs = profile_->GetPrefs();
1410 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet); 1447 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet);
1411 } 1448 }
1412 1449
1413 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { 1450 void AutofillDialogControllerImpl::GenerateSuggestionsModels() {
1414 suggested_email_.Reset(); 1451 suggested_email_.Reset();
1415 suggested_cc_.Reset(); 1452 suggested_cc_.Reset();
1416 suggested_billing_.Reset(); 1453 suggested_billing_.Reset();
1417 suggested_cc_billing_.Reset(); 1454 suggested_cc_billing_.Reset();
1418 suggested_shipping_.Reset(); 1455 suggested_shipping_.Reset();
1419 1456
1420 if (IsPayingWithWallet()) { 1457 if (IsPayingWithWallet()) {
1421 if (wallet_items_.get()) { 1458 if (wallet_items_) {
1422 // TODO(estade): seems we need to hardcode the email address. 1459 // TODO(estade): seems we need to hardcode the email address.
1423 1460
1424 const std::vector<wallet::Address*>& addresses = 1461 const std::vector<wallet::Address*>& addresses =
1425 wallet_items_->addresses(); 1462 wallet_items_->addresses();
1426 for (size_t i = 0; i < addresses.size(); ++i) { 1463 for (size_t i = 0; i < addresses.size(); ++i) {
1427 // TODO(dbeam): respect wallet_items_->default_instrument_id(). 1464 // TODO(dbeam): respect wallet_items_->default_instrument_id().
1428 suggested_shipping_.AddKeyedItemWithSublabel( 1465 suggested_shipping_.AddKeyedItemWithSublabel(
1429 base::IntToString(i), 1466 base::IntToString(i),
1430 addresses[i]->DisplayName(), 1467 addresses[i]->DisplayName(),
1431 addresses[i]->DisplayNameDetail()); 1468 addresses[i]->DisplayNameDetail());
1432 } 1469 }
1433 1470
1434 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = 1471 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1435 wallet_items_->instruments(); 1472 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments =
1436 for (size_t i = 0; i < instruments.size(); ++i) { 1473 wallet_items_->instruments();
1437 // TODO(dbeam): respect wallet_items_->default_address_id(). 1474 for (size_t i = 0; i < instruments.size(); ++i) {
1438 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( 1475 // TODO(dbeam): respect wallet_items_->default_address_id().
1439 base::IntToString(i), 1476 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon(
1440 instruments[i]->DisplayName(), 1477 base::IntToString(i),
1441 instruments[i]->DisplayNameDetail(), 1478 instruments[i]->DisplayName(),
1442 instruments[i]->CardIcon()); 1479 instruments[i]->DisplayNameDetail(),
1480 instruments[i]->CardIcon());
1481 }
1443 } 1482 }
1444 } 1483 }
1445 1484
1446 suggested_cc_billing_.AddKeyedItem( 1485 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1447 std::string(), 1486 suggested_cc_billing_.AddKeyedItem(
1448 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); 1487 std::string(),
1488 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS));
1489 }
1449 } else { 1490 } else {
1450 PersonalDataManager* manager = GetManager(); 1491 PersonalDataManager* manager = GetManager();
1451 const std::vector<CreditCard*>& cards = manager->credit_cards(); 1492 const std::vector<CreditCard*>& cards = manager->credit_cards();
1452 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1493 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1453 for (size_t i = 0; i < cards.size(); ++i) { 1494 for (size_t i = 0; i < cards.size(); ++i) {
1454 suggested_cc_.AddKeyedItemWithIcon( 1495 suggested_cc_.AddKeyedItemWithIcon(
1455 cards[i]->guid(), 1496 cards[i]->guid(),
1456 cards[i]->Label(), 1497 cards[i]->Label(),
1457 rb.GetImageNamed(cards[i]->IconResourceId())); 1498 rb.GetImageNamed(cards[i]->IconResourceId()));
1458 } 1499 }
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 wallet_items_->obfuscated_gaia_id(), 1813 wallet_items_->obfuscated_gaia_id(),
1773 source_url_); 1814 source_url_);
1774 } else if (new_address.get()) { 1815 } else if (new_address.get()) {
1775 GetWalletClient()->SaveAddress(*new_address, source_url_); 1816 GetWalletClient()->SaveAddress(*new_address, source_url_);
1776 } else { 1817 } else {
1777 GetFullWallet(); 1818 GetFullWallet();
1778 } 1819 }
1779 } 1820 }
1780 1821
1781 void AutofillDialogControllerImpl::GetFullWallet() { 1822 void AutofillDialogControllerImpl::GetFullWallet() {
1782 DCHECK(did_submit_); 1823 DCHECK(is_submitting_);
1783 DCHECK(IsPayingWithWallet()); 1824 DCHECK(IsPayingWithWallet());
1784 DCHECK(wallet_items_); 1825 DCHECK(wallet_items_);
1785 DCHECK(!active_instrument_id_.empty()); 1826 DCHECK(!active_instrument_id_.empty());
1786 DCHECK(!active_address_id_.empty()); 1827 DCHECK(!active_address_id_.empty());
1787 1828
1788 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( 1829 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest(
1789 active_instrument_id_, 1830 active_instrument_id_,
1790 active_address_id_, 1831 active_address_id_,
1791 source_url_, 1832 source_url_,
1792 wallet::Cart(base::IntToString(kCartMax), kCartCurrency), 1833 wallet::Cart(base::IntToString(kCartMax), kCartCurrency),
1793 wallet_items_->google_transaction_id(), 1834 wallet_items_->google_transaction_id(),
1794 std::vector<wallet::WalletClient::RiskCapability>())); 1835 std::vector<wallet::WalletClient::RiskCapability>()));
1795 } 1836 }
1796 1837
1797 void AutofillDialogControllerImpl::FinishSubmit() { 1838 void AutofillDialogControllerImpl::FinishSubmit() {
1798 FillOutputForSection(SECTION_EMAIL); 1839 FillOutputForSection(SECTION_EMAIL);
1799 FillOutputForSection(SECTION_CC); 1840 FillOutputForSection(SECTION_CC);
1800 FillOutputForSection(SECTION_BILLING); 1841 FillOutputForSection(SECTION_BILLING);
1801 FillOutputForSection(SECTION_CC_BILLING); 1842 FillOutputForSection(SECTION_CC_BILLING);
1843
1802 if (ShouldUseBillingForShipping()) { 1844 if (ShouldUseBillingForShipping()) {
1803 FillOutputForSectionWithComparator( 1845 FillOutputForSectionWithComparator(
1804 SECTION_BILLING, 1846 SECTION_BILLING,
1805 base::Bind(DetailInputMatchesShippingField)); 1847 base::Bind(DetailInputMatchesShippingField));
1806 FillOutputForSectionWithComparator( 1848 FillOutputForSectionWithComparator(
1807 SECTION_CC, 1849 SECTION_CC,
1808 base::Bind(DetailInputMatchesShippingField)); 1850 base::Bind(DetailInputMatchesShippingField));
1809 } else { 1851 } else {
1810 FillOutputForSection(SECTION_SHIPPING); 1852 FillOutputForSection(SECTION_SHIPPING);
1811 } 1853 }
1854
1812 callback_.Run(&form_structure_); 1855 callback_.Run(&form_structure_);
1813 callback_ = base::Callback<void(const FormStructure*)>(); 1856 callback_ = base::Callback<void(const FormStructure*)>();
1814 1857
1815 if (dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) { 1858 metric_logger_.LogDialogUiDuration(
1816 // This may delete us. 1859 base::Time::Now() - dialog_shown_timestamp_,
1817 Hide(); 1860 dialog_type_,
1861 AutofillMetrics::DIALOG_ACCEPTED);
1862
1863 switch (dialog_type_) {
1864 case DIALOG_TYPE_AUTOCHECKOUT:
1865 // Stop observing PersonalDataManager to avoid the dialog redrawing while
1866 // in an Autocheckout flow.
1867 GetManager()->RemoveObserver(this);
1868 autocheckout_is_running_ = true;
1869 autocheckout_started_timestamp_ = base::Time::Now();
1870 view_->UpdateButtonStrip();
1871 break;
1872
1873 case DIALOG_TYPE_REQUEST_AUTOCOMPLETE:
1874 // This may delete us.
1875 Hide();
1876 break;
1818 } 1877 }
1819 } 1878 }
1820 1879
1821 AutofillMetrics::DialogInitialUserStateMetric 1880 AutofillMetrics::DialogInitialUserStateMetric
1822 AutofillDialogControllerImpl::GetInitialUserState() const { 1881 AutofillDialogControllerImpl::GetInitialUserState() const {
1823 // Consider a user to be an Autofill user if the user has any credit cards 1882 // Consider a user to be an Autofill user if the user has any credit cards
1824 // or addresses saved. Check that the item count is greater than 1 because 1883 // or addresses saved. Check that the item count is greater than 1 because
1825 // an "empty" menu still has the "add new" menu item. 1884 // an "empty" menu still has the "add new" menu item.
1826 const bool has_autofill_profiles = 1885 const bool has_autofill_profiles =
1827 suggested_cc_.GetItemCount() > 1 || 1886 suggested_cc_.GetItemCount() > 1 ||
(...skipping 14 matching lines...) Expand all
1842 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; 1901 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL;
1843 } 1902 }
1844 1903
1845 // Has Wallet items. 1904 // Has Wallet items.
1846 return has_autofill_profiles ? 1905 return has_autofill_profiles ?
1847 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : 1906 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL :
1848 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; 1907 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL;
1849 } 1908 }
1850 1909
1851 } // namespace autofill 1910 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698