summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-29 02:21:50 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-29 02:21:50 +0000
commit0a57c37b8f4f803f054ea722c0181896f81e8a67 (patch)
treef0fa50b66375d2a2f95751bca430334edc7934c0
parent391cba93ec4810625581efc55c543e77cf8b2d2c (diff)
downloadchromium_src-0a57c37b8f4f803f054ea722c0181896f81e8a67.zip
chromium_src-0a57c37b8f4f803f054ea722c0181896f81e8a67.tar.gz
chromium_src-0a57c37b8f4f803f054ea722c0181896f81e8a67.tar.bz2
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
-rw-r--r--chrome/browser/ui/android/autofill/autofill_dialog_controller_android.cc57
-rw-r--r--chrome/browser/ui/autofill/autofill_dialog_common.cc8
-rw-r--r--chrome/browser/ui/autofill/autofill_dialog_common.h3
-rw-r--r--chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc37
-rw-r--r--chrome/browser/ui/autofill/autofill_dialog_controller_impl.h9
-rw-r--r--chrome/browser/ui/autofill/autofill_dialog_types.h5
-rw-r--r--chrome/browser/ui/autofill/data_model_wrapper.cc62
-rw-r--r--chrome/browser/ui/autofill/data_model_wrapper.h30
-rw-r--r--chrome/browser/ui/autofill/data_model_wrapper_unittest.cc2
-rw-r--r--chrome/chrome_browser_ui.gypi4
-rw-r--r--chrome/chrome_tests_unit.gypi1
-rw-r--r--components/autofill/content/browser/wallet/full_wallet.cc44
-rw-r--r--components/autofill/content/browser/wallet/full_wallet.h11
-rw-r--r--components/autofill/content/browser/wallet/full_wallet_unittest.cc28
-rw-r--r--components/autofill/core/browser/form_structure.cc21
-rw-r--r--components/autofill/core/browser/form_structure.h15
16 files changed, 173 insertions, 164 deletions
diff --git a/chrome/browser/ui/android/autofill/autofill_dialog_controller_android.cc b/chrome/browser/ui/android/autofill/autofill_dialog_controller_android.cc
index f3fed9a..97ea589 100644
--- a/chrome/browser/ui/android/autofill/autofill_dialog_controller_android.cc
+++ b/chrome/browser/ui/android/autofill/autofill_dialog_controller_android.cc
@@ -20,7 +20,6 @@
#include "chrome/browser/ui/android/autofill/autofill_dialog_result.h"
#include "chrome/browser/ui/android/window_android_helper.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/url_constants.h"
#include "components/autofill/content/browser/wallet/full_wallet.h"
@@ -49,6 +48,8 @@ namespace autofill {
namespace {
+using wallet::FullWallet;
+
// Keys in kAutofillDialogDefaults pref dictionary (do not change these values).
const char kLastUsedAccountName[] = "last_used_account_name";
const char kLastUsedChoiceIsAutofill[] = "last_used_choice_is_autofill";
@@ -56,42 +57,38 @@ const char kLastUsedBillingAddressGuid[] = "last_used_billing";
const char kLastUsedShippingAddressGuid[] = "last_used_shipping";
const char kLastUsedCreditCardGuid[] = "last_used_card";
-scoped_ptr<DataModelWrapper> CreateWrapper(
- DialogSection section, wallet::FullWallet* full_wallet) {
- 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>();
+base::string16 NullGetInfo(const AutofillType& type) {
+ return base::string16();
}
void FillOutputForSectionWithComparator(
DialogSection section,
const DetailInputs& inputs,
- const InputFieldComparator& compare,
+ const FormStructure::InputFieldComparator& compare,
FormStructure& form_structure,
- wallet::FullWallet* full_wallet,
+ FullWallet* full_wallet,
const base::string16& email_address) {
- scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section, full_wallet);
- if (wrapper)
- wrapper->FillFormStructure(inputs, compare, &form_structure);
+ if ((section == SECTION_CC_BILLING && !full_wallet->billing_address()) ||
+ (section == SECTION_SHIPPING && !full_wallet->shipping_address())) {
+ 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(
DialogSection section,
FormStructure& form_structure,
- wallet::FullWallet* full_wallet,
+ FullWallet* full_wallet,
const base::string16& email_address) {
DetailInputs inputs;
common::BuildInputsForSection(section, "US", &inputs);
@@ -252,11 +249,11 @@ void AutofillDialogControllerAndroid::Show() {
{
DetailInputs inputs;
common::BuildInputsForSection(SECTION_SHIPPING, "US", &inputs);
- EmptyDataModelWrapper empty_wrapper;
- request_shipping_address = empty_wrapper.FillFormStructure(
- inputs,
+ request_shipping_address = form_structure_.FillFields(
+ common::TypesFromInputs(inputs),
base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING),
- &form_structure_);
+ base::Bind(NullGetInfo),
+ g_browser_process->GetApplicationLocale());
}
const bool incognito_mode = profile_->IsOffTheRecord();
@@ -353,7 +350,7 @@ void AutofillDialogControllerAndroid::DialogContinue(
const std::string last_used_card =
base::android::ConvertJavaStringToUTF8(env, jlast_used_card);
- scoped_ptr<wallet::FullWallet> full_wallet =
+ scoped_ptr<FullWallet> full_wallet =
AutofillDialogResult::ConvertFromJava(env, wallet);
FillOutputForSection(
SECTION_CC_BILLING, form_structure_, full_wallet.get(), email);
diff --git a/chrome/browser/ui/autofill/autofill_dialog_common.cc b/chrome/browser/ui/autofill/autofill_dialog_common.cc
index a6b9b1c..0c4ef13 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_common.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_common.cc
@@ -276,5 +276,13 @@ base::string16 GetHardcodedValueForType(ServerFieldType type) {
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 autofill
diff --git a/chrome/browser/ui/autofill/autofill_dialog_common.h b/chrome/browser/ui/autofill/autofill_dialog_common.h
index be8badb..5cae5cd 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_common.h
+++ b/chrome/browser/ui/autofill/autofill_dialog_common.h
@@ -60,6 +60,9 @@ AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent(
// the country: http://crbug.com/247518
base::string16 GetHardcodedValueForType(ServerFieldType type);
+// Gets just the |type| attributes from each DetailInput.
+std::vector<ServerFieldType> TypesFromInputs(const DetailInputs& inputs);
+
} // namespace common
} // namespace autofill
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
index f96e9bb..03c9f9f 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -141,6 +141,10 @@ class 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
// is notated with a "shipping" tag, for use when the user has decided to use
// the billing address as the shipping address.
@@ -599,11 +603,11 @@ void AutofillDialogControllerImpl::Show() {
// Test whether we need to show the shipping section. If filling that section
// would be a no-op, don't show it.
- const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING);
- cares_about_shipping_ = EmptyDataModelWrapper().FillFormStructure(
- inputs,
+ cares_about_shipping_ = form_structure_.FillFields(
+ RequestedTypesForSection(SECTION_SHIPPING),
base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING),
- &form_structure_);
+ base::Bind(NullGetInfo),
+ g_browser_process->GetApplicationLocale());
account_chooser_model_.reset(
new AccountChooserModel(this,
@@ -787,8 +791,7 @@ DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() {
card_scrambling_delay_.Stop();
card_scrambling_refresher_.Stop();
- base::string16 cc_number =
- full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER));
+ base::string16 cc_number = base::ASCIIToUTF16(full_wallet_->GetPan());
DCHECK_GE(cc_number.size(), 4U);
state.image = GetGeneratedCardImage(
base::ASCIIToUTF16("XXXX XXXX XXXX ") +
@@ -1888,12 +1891,8 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
&popup_icons,
&popup_guids_);
} else {
- std::vector<ServerFieldType> field_types;
- const DetailInputs& inputs = RequestedFieldsForSection(section);
- for (DetailInputs::const_iterator iter = inputs.begin();
- iter != inputs.end(); ++iter) {
- field_types.push_back(iter->type);
- }
+ std::vector<ServerFieldType> field_types =
+ RequestedTypesForSection(section);
GetManager()->GetProfileSuggestions(AutofillType(type),
field_contents,
false,
@@ -2906,18 +2905,19 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() {
void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
DialogSection section,
- const InputFieldComparator& compare) {
+ const FormStructure::InputFieldComparator& compare) {
if (!SectionIsActive(section))
return;
DetailInputs inputs;
std::string country_code = CountryCodeForSection(section);
common::BuildInputsForSection(section, country_code, &inputs);
+ std::vector<ServerFieldType> types = common::TypesFromInputs(inputs);
scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
if (wrapper) {
// 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
// handle them. This isn't necessary when filling the combined CC and
@@ -2955,7 +2955,7 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
}
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|.
SetOutputForFieldsOfType(
@@ -2972,7 +2972,7 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
}
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(
return const_cast<DetailInputs*>(&RequestedFieldsForSection(section));
}
+std::vector<ServerFieldType> AutofillDialogControllerImpl::
+ RequestedTypesForSection(DialogSection section) const {
+ return common::TypesFromInputs(RequestedFieldsForSection(section));
+}
+
std::string AutofillDialogControllerImpl::CountryCodeForSection(
DialogSection section) {
scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h
index 3f48f73..23cc807 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h
@@ -401,8 +401,9 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
void FillOutputForSection(DialogSection section);
// As above, but uses |compare| to determine whether a DetailInput matches
// a field. Saves any new Autofill data to the PersonalDataManager.
- void FillOutputForSectionWithComparator(DialogSection section,
- const InputFieldComparator& compare);
+ void FillOutputForSectionWithComparator(
+ DialogSection section,
+ const FormStructure::InputFieldComparator& compare);
// Returns whether |form_structure|_| has any fields that match the fieldset
// represented by |section|.
@@ -461,6 +462,10 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
// Like RequestedFieldsForSection, but returns a pointer.
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|.
std::string CountryCodeForSection(DialogSection section);
diff --git a/chrome/browser/ui/autofill/autofill_dialog_types.h b/chrome/browser/ui/autofill/autofill_dialog_types.h
index 1133a61..4503b99 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_types.h
+++ b/chrome/browser/ui/autofill/autofill_dialog_types.h
@@ -52,11 +52,6 @@ struct DetailInput {
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
// one of these sections.
enum DialogSection {
diff --git a/chrome/browser/ui/autofill/data_model_wrapper.cc b/chrome/browser/ui/autofill/data_model_wrapper.cc
index a61a32b..9c1ed79 100644
--- a/chrome/browser/ui/autofill/data_model_wrapper.cc
+++ b/chrome/browser/ui/autofill/data_model_wrapper.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/autofill/data_model_wrapper.h"
+#include "base/bind.h"
#include "base/callback.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -19,13 +20,10 @@
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/credit_card.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_ui.h"
-#endif
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image.h"
namespace autofill {
@@ -52,7 +50,6 @@ gfx::Image DataModelWrapper::GetIcon() {
return gfx::Image();
}
-#if !defined(OS_ANDROID)
bool DataModelWrapper::GetDisplayText(
base::string16* vertically_compact,
base::string16* horizontally_compact) {
@@ -103,39 +100,20 @@ bool DataModelWrapper::GetDisplayText(
return true;
}
-#endif
bool DataModelWrapper::FillFormStructure(
- const DetailInputs& inputs,
- const InputFieldComparator& compare,
+ const std::vector<ServerFieldType>& types,
+ const FormStructure::InputFieldComparator& compare,
FormStructure* form_structure) const {
- bool filled_something = false;
- for (size_t i = 0; i < form_structure->field_count(); ++i) {
- AutofillField* field = form_structure->field(i);
- for (size_t j = 0; j < inputs.size(); ++j) {
- if (compare.Run(inputs[j].type, *field)) {
- AutofillField::FillFormField(*field, GetInfo(field->Type()),
- g_browser_process->GetApplicationLocale(),
- field);
- filled_something = true;
- break;
- }
- }
- }
- return filled_something;
+ return form_structure->FillFields(
+ types,
+ compare,
+ base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)),
+ g_browser_process->GetApplicationLocale());
}
DataModelWrapper::DataModelWrapper() {}
-// EmptyDataModelWrapper
-
-EmptyDataModelWrapper::EmptyDataModelWrapper() {}
-EmptyDataModelWrapper::~EmptyDataModelWrapper() {}
-
-base::string16 EmptyDataModelWrapper::GetInfo(const AutofillType& type) const {
- return base::string16();
-}
-
// AutofillProfileWrapper
AutofillProfileWrapper::AutofillProfileWrapper(const AutofillProfile* profile)
@@ -237,7 +215,6 @@ gfx::Image AutofillCreditCardWrapper::GetIcon() {
return rb.GetImageNamed(CreditCard::IconResourceId(card_->type()));
}
-#if !defined(OS_ANDROID)
bool AutofillCreditCardWrapper::GetDisplayText(
base::string16* vertically_compact,
base::string16* horizontally_compact) {
@@ -247,7 +224,6 @@ bool AutofillCreditCardWrapper::GetDisplayText(
*vertically_compact = *horizontally_compact = card_->TypeAndLastFourDigits();
return true;
}
-#endif
// WalletAddressWrapper
@@ -272,7 +248,6 @@ base::string16 WalletAddressWrapper::GetInfoForDisplay(const AutofillType& type)
return DataModelWrapper::GetInfoForDisplay(type);
}
-#if !defined(OS_ANDROID)
bool WalletAddressWrapper::GetDisplayText(
base::string16* vertically_compact,
base::string16* horizontally_compact) {
@@ -284,7 +259,6 @@ bool WalletAddressWrapper::GetDisplayText(
return DataModelWrapper::GetDisplayText(vertically_compact,
horizontally_compact);
}
-#endif
// WalletInstrumentWrapper
@@ -318,7 +292,6 @@ gfx::Image WalletInstrumentWrapper::GetIcon() {
return instrument_->CardIcon();
}
-#if !defined(OS_ANDROID)
bool WalletInstrumentWrapper::GetDisplayText(
base::string16* vertically_compact,
base::string16* horizontally_compact) {
@@ -337,7 +310,6 @@ bool WalletInstrumentWrapper::GetDisplayText(
*horizontally_compact = line1 + *horizontally_compact;
return true;
}
-#endif
// FullWalletBillingWrapper
@@ -351,17 +323,12 @@ FullWalletBillingWrapper::~FullWalletBillingWrapper() {}
base::string16 FullWalletBillingWrapper::GetInfo(const AutofillType& type)
const {
- if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH)
- return MonthComboboxModel::FormatMonth(full_wallet_->expiration_month());
-
- if (type.group() == CREDIT_CARD)
- return full_wallet_->GetInfo(type);
-
- return full_wallet_->billing_address()->GetInfo(
- type, g_browser_process->GetApplicationLocale());
+ return full_wallet_->GetInfo(
+ g_browser_process->GetApplicationLocale(),
+ AutofillType(AutofillType::GetEquivalentBillingFieldType(
+ type.GetStorableType())));
}
-#if !defined(OS_ANDROID)
bool FullWalletBillingWrapper::GetDisplayText(
base::string16* vertically_compact,
base::string16* horizontally_compact) {
@@ -372,7 +339,6 @@ bool FullWalletBillingWrapper::GetDisplayText(
return DataModelWrapper::GetDisplayText(vertically_compact,
horizontally_compact);
}
-#endif
// FullWalletShippingWrapper
diff --git a/chrome/browser/ui/autofill/data_model_wrapper.h b/chrome/browser/ui/autofill/data_model_wrapper.h
index fc90d12..de370bd 100644
--- a/chrome/browser/ui/autofill/data_model_wrapper.h
+++ b/chrome/browser/ui/autofill/data_model_wrapper.h
@@ -5,11 +5,14 @@
#ifndef 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/strings/string16.h"
#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
#include "components/autofill/content/browser/wallet/wallet_items.h"
#include "components/autofill/core/browser/field_types.h"
+#include "components/autofill/core/browser/form_structure.h"
namespace gfx {
class Image;
@@ -50,7 +53,6 @@ class DataModelWrapper {
// Returns the icon, if any, that represents this model.
virtual gfx::Image GetIcon();
-#if !defined(OS_ANDROID)
// Gets text to display to the user to summarize this data source. The
// 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
@@ -60,15 +62,14 @@ class DataModelWrapper {
// complete and valid.
virtual bool GetDisplayText(base::string16* vertically_compact,
base::string16* horizontally_compact);
-#endif
// Fills in |form_structure| with the data that this model contains. |inputs|
// and |comparator| are used to determine whether each field in the
// FormStructure should be filled in or left alone. Returns whether any fields
// in |form_structure| were found to be matching.
bool FillFormStructure(
- const DetailInputs& inputs,
- const InputFieldComparator& compare,
+ const std::vector<ServerFieldType>& types,
+ const FormStructure::InputFieldComparator& compare,
FormStructure* form_structure) const;
protected:
@@ -78,19 +79,6 @@ class 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.
class AutofillProfileWrapper : public DataModelWrapper {
public:
@@ -140,10 +128,8 @@ class AutofillCreditCardWrapper : public DataModelWrapper {
virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
virtual gfx::Image GetIcon() OVERRIDE;
-#if !defined(OS_ANDROID)
virtual bool GetDisplayText(base::string16* vertically_compact,
base::string16* horizontally_compact) OVERRIDE;
-#endif
private:
const CreditCard* card_;
@@ -160,10 +146,8 @@ class WalletAddressWrapper : public DataModelWrapper {
virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
OVERRIDE;
-#if !defined(OS_ANDROID)
virtual bool GetDisplayText(base::string16* vertically_compact,
base::string16* horizontally_compact) OVERRIDE;
-#endif
private:
const wallet::Address* address_;
@@ -182,10 +166,8 @@ class WalletInstrumentWrapper : public DataModelWrapper {
virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
OVERRIDE;
virtual gfx::Image GetIcon() OVERRIDE;
-#if !defined(OS_ANDROID)
virtual bool GetDisplayText(base::string16* vertically_compact,
base::string16* horizontally_compact) OVERRIDE;
-#endif
private:
const wallet::WalletItems::MaskedInstrument* instrument_;
@@ -200,10 +182,8 @@ class FullWalletBillingWrapper : public DataModelWrapper {
virtual ~FullWalletBillingWrapper();
virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
-#if !defined(OS_ANDROID)
virtual bool GetDisplayText(base::string16* vertically_compact,
base::string16* horizontally_compact) OVERRIDE;
-#endif
private:
wallet::FullWallet* full_wallet_;
diff --git a/chrome/browser/ui/autofill/data_model_wrapper_unittest.cc b/chrome/browser/ui/autofill/data_model_wrapper_unittest.cc
index eaf8bf1..03ed203 100644
--- a/chrome/browser/ui/autofill/data_model_wrapper_unittest.cc
+++ b/chrome/browser/ui/autofill/data_model_wrapper_unittest.cc
@@ -30,7 +30,6 @@ TEST(AutofillCreditCardWrapperTest, GetInfoCreditCardExpMonth) {
}
}
-#if !defined(OS_ANDROID)
TEST(AutofillCreditCardWrapperTest, GetDisplayTextEmptyWhenExpired) {
CreditCard card;
card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1"));
@@ -92,7 +91,6 @@ TEST(DataModelWrapperTest, GetDisplayTextEmptyWithoutPhone) {
address_wrapper.GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)));
EXPECT_FALSE(address_wrapper.GetDisplayText(&unused, &unused2));
}
-#endif
TEST(WalletInstrumentWrapperTest, GetInfoCreditCardExpMonth) {
scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument(
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 501b175..e772827 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -3353,8 +3353,6 @@
'sources!': [
'browser/ui/autofill/autofill_dialog_common.cc',
'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"', {
@@ -3371,6 +3369,8 @@
'browser/ui/autofill/autofill_dialog_view.h',
'browser/ui/autofill/autofill_dialog_view.cc',
'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', {
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 6f05e37..06c74d6 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -2253,6 +2253,7 @@
'browser/ui/autofill/autofill_credit_card_bubble_controller_unittest.cc',
'browser/ui/autofill/autofill_dialog_controller_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.h',
'browser/ui/autofill/test_autofill_credit_card_bubble.cc',
diff --git a/components/autofill/content/browser/wallet/full_wallet.cc b/components/autofill/content/browser/wallet/full_wallet.cc
index d4b390a..fda8811 100644
--- a/components/autofill/content/browser/wallet/full_wallet.cc
+++ b/components/autofill/content/browser/wallet/full_wallet.cc
@@ -154,16 +154,17 @@ scoped_ptr<FullWallet>
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()) {
case CREDIT_CARD_NUMBER:
- return base::UTF8ToUTF16(GetPan());
+ return base::ASCIIToUTF16(GetPan());
case CREDIT_CARD_NAME:
return billing_address()->recipient_name();
case CREDIT_CARD_VERIFICATION_CODE:
- return base::UTF8ToUTF16(GetCvn());
+ return base::ASCIIToUTF16(GetCvn());
case CREDIT_CARD_EXP_MONTH:
if (expiration_month() == 0)
@@ -182,7 +183,7 @@ base::string16 FullWallet::GetInfo(const AutofillType& type) {
case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR:
if (expiration_month() == 0 || expiration_year() == 0)
- return base::string16();
+ return base::string16();
return base::IntToString16(expiration_month()) + base::ASCIIToUTF16("/") +
base::IntToString16(expiration_year() % 100);
@@ -194,17 +195,27 @@ base::string16 FullWallet::GetInfo(const AutofillType& type) {
case CREDIT_CARD_TYPE: {
std::string internal_type =
- CreditCard::GetCreditCardType(base::UTF8ToUTF16(GetPan()));
+ CreditCard::GetCreditCardType(base::ASCIIToUTF16(GetPan()));
if (internal_type == kGenericCard)
return base::string16();
return CreditCard::TypeForDisplay(internal_type);
}
- default:
- NOTREACHED();
- }
+ default: {
+ 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 {
@@ -216,11 +227,16 @@ bool FullWallet::HasRequiredAction(RequiredAction action) const {
base::string16 FullWallet::TypeAndLastFourDigits() {
CreditCard card;
- card.SetRawInfo(CREDIT_CARD_NUMBER,
- GetInfo(AutofillType(CREDIT_CARD_NUMBER)));
+ card.SetRawInfo(CREDIT_CARD_NUMBER, base::ASCIIToUTF16(GetPan()));
return card.TypeAndLastFourDigits();
}
+const std::string& FullWallet::GetPan() {
+ if (pan_.empty())
+ DecryptCardInfo();
+ return pan_;
+}
+
bool FullWallet::operator==(const FullWallet& other) const {
if (expiration_month_ != other.expiration_month_)
return false;
@@ -307,12 +323,6 @@ void FullWallet::DecryptCardInfo() {
pan_ = iin_ + card_info.substr(0, split);
}
-const std::string& FullWallet::GetPan() {
- if (pan_.empty())
- DecryptCardInfo();
- return pan_;
-}
-
const std::string& FullWallet::GetCvn() {
if (cvn_.empty())
DecryptCardInfo();
diff --git a/components/autofill/content/browser/wallet/full_wallet.h b/components/autofill/content/browser/wallet/full_wallet.h
index e3d185d..9a8607b 100644
--- a/components/autofill/content/browser/wallet/full_wallet.h
+++ b/components/autofill/content/browser/wallet/full_wallet.h
@@ -52,7 +52,8 @@ class FullWallet {
scoped_ptr<Address> shipping_address);
// 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_|.
bool HasRequiredAction(RequiredAction action) const;
@@ -61,6 +62,10 @@ class FullWallet {
// like this "Visa - 4111".
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;
@@ -103,10 +108,6 @@ class FullWallet {
// Decrypts both |pan_| and |cvn_|.
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
// one time pad, |one_time_pad_|.
const std::string& GetCvn();
diff --git a/components/autofill/content/browser/wallet/full_wallet_unittest.cc b/components/autofill/content/browser/wallet/full_wallet_unittest.cc
index 3d156a8..cf5dc6a 100644
--- a/components/autofill/content/browser/wallet/full_wallet_unittest.cc
+++ b/components/autofill/content/browser/wallet/full_wallet_unittest.cc
@@ -456,9 +456,10 @@ TEST_F(FullWalletTest, RestLengthCorrectDecryptionTest) {
EXPECT_TRUE(base::HexStringToBytes("5F04A8704183", &one_time_pad));
full_wallet.set_one_time_pad(one_time_pad);
EXPECT_EQ(ASCIIToUTF16("5285121925598459"),
- full_wallet.GetInfo(AutofillType(CREDIT_CARD_NUMBER)));
+ full_wallet.GetInfo("", AutofillType(CREDIT_CARD_NUMBER)));
EXPECT_EQ(ASCIIToUTF16("989"),
- full_wallet.GetInfo(AutofillType(CREDIT_CARD_VERIFICATION_CODE)));
+ full_wallet.GetInfo(
+ "", AutofillType(CREDIT_CARD_VERIFICATION_CODE)));
}
TEST_F(FullWalletTest, RestLengthUnderDecryptionTest) {
@@ -474,9 +475,10 @@ TEST_F(FullWalletTest, RestLengthUnderDecryptionTest) {
EXPECT_TRUE(base::HexStringToBytes("063AD35324BF", &one_time_pad));
full_wallet.set_one_time_pad(one_time_pad);
EXPECT_EQ(ASCIIToUTF16("5285127106109719"),
- full_wallet.GetInfo(AutofillType(CREDIT_CARD_NUMBER)));
+ full_wallet.GetInfo("", AutofillType(CREDIT_CARD_NUMBER)));
EXPECT_EQ(ASCIIToUTF16("385"),
- full_wallet.GetInfo(AutofillType(CREDIT_CARD_VERIFICATION_CODE)));
+ full_wallet.GetInfo(
+ "", AutofillType(CREDIT_CARD_VERIFICATION_CODE)));
}
TEST_F(FullWalletTest, GetCreditCardInfo) {
@@ -490,21 +492,22 @@ TEST_F(FullWalletTest, GetCreditCardInfo) {
required_actions);
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"),
full_wallet.GetInfo(
- AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)));
+ "", AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)));
EXPECT_EQ(ASCIIToUTF16("12/2015"),
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;
EXPECT_TRUE(base::HexStringToBytes("075DA779F98B", &one_time_pad));
full_wallet.set_one_time_pad(one_time_pad);
EXPECT_EQ(ASCIIToUTF16("MasterCard"),
- full_wallet.GetInfo(AutofillType(CREDIT_CARD_TYPE)));
+ full_wallet.GetInfo("", AutofillType(CREDIT_CARD_TYPE)));
}
TEST_F(FullWalletTest, CreateFullWalletFromClearTextData) {
@@ -514,14 +517,15 @@ TEST_F(FullWalletTest, CreateFullWalletFromClearTextData) {
"5555555555554444", "123",
GetTestAddress(), GetTestShippingAddress());
EXPECT_EQ(ASCIIToUTF16("5555555555554444"),
- full_wallet->GetInfo(AutofillType(CREDIT_CARD_NUMBER)));
+ full_wallet->GetInfo("", AutofillType(CREDIT_CARD_NUMBER)));
EXPECT_EQ(ASCIIToUTF16("MasterCard"),
- full_wallet->GetInfo(AutofillType(CREDIT_CARD_TYPE)));
+ full_wallet->GetInfo("", AutofillType(CREDIT_CARD_TYPE)));
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"),
full_wallet->GetInfo(
- AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)));
+ "", AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)));
EXPECT_TRUE(GetTestAddress()->EqualsIgnoreID(
*full_wallet->billing_address()));
EXPECT_TRUE(GetTestShippingAddress()->EqualsIgnoreID(
diff --git a/components/autofill/core/browser/form_structure.cc b/components/autofill/core/browser/form_structure.cc
index a953798..aa42b4f 100644
--- a/components/autofill/core/browser/form_structure.cc
+++ b/components/autofill/core/browser/form_structure.cc
@@ -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) {
if (fields_.empty())
return;
diff --git a/components/autofill/core/browser/form_structure.h b/components/autofill/core/browser/form_structure.h
index 6382c20..578c413 100644
--- a/components/autofill/core/browser/form_structure.h
+++ b/components/autofill/core/browser/form_structure.h
@@ -8,9 +8,11 @@
#include <string>
#include <vector>
+#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.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_type.h"
#include "components/autofill/core/browser/field_types.h"
@@ -136,6 +138,19 @@ class FormStructure {
void ParseFieldTypesFromAutocompleteAttributes(bool* found_types,
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;
AutofillField* field(size_t index);
size_t field_count() const;