summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/autofill
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/ui/autofill')
-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
8 files changed, 58 insertions, 98 deletions
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(