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

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, 8 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 CreditCard* card, 165 CreditCard* card,
166 string16* cvc, 166 string16* cvc,
167 AutofillProfile* profile) { 167 AutofillProfile* profile) {
168 for (DetailOutputMap::const_iterator it = output.begin(); 168 for (DetailOutputMap::const_iterator it = output.begin();
169 it != output.end(); ++it) { 169 it != output.end(); ++it) {
170 string16 trimmed; 170 string16 trimmed;
171 TrimWhitespace(it->second, TRIM_ALL, &trimmed); 171 TrimWhitespace(it->second, TRIM_ALL, &trimmed);
172 172
173 // Special case CVC as CreditCard just swallows it. 173 // Special case CVC as CreditCard just swallows it.
174 if (it->first->type == CREDIT_CARD_VERIFICATION_CODE) { 174 if (it->first->type == CREDIT_CARD_VERIFICATION_CODE) {
175 cvc->assign(trimmed); 175 if (cvc)
176 cvc->assign(trimmed);
176 } else { 177 } else {
177 // Copy the credit card name to |profile| in addition to |card| as 178 // Copy the credit card name to |profile| in addition to |card| as
178 // wallet::Instrument requires a recipient name for its billing address. 179 // wallet::Instrument requires a recipient name for its billing address.
179 if (it->first->type == CREDIT_CARD_NAME) 180 if (profile && it->first->type == CREDIT_CARD_NAME)
180 profile->SetRawInfo(NAME_FULL, trimmed); 181 profile->SetRawInfo(NAME_FULL, trimmed);
181 182
182 if (IsCreditCardType(it->first->type)) 183 if (IsCreditCardType(it->first->type)) {
183 card->SetRawInfo(it->first->type, trimmed); 184 if (card)
184 else 185 card->SetRawInfo(it->first->type, trimmed);
186 } else if (profile) {
185 profile->SetRawInfo(it->first->type, trimmed); 187 profile->SetRawInfo(it->first->type, trimmed);
188 }
186 } 189 }
187 } 190 }
188 } 191 }
189 192
190 // Returns the containing window for the given |web_contents|. The containing 193 // Returns the containing window for the given |web_contents|. The containing
191 // window might be a browser window for a Chrome tab, or it might be a shell 194 // window might be a browser window for a Chrome tab, or it might be a shell
192 // window for a platform app. 195 // window for a platform app.
193 BaseWindow* GetBaseWindowForWebContents( 196 BaseWindow* GetBaseWindowForWebContents(
194 const content::WebContents* web_contents) { 197 const content::WebContents* web_contents) {
195 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 198 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)), 245 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)),
243 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)), 246 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)),
244 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)), 247 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)),
245 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_billing_(this)), 248 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_billing_(this)),
246 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)), 249 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)),
247 section_showing_popup_(SECTION_BILLING), 250 section_showing_popup_(SECTION_BILLING),
248 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 251 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
249 metric_logger_(metric_logger), 252 metric_logger_(metric_logger),
250 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), 253 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN),
251 dialog_type_(dialog_type), 254 dialog_type_(dialog_type),
252 did_submit_(false), 255 is_submitting_(false),
253 autocheckout_is_running_(false), 256 autocheckout_is_running_(false),
254 had_autocheckout_error_(false) { 257 had_autocheckout_error_(false) {
255 // TODO(estade): remove duplicates from |form|? 258 // TODO(estade): remove duplicates from |form|?
256 } 259 }
257 260
258 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { 261 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() {
259 if (popup_controller_) 262 if (popup_controller_)
260 popup_controller_->Hide(); 263 popup_controller_->Hide();
261 264
262 metric_logger_.LogDialogInitialUserState(dialog_type_, initial_user_state_); 265 metric_logger_.LogDialogInitialUserState(dialog_type_, initial_user_state_);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 string16 AutofillDialogControllerImpl::UseBillingForShippingText() const { 424 string16 AutofillDialogControllerImpl::UseBillingForShippingText() const {
422 return l10n_util::GetStringUTF16( 425 return l10n_util::GetStringUTF16(
423 IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING); 426 IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING);
424 } 427 }
425 428
426 string16 AutofillDialogControllerImpl::CancelButtonText() const { 429 string16 AutofillDialogControllerImpl::CancelButtonText() const {
427 return l10n_util::GetStringUTF16(IDS_CANCEL); 430 return l10n_util::GetStringUTF16(IDS_CANCEL);
428 } 431 }
429 432
430 string16 AutofillDialogControllerImpl::ConfirmButtonText() const { 433 string16 AutofillDialogControllerImpl::ConfirmButtonText() const {
431 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON); 434 return l10n_util::GetStringUTF16(IsSubmitPausedOn(wallet::VERIFY_CVV) ?
435 IDS_AUTOFILL_DIALOG_VERIFY_BUTTON : IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON);
432 } 436 }
433 437
434 string16 AutofillDialogControllerImpl::CancelSignInText() const { 438 string16 AutofillDialogControllerImpl::CancelSignInText() const {
435 // TODO(abodenha): real strings and l10n. 439 // TODO(abodenha): real strings and l10n.
436 return ASCIIToUTF16("Don't sign in."); 440 return ASCIIToUTF16("Don't sign in.");
437 } 441 }
438 442
439 string16 AutofillDialogControllerImpl::SaveLocallyText() const { 443 string16 AutofillDialogControllerImpl::SaveLocallyText() const {
440 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); 444 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX);
441 } 445 }
(...skipping 22 matching lines...) Expand all
464 } 468 }
465 469
466 bool AutofillDialogControllerImpl::ShouldShowSpinner() const { 470 bool AutofillDialogControllerImpl::ShouldShowSpinner() const {
467 return IsPayingWithWallet() && SignedInState() == REQUIRES_RESPONSE; 471 return IsPayingWithWallet() && SignedInState() == REQUIRES_RESPONSE;
468 } 472 }
469 473
470 string16 AutofillDialogControllerImpl::AccountChooserText() const { 474 string16 AutofillDialogControllerImpl::AccountChooserText() const {
471 if (!IsPayingWithWallet()) 475 if (!IsPayingWithWallet())
472 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); 476 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET);
473 477
474 // TODO(dbeam): real strings and l10n.
475 if (SignedInState() == SIGNED_IN) 478 if (SignedInState() == SIGNED_IN)
476 return ASCIIToUTF16(current_username_); 479 return ASCIIToUTF16(current_username_);
477 480
478 // In this case, the account chooser should be showing the signin link. 481 // In this case, the account chooser should be showing the signin link.
479 return string16(); 482 return string16();
480 } 483 }
481 484
482 string16 AutofillDialogControllerImpl::SignInLinkText() const { 485 string16 AutofillDialogControllerImpl::SignInLinkText() const {
483 // TODO(estade): real strings and l10n. 486 // TODO(estade): real strings and l10n.
484 return ASCIIToUTF16("Sign in to use Google Wallet"); 487 return ASCIIToUTF16("Sign in to use Google Wallet");
485 } 488 }
486 489
487 bool AutofillDialogControllerImpl::ShouldOfferToSaveInChrome() const { 490 bool AutofillDialogControllerImpl::ShouldOfferToSaveInChrome() const {
488 return !IsPayingWithWallet(); 491 return !IsPayingWithWallet();
489 } 492 }
490 493
491 bool AutofillDialogControllerImpl::AutocheckoutIsRunning() const { 494 bool AutofillDialogControllerImpl::AutocheckoutIsRunning() const {
492 return autocheckout_is_running_; 495 return autocheckout_is_running_;
493 } 496 }
494 497
495 bool AutofillDialogControllerImpl::HadAutocheckoutError() const { 498 bool AutofillDialogControllerImpl::HadAutocheckoutError() const {
496 return had_autocheckout_error_; 499 return had_autocheckout_error_;
497 } 500 }
498 501
499 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( 502 bool AutofillDialogControllerImpl::IsDialogButtonEnabled(
500 ui::DialogButton button) const { 503 ui::DialogButton button) const {
504 const bool is_submit_going = is_submitting_ &&
505 !IsSubmitPausedOn(wallet::VERIFY_CVV);
501 if (button == ui::DIALOG_BUTTON_OK) 506 if (button == ui::DIALOG_BUTTON_OK)
502 return !did_submit_; 507 return !is_submit_going;
508
503 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); 509 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button);
510 if (dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE)
511 return true;
Ilya Sherman 2013/03/31 06:04:37 It doesn't seem like you should need this check at
Dan Beam 2013/04/01 22:17:23 Done.
512
504 // TODO(ahutter): Make it possible for the user to cancel out of the dialog 513 // TODO(ahutter): Make it possible for the user to cancel out of the dialog
505 // while Autocheckout is in progress. 514 // while Autocheckout is in progress.
506 return had_autocheckout_error_ || !did_submit_; 515 return had_autocheckout_error_ || !is_submit_going;
Ilya Sherman 2013/03/31 06:04:37 I think what you want to check is !callback_.is_nu
Dan Beam 2013/04/01 22:17:23 Done.
507 } 516 }
508 517
509 const std::vector<ui::Range>& AutofillDialogControllerImpl:: 518 const std::vector<ui::Range>& AutofillDialogControllerImpl::
510 LegalDocumentLinks() { 519 LegalDocumentLinks() {
511 EnsureLegalDocumentsText(); 520 EnsureLegalDocumentsText();
512 return legal_document_link_ranges_; 521 return legal_document_link_ranges_;
513 } 522 }
514 523
515 bool AutofillDialogControllerImpl::SectionIsActive(DialogSection section) 524 bool AutofillDialogControllerImpl::SectionIsActive(DialogSection section)
516 const { 525 const {
526 if (IsSubmitPausedOn(wallet::VERIFY_CVV))
527 return section == SECTION_CC_BILLING;
528
517 if (IsPayingWithWallet()) 529 if (IsPayingWithWallet())
518 return section != SECTION_BILLING && section != SECTION_CC; 530 return section != SECTION_BILLING && section != SECTION_CC;
519 531
520 return section != SECTION_CC_BILLING; 532 return section != SECTION_CC_BILLING;
521 } 533 }
522 534
523 bool AutofillDialogControllerImpl::HasCompleteWallet() const { 535 bool AutofillDialogControllerImpl::HasCompleteWallet() const {
524 return wallet_items_.get() != NULL && 536 return wallet_items_.get() != NULL &&
525 !wallet_items_->instruments().empty() && 537 !wallet_items_->instruments().empty() &&
526 !wallet_items_->addresses().empty(); 538 !wallet_items_->addresses().empty();
527 } 539 }
528 540
541 bool AutofillDialogControllerImpl::IsSubmitPausedOn(
542 wallet::RequiredAction required_action) const {
543 return full_wallet_ && full_wallet_->HasRequiredAction(required_action);
544 }
545
529 void AutofillDialogControllerImpl::StartFetchingWalletItems() { 546 void AutofillDialogControllerImpl::StartFetchingWalletItems() {
530 DCHECK(IsPayingWithWallet()); 547 DCHECK(IsPayingWithWallet());
531 // TODO(dbeam): Add Risk capabilites once the UI supports risk challenges. 548 // TODO(dbeam): Add Risk capabilites once the UI supports risk challenges.
532 GetWalletClient()->GetWalletItems( 549 GetWalletClient()->GetWalletItems(
533 source_url_, 550 source_url_,
534 std::vector<wallet::WalletClient::RiskCapability>()); 551 std::vector<wallet::WalletClient::RiskCapability>());
535 } 552 }
536 553
537 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { 554 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() {
538 if (wallet_items_.get()) { 555 if (wallet_items_.get()) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 case SECTION_CC_BILLING: 709 case SECTION_CC_BILLING:
693 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC_BILLING); 710 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC_BILLING);
694 case SECTION_SHIPPING: 711 case SECTION_SHIPPING:
695 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); 712 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING);
696 default: 713 default:
697 NOTREACHED(); 714 NOTREACHED();
698 return string16(); 715 return string16();
699 } 716 }
700 } 717 }
701 718
719 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection(
720 DialogSection section) {
721 return SuggestionState(SuggestionTextForSection(section),
722 SuggestionIconForSection(section),
723 ExtraSuggestionTextForSection(section),
724 ExtraSuggestionIconForSection(section),
725 EditEnabledForSection(section));
726 }
727
702 string16 AutofillDialogControllerImpl::SuggestionTextForSection( 728 string16 AutofillDialogControllerImpl::SuggestionTextForSection(
703 DialogSection section) { 729 DialogSection section) {
730 string16 action_text = RequiredActionTextForSection(section);
731 if (!action_text.empty())
732 return action_text;
733
704 // When the user has clicked 'edit', don't show a suggestion (even though 734 // When the user has clicked 'edit', don't show a suggestion (even though
705 // there is a profile selected in the model). 735 // there is a profile selected in the model).
706 if (section_editing_state_[section]) 736 if (section_editing_state_[section])
707 return string16(); 737 return string16();
708 738
709 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 739 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
710 std::string item_key = model->GetItemKeyForCheckedItem(); 740 std::string item_key = model->GetItemKeyForCheckedItem();
711 if (item_key.empty()) 741 if (item_key.empty())
712 return string16(); 742 return string16();
713 743
714 if (section == SECTION_EMAIL) 744 if (section == SECTION_EMAIL)
715 return model->GetLabelAt(model->checked_item()); 745 return model->GetLabelAt(model->checked_item());
716 746
717 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 747 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
718 return wrapper->GetDisplayText(); 748 return wrapper->GetDisplayText();
719 } 749 }
720 750
751 string16 AutofillDialogControllerImpl::RequiredActionTextForSection(
752 DialogSection section) const {
753 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) {
754 const wallet::WalletItems::MaskedInstrument* current_instrument =
755 wallet_items_->GetInstrumentById(active_instrument_id_);
756 if (current_instrument)
757 return current_instrument->TypeAndLastFourDigits();
758
759 DetailOutputMap output;
760 view_->GetUserInput(section, &output);
761 CreditCard card;
762 GetBillingInfoFromOutputs(output, &card, NULL, NULL);
763 return card.TypeAndLastFourDigits();
764 }
765
766 return string16();
767 }
768
769 string16 AutofillDialogControllerImpl::ExtraSuggestionTextForSection(
770 DialogSection section) const {
771 if (section == SECTION_CC ||
772 (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV))) {
773 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC);
774 }
775
776 return string16();
777 }
778
721 scoped_ptr<DataModelWrapper> AutofillDialogControllerImpl::CreateWrapper( 779 scoped_ptr<DataModelWrapper> AutofillDialogControllerImpl::CreateWrapper(
722 DialogSection section) { 780 DialogSection section) {
723 if (IsPayingWithWallet() && full_wallet_) { 781 if (IsPayingWithWallet() && full_wallet_ &&
782 !IsSubmitPausedOn(wallet::VERIFY_CVV)) {
724 if (section == SECTION_CC_BILLING) { 783 if (section == SECTION_CC_BILLING) {
725 return scoped_ptr<DataModelWrapper>( 784 return scoped_ptr<DataModelWrapper>(
726 new FullWalletBillingWrapper(full_wallet_.get())); 785 new FullWalletBillingWrapper(full_wallet_.get()));
727 } 786 }
728 if (section == SECTION_SHIPPING) { 787 if (section == SECTION_SHIPPING) {
729 return scoped_ptr<DataModelWrapper>( 788 return scoped_ptr<DataModelWrapper>(
730 new FullWalletShippingWrapper(full_wallet_.get())); 789 new FullWalletShippingWrapper(full_wallet_.get()));
731 } 790 }
732 } 791 }
733 792
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 833
775 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( 834 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection(
776 DialogSection section) { 835 DialogSection section) {
777 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); 836 scoped_ptr<DataModelWrapper> model = CreateWrapper(section);
778 if (!model.get()) 837 if (!model.get())
779 return gfx::Image(); 838 return gfx::Image();
780 839
781 return model->GetIcon(); 840 return model->GetIcon();
782 } 841 }
783 842
843 gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection(
844 DialogSection section) const {
845 if (section == SECTION_CC || section == SECTION_CC_BILLING)
846 return IconForField(CREDIT_CARD_VERIFICATION_CODE, string16());
847
848 return gfx::Image();
849 }
850
851 bool AutofillDialogControllerImpl::EditEnabledForSection(
852 DialogSection section) const {
853 return section != SECTION_CC_BILLING || !IsSubmitPausedOn(wallet::VERIFY_CVV);
854 }
855
784 void AutofillDialogControllerImpl::EditClickedForSection( 856 void AutofillDialogControllerImpl::EditClickedForSection(
785 DialogSection section) { 857 DialogSection section) {
786 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 858 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
787 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); 859 scoped_ptr<DataModelWrapper> model = CreateWrapper(section);
788 model->FillInputs(inputs); 860 model->FillInputs(inputs);
789 section_editing_state_[section] = true; 861 section_editing_state_[section] = true;
790 view_->UpdateSection(section); 862 view_->UpdateSection(section);
791 } 863 }
792 864
793 void AutofillDialogControllerImpl::EditCancelledForSection( 865 void AutofillDialogControllerImpl::EditCancelledForSection(
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 std::vector<DialogNotification> 1108 std::vector<DialogNotification>
1037 AutofillDialogControllerImpl::CurrentNotifications() const { 1109 AutofillDialogControllerImpl::CurrentNotifications() const {
1038 std::vector<DialogNotification> notifications; 1110 std::vector<DialogNotification> notifications;
1039 1111
1040 if (IsPayingWithWallet()) { 1112 if (IsPayingWithWallet()) {
1041 // TODO(dbeam): what about REQUIRES_PASSIVE_SIGN_IN? 1113 // TODO(dbeam): what about REQUIRES_PASSIVE_SIGN_IN?
1042 if (SignedInState() == SIGNED_IN) { 1114 if (SignedInState() == SIGNED_IN) {
1043 // On first run with a complete wallet profile, show a notification 1115 // On first run with a complete wallet profile, show a notification
1044 // explaining where this data came from. 1116 // explaining where this data came from.
1045 if (IsFirstRun() && HasCompleteWallet()) { 1117 if (IsFirstRun() && HasCompleteWallet()) {
1046 notifications.push_back( 1118 notifications.push_back(DialogNotification(
1047 DialogNotification( 1119 DialogNotification::EXPLANATORY_MESSAGE,
1048 DialogNotification::EXPLANATORY_MESSAGE, 1120 l10n_util::GetStringUTF16(
1049 l10n_util::GetStringUTF16( 1121 IDS_AUTOFILL_DIALOG_DETAILS_FROM_WALLET)));
1050 IDS_AUTOFILL_DIALOG_DETAILS_FROM_WALLET)));
1051 } else { 1122 } else {
1052 notifications.push_back( 1123 notifications.push_back(DialogNotification(
1053 DialogNotification( 1124 DialogNotification::WALLET_PROMO,
1054 DialogNotification::WALLET_PROMO, 1125 l10n_util::GetStringUTF16(
1055 l10n_util::GetStringUTF16( 1126 IDS_AUTOFILL_DIALOG_SAVE_DETAILS_IN_WALLET)));
1056 IDS_AUTOFILL_DIALOG_SAVE_DETAILS_IN_WALLET)));
1057 } 1127 }
1058 } else if (IsFirstRun()) { 1128 } else if (IsFirstRun()) {
1059 // If the user is not signed in, show an upsell notification on first run. 1129 // If the user is not signed in, show an upsell notification on first run.
1060 notifications.push_back( 1130 notifications.push_back(DialogNotification(
1061 DialogNotification( 1131 DialogNotification::WALLET_PROMO,
1062 DialogNotification::WALLET_PROMO, 1132 l10n_util::GetStringUTF16(
1063 l10n_util::GetStringUTF16( 1133 IDS_AUTOFILL_DIALOG_SIGN_IN_AND_SAVE_DETAILS)));
1064 IDS_AUTOFILL_DIALOG_SIGN_IN_AND_SAVE_DETAILS)));
1065 } 1134 }
1066 } 1135 }
1067 1136
1068 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) { 1137 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) {
1069 notifications.push_back( 1138 notifications.push_back(DialogNotification(
1070 DialogNotification( 1139 DialogNotification::SECURITY_WARNING,
1071 DialogNotification::SECURITY_WARNING, 1140 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)));
1072 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)));
1073 } 1141 }
1074 1142
1075 if (!invoked_from_same_origin_) { 1143 if (!invoked_from_same_origin_) {
1076 notifications.push_back( 1144 notifications.push_back(DialogNotification(
1077 DialogNotification( 1145 DialogNotification::SECURITY_WARNING,
1078 DialogNotification::SECURITY_WARNING, 1146 l10n_util::GetStringFUTF16(IDS_AUTOFILL_DIALOG_SITE_WARNING,
1079 l10n_util::GetStringFUTF16( 1147 UTF8ToUTF16(source_url_.host()))));
1080 IDS_AUTOFILL_DIALOG_SITE_WARNING, 1148 }
1081 UTF8ToUTF16(source_url_.host())))); 1149
1150 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1151 notifications.push_back(DialogNotification(
1152 DialogNotification::REQUIRED_ACTION,
1153 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV)));
1082 } 1154 }
1083 1155
1084 if (had_autocheckout_error_) { 1156 if (had_autocheckout_error_) {
1085 notifications.push_back( 1157 notifications.push_back(DialogNotification(
1086 DialogNotification( 1158 DialogNotification::AUTOCHECKOUT_ERROR,
1087 DialogNotification::AUTOCHECKOUT_ERROR, 1159 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_ERROR)));
1088 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_ERROR)));
1089 } 1160 }
1090 1161
1091 if (account_chooser_model_.had_wallet_error()) { 1162 if (account_chooser_model_.had_wallet_error()) {
1092 // TODO(dbeam): pass along the Wallet error or remove from the translation. 1163 // TODO(dbeam): pass along the Wallet error or remove from the translation.
1093 // TODO(dbeam): figure out a way to dismiss this error after a while. 1164 // TODO(dbeam): figure out a way to dismiss this error after a while.
1094 notifications.push_back(DialogNotification( 1165 notifications.push_back(DialogNotification(
1095 DialogNotification::WALLET_ERROR, 1166 DialogNotification::WALLET_ERROR,
1096 l10n_util::GetStringFUTF16( 1167 l10n_util::GetStringFUTF16(
1097 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET, 1168 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET,
1098 ASCIIToUTF16("Oops, [Wallet-Error].")))); 1169 ASCIIToUTF16("Oops, [Wallet-Error]."))));
(...skipping 30 matching lines...) Expand all
1129 } 1200 }
1130 } 1201 }
1131 1202
1132 NOTREACHED(); 1203 NOTREACHED();
1133 #else 1204 #else
1134 // TODO(estade): use TabModelList? 1205 // TODO(estade): use TabModelList?
1135 #endif 1206 #endif
1136 } 1207 }
1137 1208
1138 void AutofillDialogControllerImpl::OnCancel() { 1209 void AutofillDialogControllerImpl::OnCancel() {
1139 if (!did_submit_) { 1210 // If the submit was successful, |callback_| will have already been |.Run()|
1140 metric_logger_.LogDialogUiDuration( 1211 // and nullified. If this is the case, no further actions are required. If
1141 base::Time::Now() - dialog_shown_timestamp_, 1212 // Autocheckout has an error, it's possible that the dialog will be submitted
1142 dialog_type_, 1213 // to start the flow and then cancelled to close the dialog after the error.
1143 AutofillMetrics::DIALOG_CANCELED); 1214 if (callback_.is_null())
1144 } 1215 return;
1145 1216
1146 // If Autocheckout has an error, it's possible that the dialog will be 1217 metric_logger_.LogDialogUiDuration(
1147 // submitted to start the flow and then cancelled to close the dialog after 1218 base::Time::Now() - dialog_shown_timestamp_,
1148 // the error. 1219 dialog_type_,
1149 if (!callback_.is_null()) { 1220 AutofillMetrics::DIALOG_CANCELED);
1150 callback_.Run(NULL); 1221
1151 callback_ = base::Callback<void(const FormStructure*)>(); 1222 callback_.Run(NULL);
1223 callback_ = base::Callback<void(const FormStructure*)>();
1224 }
1225
1226 void AutofillDialogControllerImpl::OnAccept() {
1227 is_submitting_ = true;
1228 view_->UpdateButtonStrip();
1229
1230 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1231 DCHECK(!active_instrument_id_.empty());
1232 GetWalletClient()->AuthenticateInstrument(
1233 active_instrument_id_,
1234 UTF16ToUTF8(view_->GetCvc()),
1235 wallet_items_->obfuscated_gaia_id());
1236 } else if (IsPayingWithWallet()) {
1237 // TODO(dbeam): disallow switching payment methods while submitting.
1238 SubmitWithWallet();
1239 } else {
1240 FinishSubmit();
1152 } 1241 }
1153 } 1242 }
1154 1243
1155 void AutofillDialogControllerImpl::OnSubmit() {
1156 did_submit_ = true;
1157 metric_logger_.LogDialogUiDuration(
1158 base::Time::Now() - dialog_shown_timestamp_,
1159 dialog_type_,
1160 AutofillMetrics::DIALOG_ACCEPTED);
1161
1162 if (dialog_type_ == DIALOG_TYPE_AUTOCHECKOUT) {
1163 // Stop observing PersonalDataManager to avoid the dialog redrawing while
1164 // in an Autocheckout flow.
1165 GetManager()->RemoveObserver(this);
1166 autocheckout_is_running_ = true;
1167 autocheckout_started_timestamp_ = base::Time::Now();
1168 view_->UpdateButtonStrip();
1169 }
1170
1171 if (IsPayingWithWallet())
1172 SubmitWithWallet();
1173 else
1174 FinishSubmit();
1175 }
1176
1177 Profile* AutofillDialogControllerImpl::profile() { 1244 Profile* AutofillDialogControllerImpl::profile() {
1178 return profile_; 1245 return profile_;
1179 } 1246 }
1180 1247
1181 content::WebContents* AutofillDialogControllerImpl::web_contents() { 1248 content::WebContents* AutofillDialogControllerImpl::web_contents() {
1182 return contents_; 1249 return contents_;
1183 } 1250 }
1184 1251
1185 //////////////////////////////////////////////////////////////////////////////// 1252 ////////////////////////////////////////////////////////////////////////////////
1186 // AutofillPopupDelegate implementation. 1253 // AutofillPopupDelegate implementation.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) { 1346 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) {
1280 // TODO(dbeam): use the returned full wallet. b/8332329 1347 // TODO(dbeam): use the returned full wallet. b/8332329
1281 if (success) 1348 if (success)
1282 GetFullWallet(); 1349 GetFullWallet();
1283 else 1350 else
1284 DisableWallet(); 1351 DisableWallet();
1285 } 1352 }
1286 1353
1287 void AutofillDialogControllerImpl::OnDidGetFullWallet( 1354 void AutofillDialogControllerImpl::OnDidGetFullWallet(
1288 scoped_ptr<wallet::FullWallet> full_wallet) { 1355 scoped_ptr<wallet::FullWallet> full_wallet) {
1289 // TODO(dbeam): handle more required actions.
1290 full_wallet_ = full_wallet.Pass(); 1356 full_wallet_ = full_wallet.Pass();
1291 1357
1292 if (full_wallet_->HasRequiredAction(wallet::VERIFY_CVV)) 1358 if (full_wallet_->required_actions().empty()) {
1293 DisableWallet();
1294 else
1295 FinishSubmit(); 1359 FinishSubmit();
1360 return;
1361 }
1362
1363 GenerateSuggestionsModels();
1364 view_->ModelChanged();
1365 view_->UpdateNotificationArea();
1366 view_->UpdateButtonStrip();
1296 } 1367 }
1297 1368
1298 void AutofillDialogControllerImpl::OnPassiveSigninSuccess( 1369 void AutofillDialogControllerImpl::OnPassiveSigninSuccess(
1299 const std::string& username) { 1370 const std::string& username) {
1300 DCHECK(IsPayingWithWallet()); 1371 DCHECK(IsPayingWithWallet());
1301 current_username_ = username; 1372 current_username_ = username;
1302 signin_helper_.reset(); 1373 signin_helper_.reset();
1303 wallet_items_.reset(); 1374 wallet_items_.reset();
1304 StartFetchingWalletItems(); 1375 StartFetchingWalletItems();
1305 } 1376 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 1540
1470 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { 1541 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() {
1471 return &wallet_client_; 1542 return &wallet_client_;
1472 } 1543 }
1473 1544
1474 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { 1545 bool AutofillDialogControllerImpl::IsPayingWithWallet() const {
1475 return account_chooser_model_.WalletIsSelected(); 1546 return account_chooser_model_.WalletIsSelected();
1476 } 1547 }
1477 1548
1478 void AutofillDialogControllerImpl::DisableWallet() { 1549 void AutofillDialogControllerImpl::DisableWallet() {
1550 is_submitting_ = false;
1551 if (view_)
1552 view_->UpdateButtonStrip();
1553
1479 signin_helper_.reset(); 1554 signin_helper_.reset();
1480 current_username_.clear(); 1555 current_username_.clear();
1481 account_chooser_model_.SetHadWalletError(); 1556 account_chooser_model_.SetHadWalletError();
1482 GetWalletClient()->CancelPendingRequests(); 1557 GetWalletClient()->CancelPendingRequests();
1558 full_wallet_.reset();
1483 } 1559 }
1484 1560
1485 void AutofillDialogControllerImpl::OnWalletSigninError() { 1561 void AutofillDialogControllerImpl::OnWalletSigninError() {
1486 signin_helper_.reset(); 1562 signin_helper_.reset();
1487 current_username_.clear(); 1563 current_username_.clear();
1488 account_chooser_model_.SetHadWalletSigninError(); 1564 account_chooser_model_.SetHadWalletSigninError();
1489 GetWalletClient()->CancelPendingRequests(); 1565 GetWalletClient()->CancelPendingRequests();
1490 } 1566 }
1491 1567
1492 bool AutofillDialogControllerImpl::IsFirstRun() const { 1568 bool AutofillDialogControllerImpl::IsFirstRun() const {
1493 PrefService* prefs = profile_->GetPrefs(); 1569 PrefService* prefs = profile_->GetPrefs();
1494 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet); 1570 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet);
1495 } 1571 }
1496 1572
1497 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { 1573 void AutofillDialogControllerImpl::GenerateSuggestionsModels() {
1498 suggested_email_.Reset(); 1574 suggested_email_.Reset();
1499 suggested_cc_.Reset(); 1575 suggested_cc_.Reset();
1500 suggested_billing_.Reset(); 1576 suggested_billing_.Reset();
1501 suggested_cc_billing_.Reset(); 1577 suggested_cc_billing_.Reset();
1502 suggested_shipping_.Reset(); 1578 suggested_shipping_.Reset();
1503 1579
1504 if (IsPayingWithWallet()) { 1580 if (IsPayingWithWallet()) {
1505 if (wallet_items_.get()) { 1581 if (wallet_items_) {
1506 // TODO(estade): seems we need to hardcode the email address. 1582 // TODO(estade): seems we need to hardcode the email address.
1507 1583
1508 const std::vector<wallet::Address*>& addresses = 1584 const std::vector<wallet::Address*>& addresses =
1509 wallet_items_->addresses(); 1585 wallet_items_->addresses();
1510 for (size_t i = 0; i < addresses.size(); ++i) { 1586 for (size_t i = 0; i < addresses.size(); ++i) {
1511 // TODO(dbeam): respect wallet_items_->default_instrument_id(). 1587 // TODO(dbeam): respect wallet_items_->default_instrument_id().
1512 suggested_shipping_.AddKeyedItemWithSublabel( 1588 suggested_shipping_.AddKeyedItemWithSublabel(
1513 base::IntToString(i), 1589 base::IntToString(i),
1514 addresses[i]->DisplayName(), 1590 addresses[i]->DisplayName(),
1515 addresses[i]->DisplayNameDetail()); 1591 addresses[i]->DisplayNameDetail());
1516 } 1592 }
1517 1593
1518 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = 1594 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1519 wallet_items_->instruments(); 1595 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments =
1520 for (size_t i = 0; i < instruments.size(); ++i) { 1596 wallet_items_->instruments();
1521 // TODO(dbeam): respect wallet_items_->default_address_id(). 1597 for (size_t i = 0; i < instruments.size(); ++i) {
1522 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( 1598 // TODO(dbeam): respect wallet_items_->default_address_id().
1523 base::IntToString(i), 1599 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon(
1524 instruments[i]->DisplayName(), 1600 base::IntToString(i),
1525 instruments[i]->DisplayNameDetail(), 1601 instruments[i]->DisplayName(),
1526 instruments[i]->CardIcon()); 1602 instruments[i]->DisplayNameDetail(),
1603 instruments[i]->CardIcon());
1604 }
1527 } 1605 }
1528 } 1606 }
1529 1607
1530 suggested_cc_billing_.AddKeyedItem( 1608 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1531 std::string(), 1609 suggested_cc_billing_.AddKeyedItem(
1532 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); 1610 std::string(),
1611 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS));
1612 }
1533 } else { 1613 } else {
1534 PersonalDataManager* manager = GetManager(); 1614 PersonalDataManager* manager = GetManager();
1535 const std::vector<CreditCard*>& cards = manager->credit_cards(); 1615 const std::vector<CreditCard*>& cards = manager->credit_cards();
1536 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1616 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1537 for (size_t i = 0; i < cards.size(); ++i) { 1617 for (size_t i = 0; i < cards.size(); ++i) {
1538 suggested_cc_.AddKeyedItemWithIcon( 1618 suggested_cc_.AddKeyedItemWithIcon(
1539 cards[i]->guid(), 1619 cards[i]->guid(),
1540 cards[i]->Label(), 1620 cards[i]->Label(),
1541 rb.GetImageNamed(cards[i]->IconResourceId())); 1621 rb.GetImageNamed(cards[i]->IconResourceId()));
1542 } 1622 }
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 wallet_items_->obfuscated_gaia_id(), 1936 wallet_items_->obfuscated_gaia_id(),
1857 source_url_); 1937 source_url_);
1858 } else if (new_address.get()) { 1938 } else if (new_address.get()) {
1859 GetWalletClient()->SaveAddress(*new_address, source_url_); 1939 GetWalletClient()->SaveAddress(*new_address, source_url_);
1860 } else { 1940 } else {
1861 GetFullWallet(); 1941 GetFullWallet();
1862 } 1942 }
1863 } 1943 }
1864 1944
1865 void AutofillDialogControllerImpl::GetFullWallet() { 1945 void AutofillDialogControllerImpl::GetFullWallet() {
1866 DCHECK(did_submit_); 1946 DCHECK(is_submitting_);
1867 DCHECK(IsPayingWithWallet()); 1947 DCHECK(IsPayingWithWallet());
1868 DCHECK(wallet_items_); 1948 DCHECK(wallet_items_);
1869 DCHECK(!active_instrument_id_.empty()); 1949 DCHECK(!active_instrument_id_.empty());
1870 DCHECK(!active_address_id_.empty()); 1950 DCHECK(!active_address_id_.empty());
1871 1951
1872 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( 1952 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest(
1873 active_instrument_id_, 1953 active_instrument_id_,
1874 active_address_id_, 1954 active_address_id_,
1875 source_url_, 1955 source_url_,
1876 wallet::Cart(base::IntToString(kCartMax), kCartCurrency), 1956 wallet::Cart(base::IntToString(kCartMax), kCartCurrency),
1877 wallet_items_->google_transaction_id(), 1957 wallet_items_->google_transaction_id(),
1878 std::vector<wallet::WalletClient::RiskCapability>())); 1958 std::vector<wallet::WalletClient::RiskCapability>()));
1879 } 1959 }
1880 1960
1881 void AutofillDialogControllerImpl::FinishSubmit() { 1961 void AutofillDialogControllerImpl::FinishSubmit() {
1882 FillOutputForSection(SECTION_EMAIL); 1962 FillOutputForSection(SECTION_EMAIL);
1883 FillOutputForSection(SECTION_CC); 1963 FillOutputForSection(SECTION_CC);
1884 FillOutputForSection(SECTION_BILLING); 1964 FillOutputForSection(SECTION_BILLING);
1885 FillOutputForSection(SECTION_CC_BILLING); 1965 FillOutputForSection(SECTION_CC_BILLING);
1966
1886 if (ShouldUseBillingForShipping()) { 1967 if (ShouldUseBillingForShipping()) {
1887 FillOutputForSectionWithComparator( 1968 FillOutputForSectionWithComparator(
1888 SECTION_BILLING, 1969 SECTION_BILLING,
1889 base::Bind(DetailInputMatchesShippingField)); 1970 base::Bind(DetailInputMatchesShippingField));
1890 FillOutputForSectionWithComparator( 1971 FillOutputForSectionWithComparator(
1891 SECTION_CC, 1972 SECTION_CC,
1892 base::Bind(DetailInputMatchesShippingField)); 1973 base::Bind(DetailInputMatchesShippingField));
1893 } else { 1974 } else {
1894 FillOutputForSection(SECTION_SHIPPING); 1975 FillOutputForSection(SECTION_SHIPPING);
1895 } 1976 }
1977
1896 callback_.Run(&form_structure_); 1978 callback_.Run(&form_structure_);
1897 callback_ = base::Callback<void(const FormStructure*)>(); 1979 callback_ = base::Callback<void(const FormStructure*)>();
1898 1980
1899 if (dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) { 1981 metric_logger_.LogDialogUiDuration(
1900 // This may delete us. 1982 base::Time::Now() - dialog_shown_timestamp_,
1901 Hide(); 1983 dialog_type_,
1984 AutofillMetrics::DIALOG_ACCEPTED);
1985
1986 switch (dialog_type_) {
1987 case DIALOG_TYPE_AUTOCHECKOUT:
1988 // Stop observing PersonalDataManager to avoid the dialog redrawing while
1989 // in an Autocheckout flow.
1990 GetManager()->RemoveObserver(this);
1991 autocheckout_is_running_ = true;
1992 autocheckout_started_timestamp_ = base::Time::Now();
1993 view_->UpdateButtonStrip();
1994 break;
1995
1996 case DIALOG_TYPE_REQUEST_AUTOCOMPLETE:
1997 // This may delete us.
1998 Hide();
1999 break;
1902 } 2000 }
1903 } 2001 }
1904 2002
1905 AutofillMetrics::DialogInitialUserStateMetric 2003 AutofillMetrics::DialogInitialUserStateMetric
1906 AutofillDialogControllerImpl::GetInitialUserState() const { 2004 AutofillDialogControllerImpl::GetInitialUserState() const {
1907 // Consider a user to be an Autofill user if the user has any credit cards 2005 // Consider a user to be an Autofill user if the user has any credit cards
1908 // or addresses saved. Check that the item count is greater than 1 because 2006 // or addresses saved. Check that the item count is greater than 1 because
1909 // an "empty" menu still has the "add new" menu item. 2007 // an "empty" menu still has the "add new" menu item.
1910 const bool has_autofill_profiles = 2008 const bool has_autofill_profiles =
1911 suggested_cc_.GetItemCount() > 1 || 2009 suggested_cc_.GetItemCount() > 1 ||
(...skipping 14 matching lines...) Expand all
1926 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; 2024 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL;
1927 } 2025 }
1928 2026
1929 // Has Wallet items. 2027 // Has Wallet items.
1930 return has_autofill_profiles ? 2028 return has_autofill_profiles ?
1931 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : 2029 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL :
1932 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; 2030 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL;
1933 } 2031 }
1934 2032
1935 } // namespace autofill 2033 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698