Commit 0a57c37b authored by estade@chromium.org's avatar estade@chromium.org

Remove DataModelWrapper from android build.

BUG=none

Review URL: https://codereview.chromium.org/137723008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247593 0039d316-1c4b-4281-b951-d872f2087c98
parent 391cba93
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "chrome/browser/ui/android/autofill/autofill_dialog_result.h" #include "chrome/browser/ui/android/autofill/autofill_dialog_result.h"
#include "chrome/browser/ui/android/window_android_helper.h" #include "chrome/browser/ui/android/window_android_helper.h"
#include "chrome/browser/ui/autofill/autofill_dialog_common.h" #include "chrome/browser/ui/autofill/autofill_dialog_common.h"
#include "chrome/browser/ui/autofill/data_model_wrapper.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "components/autofill/content/browser/wallet/full_wallet.h" #include "components/autofill/content/browser/wallet/full_wallet.h"
...@@ -49,6 +48,8 @@ namespace autofill { ...@@ -49,6 +48,8 @@ namespace autofill {
namespace { namespace {
using wallet::FullWallet;
// Keys in kAutofillDialogDefaults pref dictionary (do not change these values). // Keys in kAutofillDialogDefaults pref dictionary (do not change these values).
const char kLastUsedAccountName[] = "last_used_account_name"; const char kLastUsedAccountName[] = "last_used_account_name";
const char kLastUsedChoiceIsAutofill[] = "last_used_choice_is_autofill"; const char kLastUsedChoiceIsAutofill[] = "last_used_choice_is_autofill";
...@@ -56,42 +57,38 @@ const char kLastUsedBillingAddressGuid[] = "last_used_billing"; ...@@ -56,42 +57,38 @@ const char kLastUsedBillingAddressGuid[] = "last_used_billing";
const char kLastUsedShippingAddressGuid[] = "last_used_shipping"; const char kLastUsedShippingAddressGuid[] = "last_used_shipping";
const char kLastUsedCreditCardGuid[] = "last_used_card"; const char kLastUsedCreditCardGuid[] = "last_used_card";
scoped_ptr<DataModelWrapper> CreateWrapper( base::string16 NullGetInfo(const AutofillType& type) {
DialogSection section, wallet::FullWallet* full_wallet) { return base::string16();
if (section == SECTION_CC_BILLING) {
if (!full_wallet->billing_address())
return scoped_ptr<DataModelWrapper>();
return scoped_ptr<DataModelWrapper>(
new FullWalletBillingWrapper(full_wallet));
}
if (section == SECTION_SHIPPING) {
if (!full_wallet->shipping_address())
return scoped_ptr<DataModelWrapper>();
return scoped_ptr<DataModelWrapper>(
new FullWalletShippingWrapper(full_wallet));
}
NOTREACHED();
return scoped_ptr<DataModelWrapper>();
} }
void FillOutputForSectionWithComparator( void FillOutputForSectionWithComparator(
DialogSection section, DialogSection section,
const DetailInputs& inputs, const DetailInputs& inputs,
const InputFieldComparator& compare, const FormStructure::InputFieldComparator& compare,
FormStructure& form_structure, FormStructure& form_structure,
wallet::FullWallet* full_wallet, FullWallet* full_wallet,
const base::string16& email_address) { const base::string16& email_address) {
scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section, full_wallet); if ((section == SECTION_CC_BILLING && !full_wallet->billing_address()) ||
if (wrapper) (section == SECTION_SHIPPING && !full_wallet->shipping_address())) {
wrapper->FillFormStructure(inputs, compare, &form_structure); return;
}
base::Callback<base::string16(const AutofillType&)> get_info =
base::Bind(&FullWallet::GetInfo,
base::Unretained(full_wallet),
g_browser_process->GetApplicationLocale());
std::vector<ServerFieldType> types = common::TypesFromInputs(inputs);
form_structure.FillFields(types,
compare,
get_info,
g_browser_process->GetApplicationLocale());
} }
void FillOutputForSection( void FillOutputForSection(
DialogSection section, DialogSection section,
FormStructure& form_structure, FormStructure& form_structure,
wallet::FullWallet* full_wallet, FullWallet* full_wallet,
const base::string16& email_address) { const base::string16& email_address) {
DetailInputs inputs; DetailInputs inputs;
common::BuildInputsForSection(section, "US", &inputs); common::BuildInputsForSection(section, "US", &inputs);
...@@ -252,11 +249,11 @@ void AutofillDialogControllerAndroid::Show() { ...@@ -252,11 +249,11 @@ void AutofillDialogControllerAndroid::Show() {
{ {
DetailInputs inputs; DetailInputs inputs;
common::BuildInputsForSection(SECTION_SHIPPING, "US", &inputs); common::BuildInputsForSection(SECTION_SHIPPING, "US", &inputs);
EmptyDataModelWrapper empty_wrapper; request_shipping_address = form_structure_.FillFields(
request_shipping_address = empty_wrapper.FillFormStructure( common::TypesFromInputs(inputs),
inputs,
base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING),
&form_structure_); base::Bind(NullGetInfo),
g_browser_process->GetApplicationLocale());
} }
const bool incognito_mode = profile_->IsOffTheRecord(); const bool incognito_mode = profile_->IsOffTheRecord();
...@@ -353,7 +350,7 @@ void AutofillDialogControllerAndroid::DialogContinue( ...@@ -353,7 +350,7 @@ void AutofillDialogControllerAndroid::DialogContinue(
const std::string last_used_card = const std::string last_used_card =
base::android::ConvertJavaStringToUTF8(env, jlast_used_card); base::android::ConvertJavaStringToUTF8(env, jlast_used_card);
scoped_ptr<wallet::FullWallet> full_wallet = scoped_ptr<FullWallet> full_wallet =
AutofillDialogResult::ConvertFromJava(env, wallet); AutofillDialogResult::ConvertFromJava(env, wallet);
FillOutputForSection( FillOutputForSection(
SECTION_CC_BILLING, form_structure_, full_wallet.get(), email); SECTION_CC_BILLING, form_structure_, full_wallet.get(), email);
......
...@@ -276,5 +276,13 @@ base::string16 GetHardcodedValueForType(ServerFieldType type) { ...@@ -276,5 +276,13 @@ base::string16 GetHardcodedValueForType(ServerFieldType type) {
return base::string16(); return base::string16();
} }
std::vector<ServerFieldType> TypesFromInputs(const DetailInputs& inputs) {
std::vector<ServerFieldType> types;
for (size_t i = 0; i < inputs.size(); ++i) {
types.push_back(inputs[i].type);
}
return types;
}
} // namespace common } // namespace common
} // namespace autofill } // namespace autofill
...@@ -60,6 +60,9 @@ AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent( ...@@ -60,6 +60,9 @@ AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent(
// the country: http://crbug.com/247518 // the country: http://crbug.com/247518
base::string16 GetHardcodedValueForType(ServerFieldType type); base::string16 GetHardcodedValueForType(ServerFieldType type);
// Gets just the |type| attributes from each DetailInput.
std::vector<ServerFieldType> TypesFromInputs(const DetailInputs& inputs);
} // namespace common } // namespace common
} // namespace autofill } // namespace autofill
......
...@@ -141,6 +141,10 @@ class ScopedViewUpdates { ...@@ -141,6 +141,10 @@ class ScopedViewUpdates {
DISALLOW_COPY_AND_ASSIGN(ScopedViewUpdates); DISALLOW_COPY_AND_ASSIGN(ScopedViewUpdates);
}; };
base::string16 NullGetInfo(const AutofillType& type) {
return base::string16();
}
// Returns true if |input| should be used to fill a site-requested |field| which // 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 // is notated with a "shipping" tag, for use when the user has decided to use
// the billing address as the shipping address. // the billing address as the shipping address.
...@@ -599,11 +603,11 @@ void AutofillDialogControllerImpl::Show() { ...@@ -599,11 +603,11 @@ void AutofillDialogControllerImpl::Show() {
// Test whether we need to show the shipping section. If filling that section // Test whether we need to show the shipping section. If filling that section
// would be a no-op, don't show it. // would be a no-op, don't show it.
const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); cares_about_shipping_ = form_structure_.FillFields(
cares_about_shipping_ = EmptyDataModelWrapper().FillFormStructure( RequestedTypesForSection(SECTION_SHIPPING),
inputs,
base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING),
&form_structure_); base::Bind(NullGetInfo),
g_browser_process->GetApplicationLocale());
account_chooser_model_.reset( account_chooser_model_.reset(
new AccountChooserModel(this, new AccountChooserModel(this,
...@@ -787,8 +791,7 @@ DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() { ...@@ -787,8 +791,7 @@ DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() {
card_scrambling_delay_.Stop(); card_scrambling_delay_.Stop();
card_scrambling_refresher_.Stop(); card_scrambling_refresher_.Stop();
base::string16 cc_number = base::string16 cc_number = base::ASCIIToUTF16(full_wallet_->GetPan());
full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER));
DCHECK_GE(cc_number.size(), 4U); DCHECK_GE(cc_number.size(), 4U);
state.image = GetGeneratedCardImage( state.image = GetGeneratedCardImage(
base::ASCIIToUTF16("XXXX XXXX XXXX ") + base::ASCIIToUTF16("XXXX XXXX XXXX ") +
...@@ -1888,12 +1891,8 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput( ...@@ -1888,12 +1891,8 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
&popup_icons, &popup_icons,
&popup_guids_); &popup_guids_);
} else { } else {
std::vector<ServerFieldType> field_types; std::vector<ServerFieldType> field_types =
const DetailInputs& inputs = RequestedFieldsForSection(section); RequestedTypesForSection(section);
for (DetailInputs::const_iterator iter = inputs.begin();
iter != inputs.end(); ++iter) {
field_types.push_back(iter->type);
}
GetManager()->GetProfileSuggestions(AutofillType(type), GetManager()->GetProfileSuggestions(AutofillType(type),
field_contents, field_contents,
false, false,
...@@ -2906,18 +2905,19 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() { ...@@ -2906,18 +2905,19 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() {
void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
DialogSection section, DialogSection section,
const InputFieldComparator& compare) { const FormStructure::InputFieldComparator& compare) {
if (!SectionIsActive(section)) if (!SectionIsActive(section))
return; return;
DetailInputs inputs; DetailInputs inputs;
std::string country_code = CountryCodeForSection(section); std::string country_code = CountryCodeForSection(section);
common::BuildInputsForSection(section, country_code, &inputs); common::BuildInputsForSection(section, country_code, &inputs);
std::vector<ServerFieldType> types = common::TypesFromInputs(inputs);
scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
if (wrapper) { if (wrapper) {
// Only fill in data that is associated with this section. // Only fill in data that is associated with this section.
wrapper->FillFormStructure(inputs, compare, &form_structure_); wrapper->FillFormStructure(types, compare, &form_structure_);
// CVC needs special-casing because the CreditCard class doesn't store or // CVC needs special-casing because the CreditCard class doesn't store or
// handle them. This isn't necessary when filling the combined CC and // handle them. This isn't necessary when filling the combined CC and
...@@ -2955,7 +2955,7 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( ...@@ -2955,7 +2955,7 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
} }
AutofillCreditCardWrapper card_wrapper(&card); AutofillCreditCardWrapper card_wrapper(&card);
card_wrapper.FillFormStructure(inputs, compare, &form_structure_); card_wrapper.FillFormStructure(types, compare, &form_structure_);
// Again, CVC needs special-casing. Fill it in directly from |output|. // Again, CVC needs special-casing. Fill it in directly from |output|.
SetOutputForFieldsOfType( SetOutputForFieldsOfType(
...@@ -2972,7 +2972,7 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( ...@@ -2972,7 +2972,7 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
} }
AutofillProfileWrapper profile_wrapper(&profile); AutofillProfileWrapper profile_wrapper(&profile);
profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); profile_wrapper.FillFormStructure(types, compare, &form_structure_);
} }
} }
} }
...@@ -3070,6 +3070,11 @@ DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( ...@@ -3070,6 +3070,11 @@ DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection(
return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); return const_cast<DetailInputs*>(&RequestedFieldsForSection(section));
} }
std::vector<ServerFieldType> AutofillDialogControllerImpl::
RequestedTypesForSection(DialogSection section) const {
return common::TypesFromInputs(RequestedFieldsForSection(section));
}
std::string AutofillDialogControllerImpl::CountryCodeForSection( std::string AutofillDialogControllerImpl::CountryCodeForSection(
DialogSection section) { DialogSection section) {
scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
......
...@@ -401,8 +401,9 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate, ...@@ -401,8 +401,9 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
void FillOutputForSection(DialogSection section); void FillOutputForSection(DialogSection section);
// As above, but uses |compare| to determine whether a DetailInput matches // As above, but uses |compare| to determine whether a DetailInput matches
// a field. Saves any new Autofill data to the PersonalDataManager. // a field. Saves any new Autofill data to the PersonalDataManager.
void FillOutputForSectionWithComparator(DialogSection section, void FillOutputForSectionWithComparator(
const InputFieldComparator& compare); DialogSection section,
const FormStructure::InputFieldComparator& compare);
// Returns whether |form_structure|_| has any fields that match the fieldset // Returns whether |form_structure|_| has any fields that match the fieldset
// represented by |section|. // represented by |section|.
...@@ -461,6 +462,10 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate, ...@@ -461,6 +462,10 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
// Like RequestedFieldsForSection, but returns a pointer. // Like RequestedFieldsForSection, but returns a pointer.
DetailInputs* MutableRequestedFieldsForSection(DialogSection section); DetailInputs* MutableRequestedFieldsForSection(DialogSection section);
// Returns just the |type| attributes of RequestedFieldsForSection(section).
std::vector<ServerFieldType> RequestedTypesForSection(DialogSection section)
const;
// Returns the country code (e.g. "US") for |section|. // Returns the country code (e.g. "US") for |section|.
std::string CountryCodeForSection(DialogSection section); std::string CountryCodeForSection(DialogSection section);
......
...@@ -52,11 +52,6 @@ struct DetailInput { ...@@ -52,11 +52,6 @@ struct DetailInput {
base::string16 initial_value; base::string16 initial_value;
}; };
// Determines whether |type| and |field| match.
typedef base::Callback<bool(ServerFieldType type,
const AutofillField& field)>
InputFieldComparator;
// Sections of the dialog --- all fields that may be shown to the user fit under // Sections of the dialog --- all fields that may be shown to the user fit under
// one of these sections. // one of these sections.
enum DialogSection { enum DialogSection {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/ui/autofill/data_model_wrapper.h" #include "chrome/browser/ui/autofill/data_model_wrapper.h"
#include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -19,13 +20,10 @@ ...@@ -19,13 +20,10 @@
#include "components/autofill/core/browser/autofill_type.h" #include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/credit_card.h" #include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/form_structure.h" #include "components/autofill/core/browser/form_structure.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
#if !defined(OS_ANDROID)
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_data.h" #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_ui.h" #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_ui.h"
#endif #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
namespace autofill { namespace autofill {
...@@ -52,7 +50,6 @@ gfx::Image DataModelWrapper::GetIcon() { ...@@ -52,7 +50,6 @@ gfx::Image DataModelWrapper::GetIcon() {
return gfx::Image(); return gfx::Image();
} }
#if !defined(OS_ANDROID)
bool DataModelWrapper::GetDisplayText( bool DataModelWrapper::GetDisplayText(
base::string16* vertically_compact, base::string16* vertically_compact,
base::string16* horizontally_compact) { base::string16* horizontally_compact) {
...@@ -103,39 +100,20 @@ bool DataModelWrapper::GetDisplayText( ...@@ -103,39 +100,20 @@ bool DataModelWrapper::GetDisplayText(
return true; return true;
} }
#endif
bool DataModelWrapper::FillFormStructure( bool DataModelWrapper::FillFormStructure(
const DetailInputs& inputs, const std::vector<ServerFieldType>& types,
const InputFieldComparator& compare, const FormStructure::InputFieldComparator& compare,
FormStructure* form_structure) const { FormStructure* form_structure) const {
bool filled_something = false; return form_structure->FillFields(
for (size_t i = 0; i < form_structure->field_count(); ++i) { types,
AutofillField* field = form_structure->field(i); compare,
for (size_t j = 0; j < inputs.size(); ++j) { base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)),
if (compare.Run(inputs[j].type, *field)) { g_browser_process->GetApplicationLocale());
AutofillField::FillFormField(*field, GetInfo(field->Type()),
g_browser_process->GetApplicationLocale(),
field);
filled_something = true;
break;
}
}
}
return filled_something;
} }
DataModelWrapper::DataModelWrapper() {} DataModelWrapper::DataModelWrapper() {}
// EmptyDataModelWrapper
EmptyDataModelWrapper::EmptyDataModelWrapper() {}
EmptyDataModelWrapper::~EmptyDataModelWrapper() {}
base::string16 EmptyDataModelWrapper::GetInfo(const AutofillType& type) const {
return base::string16();
}
// AutofillProfileWrapper // AutofillProfileWrapper
AutofillProfileWrapper::AutofillProfileWrapper(const AutofillProfile* profile) AutofillProfileWrapper::AutofillProfileWrapper(const AutofillProfile* profile)
...@@ -237,7 +215,6 @@ gfx::Image AutofillCreditCardWrapper::GetIcon() { ...@@ -237,7 +215,6 @@ gfx::Image AutofillCreditCardWrapper::GetIcon() {
return rb.GetImageNamed(CreditCard::IconResourceId(card_->type())); return rb.GetImageNamed(CreditCard::IconResourceId(card_->type()));
} }
#if !defined(OS_ANDROID)
bool AutofillCreditCardWrapper::GetDisplayText( bool AutofillCreditCardWrapper::GetDisplayText(
base::string16* vertically_compact, base::string16* vertically_compact,
base::string16* horizontally_compact) { base::string16* horizontally_compact) {
...@@ -247,7 +224,6 @@ bool AutofillCreditCardWrapper::GetDisplayText( ...@@ -247,7 +224,6 @@ bool AutofillCreditCardWrapper::GetDisplayText(
*vertically_compact = *horizontally_compact = card_->TypeAndLastFourDigits(); *vertically_compact = *horizontally_compact = card_->TypeAndLastFourDigits();
return true; return true;
} }
#endif
// WalletAddressWrapper // WalletAddressWrapper
...@@ -272,7 +248,6 @@ base::string16 WalletAddressWrapper::GetInfoForDisplay(const AutofillType& type) ...@@ -272,7 +248,6 @@ base::string16 WalletAddressWrapper::GetInfoForDisplay(const AutofillType& type)
return DataModelWrapper::GetInfoForDisplay(type); return DataModelWrapper::GetInfoForDisplay(type);
} }
#if !defined(OS_ANDROID)
bool WalletAddressWrapper::GetDisplayText( bool WalletAddressWrapper::GetDisplayText(
base::string16* vertically_compact, base::string16* vertically_compact,
base::string16* horizontally_compact) { base::string16* horizontally_compact) {
...@@ -284,7 +259,6 @@ bool WalletAddressWrapper::GetDisplayText( ...@@ -284,7 +259,6 @@ bool WalletAddressWrapper::GetDisplayText(
return DataModelWrapper::GetDisplayText(vertically_compact, return DataModelWrapper::GetDisplayText(vertically_compact,
horizontally_compact); horizontally_compact);
} }
#endif
// WalletInstrumentWrapper // WalletInstrumentWrapper
...@@ -318,7 +292,6 @@ gfx::Image WalletInstrumentWrapper::GetIcon() { ...@@ -318,7 +292,6 @@ gfx::Image WalletInstrumentWrapper::GetIcon() {
return instrument_->CardIcon(); return instrument_->CardIcon();
} }
#if !defined(OS_ANDROID)
bool WalletInstrumentWrapper::GetDisplayText( bool WalletInstrumentWrapper::GetDisplayText(
base::string16* vertically_compact, base::string16* vertically_compact,
base::string16* horizontally_compact) { base::string16* horizontally_compact) {
...@@ -337,7 +310,6 @@ bool WalletInstrumentWrapper::GetDisplayText( ...@@ -337,7 +310,6 @@ bool WalletInstrumentWrapper::GetDisplayText(
*horizontally_compact = line1 + *horizontally_compact; *horizontally_compact = line1 + *horizontally_compact;
return true; return true;
} }
#endif
// FullWalletBillingWrapper // FullWalletBillingWrapper
...@@ -351,17 +323,12 @@ FullWalletBillingWrapper::~FullWalletBillingWrapper() {} ...@@ -351,17 +323,12 @@ FullWalletBillingWrapper::~FullWalletBillingWrapper() {}
base::string16 FullWalletBillingWrapper::GetInfo(const AutofillType& type) base::string16 FullWalletBillingWrapper::GetInfo(const AutofillType& type)
const { const {
if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) return full_wallet_->GetInfo(
return MonthComboboxModel::FormatMonth(full_wallet_->expiration_month()); g_browser_process->GetApplicationLocale(),
AutofillType(AutofillType::GetEquivalentBillingFieldType(
if (type.group() == CREDIT_CARD) type.GetStorableType())));
return full_wallet_->GetInfo(type);
return full_wallet_->billing_address()->GetInfo(
type, g_browser_process->GetApplicationLocale());
} }
#if !defined(OS_ANDROID)
bool FullWalletBillingWrapper::GetDisplayText( bool FullWalletBillingWrapper::GetDisplayText(
base::string16* vertically_compact, base::string16* vertically_compact,
base::string16* horizontally_compact) { base::string16* horizontally_compact) {
...@@ -372,7 +339,6 @@ bool FullWalletBillingWrapper::GetDisplayText( ...@@ -372,7 +339,6 @@ bool FullWalletBillingWrapper::GetDisplayText(
return DataModelWrapper::GetDisplayText(vertically_compact, return DataModelWrapper::GetDisplayText(vertically_compact,
horizontally_compact); horizontally_compact);
} }
#endif
// FullWalletShippingWrapper // FullWalletShippingWrapper
......
...@@ -5,11 +5,14 @@ ...@@ -5,11 +5,14 @@
#ifndef CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ #ifndef CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_
#define CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ #define CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_
#include <vector>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/ui/autofill/autofill_dialog_types.h" #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
#include "components/autofill/content/browser/wallet/wallet_items.h" #include "components/autofill/content/browser/wallet/wallet_items.h"
#include "components/autofill/core/browser/field_types.h" #include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/form_structure.h"
namespace gfx { namespace gfx {
class Image; class Image;
...@@ -50,7 +53,6 @@ class DataModelWrapper { ...@@ -50,7 +53,6 @@ class DataModelWrapper {
// Returns the icon, if any, that represents this model. // Returns the icon, if any, that represents this model.
virtual gfx::Image GetIcon(); virtual gfx::Image GetIcon();
#if !defined(OS_ANDROID)
// Gets text to display to the user to summarize this data source. The // Gets text to display to the user to summarize this data source. The
// default implementation assumes this is an address. Both params are required // default implementation assumes this is an address. Both params are required
// to be non-NULL and will be filled in with text that is vertically compact // to be non-NULL and will be filled in with text that is vertically compact
...@@ -60,15 +62,14 @@ class DataModelWrapper { ...@@ -60,15 +62,14 @@ class DataModelWrapper {
// complete and valid. // complete and valid.
virtual bool GetDisplayText(base::string16* vertically_compact, virtual bool GetDisplayText(base::string16* vertically_compact,
base::string16* horizontally_compact); base::string16* horizontally_compact);
#endif
// Fills in |form_structure| with the data that this model contains. |inputs| // Fills in |form_structure| with the data that this model contains. |inputs|
// and |comparator| are used to determine whether each field in the // and |comparator| are used to determine whether each field in the
// FormStructure should be filled in or left alone. Returns whether any fields // FormStructure should be filled in or left alone. Returns whether any fields
// in |form_structure| were found to be matching. // in |form_structure| were found to be matching.
bool FillFormStructure( bool FillFormStructure(
const DetailInputs& inputs, const std::vector<ServerFieldType>& types,
const InputFieldComparator& compare, const FormStructure::InputFieldComparator& compare,
FormStructure* form_structure) const; FormStructure* form_structure) const;
protected: protected:
...@@ -78,19 +79,6 @@ class DataModelWrapper { ...@@ -78,19 +79,6 @@ class DataModelWrapper {
DISALLOW_COPY_AND_ASSIGN(DataModelWrapper); DISALLOW_COPY_AND_ASSIGN(DataModelWrapper);
}; };
// A DataModelWrapper that does not hold data and does nothing when told to
// fill in a form.
class EmptyDataModelWrapper : public DataModelWrapper {
public:
EmptyDataModelWrapper();
virtual ~EmptyDataModelWrapper();
virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
protected:
DISALLOW_COPY_AND_ASSIGN(EmptyDataModelWrapper);
};
// A DataModelWrapper for Autofill profiles. // A DataModelWrapper for Autofill profiles.
class AutofillProfileWrapper : public DataModelWrapper { class AutofillProfileWrapper : public DataModelWrapper {
public: public:
...@@ -140,10 +128,8 @@ class AutofillCreditCardWrapper : public DataModelWrapper { ...@@ -140,10 +128,8 @@ class AutofillCreditCardWrapper : public DataModelWrapper {
virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE; virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
virtual gfx::Image GetIcon() OVERRIDE; virtual gfx::Image GetIcon() OVERRIDE;
#if !defined(OS_ANDROID)
virtual bool GetDisplayText(base::string16* vertically_compact, virtual bool GetDisplayText(base::string16* vertically_compact,
base::string16* horizontally_compact) OVERRIDE; base::string16* horizontally_compact) OVERRIDE;
#endif
private: private:
const CreditCard* card_; const CreditCard* card_;
...@@ -160,10 +146,8 @@ class WalletAddressWrapper : public DataModelWrapper { ...@@ -160,10 +146,8 @@ class WalletAddressWrapper : public DataModelWrapper {
virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE; virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
virtual base::string16 GetInfoForDisplay(const AutofillType& type) const virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
OVERRIDE; OVERRIDE;
#if !defined(OS_ANDROID)
virtual bool GetDisplayText(base::string16* vertically_compact, virtual bool GetDisplayText(base::string16* vertically_compact,
base::string16* horizontally_compact) OVERRIDE; base::string16* horizontally_compact) OVERRIDE;
#endif
private: private:
const wallet::Address* address_; const wallet::Address* address_;
...@@ -182,10 +166,8 @@ class WalletInstrumentWrapper : public DataModelWrapper { ...@@ -182,10 +166,8 @@ class WalletInstrumentWrapper : public DataModelWrapper {
virtual base::string16 GetInfoForDisplay(const AutofillType& type) const virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
OVERRIDE; OVERRIDE;
virtual gfx::Image GetIcon() OVERRIDE; virtual gfx::Image GetIcon() OVERRIDE;
#if !defined(OS_ANDROID)
virtual bool GetDisplayText(base::string16* vertically_compact, virtual bool GetDisplayText(base::string16* vertically_compact,
base::string16* horizontally_compact) OVERRIDE; base::string16* horizontally_compact) OVERRIDE;
#endif
private: private:
const wallet::WalletItems::MaskedInstrument* instrument_; const wallet::WalletItems::MaskedInstrument* instrument_;
...@@ -200,10 +182,8 @@ class FullWalletBillingWrapper : public DataModelWrapper { ...@@ -200,10 +182,8 @@ class FullWalletBillingWrapper : public DataModelWrapper {
virtual ~FullWalletBillingWrapper(); virtual ~FullWalletBillingWrapper();
virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE; virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
#if !defined(OS_ANDROID)
virtual bool GetDisplayText(base::string16* vertically_compact, virtual bool GetDisplayText(base::string16* vertically_compact,
base::string16* horizontally_compact) OVERRIDE; base::string16* horizontally_compact) OVERRIDE;
#endif
private: private:
wallet::FullWallet* full_wallet_; wallet::FullWallet* full_wallet_;
......
...@@ -30,7 +30,6 @@ TEST(AutofillCreditCardWrapperTest, GetInfoCreditCardExpMonth) { ...@@ -30,7 +30,6 @@ TEST(AutofillCreditCardWrapperTest, GetInfoCreditCardExpMonth) {
} }
} }
#if !defined(OS_ANDROID)
TEST(AutofillCreditCardWrapperTest, GetDisplayTextEmptyWhenExpired) { TEST(AutofillCreditCardWrapperTest, GetDisplayTextEmptyWhenExpired) {
CreditCard card; CreditCard card;
card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1")); card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1"));
...@@ -92,7 +91,6 @@ TEST(DataModelWrapperTest, GetDisplayTextEmptyWithoutPhone) { ...@@ -92,7 +91,6 @@ TEST(DataModelWrapperTest, GetDisplayTextEmptyWithoutPhone) {
address_wrapper.GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER))); address_wrapper.GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)));
EXPECT_FALSE(address_wrapper.GetDisplayText(&unused, &unused2)); EXPECT_FALSE(address_wrapper.GetDisplayText(&unused, &unused2));
} }
#endif
TEST(WalletInstrumentWrapperTest, GetInfoCreditCardExpMonth) { TEST(WalletInstrumentWrapperTest, GetInfoCreditCardExpMonth) {
scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument(
......
...@@ -3353,8 +3353,6 @@ ...@@ -3353,8 +3353,6 @@
'sources!': [ 'sources!': [
'browser/ui/autofill/autofill_dialog_common.cc', 'browser/ui/autofill/autofill_dialog_common.cc',
'browser/ui/autofill/autofill_dialog_common.h', 'browser/ui/autofill/autofill_dialog_common.h',
'browser/ui/autofill/data_model_wrapper.cc',
'browser/ui/autofill/data_model_wrapper.h',
], ],
}], }],
['enable_autofill_dialog==1 and OS!="android" and OS!="ios"', { ['enable_autofill_dialog==1 and OS!="android" and OS!="ios"', {
...@@ -3371,6 +3369,8 @@ ...@@ -3371,6 +3369,8 @@
'browser/ui/autofill/autofill_dialog_view.h', 'browser/ui/autofill/autofill_dialog_view.h',
'browser/ui/autofill/autofill_dialog_view.cc', 'browser/ui/autofill/autofill_dialog_view.cc',
'browser/ui/autofill/autofill_dialog_view_delegate.h', 'browser/ui/autofill/autofill_dialog_view_delegate.h',
'browser/ui/autofill/data_model_wrapper.cc',
'browser/ui/autofill/data_model_wrapper.h',
], ],
}], }],
['enable_google_now==0', { ['enable_google_now==0', {
......
...@@ -2253,6 +2253,7 @@ ...@@ -2253,6 +2253,7 @@
'browser/ui/autofill/autofill_credit_card_bubble_controller_unittest.cc', 'browser/ui/autofill/autofill_credit_card_bubble_controller_unittest.cc',
'browser/ui/autofill/autofill_dialog_controller_unittest.cc', 'browser/ui/autofill/autofill_dialog_controller_unittest.cc',
'browser/ui/autofill/autofill_dialog_i18n_input_unittest.cc', 'browser/ui/autofill/autofill_dialog_i18n_input_unittest.cc',
'browser/ui/autofill/data_model_wrapper_unittest.cc',
'browser/ui/autofill/mock_autofill_dialog_view_delegate.cc', 'browser/ui/autofill/mock_autofill_dialog_view_delegate.cc',
'browser/ui/autofill/mock_autofill_dialog_view_delegate.h', 'browser/ui/autofill/mock_autofill_dialog_view_delegate.h',
'browser/ui/autofill/test_autofill_credit_card_bubble.cc', 'browser/ui/autofill/test_autofill_credit_card_bubble.cc',
......
...@@ -154,16 +154,17 @@ scoped_ptr<FullWallet> ...@@ -154,16 +154,17 @@ scoped_ptr<FullWallet>
return wallet.Pass(); return wallet.Pass();
} }
base::string16 FullWallet::GetInfo(const AutofillType& type) { base::string16 FullWallet::GetInfo(const std::string& app_locale,
const AutofillType& type) {
switch (type.GetStorableType()) { switch (type.GetStorableType()) {
case CREDIT_CARD_NUMBER: case CREDIT_CARD_NUMBER:
return base::UTF8ToUTF16(GetPan()); return base::ASCIIToUTF16(GetPan());
case CREDIT_CARD_NAME: case CREDIT_CARD_NAME:
return billing_address()->recipient_name(); return billing_address()->recipient_name();
case CREDIT_CARD_VERIFICATION_CODE: case CREDIT_CARD_VERIFICATION_CODE:
return base::UTF8ToUTF16(GetCvn()); return base::ASCIIToUTF16(GetCvn());
case CREDIT_CARD_EXP_MONTH: case CREDIT_CARD_EXP_MONTH:
if (expiration_month() == 0) if (expiration_month() == 0)
...@@ -182,7 +183,7 @@ base::string16 FullWallet::GetInfo(const AutofillType& type) { ...@@ -182,7 +183,7 @@ base::string16 FullWallet::GetInfo(const AutofillType& type) {
case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR:
if (expiration_month() == 0 || expiration_year() == 0) if (expiration_month() == 0 || expiration_year() == 0)
return base::string16(); return base::string16();
return base::IntToString16(expiration_month()) + base::ASCIIToUTF16("/") + return base::IntToString16(expiration_month()) + base::ASCIIToUTF16("/") +
base::IntToString16(expiration_year() % 100); base::IntToString16(expiration_year() % 100);
...@@ -194,17 +195,27 @@ base::string16 FullWallet::GetInfo(const AutofillType& type) { ...@@ -194,17 +195,27 @@ base::string16 FullWallet::GetInfo(const AutofillType& type) {
case CREDIT_CARD_TYPE: { case CREDIT_CARD_TYPE: {
std::string internal_type = std::string internal_type =
CreditCard::GetCreditCardType(base::UTF8ToUTF16(GetPan())); CreditCard::GetCreditCardType(base::ASCIIToUTF16(GetPan()));
if (internal_type == kGenericCard) if (internal_type == kGenericCard)
return base::string16(); return base::string16();
return CreditCard::TypeForDisplay(internal_type); return CreditCard::TypeForDisplay(internal_type);
} }
default: default: {
NOTREACHED(); switch (type.group()) {
} case NAME_BILLING:
case PHONE_BILLING:
case ADDRESS_BILLING:
return billing_address_->GetInfo(type, app_locale);
return base::string16(); case CREDIT_CARD:
NOTREACHED();
default:
return shipping_address_->GetInfo(type, app_locale);
}
}
}
} }
bool FullWallet::HasRequiredAction(RequiredAction action) const { bool FullWallet::HasRequiredAction(RequiredAction action) const {
...@@ -216,11 +227,16 @@ bool FullWallet::HasRequiredAction(RequiredAction action) const { ...@@ -216,11 +227,16 @@ bool FullWallet::HasRequiredAction(RequiredAction action) const {
base::string16 FullWallet::TypeAndLastFourDigits() { base::string16 FullWallet::TypeAndLastFourDigits() {
CreditCard card; CreditCard card;
card.SetRawInfo(CREDIT_CARD_NUMBER, card.SetRawInfo(CREDIT_CARD_NUMBER, base::ASCIIToUTF16(GetPan()));
GetInfo(AutofillType(CREDIT_CARD_NUMBER)));
return card.TypeAndLastFourDigits(); return card.TypeAndLastFourDigits();
} }
const std::string& FullWallet::GetPan() {
if (pan_.empty())
DecryptCardInfo();
return pan_;
}
bool FullWallet::operator==(const FullWallet& other) const { bool FullWallet::operator==(const FullWallet& other) const {
if (expiration_month_ != other.expiration_month_) if (expiration_month_ != other.expiration_month_)
return false; return false;
...@@ -307,12 +323,6 @@ void FullWallet::DecryptCardInfo() { ...@@ -307,12 +323,6 @@ void FullWallet::DecryptCardInfo() {
pan_ = iin_ + card_info.substr(0, split); pan_ = iin_ + card_info.substr(0, split);
} }
const std::string& FullWallet::GetPan() {
if (pan_.empty())
DecryptCardInfo();
return pan_;
}
const std::string& FullWallet::GetCvn() { const std::string& FullWallet::GetCvn() {
if (cvn_.empty()) if (cvn_.empty())
DecryptCardInfo(); DecryptCardInfo();
......
...@@ -52,7 +52,8 @@ class FullWallet { ...@@ -52,7 +52,8 @@ class FullWallet {
scoped_ptr<Address> shipping_address); scoped_ptr<Address> shipping_address);
// Returns corresponding data for |type|. // Returns corresponding data for |type|.
base::string16 GetInfo(const AutofillType& type); base::string16 GetInfo(const std::string& app_locale,
const AutofillType& type);
// Whether or not |action| is in |required_actions_|. // Whether or not |action| is in |required_actions_|.
bool HasRequiredAction(RequiredAction action) const; bool HasRequiredAction(RequiredAction action) const;
...@@ -61,6 +62,10 @@ class FullWallet { ...@@ -61,6 +62,10 @@ class FullWallet {
// like this "Visa - 4111". // like this "Visa - 4111".
base::string16 TypeAndLastFourDigits(); base::string16 TypeAndLastFourDigits();
// Decrypts and returns the primary account number (PAN) using the generated
// one time pad, |one_time_pad_|.
const std::string& GetPan();
bool operator==(const FullWallet& other) const; bool operator==(const FullWallet& other) const;
bool operator!=(const FullWallet& other) const; bool operator!=(const FullWallet& other) const;
...@@ -103,10 +108,6 @@ class FullWallet { ...@@ -103,10 +108,6 @@ class FullWallet {
// Decrypts both |pan_| and |cvn_|. // Decrypts both |pan_| and |cvn_|.
void DecryptCardInfo(); void DecryptCardInfo();
// Decrypts and returns the primary account number (PAN) using the generated
// one time pad, |one_time_pad_|.
const std::string& GetPan();
// Decrypts and returns the card verification number (CVN) using the generated // Decrypts and returns the card verification number (CVN) using the generated
// one time pad, |one_time_pad_|. // one time pad, |one_time_pad_|.
const std::string& GetCvn(); const std::string& GetCvn();
......
...@@ -456,9 +456,10 @@ TEST_F(FullWalletTest, RestLengthCorrectDecryptionTest) { ...@@ -456,9 +456,10 @@ TEST_F(FullWalletTest, RestLengthCorrectDecryptionTest) {
EXPECT_TRUE(base::HexStringToBytes("5F04A8704183", &one_time_pad)); EXPECT_TRUE(base::HexStringToBytes("5F04A8704183", &one_time_pad));
full_wallet.set_one_time_pad(one_time_pad); full_wallet.set_one_time_pad(one_time_pad);
EXPECT_EQ(ASCIIToUTF16("5285121925598459"), EXPECT_EQ(ASCIIToUTF16("5285121925598459"),
full_wallet.GetInfo(AutofillType(CREDIT_CARD_NUMBER))); full_wallet.GetInfo("", AutofillType(CREDIT_CARD_NUMBER)));
EXPECT_EQ(ASCIIToUTF16("989"), EXPECT_EQ(ASCIIToUTF16("989"),
full_wallet.GetInfo(AutofillType(CREDIT_CARD_VERIFICATION_CODE))); full_wallet.GetInfo(
"", AutofillType(CREDIT_CARD_VERIFICATION_CODE)));
} }
TEST_F(FullWalletTest, RestLengthUnderDecryptionTest) { TEST_F(FullWalletTest, RestLengthUnderDecryptionTest) {
...@@ -474,9 +475,10 @@ TEST_F(FullWalletTest, RestLengthUnderDecryptionTest) { ...@@ -474,9 +475,10 @@ TEST_F(FullWalletTest, RestLengthUnderDecryptionTest) {
EXPECT_TRUE(base::HexStringToBytes("063AD35324BF", &one_time_pad)); EXPECT_TRUE(base::HexStringToBytes("063AD35324BF", &one_time_pad));
full_wallet.set_one_time_pad(one_time_pad); full_wallet.set_one_time_pad(one_time_pad);
EXPECT_EQ(ASCIIToUTF16("5285127106109719"), EXPECT_EQ(ASCIIToUTF16("5285127106109719"),
full_wallet.GetInfo(AutofillType(CREDIT_CARD_NUMBER))); full_wallet.GetInfo("", AutofillType(CREDIT_CARD_NUMBER)));
EXPECT_EQ(ASCIIToUTF16("385"), EXPECT_EQ(ASCIIToUTF16("385"),
full_wallet.GetInfo(AutofillType(CREDIT_CARD_VERIFICATION_CODE))); full_wallet.GetInfo(
"", AutofillType(CREDIT_CARD_VERIFICATION_CODE)));
} }
TEST_F(FullWalletTest, GetCreditCardInfo) { TEST_F(FullWalletTest, GetCreditCardInfo) {
...@@ -490,21 +492,22 @@ TEST_F(FullWalletTest, GetCreditCardInfo) { ...@@ -490,21 +492,22 @@ TEST_F(FullWalletTest, GetCreditCardInfo) {
required_actions); required_actions);
EXPECT_EQ(ASCIIToUTF16("15"), EXPECT_EQ(ASCIIToUTF16("15"),
full_wallet.GetInfo(AutofillType(CREDIT_CARD_EXP_2_DIGIT_YEAR))); full_wallet.GetInfo(
"", AutofillType(CREDIT_CARD_EXP_2_DIGIT_YEAR)));
EXPECT_EQ(ASCIIToUTF16("12/15"), EXPECT_EQ(ASCIIToUTF16("12/15"),
full_wallet.GetInfo( full_wallet.GetInfo(
AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR))); "", AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)));
EXPECT_EQ(ASCIIToUTF16("12/2015"), EXPECT_EQ(ASCIIToUTF16("12/2015"),
full_wallet.GetInfo( full_wallet.GetInfo(
AutofillType(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR))); "", AutofillType(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR)));
std::vector<uint8> one_time_pad; std::vector<uint8> one_time_pad;
EXPECT_TRUE(base::HexStringToBytes("075DA779F98B", &one_time_pad)); EXPECT_TRUE(base::HexStringToBytes("075DA779F98B", &one_time_pad));
full_wallet.set_one_time_pad(one_time_pad); full_wallet.set_one_time_pad(one_time_pad);
EXPECT_EQ(ASCIIToUTF16("MasterCard"), EXPECT_EQ(ASCIIToUTF16("MasterCard"),
full_wallet.GetInfo(AutofillType(CREDIT_CARD_TYPE))); full_wallet.GetInfo("", AutofillType(CREDIT_CARD_TYPE)));
} }
TEST_F(FullWalletTest, CreateFullWalletFromClearTextData) { TEST_F(FullWalletTest, CreateFullWalletFromClearTextData) {
...@@ -514,14 +517,15 @@ TEST_F(FullWalletTest, CreateFullWalletFromClearTextData) { ...@@ -514,14 +517,15 @@ TEST_F(FullWalletTest, CreateFullWalletFromClearTextData) {
"5555555555554444", "123", "5555555555554444", "123",
GetTestAddress(), GetTestShippingAddress()); GetTestAddress(), GetTestShippingAddress());
EXPECT_EQ(ASCIIToUTF16("5555555555554444"), EXPECT_EQ(ASCIIToUTF16("5555555555554444"),
full_wallet->GetInfo(AutofillType(CREDIT_CARD_NUMBER))); full_wallet->GetInfo("", AutofillType(CREDIT_CARD_NUMBER)));
EXPECT_EQ(ASCIIToUTF16("MasterCard"), EXPECT_EQ(ASCIIToUTF16("MasterCard"),
full_wallet->GetInfo(AutofillType(CREDIT_CARD_TYPE))); full_wallet->GetInfo("", AutofillType(CREDIT_CARD_TYPE)));
EXPECT_EQ(ASCIIToUTF16("123"), EXPECT_EQ(ASCIIToUTF16("123"),
full_wallet->GetInfo(AutofillType(CREDIT_CARD_VERIFICATION_CODE))); full_wallet->GetInfo(
"", AutofillType(CREDIT_CARD_VERIFICATION_CODE)));
EXPECT_EQ(ASCIIToUTF16("11/12"), EXPECT_EQ(ASCIIToUTF16("11/12"),
full_wallet->GetInfo( full_wallet->GetInfo(
AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR))); "", AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)));
EXPECT_TRUE(GetTestAddress()->EqualsIgnoreID( EXPECT_TRUE(GetTestAddress()->EqualsIgnoreID(
*full_wallet->billing_address())); *full_wallet->billing_address()));
EXPECT_TRUE(GetTestShippingAddress()->EqualsIgnoreID( EXPECT_TRUE(GetTestShippingAddress()->EqualsIgnoreID(
......
...@@ -1150,6 +1150,27 @@ void FormStructure::ParseFieldTypesFromAutocompleteAttributes( ...@@ -1150,6 +1150,27 @@ void FormStructure::ParseFieldTypesFromAutocompleteAttributes(
} }
} }
bool FormStructure::FillFields(
const std::vector<ServerFieldType>& types,
const InputFieldComparator& matches,
const base::Callback<base::string16(const AutofillType&)>& get_info,
const std::string& app_locale) {
bool filled_something = false;
for (size_t i = 0; i < field_count(); ++i) {
for (size_t j = 0; j < types.size(); ++j) {
if (matches.Run(types[j], *field(i))) {
AutofillField::FillFormField(*field(i),
get_info.Run(field(i)->Type()),
app_locale,
field(i));
filled_something = true;
break;
}
}
}
return filled_something;
}
void FormStructure::IdentifySections(bool has_author_specified_sections) { void FormStructure::IdentifySections(bool has_author_specified_sections) {
if (fields_.empty()) if (fields_.empty())
return; return;
......
...@@ -8,9 +8,11 @@ ...@@ -8,9 +8,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/callback.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/strings/string16.h"
#include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/autofill_type.h" #include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/field_types.h" #include "components/autofill/core/browser/field_types.h"
...@@ -136,6 +138,19 @@ class FormStructure { ...@@ -136,6 +138,19 @@ class FormStructure {
void ParseFieldTypesFromAutocompleteAttributes(bool* found_types, void ParseFieldTypesFromAutocompleteAttributes(bool* found_types,
bool* found_sections); bool* found_sections);
// Determines whether |type| and |field| match.
typedef base::Callback<bool(ServerFieldType type,
const AutofillField& field)>
InputFieldComparator;
// Fills in |fields_| that match |types| (via |matches|) with info from
// |get_info|.
bool FillFields(
const std::vector<ServerFieldType>& types,
const InputFieldComparator& matches,
const base::Callback<base::string16(const AutofillType&)>& get_info,
const std::string& app_locale);
const AutofillField* field(size_t index) const; const AutofillField* field(size_t index) const;
AutofillField* field(size_t index); AutofillField* field(size_t index);
size_t field_count() const; size_t field_count() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment