| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 CreditCard* card, | 163 CreditCard* card, |
| 164 string16* cvc, | 164 string16* cvc, |
| 165 AutofillProfile* profile) { | 165 AutofillProfile* profile) { |
| 166 for (DetailOutputMap::const_iterator it = output.begin(); | 166 for (DetailOutputMap::const_iterator it = output.begin(); |
| 167 it != output.end(); ++it) { | 167 it != output.end(); ++it) { |
| 168 string16 trimmed; | 168 string16 trimmed; |
| 169 TrimWhitespace(it->second, TRIM_ALL, &trimmed); | 169 TrimWhitespace(it->second, TRIM_ALL, &trimmed); |
| 170 | 170 |
| 171 // Special case CVC as CreditCard just swallows it. | 171 // Special case CVC as CreditCard just swallows it. |
| 172 if (it->first->type == CREDIT_CARD_VERIFICATION_CODE) { | 172 if (it->first->type == CREDIT_CARD_VERIFICATION_CODE) { |
| 173 cvc->assign(trimmed); | 173 if (cvc) |
| 174 cvc->assign(trimmed); |
| 174 } else { | 175 } else { |
| 175 // Copy the credit card name to |profile| in addition to |card| as | 176 // Copy the credit card name to |profile| in addition to |card| as |
| 176 // wallet::Instrument requires a recipient name for its billing address. | 177 // wallet::Instrument requires a recipient name for its billing address. |
| 177 if (it->first->type == CREDIT_CARD_NAME) | 178 if (profile && it->first->type == CREDIT_CARD_NAME) |
| 178 profile->SetRawInfo(NAME_FULL, trimmed); | 179 profile->SetRawInfo(NAME_FULL, trimmed); |
| 179 | 180 |
| 180 if (IsCreditCardType(it->first->type)) | 181 if (IsCreditCardType(it->first->type)) { |
| 181 card->SetRawInfo(it->first->type, trimmed); | 182 if (card) |
| 182 else | 183 card->SetRawInfo(it->first->type, trimmed); |
| 184 } else if (profile) { |
| 183 profile->SetRawInfo(it->first->type, trimmed); | 185 profile->SetRawInfo(it->first->type, trimmed); |
| 186 } |
| 184 } | 187 } |
| 185 } | 188 } |
| 186 } | 189 } |
| 187 | 190 |
| 188 // Returns the containing window for the given |web_contents|. The containing | 191 // Returns the containing window for the given |web_contents|. The containing |
| 189 // window might be a browser window for a Chrome tab, or it might be a shell | 192 // window might be a browser window for a Chrome tab, or it might be a shell |
| 190 // window for a platform app. | 193 // window for a platform app. |
| 191 BaseWindow* GetBaseWindowForWebContents( | 194 BaseWindow* GetBaseWindowForWebContents( |
| 192 const content::WebContents* web_contents) { | 195 const content::WebContents* web_contents) { |
| 193 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 196 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)), | 243 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)), |
| 241 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)), | 244 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)), |
| 242 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)), | 245 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)), |
| 243 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_billing_(this)), | 246 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_billing_(this)), |
| 244 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)), | 247 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)), |
| 245 section_showing_popup_(SECTION_BILLING), | 248 section_showing_popup_(SECTION_BILLING), |
| 246 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 249 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 247 metric_logger_(metric_logger), | 250 metric_logger_(metric_logger), |
| 248 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 251 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
| 249 dialog_type_(dialog_type), | 252 dialog_type_(dialog_type), |
| 250 did_submit_(false), | 253 is_submitting_(false), |
| 251 autocheckout_is_running_(false), | 254 autocheckout_is_running_(false), |
| 252 had_autocheckout_error_(false) { | 255 had_autocheckout_error_(false) { |
| 253 // TODO(estade): remove duplicates from |form|? | 256 // TODO(estade): remove duplicates from |form|? |
| 254 } | 257 } |
| 255 | 258 |
| 256 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { | 259 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { |
| 257 if (popup_controller_) | 260 if (popup_controller_) |
| 258 popup_controller_->Hide(); | 261 popup_controller_->Hide(); |
| 259 | 262 |
| 260 metric_logger_.LogDialogInitialUserState(dialog_type_, initial_user_state_); | 263 metric_logger_.LogDialogInitialUserState(dialog_type_, initial_user_state_); |
| (...skipping 159 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 return autocheckout_is_running_; | 486 return autocheckout_is_running_; |
| 483 } | 487 } |
| 484 | 488 |
| 485 bool AutofillDialogControllerImpl::HadAutocheckoutError() const { | 489 bool AutofillDialogControllerImpl::HadAutocheckoutError() const { |
| 486 return had_autocheckout_error_; | 490 return had_autocheckout_error_; |
| 487 } | 491 } |
| 488 | 492 |
| 489 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( | 493 bool AutofillDialogControllerImpl::IsDialogButtonEnabled( |
| 490 ui::DialogButton button) const { | 494 ui::DialogButton button) const { |
| 491 if (button == ui::DIALOG_BUTTON_OK) | 495 if (button == ui::DIALOG_BUTTON_OK) |
| 492 return !did_submit_; | 496 return !is_submitting_ || IsSubmitPausedOn(wallet::VERIFY_CVV); |
| 497 |
| 493 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); | 498 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); |
| 494 // TODO(ahutter): Make it possible for the user to cancel out of the dialog | 499 // TODO(ahutter): Make it possible for the user to cancel out of the dialog |
| 495 // while Autocheckout is in progress. | 500 // while Autocheckout is in progress. |
| 496 return had_autocheckout_error_ || !did_submit_; | 501 return had_autocheckout_error_ || |
| 502 dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE; |
| 497 } | 503 } |
| 498 | 504 |
| 499 bool AutofillDialogControllerImpl::SectionIsActive(DialogSection section) | 505 bool AutofillDialogControllerImpl::SectionIsActive(DialogSection section) |
| 500 const { | 506 const { |
| 507 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) |
| 508 return section == SECTION_CC_BILLING; |
| 509 |
| 501 if (IsPayingWithWallet()) | 510 if (IsPayingWithWallet()) |
| 502 return section != SECTION_BILLING && section != SECTION_CC; | 511 return section != SECTION_BILLING && section != SECTION_CC; |
| 503 | 512 |
| 504 return section != SECTION_CC_BILLING; | 513 return section != SECTION_CC_BILLING; |
| 505 } | 514 } |
| 506 | 515 |
| 507 bool AutofillDialogControllerImpl::HasCompleteWallet() const { | 516 bool AutofillDialogControllerImpl::HasCompleteWallet() const { |
| 508 return wallet_items_.get() != NULL && | 517 return wallet_items_.get() != NULL && |
| 509 !wallet_items_->instruments().empty() && | 518 !wallet_items_->instruments().empty() && |
| 510 !wallet_items_->addresses().empty(); | 519 !wallet_items_->addresses().empty(); |
| 511 } | 520 } |
| 512 | 521 |
| 522 bool AutofillDialogControllerImpl::IsSubmitPausedOn( |
| 523 wallet::RequiredAction required_action) const { |
| 524 return full_wallet_ && full_wallet_->HasRequiredAction(required_action); |
| 525 } |
| 526 |
| 513 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( | 527 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( |
| 514 DialogSection section) const { | 528 DialogSection section) const { |
| 515 switch (section) { | 529 switch (section) { |
| 516 case SECTION_EMAIL: | 530 case SECTION_EMAIL: |
| 517 return requested_email_fields_; | 531 return requested_email_fields_; |
| 518 case SECTION_CC: | 532 case SECTION_CC: |
| 519 return requested_cc_fields_; | 533 return requested_cc_fields_; |
| 520 case SECTION_BILLING: | 534 case SECTION_BILLING: |
| 521 return requested_billing_fields_; | 535 return requested_billing_fields_; |
| 522 case SECTION_CC_BILLING: | 536 case SECTION_CC_BILLING: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 case SECTION_SHIPPING: | 600 case SECTION_SHIPPING: |
| 587 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); | 601 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); |
| 588 default: | 602 default: |
| 589 NOTREACHED(); | 603 NOTREACHED(); |
| 590 return string16(); | 604 return string16(); |
| 591 } | 605 } |
| 592 } | 606 } |
| 593 | 607 |
| 594 string16 AutofillDialogControllerImpl::SuggestionTextForSection( | 608 string16 AutofillDialogControllerImpl::SuggestionTextForSection( |
| 595 DialogSection section) { | 609 DialogSection section) { |
| 610 string16 action_text = RequiredActionSuggestionTextForSection(section); |
| 611 if (!action_text.empty()) |
| 612 return action_text; |
| 613 |
| 596 // When the user has clicked 'edit', don't show a suggestion (even though | 614 // When the user has clicked 'edit', don't show a suggestion (even though |
| 597 // there is a profile selected in the model). | 615 // there is a profile selected in the model). |
| 598 if (section_editing_state_[section]) | 616 if (section_editing_state_[section]) |
| 599 return string16(); | 617 return string16(); |
| 600 | 618 |
| 601 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 619 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 602 std::string item_key = model->GetItemKeyForCheckedItem(); | 620 std::string item_key = model->GetItemKeyForCheckedItem(); |
| 603 if (item_key.empty()) | 621 if (item_key.empty()) |
| 604 return string16(); | 622 return string16(); |
| 605 | 623 |
| 606 if (section == SECTION_EMAIL) | 624 if (section == SECTION_EMAIL) |
| 607 return model->GetLabelAt(model->checked_item()); | 625 return model->GetLabelAt(model->checked_item()); |
| 608 | 626 |
| 609 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 627 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 610 return wrapper->GetDisplayText(); | 628 return wrapper->GetDisplayText(); |
| 611 } | 629 } |
| 612 | 630 |
| 631 string16 AutofillDialogControllerImpl::RequiredActionSuggestionTextForSection( |
| 632 DialogSection section) { |
| 633 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
| 634 const wallet::WalletItems::MaskedInstrument* current_instrument = |
| 635 wallet_items_->GetInstrumentById(active_instrument_id_); |
| 636 if (current_instrument) |
| 637 return current_instrument->TypeAndLastFourDigits(); |
| 638 |
| 639 DetailOutputMap output; |
| 640 view_->GetUserInput(section, &output); |
| 641 CreditCard card; |
| 642 GetBillingInfoFromOutputs(output, &card, NULL, NULL); |
| 643 return card.TypeAndLastFourDigits(); |
| 644 } |
| 645 |
| 646 return string16(); |
| 647 } |
| 648 |
| 613 scoped_ptr<DataModelWrapper> AutofillDialogControllerImpl::CreateWrapper( | 649 scoped_ptr<DataModelWrapper> AutofillDialogControllerImpl::CreateWrapper( |
| 614 DialogSection section) { | 650 DialogSection section) { |
| 615 if (IsPayingWithWallet() && full_wallet_) { | 651 if (IsPayingWithWallet() && full_wallet_ && |
| 652 !IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
| 616 if (section == SECTION_CC_BILLING) { | 653 if (section == SECTION_CC_BILLING) { |
| 617 return scoped_ptr<DataModelWrapper>( | 654 return scoped_ptr<DataModelWrapper>( |
| 618 new FullWalletBillingWrapper(full_wallet_.get())); | 655 new FullWalletBillingWrapper(full_wallet_.get())); |
| 619 } | 656 } |
| 620 if (section == SECTION_SHIPPING) { | 657 if (section == SECTION_SHIPPING) { |
| 621 return scoped_ptr<DataModelWrapper>( | 658 return scoped_ptr<DataModelWrapper>( |
| 622 new FullWalletShippingWrapper(full_wallet_.get())); | 659 new FullWalletShippingWrapper(full_wallet_.get())); |
| 623 } | 660 } |
| 624 } | 661 } |
| 625 | 662 |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 | 988 |
| 952 if (!invoked_from_same_origin_) { | 989 if (!invoked_from_same_origin_) { |
| 953 notifications.push_back( | 990 notifications.push_back( |
| 954 DialogNotification( | 991 DialogNotification( |
| 955 DialogNotification::SECURITY_WARNING, | 992 DialogNotification::SECURITY_WARNING, |
| 956 l10n_util::GetStringFUTF16( | 993 l10n_util::GetStringFUTF16( |
| 957 IDS_AUTOFILL_DIALOG_SITE_WARNING, | 994 IDS_AUTOFILL_DIALOG_SITE_WARNING, |
| 958 UTF8ToUTF16(source_url_.host())))); | 995 UTF8ToUTF16(source_url_.host())))); |
| 959 } | 996 } |
| 960 | 997 |
| 998 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
| 999 notifications.push_back( |
| 1000 DialogNotification( |
| 1001 DialogNotification::REQUIRED_ACTION, |
| 1002 l10n_util::GetStringUTF16( |
| 1003 IDS_AUTOFILL_DIALOG_VERIFY_CVV))); |
| 1004 } |
| 1005 |
| 961 if (had_autocheckout_error_) { | 1006 if (had_autocheckout_error_) { |
| 962 notifications.push_back( | 1007 notifications.push_back( |
| 963 DialogNotification( | 1008 DialogNotification( |
| 964 DialogNotification::AUTOCHECKOUT_ERROR, | 1009 DialogNotification::AUTOCHECKOUT_ERROR, |
| 965 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_ERROR))); | 1010 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_ERROR))); |
| 966 } | 1011 } |
| 967 | 1012 |
| 968 if (account_chooser_model_.had_wallet_error()) { | 1013 if (account_chooser_model_.had_wallet_error()) { |
| 969 // TODO(dbeam): pass along the Wallet error or remove from the translation. | 1014 // TODO(dbeam): pass along the Wallet error or remove from the translation. |
| 970 // TODO(dbeam): figure out a way to dismiss this error after a while. | 1015 // TODO(dbeam): figure out a way to dismiss this error after a while. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 985 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); | 1030 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); |
| 986 } | 1031 } |
| 987 | 1032 |
| 988 void AutofillDialogControllerImpl::EndSignInFlow() { | 1033 void AutofillDialogControllerImpl::EndSignInFlow() { |
| 989 DCHECK(!registrar_.IsEmpty()); | 1034 DCHECK(!registrar_.IsEmpty()); |
| 990 registrar_.RemoveAll(); | 1035 registrar_.RemoveAll(); |
| 991 view_->HideSignIn(); | 1036 view_->HideSignIn(); |
| 992 } | 1037 } |
| 993 | 1038 |
| 994 void AutofillDialogControllerImpl::OnCancel() { | 1039 void AutofillDialogControllerImpl::OnCancel() { |
| 995 if (!did_submit_) { | 1040 if (!is_submitting_) { |
| 996 metric_logger_.LogDialogUiDuration( | 1041 metric_logger_.LogDialogUiDuration( |
| 997 base::Time::Now() - dialog_shown_timestamp_, | 1042 base::Time::Now() - dialog_shown_timestamp_, |
| 998 dialog_type_, | 1043 dialog_type_, |
| 999 AutofillMetrics::DIALOG_CANCELED); | 1044 AutofillMetrics::DIALOG_CANCELED); |
| 1000 } | 1045 } |
| 1001 | 1046 |
| 1002 // If Autocheckout has an error, it's possible that the dialog will be | 1047 // If Autocheckout has an error, it's possible that the dialog will be |
| 1003 // submitted to start the flow and then cancelled to close the dialog after | 1048 // submitted to start the flow and then cancelled to close the dialog after |
| 1004 // the error. | 1049 // the error. |
| 1005 if (!callback_.is_null()) { | 1050 if (!callback_.is_null()) { |
| 1006 callback_.Run(NULL); | 1051 callback_.Run(NULL); |
| 1007 callback_ = base::Callback<void(const FormStructure*)>(); | 1052 callback_ = base::Callback<void(const FormStructure*)>(); |
| 1008 } | 1053 } |
| 1009 } | 1054 } |
| 1010 | 1055 |
| 1011 void AutofillDialogControllerImpl::OnSubmit() { | 1056 void AutofillDialogControllerImpl::OnAccept() { |
| 1012 did_submit_ = true; | |
| 1013 metric_logger_.LogDialogUiDuration( | 1057 metric_logger_.LogDialogUiDuration( |
| 1014 base::Time::Now() - dialog_shown_timestamp_, | 1058 base::Time::Now() - dialog_shown_timestamp_, |
| 1015 dialog_type_, | 1059 dialog_type_, |
| 1016 AutofillMetrics::DIALOG_ACCEPTED); | 1060 AutofillMetrics::DIALOG_ACCEPTED); |
| 1017 | 1061 |
| 1018 if (dialog_type_ == DIALOG_TYPE_AUTOCHECKOUT) { | 1062 // Update the button strip after Autocheckout may have started. |
| 1019 // Stop observing PersonalDataManager to avoid the dialog redrawing while | 1063 is_submitting_ = true; |
| 1020 // in an Autocheckout flow. | 1064 view_->UpdateButtonStrip(); |
| 1021 GetManager()->RemoveObserver(this); | 1065 |
| 1022 autocheckout_is_running_ = true; | 1066 if (IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
| 1023 autocheckout_started_timestamp_ = base::Time::Now(); | 1067 DCHECK(!active_instrument_id_.empty()); |
| 1024 view_->UpdateButtonStrip(); | 1068 GetWalletClient()->AuthenticateInstrument( |
| 1069 active_instrument_id_, |
| 1070 UTF16ToUTF8(view_->GetCvc()), |
| 1071 wallet_items_->obfuscated_gaia_id()); |
| 1072 } else if (IsPayingWithWallet()) { |
| 1073 SubmitWithWallet(); |
| 1074 } else { |
| 1075 FinishSubmit(); |
| 1025 } | 1076 } |
| 1026 | |
| 1027 if (IsPayingWithWallet()) | |
| 1028 SubmitWithWallet(); | |
| 1029 else | |
| 1030 FinishSubmit(); | |
| 1031 } | 1077 } |
| 1032 | 1078 |
| 1033 Profile* AutofillDialogControllerImpl::profile() { | 1079 Profile* AutofillDialogControllerImpl::profile() { |
| 1034 return profile_; | 1080 return profile_; |
| 1035 } | 1081 } |
| 1036 | 1082 |
| 1037 content::WebContents* AutofillDialogControllerImpl::web_contents() { | 1083 content::WebContents* AutofillDialogControllerImpl::web_contents() { |
| 1038 return contents_; | 1084 return contents_; |
| 1039 } | 1085 } |
| 1040 | 1086 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) { | 1184 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) { |
| 1139 // TODO(dbeam): use the returned full wallet. b/8332329 | 1185 // TODO(dbeam): use the returned full wallet. b/8332329 |
| 1140 if (success) | 1186 if (success) |
| 1141 GetFullWallet(); | 1187 GetFullWallet(); |
| 1142 else | 1188 else |
| 1143 DisableWallet(); | 1189 DisableWallet(); |
| 1144 } | 1190 } |
| 1145 | 1191 |
| 1146 void AutofillDialogControllerImpl::OnDidGetFullWallet( | 1192 void AutofillDialogControllerImpl::OnDidGetFullWallet( |
| 1147 scoped_ptr<wallet::FullWallet> full_wallet) { | 1193 scoped_ptr<wallet::FullWallet> full_wallet) { |
| 1148 // TODO(dbeam): handle more required actions. | |
| 1149 full_wallet_ = full_wallet.Pass(); | 1194 full_wallet_ = full_wallet.Pass(); |
| 1150 | 1195 |
| 1151 if (full_wallet_->HasRequiredAction(wallet::VERIFY_CVV)) | 1196 if (full_wallet_->required_actions().empty()) { |
| 1152 DisableWallet(); | |
| 1153 else | |
| 1154 FinishSubmit(); | 1197 FinishSubmit(); |
| 1198 return; |
| 1199 } |
| 1200 |
| 1201 GenerateSuggestionsModels(); |
| 1202 view_->ModelChanged(); |
| 1203 view_->UpdateNotificationArea(); |
| 1204 view_->UpdateButtonStrip(); |
| 1155 } | 1205 } |
| 1156 | 1206 |
| 1157 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 1207 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
| 1158 scoped_ptr<wallet::WalletItems> wallet_items) { | 1208 scoped_ptr<wallet::WalletItems> wallet_items) { |
| 1159 // TODO(dbeam): verify all items support kCartCurrency? | 1209 // TODO(dbeam): verify all items support kCartCurrency? |
| 1160 wallet_items_ = wallet_items.Pass(); | 1210 wallet_items_ = wallet_items.Pass(); |
| 1211 |
| 1161 GenerateSuggestionsModels(); | 1212 GenerateSuggestionsModels(); |
| 1162 view_->ModelChanged(); | 1213 view_->ModelChanged(); |
| 1163 view_->UpdateAccountChooser(); | 1214 view_->UpdateAccountChooser(); |
| 1164 view_->UpdateNotificationArea(); | 1215 view_->UpdateNotificationArea(); |
| 1165 | 1216 |
| 1166 // On the first successful response, compute the initial user state metric. | 1217 // On the first successful response, compute the initial user state metric. |
| 1167 if (initial_user_state_ == AutofillMetrics::DIALOG_USER_STATE_UNKNOWN) | 1218 if (initial_user_state_ == AutofillMetrics::DIALOG_USER_STATE_UNKNOWN) |
| 1168 initial_user_state_ = GetInitialUserState(); | 1219 initial_user_state_ = GetInitialUserState(); |
| 1169 } | 1220 } |
| 1170 | 1221 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 } | 1342 } |
| 1292 | 1343 |
| 1293 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { | 1344 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { |
| 1294 return account_chooser_model_.WalletIsSelected(); | 1345 return account_chooser_model_.WalletIsSelected(); |
| 1295 } | 1346 } |
| 1296 | 1347 |
| 1297 void AutofillDialogControllerImpl::DisableWallet() { | 1348 void AutofillDialogControllerImpl::DisableWallet() { |
| 1298 account_chooser_model_.SetHadWalletError(); | 1349 account_chooser_model_.SetHadWalletError(); |
| 1299 GetWalletClient()->CancelPendingRequests(); | 1350 GetWalletClient()->CancelPendingRequests(); |
| 1300 wallet_items_.reset(); | 1351 wallet_items_.reset(); |
| 1352 full_wallet_.reset(); |
| 1301 | 1353 |
| 1302 GenerateSuggestionsModels(); | 1354 GenerateSuggestionsModels(); |
| 1303 if (view_) { | 1355 if (view_) { |
| 1304 view_->ModelChanged(); | 1356 view_->ModelChanged(); |
| 1305 view_->UpdateNotificationArea(); | 1357 view_->UpdateNotificationArea(); |
| 1306 } | 1358 } |
| 1307 } | 1359 } |
| 1308 | 1360 |
| 1309 bool AutofillDialogControllerImpl::IsFirstRun() const { | 1361 bool AutofillDialogControllerImpl::IsFirstRun() const { |
| 1310 PrefService* prefs = profile_->GetPrefs(); | 1362 PrefService* prefs = profile_->GetPrefs(); |
| 1311 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet); | 1363 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet); |
| 1312 } | 1364 } |
| 1313 | 1365 |
| 1314 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { | 1366 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { |
| 1315 suggested_email_.Reset(); | 1367 suggested_email_.Reset(); |
| 1316 suggested_cc_.Reset(); | 1368 suggested_cc_.Reset(); |
| 1317 suggested_billing_.Reset(); | 1369 suggested_billing_.Reset(); |
| 1318 suggested_cc_billing_.Reset(); | 1370 suggested_cc_billing_.Reset(); |
| 1319 suggested_shipping_.Reset(); | 1371 suggested_shipping_.Reset(); |
| 1320 | 1372 |
| 1321 if (IsPayingWithWallet()) { | 1373 if (IsPayingWithWallet()) { |
| 1322 if (wallet_items_.get()) { | 1374 if (wallet_items_) { |
| 1323 // TODO(estade): seems we need to hardcode the email address. | 1375 // TODO(estade): seems we need to hardcode the email address. |
| 1324 | 1376 |
| 1325 const std::vector<wallet::Address*>& addresses = | 1377 const std::vector<wallet::Address*>& addresses = |
| 1326 wallet_items_->addresses(); | 1378 wallet_items_->addresses(); |
| 1327 for (size_t i = 0; i < addresses.size(); ++i) { | 1379 for (size_t i = 0; i < addresses.size(); ++i) { |
| 1328 // TODO(dbeam): respect wallet_items_->default_instrument_id(). | 1380 // TODO(dbeam): respect wallet_items_->default_instrument_id(). |
| 1329 suggested_shipping_.AddKeyedItemWithSublabel( | 1381 suggested_shipping_.AddKeyedItemWithSublabel( |
| 1330 base::IntToString(i), | 1382 base::IntToString(i), |
| 1331 addresses[i]->DisplayName(), | 1383 addresses[i]->DisplayName(), |
| 1332 addresses[i]->DisplayNameDetail()); | 1384 addresses[i]->DisplayNameDetail()); |
| 1333 } | 1385 } |
| 1334 | 1386 |
| 1335 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = | 1387 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
| 1336 wallet_items_->instruments(); | 1388 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = |
| 1337 for (size_t i = 0; i < instruments.size(); ++i) { | 1389 wallet_items_->instruments(); |
| 1338 // TODO(dbeam): respect wallet_items_->default_address_id(). | 1390 for (size_t i = 0; i < instruments.size(); ++i) { |
| 1339 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( | 1391 // TODO(dbeam): respect wallet_items_->default_address_id(). |
| 1340 base::IntToString(i), | 1392 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( |
| 1341 instruments[i]->DisplayName(), | 1393 base::IntToString(i), |
| 1342 instruments[i]->DisplayNameDetail(), | 1394 instruments[i]->DisplayName(), |
| 1343 instruments[i]->CardIcon()); | 1395 instruments[i]->DisplayNameDetail(), |
| 1396 instruments[i]->CardIcon()); |
| 1397 } |
| 1344 } | 1398 } |
| 1345 } | 1399 } |
| 1346 | 1400 |
| 1347 suggested_cc_billing_.AddKeyedItem( | 1401 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
| 1348 std::string(), | 1402 suggested_cc_billing_.AddKeyedItem( |
| 1349 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); | 1403 std::string(), |
| 1404 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); |
| 1405 } |
| 1350 } else { | 1406 } else { |
| 1351 PersonalDataManager* manager = GetManager(); | 1407 PersonalDataManager* manager = GetManager(); |
| 1352 const std::vector<CreditCard*>& cards = manager->credit_cards(); | 1408 const std::vector<CreditCard*>& cards = manager->credit_cards(); |
| 1353 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1409 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 1354 for (size_t i = 0; i < cards.size(); ++i) { | 1410 for (size_t i = 0; i < cards.size(); ++i) { |
| 1355 suggested_cc_.AddKeyedItemWithIcon( | 1411 suggested_cc_.AddKeyedItemWithIcon( |
| 1356 cards[i]->guid(), | 1412 cards[i]->guid(), |
| 1357 cards[i]->Label(), | 1413 cards[i]->Label(), |
| 1358 rb.GetImageNamed(cards[i]->IconResourceId())); | 1414 rb.GetImageNamed(cards[i]->IconResourceId())); |
| 1359 } | 1415 } |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 wallet_items_->obfuscated_gaia_id(), | 1733 wallet_items_->obfuscated_gaia_id(), |
| 1678 source_url_); | 1734 source_url_); |
| 1679 } else if (new_address.get()) { | 1735 } else if (new_address.get()) { |
| 1680 GetWalletClient()->SaveAddress(*new_address, source_url_); | 1736 GetWalletClient()->SaveAddress(*new_address, source_url_); |
| 1681 } else { | 1737 } else { |
| 1682 GetFullWallet(); | 1738 GetFullWallet(); |
| 1683 } | 1739 } |
| 1684 } | 1740 } |
| 1685 | 1741 |
| 1686 void AutofillDialogControllerImpl::GetFullWallet() { | 1742 void AutofillDialogControllerImpl::GetFullWallet() { |
| 1687 DCHECK(did_submit_); | 1743 DCHECK(is_submitting_); |
| 1688 DCHECK(IsPayingWithWallet()); | 1744 DCHECK(IsPayingWithWallet()); |
| 1689 DCHECK(wallet_items_); | 1745 DCHECK(wallet_items_); |
| 1690 DCHECK(!active_instrument_id_.empty()); | 1746 DCHECK(!active_instrument_id_.empty()); |
| 1691 DCHECK(!active_address_id_.empty()); | 1747 DCHECK(!active_address_id_.empty()); |
| 1692 | 1748 |
| 1693 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( | 1749 GetWalletClient()->GetFullWallet(wallet::WalletClient::FullWalletRequest( |
| 1694 active_instrument_id_, | 1750 active_instrument_id_, |
| 1695 active_address_id_, | 1751 active_address_id_, |
| 1696 source_url_, | 1752 source_url_, |
| 1697 wallet::Cart(base::IntToString(kCartMax), kCartCurrency), | 1753 wallet::Cart(base::IntToString(kCartMax), kCartCurrency), |
| 1698 wallet_items_->google_transaction_id(), | 1754 wallet_items_->google_transaction_id(), |
| 1699 std::vector<wallet::WalletClient::RiskCapability>())); | 1755 std::vector<wallet::WalletClient::RiskCapability>())); |
| 1700 } | 1756 } |
| 1701 | 1757 |
| 1702 void AutofillDialogControllerImpl::FinishSubmit() { | 1758 void AutofillDialogControllerImpl::FinishSubmit() { |
| 1703 FillOutputForSection(SECTION_EMAIL); | 1759 FillOutputForSection(SECTION_EMAIL); |
| 1704 FillOutputForSection(SECTION_CC); | 1760 FillOutputForSection(SECTION_CC); |
| 1705 FillOutputForSection(SECTION_BILLING); | 1761 FillOutputForSection(SECTION_BILLING); |
| 1706 FillOutputForSection(SECTION_CC_BILLING); | 1762 FillOutputForSection(SECTION_CC_BILLING); |
| 1763 |
| 1707 if (ShouldUseBillingForShipping()) { | 1764 if (ShouldUseBillingForShipping()) { |
| 1708 FillOutputForSectionWithComparator( | 1765 FillOutputForSectionWithComparator( |
| 1709 SECTION_BILLING, | 1766 SECTION_BILLING, |
| 1710 base::Bind(DetailInputMatchesShippingField)); | 1767 base::Bind(DetailInputMatchesShippingField)); |
| 1711 FillOutputForSectionWithComparator( | 1768 FillOutputForSectionWithComparator( |
| 1712 SECTION_CC, | 1769 SECTION_CC, |
| 1713 base::Bind(DetailInputMatchesShippingField)); | 1770 base::Bind(DetailInputMatchesShippingField)); |
| 1714 } else { | 1771 } else { |
| 1715 FillOutputForSection(SECTION_SHIPPING); | 1772 FillOutputForSection(SECTION_SHIPPING); |
| 1716 } | 1773 } |
| 1774 |
| 1717 callback_.Run(&form_structure_); | 1775 callback_.Run(&form_structure_); |
| 1718 callback_ = base::Callback<void(const FormStructure*)>(); | 1776 callback_ = base::Callback<void(const FormStructure*)>(); |
| 1719 | 1777 |
| 1720 if (dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) { | 1778 switch (dialog_type_) { |
| 1721 // This may delete us. | 1779 case DIALOG_TYPE_AUTOCHECKOUT: |
| 1722 Hide(); | 1780 // Stop observing PersonalDataManager to avoid the dialog redrawing while |
| 1781 // in an Autocheckout flow. |
| 1782 GetManager()->RemoveObserver(this); |
| 1783 autocheckout_is_running_ = true; |
| 1784 autocheckout_started_timestamp_ = base::Time::Now(); |
| 1785 view_->UpdateButtonStrip(); |
| 1786 break; |
| 1787 |
| 1788 case DIALOG_TYPE_REQUEST_AUTOCOMPLETE: |
| 1789 // This may delete us. |
| 1790 Hide(); |
| 1791 break; |
| 1723 } | 1792 } |
| 1724 } | 1793 } |
| 1725 | 1794 |
| 1726 AutofillMetrics::DialogInitialUserStateMetric | 1795 AutofillMetrics::DialogInitialUserStateMetric |
| 1727 AutofillDialogControllerImpl::GetInitialUserState() const { | 1796 AutofillDialogControllerImpl::GetInitialUserState() const { |
| 1728 // Consider a user to be an Autofill user if the user has any credit cards | 1797 // Consider a user to be an Autofill user if the user has any credit cards |
| 1729 // or addresses saved. Check that the item count is greater than 1 because | 1798 // or addresses saved. Check that the item count is greater than 1 because |
| 1730 // an "empty" menu still has the "add new" menu item. | 1799 // an "empty" menu still has the "add new" menu item. |
| 1731 const bool has_autofill_profiles = | 1800 const bool has_autofill_profiles = |
| 1732 suggested_cc_.GetItemCount() > 1 || | 1801 suggested_cc_.GetItemCount() > 1 || |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1747 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; | 1816 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; |
| 1748 } | 1817 } |
| 1749 | 1818 |
| 1750 // Has Wallet items. | 1819 // Has Wallet items. |
| 1751 return has_autofill_profiles ? | 1820 return has_autofill_profiles ? |
| 1752 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : | 1821 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : |
| 1753 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; | 1822 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; |
| 1754 } | 1823 } |
| 1755 | 1824 |
| 1756 } // namespace autofill | 1825 } // namespace autofill |
| OLD | NEW |