Chromium Code Reviews| Index: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| index a2ad411eb6103c197bbb6e6959d6b707bbe00c39..bfa545024510c9c9023bac86549dcd0f94f76b09 100644 |
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| @@ -106,6 +106,20 @@ bool DetailInputMatchesField(const DetailInput& input, |
| return InputTypeMatchesFieldType(input, field) && right_section; |
| } |
| +bool CreditCardType(AutofillFieldType type) { |
|
Ilya Sherman
2013/03/14 21:59:08
nit: IsCreditCardType
Dan Beam
2013/03/14 23:49:35
Done.
|
| + return AutofillType(type).group() == AutofillType::CREDIT_CARD; |
| +} |
| + |
| +bool DetailInputMatchesCreditCard(const DetailInput& input, |
| + const AutofillField& field) { |
| + return DetailInputMatchesField(input, field) && CreditCardType(input.type); |
| +} |
| + |
| +bool DetailInputMatchesBilling(const DetailInput& input, |
| + const AutofillField& field) { |
| + return DetailInputMatchesField(input, field) && !CreditCardType(input.type); |
| +} |
| + |
| // Returns true if |input| should be used to fill a site-requested |field| which |
| // is notated with a "shipping" tag, for use when the user has decided to use |
| // the billing address as the shipping address. |
| @@ -159,6 +173,10 @@ void GetBillingInfoFromOutputs(const DetailOutputMap& output, |
| CreditCard* card, |
| string16* cvc, |
| AutofillProfile* profile) { |
| + DCHECK(card); |
| + DCHECK(cvc); |
| + DCHECK(profile); |
|
Ilya Sherman
2013/03/14 21:59:08
These don't seem very helpful, since you dereferen
Dan Beam
2013/03/14 23:49:35
Done.
|
| + |
| for (DetailOutputMap::const_iterator it = output.begin(); |
| it != output.end(); ++it) { |
| string16 trimmed; |
| @@ -166,14 +184,14 @@ void GetBillingInfoFromOutputs(const DetailOutputMap& output, |
| // Special case CVC as CreditCard just swallows it. |
| if (it->first->type == CREDIT_CARD_VERIFICATION_CODE) { |
| - *cvc = trimmed; |
| + cvc->assign(trimmed); |
|
Ilya Sherman
2013/03/14 21:59:08
Just curious, why did you change this?
Dan Beam
2013/03/14 23:49:35
seemed like this is the intended API, akin to sayi
|
| } else { |
| // Copy the credit card name to |profile| in addition to |card| as |
| // wallet::Instrument requires a recipient name for its billing address. |
| if (it->first->type == CREDIT_CARD_NAME) |
| profile->SetRawInfo(NAME_FULL, trimmed); |
| - if (AutofillType(it->first->type).group() == AutofillType::CREDIT_CARD) |
| + if (CreditCardType(it->first->type)) |
| card->SetRawInfo(it->first->type, trimmed); |
| else |
| profile->SetRawInfo(it->first->type, trimmed); |
| @@ -595,16 +613,23 @@ scoped_ptr<DataModelWrapper> AutofillDialogControllerImpl::CreateWrapper( |
| return wrapper.Pass(); |
| if (IsPayingWithWallet()) { |
| - int index; |
| - bool success = base::StringToInt(item_key, &index); |
| - DCHECK(success); |
| - |
| - if (section == SECTION_CC_BILLING) { |
| - wrapper.reset( |
| - new WalletInstrumentWrapper(wallet_items_->instruments()[index])); |
| + if (did_submit_ && full_wallet_.get()) { |
| + if (section == SECTION_CC_BILLING) |
| + wrapper.reset(new FullWalletBillingWrapper(full_wallet_.get())); |
| + else |
| + wrapper.reset(new FullWalletShippingWrapper(full_wallet_.get())); |
| } else { |
| - wrapper.reset( |
| - new WalletAddressWrapper(wallet_items_->addresses()[index])); |
| + int index; |
| + bool success = base::StringToInt(item_key, &index); |
| + DCHECK(success); |
| + |
| + if (section == SECTION_CC_BILLING) { |
| + wrapper.reset( |
| + new WalletInstrumentWrapper(wallet_items_->instruments()[index])); |
| + } else { |
| + wrapper.reset( |
| + new WalletAddressWrapper(wallet_items_->addresses()[index])); |
| + } |
| } |
|
Ilya Sherman
2013/03/14 21:59:08
nit: Some docs for the code flow logic here would
Dan Beam
2013/03/14 23:49:35
Done.
|
| } else if (section == SECTION_CC) { |
| CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); |
| @@ -1183,10 +1208,8 @@ bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { |
| DCHECK_GT(form_structure_.field_count(), 0U); |
| for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
| - if (AutofillType(form_structure_.field(i)->type()).group() == |
| - AutofillType::CREDIT_CARD) { |
| + if (CreditCardType(form_structure_.field(i)->type())) |
| return true; |
| - } |
| } |
| return false; |
| @@ -1330,51 +1353,56 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
| return; |
| if (!IsManuallyEditingSection(section)) { |
| - if (section == SECTION_CC_BILLING) { |
| - // TODO(dbeam): implement. |
| - } else { |
| - scoped_ptr<DataModelWrapper> model = CreateWrapper(section); |
| - // Only fill in data that is associated with this section. |
| - const DetailInputs& inputs = RequestedFieldsForSection(section); |
| - model->FillFormStructure(inputs, compare, &form_structure_); |
| - |
| - // CVC needs special-casing because the CreditCard class doesn't store |
| - // or handle them. |
| - if (section == SECTION_CC) |
| - SetCvcResult(view_->GetCvc()); |
| - } |
| + scoped_ptr<DataModelWrapper> model = CreateWrapper(section); |
| + // Only fill in data that is associated with this section. |
| + const DetailInputs& inputs = RequestedFieldsForSection(section); |
| + model->FillFormStructure(inputs, compare, &form_structure_); |
| + |
| + // CVC needs special-casing because the CreditCard class doesn't store |
| + // or handle them. |
| + if (section == SECTION_CC) |
|
Ilya Sherman
2013/03/14 21:59:08
Should this apply to SECTION_CC_BILLING as well?
Dan Beam
2013/03/14 23:49:35
No, we need to get the CVC from |full_wallet_|; ad
|
| + SetCvcResult(view_->GetCvc()); |
| } else { |
| - // The user manually input data. |
| + // The user manually input data. If using Autofill, save the info as new or |
| + // edited data. Always fill local data into |form_structure_|. |
| DetailOutputMap output; |
| view_->GetUserInput(section, &output); |
| - if (IsPayingWithWallet()) { |
| - // TODO(dbeam): implement. |
| + if (section == SECTION_CC_BILLING) { |
| + CreditCard card; |
| + string16 cvc; |
| + AutofillProfile profile; |
| + GetBillingInfoFromOutputs(output, &card, &cvc, &profile); |
| + |
| + // |card| and |profile| can't be asked for the wrong types without |
| + // DCHECK()'ing, so we split the filling into CC and non-CC. |
| + FillFormStructureForSection(card, 0, section, |
| + base::Bind(DetailInputMatchesCreditCard)); |
| + FillFormStructureForSection(profile, 0, section, |
| + base::Bind(DetailInputMatchesBilling)); |
| + SetCvcResult(cvc); |
| + } else if (section == SECTION_CC) { |
| + CreditCard card; |
| + FillFormGroupFromOutputs(output, &card); |
| + |
| + if (ShouldSaveDetailsLocally()) |
| + GetManager()->SaveImportedCreditCard(card); |
| + |
| + FillFormStructureForSection(card, 0, section, compare); |
| + |
| + // Again, CVC needs special-casing. Fill it in directly from |output|. |
| + SetCvcResult(GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); |
| } else { |
|
Ilya Sherman
2013/03/14 21:59:08
Can you DCHECK that the section is the one you exp
Dan Beam
2013/03/14 23:49:35
This hunk of the diff was reverted and now it'd be
|
| - // Save the info as new or edited data and fill it into |form_structure_|. |
| - if (section == SECTION_CC) { |
| - CreditCard card; |
| - FillFormGroupFromOutputs(output, &card); |
| - |
| - if (view_->SaveDetailsLocally()) |
| - GetManager()->SaveImportedCreditCard(card); |
| - |
| - FillFormStructureForSection(card, 0, section, compare); |
| - |
| - // Again, CVC needs special-casing. Fill it in directly from |output|. |
| - SetCvcResult(GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); |
| - } else { |
| - AutofillProfile profile; |
| - FillFormGroupFromOutputs(output, &profile); |
| + AutofillProfile profile; |
| + FillFormGroupFromOutputs(output, &profile); |
| - // TODO(estade): we should probably edit the existing profile in the |
| - // cases where the input data is based on an existing profile (user |
| - // clicked "Edit" or autofill popup filled in the form). |
| - if (view_->SaveDetailsLocally()) |
| - GetManager()->SaveImportedProfile(profile); |
| + // TODO(estade): we should probably edit the existing profile in the |
| + // cases where the input data is based on an existing profile (user |
| + // clicked "Edit" or autofill popup filled in the form). |
| + if (ShouldSaveDetailsLocally()) |
| + GetManager()->SaveImportedProfile(profile); |
| - FillFormStructureForSection(profile, 0, section, compare); |
| - } |
| + FillFormStructureForSection(profile, 0, section, compare); |
| } |
| } |
| } |
| @@ -1498,7 +1526,7 @@ bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
| GetItemKeyForCheckedItem().empty(); |
| } |
| -bool AutofillDialogControllerImpl::UseBillingForShipping() { |
| +bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { |
| // If the user is editing or inputting data, ask the view. |
| if (IsManuallyEditingSection(SECTION_SHIPPING)) |
| return view_->UseBillingForShipping(); |
| @@ -1508,6 +1536,10 @@ bool AutofillDialogControllerImpl::UseBillingForShipping() { |
| return false; |
| } |
| +bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { |
| + return !IsPayingWithWallet() && view_->SaveDetailsLocally(); |
|
Ilya Sherman
2013/03/14 21:59:08
nit: Please include a comment explaining why we ne
Dan Beam
2013/03/14 23:49:35
Done.
|
| +} |
| + |
| void AutofillDialogControllerImpl::SubmitWithWallet() { |
| // TODO(dbeam): disallow interacting with the dialog while submitting. |
| @@ -1525,7 +1557,7 @@ void AutofillDialogControllerImpl::SubmitWithWallet() { |
| active_instrument_id_ = active_instrument->object_id(); |
| // TODO(dbeam): does re-using instrument address IDs work? |
| - if (UseBillingForShipping()) |
| + if (ShouldUseBillingForShipping()) |
| active_address_id_ = active_instrument->address().object_id(); |
| } |
| } |
| @@ -1566,7 +1598,7 @@ void AutofillDialogControllerImpl::SubmitWithWallet() { |
| scoped_ptr<wallet::Address> new_address; |
| if (active_address_id_.empty()) { |
| - if (UseBillingForShipping() && new_instrument.get()) { |
| + if (ShouldUseBillingForShipping() && new_instrument.get()) { |
| new_address.reset(new wallet::Address(new_instrument->address())); |
| } else { |
| DetailOutputMap output; |
| @@ -1617,7 +1649,7 @@ void AutofillDialogControllerImpl::FinishSubmit() { |
| FillOutputForSection(SECTION_CC); |
| FillOutputForSection(SECTION_BILLING); |
| FillOutputForSection(SECTION_CC_BILLING); |
| - if (UseBillingForShipping()) { |
| + if (ShouldUseBillingForShipping()) { |
| FillOutputForSectionWithComparator( |
| SECTION_BILLING, |
| base::Bind(DetailInputMatchesShippingField)); |