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 <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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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; | |
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 Loading... | |
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 Loading... | |
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_) { |
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; | |
1074 metric_logger_.LogDialogUiDuration( | 1109 metric_logger_.LogDialogUiDuration( |
1075 base::Time::Now() - dialog_shown_timestamp_, | 1110 base::Time::Now() - dialog_shown_timestamp_, |
1076 dialog_type_, | 1111 dialog_type_, |
1077 AutofillMetrics::DIALOG_ACCEPTED); | 1112 AutofillMetrics::DIALOG_ACCEPTED); |
Ilya Sherman
2013/03/27 23:59:23
Should we log the metric now, or after the CVC cha
Dan Beam
2013/03/28 03:38:12
Moved to FinishSubmit().
| |
1078 | 1113 |
1079 if (dialog_type_ == DIALOG_TYPE_AUTOCHECKOUT) { | 1114 // Update the button strip after Autocheckout may have started. |
1080 // Stop observing PersonalDataManager to avoid the dialog redrawing while | 1115 is_submitting_ = true; |
1081 // in an Autocheckout flow. | 1116 view_->UpdateButtonStrip(); |
1082 GetManager()->RemoveObserver(this); | 1117 |
1083 autocheckout_is_running_ = true; | 1118 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
1084 autocheckout_started_timestamp_ = base::Time::Now(); | 1119 DCHECK(!active_instrument_id_.empty()); |
1085 view_->UpdateButtonStrip(); | 1120 GetWalletClient()->AuthenticateInstrument( |
1121 active_instrument_id_, | |
1122 UTF16ToUTF8(view_->GetCvc()), | |
1123 wallet_items_->obfuscated_gaia_id()); | |
1124 } else if (IsPayingWithWallet()) { | |
1125 SubmitWithWallet(); | |
1126 } else { | |
1127 FinishSubmit(); | |
1086 } | 1128 } |
1087 | |
1088 if (IsPayingWithWallet()) | |
1089 SubmitWithWallet(); | |
1090 else | |
1091 FinishSubmit(); | |
1092 } | 1129 } |
1093 | 1130 |
1094 Profile* AutofillDialogControllerImpl::profile() { | 1131 Profile* AutofillDialogControllerImpl::profile() { |
1095 return profile_; | 1132 return profile_; |
1096 } | 1133 } |
1097 | 1134 |
1098 content::WebContents* AutofillDialogControllerImpl::web_contents() { | 1135 content::WebContents* AutofillDialogControllerImpl::web_contents() { |
1099 return contents_; | 1136 return contents_; |
1100 } | 1137 } |
1101 | 1138 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1197 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) { | 1234 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) { |
1198 // TODO(dbeam): use the returned full wallet. b/8332329 | 1235 // TODO(dbeam): use the returned full wallet. b/8332329 |
1199 if (success) | 1236 if (success) |
1200 GetFullWallet(); | 1237 GetFullWallet(); |
1201 else | 1238 else |
1202 DisableWallet(); | 1239 DisableWallet(); |
1203 } | 1240 } |
1204 | 1241 |
1205 void AutofillDialogControllerImpl::OnDidGetFullWallet( | 1242 void AutofillDialogControllerImpl::OnDidGetFullWallet( |
1206 scoped_ptr<wallet::FullWallet> full_wallet) { | 1243 scoped_ptr<wallet::FullWallet> full_wallet) { |
1207 // TODO(dbeam): handle more required actions. | |
1208 full_wallet_ = full_wallet.Pass(); | 1244 full_wallet_ = full_wallet.Pass(); |
1209 | 1245 |
1210 if (full_wallet_->HasRequiredAction(wallet::VERIFY_CVV)) | 1246 if (full_wallet_->required_actions().empty()) { |
1211 DisableWallet(); | |
1212 else | |
1213 FinishSubmit(); | 1247 FinishSubmit(); |
1248 return; | |
1249 } | |
1250 | |
1251 GenerateSuggestionsModels(); | |
1252 view_->ModelChanged(); | |
1253 view_->UpdateNotificationArea(); | |
1254 view_->UpdateButtonStrip(); | |
1214 } | 1255 } |
1215 | 1256 |
1216 void AutofillDialogControllerImpl::OnPassiveSigninSuccess( | 1257 void AutofillDialogControllerImpl::OnPassiveSigninSuccess( |
1217 const std::string& username) { | 1258 const std::string& username) { |
1218 DCHECK(IsPayingWithWallet()); | 1259 DCHECK(IsPayingWithWallet()); |
1219 current_username_ = username; | 1260 current_username_ = username; |
1220 signin_helper_.reset(); | 1261 signin_helper_.reset(); |
1221 wallet_items_.reset(); | 1262 wallet_items_.reset(); |
1222 StartFetchingWalletItems(); | 1263 StartFetchingWalletItems(); |
1223 } | 1264 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1389 | 1430 |
1390 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { | 1431 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { |
1391 return account_chooser_model_.WalletIsSelected(); | 1432 return account_chooser_model_.WalletIsSelected(); |
1392 } | 1433 } |
1393 | 1434 |
1394 void AutofillDialogControllerImpl::DisableWallet() { | 1435 void AutofillDialogControllerImpl::DisableWallet() { |
1395 signin_helper_.reset(); | 1436 signin_helper_.reset(); |
1396 current_username_.clear(); | 1437 current_username_.clear(); |
1397 account_chooser_model_.SetHadWalletError(); | 1438 account_chooser_model_.SetHadWalletError(); |
1398 GetWalletClient()->CancelPendingRequests(); | 1439 GetWalletClient()->CancelPendingRequests(); |
1440 full_wallet_.reset(); | |
1399 } | 1441 } |
1400 | 1442 |
1401 void AutofillDialogControllerImpl::OnWalletSigninError() { | 1443 void AutofillDialogControllerImpl::OnWalletSigninError() { |
1402 signin_helper_.reset(); | 1444 signin_helper_.reset(); |
1403 current_username_.clear(); | 1445 current_username_.clear(); |
1404 account_chooser_model_.SetHadWalletSigninError(); | 1446 account_chooser_model_.SetHadWalletSigninError(); |
1405 GetWalletClient()->CancelPendingRequests(); | 1447 GetWalletClient()->CancelPendingRequests(); |
1406 } | 1448 } |
1407 | 1449 |
1408 bool AutofillDialogControllerImpl::IsFirstRun() const { | 1450 bool AutofillDialogControllerImpl::IsFirstRun() const { |
1409 PrefService* prefs = profile_->GetPrefs(); | 1451 PrefService* prefs = profile_->GetPrefs(); |
1410 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet); | 1452 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet); |
1411 } | 1453 } |
1412 | 1454 |
1413 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { | 1455 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { |
1414 suggested_email_.Reset(); | 1456 suggested_email_.Reset(); |
1415 suggested_cc_.Reset(); | 1457 suggested_cc_.Reset(); |
1416 suggested_billing_.Reset(); | 1458 suggested_billing_.Reset(); |
1417 suggested_cc_billing_.Reset(); | 1459 suggested_cc_billing_.Reset(); |
1418 suggested_shipping_.Reset(); | 1460 suggested_shipping_.Reset(); |
1419 | 1461 |
1420 if (IsPayingWithWallet()) { | 1462 if (IsPayingWithWallet()) { |
1421 if (wallet_items_.get()) { | 1463 if (wallet_items_) { |
1422 // TODO(estade): seems we need to hardcode the email address. | 1464 // TODO(estade): seems we need to hardcode the email address. |
1423 | 1465 |
1424 const std::vector<wallet::Address*>& addresses = | 1466 const std::vector<wallet::Address*>& addresses = |
1425 wallet_items_->addresses(); | 1467 wallet_items_->addresses(); |
1426 for (size_t i = 0; i < addresses.size(); ++i) { | 1468 for (size_t i = 0; i < addresses.size(); ++i) { |
1427 // TODO(dbeam): respect wallet_items_->default_instrument_id(). | 1469 // TODO(dbeam): respect wallet_items_->default_instrument_id(). |
1428 suggested_shipping_.AddKeyedItemWithSublabel( | 1470 suggested_shipping_.AddKeyedItemWithSublabel( |
1429 base::IntToString(i), | 1471 base::IntToString(i), |
1430 addresses[i]->DisplayName(), | 1472 addresses[i]->DisplayName(), |
1431 addresses[i]->DisplayNameDetail()); | 1473 addresses[i]->DisplayNameDetail()); |
1432 } | 1474 } |
1433 | 1475 |
1434 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = | 1476 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
1435 wallet_items_->instruments(); | 1477 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = |
1436 for (size_t i = 0; i < instruments.size(); ++i) { | 1478 wallet_items_->instruments(); |
1437 // TODO(dbeam): respect wallet_items_->default_address_id(). | 1479 for (size_t i = 0; i < instruments.size(); ++i) { |
1438 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( | 1480 // TODO(dbeam): respect wallet_items_->default_address_id(). |
1439 base::IntToString(i), | 1481 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( |
1440 instruments[i]->DisplayName(), | 1482 base::IntToString(i), |
1441 instruments[i]->DisplayNameDetail(), | 1483 instruments[i]->DisplayName(), |
1442 instruments[i]->CardIcon()); | 1484 instruments[i]->DisplayNameDetail(), |
1485 instruments[i]->CardIcon()); | |
1486 } | |
1443 } | 1487 } |
1444 } | 1488 } |
1445 | 1489 |
1446 suggested_cc_billing_.AddKeyedItem( | 1490 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
1447 std::string(), | 1491 suggested_cc_billing_.AddKeyedItem( |
1448 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); | 1492 std::string(), |
1493 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); | |
1494 } | |
1449 } else { | 1495 } else { |
1450 PersonalDataManager* manager = GetManager(); | 1496 PersonalDataManager* manager = GetManager(); |
1451 const std::vector<CreditCard*>& cards = manager->credit_cards(); | 1497 const std::vector<CreditCard*>& cards = manager->credit_cards(); |
1452 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1498 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1453 for (size_t i = 0; i < cards.size(); ++i) { | 1499 for (size_t i = 0; i < cards.size(); ++i) { |
1454 suggested_cc_.AddKeyedItemWithIcon( | 1500 suggested_cc_.AddKeyedItemWithIcon( |
1455 cards[i]->guid(), | 1501 cards[i]->guid(), |
1456 cards[i]->Label(), | 1502 cards[i]->Label(), |
1457 rb.GetImageNamed(cards[i]->IconResourceId())); | 1503 rb.GetImageNamed(cards[i]->IconResourceId())); |
1458 } | 1504 } |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1772 wallet_items_->obfuscated_gaia_id(), | 1818 wallet_items_->obfuscated_gaia_id(), |
1773 source_url_); | 1819 source_url_); |
1774 } else if (new_address.get()) { | 1820 } else if (new_address.get()) { |
1775 GetWalletClient()->SaveAddress(*new_address, source_url_); | 1821 GetWalletClient()->SaveAddress(*new_address, source_url_); |
1776 } else { | 1822 } else { |
1777 GetFullWallet(); | 1823 GetFullWallet(); |
1778 } | 1824 } |
1779 } | 1825 } |
1780 | 1826 |
1781 void AutofillDialogControllerImpl::GetFullWallet() { | 1827 void AutofillDialogControllerImpl::GetFullWallet() { |
1782 DCHECK(did_submit_); | 1828 DCHECK(is_submitting_); |
1783 DCHECK(IsPayingWithWallet()); | 1829 DCHECK(IsPayingWithWallet()); |
1784 DCHECK(wallet_items_); | 1830 DCHECK(wallet_items_); |
1785 DCHECK(!active_instrument_id_.empty()); | 1831 DCHECK(!active_instrument_id_.empty()); |
1786 DCHECK(!active_address_id_.empty()); | 1832 DCHECK(!active_address_id_.empty()); |
1787 | 1833 |
1788 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( | 1834 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( |
1789 active_instrument_id_, | 1835 active_instrument_id_, |
1790 active_address_id_, | 1836 active_address_id_, |
1791 source_url_, | 1837 source_url_, |
1792 wallet::Cart(base::IntToString(kCartMax), kCartCurrency), | 1838 wallet::Cart(base::IntToString(kCartMax), kCartCurrency), |
1793 wallet_items_->google_transaction_id(), | 1839 wallet_items_->google_transaction_id(), |
1794 std::vector<wallet::WalletClient::RiskCapability>())); | 1840 std::vector<wallet::WalletClient::RiskCapability>())); |
1795 } | 1841 } |
1796 | 1842 |
1797 void AutofillDialogControllerImpl::FinishSubmit() { | 1843 void AutofillDialogControllerImpl::FinishSubmit() { |
1798 FillOutputForSection(SECTION_EMAIL); | 1844 FillOutputForSection(SECTION_EMAIL); |
1799 FillOutputForSection(SECTION_CC); | 1845 FillOutputForSection(SECTION_CC); |
1800 FillOutputForSection(SECTION_BILLING); | 1846 FillOutputForSection(SECTION_BILLING); |
1801 FillOutputForSection(SECTION_CC_BILLING); | 1847 FillOutputForSection(SECTION_CC_BILLING); |
1848 | |
1802 if (ShouldUseBillingForShipping()) { | 1849 if (ShouldUseBillingForShipping()) { |
1803 FillOutputForSectionWithComparator( | 1850 FillOutputForSectionWithComparator( |
1804 SECTION_BILLING, | 1851 SECTION_BILLING, |
1805 base::Bind(DetailInputMatchesShippingField)); | 1852 base::Bind(DetailInputMatchesShippingField)); |
1806 FillOutputForSectionWithComparator( | 1853 FillOutputForSectionWithComparator( |
1807 SECTION_CC, | 1854 SECTION_CC, |
1808 base::Bind(DetailInputMatchesShippingField)); | 1855 base::Bind(DetailInputMatchesShippingField)); |
1809 } else { | 1856 } else { |
1810 FillOutputForSection(SECTION_SHIPPING); | 1857 FillOutputForSection(SECTION_SHIPPING); |
1811 } | 1858 } |
1859 | |
1812 callback_.Run(&form_structure_); | 1860 callback_.Run(&form_structure_); |
1813 callback_ = base::Callback<void(const FormStructure*)>(); | 1861 callback_ = base::Callback<void(const FormStructure*)>(); |
1814 | 1862 |
1815 if (dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) { | 1863 switch (dialog_type_) { |
1816 // This may delete us. | 1864 case DIALOG_TYPE_AUTOCHECKOUT: |
1817 Hide(); | 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 Loading... | |
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 |
OLD | NEW |