summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r--chrome/browser/autofill/address.h14
-rw-r--r--chrome/browser/autofill/autofill_field.h2
-rw-r--r--chrome/browser/autofill/autofill_profile.h2
-rw-r--r--chrome/browser/autofill/contact_info.cc26
-rw-r--r--chrome/browser/autofill/contact_info.h21
-rw-r--r--chrome/browser/autofill/credit_card.cc118
-rw-r--r--chrome/browser/autofill/credit_card.h65
-rw-r--r--chrome/browser/autofill/credit_card_unittest.cc12
-rw-r--r--chrome/browser/autofill/form_group.h2
-rw-r--r--chrome/browser/autofill/phone_number.h28
10 files changed, 143 insertions, 147 deletions
diff --git a/chrome/browser/autofill/address.h b/chrome/browser/autofill/address.h
index 191dfa7..dea406a 100644
--- a/chrome/browser/autofill/address.h
+++ b/chrome/browser/autofill/address.h
@@ -39,13 +39,13 @@ class Address : public FormGroup {
// Vector of tokens in an address line.
typedef std::vector<string16> LineTokens;
- string16 line1() const { return line1_; }
- string16 line2() const { return line2_; }
- string16 apt_num() const { return apt_num_; }
- string16 city() const { return city_; }
- string16 state() const { return state_; }
- string16 country() const { return country_; }
- string16 zip_code() const { return zip_code_; }
+ const string16& line1() const { return line1_; }
+ const string16& line2() const { return line2_; }
+ const string16& apt_num() const { return apt_num_; }
+ const string16& city() const { return city_; }
+ const string16& state() const { return state_; }
+ const string16& country() const { return country_; }
+ const string16& zip_code() const { return zip_code_; }
void set_line1(const string16& line1);
void set_line2(const string16& line2);
diff --git a/chrome/browser/autofill/autofill_field.h b/chrome/browser/autofill/autofill_field.h
index 9ed87e2..2deb239 100644
--- a/chrome/browser/autofill/autofill_field.h
+++ b/chrome/browser/autofill/autofill_field.h
@@ -17,7 +17,7 @@ class AutoFillField : public webkit_glue::FormField {
AutoFillField(const webkit_glue::FormField& field,
const string16& unique_name);
- string16 unique_name() const { return unique_name_; }
+ const string16& unique_name() const { return unique_name_; }
AutoFillFieldType heuristic_type() const { return heuristic_type_; }
const FieldTypeSet& possible_types() const { return possible_types_; }
diff --git a/chrome/browser/autofill/autofill_profile.h b/chrome/browser/autofill/autofill_profile.h
index 168c790..613ff02 100644
--- a/chrome/browser/autofill/autofill_profile.h
+++ b/chrome/browser/autofill/autofill_profile.h
@@ -40,7 +40,7 @@ class AutoFillProfile : public FormGroup {
// Returns a copy of the profile it is called on. The caller is responsible
// for deleting profile when they are done with it.
virtual FormGroup* Clone() const;
- virtual string16 Label() const { return label_; }
+ virtual const string16& Label() const { return label_; }
// NOTE: callers must write the profile to the WebDB after changing the value
// of use_billing_address.
diff --git a/chrome/browser/autofill/contact_info.cc b/chrome/browser/autofill/contact_info.cc
index 37c5714..f77652a 100644
--- a/chrome/browser/autofill/contact_info.cc
+++ b/chrome/browser/autofill/contact_info.cc
@@ -120,6 +120,19 @@ void ContactInfo::SetInfo(const AutoFillType& type, const string16& value) {
NOTREACHED();
}
+ContactInfo::ContactInfo(const ContactInfo& contact_info)
+ : FormGroup(),
+ first_tokens_(contact_info.first_tokens_),
+ middle_tokens_(contact_info.middle_tokens_),
+ last_tokens_(contact_info.last_tokens_),
+ first_(contact_info.first_),
+ middle_(contact_info.middle_),
+ last_(contact_info.last_),
+ suffix_(contact_info.suffix_),
+ email_(contact_info.email_),
+ company_name_(contact_info.company_name_) {
+}
+
string16 ContactInfo::FullName() const {
if (first_.empty())
return string16();
@@ -149,19 +162,6 @@ string16 ContactInfo::MiddleInitial() const {
return initial;
}
-ContactInfo::ContactInfo(const ContactInfo& contact_info)
- : FormGroup(),
- first_tokens_(contact_info.first_tokens_),
- middle_tokens_(contact_info.middle_tokens_),
- last_tokens_(contact_info.last_tokens_),
- first_(contact_info.first_),
- middle_(contact_info.middle_),
- last_(contact_info.last_),
- suffix_(contact_info.suffix_),
- email_(contact_info.email_),
- company_name_(contact_info.company_name_) {
-}
-
bool ContactInfo::FindInfoMatchesHelper(const AutoFillFieldType& field_type,
const string16& info,
string16* match) const {
diff --git a/chrome/browser/autofill/contact_info.h b/chrome/browser/autofill/contact_info.h
index 957e55e..adbc66a 100644
--- a/chrome/browser/autofill/contact_info.h
+++ b/chrome/browser/autofill/contact_info.h
@@ -27,21 +27,24 @@ class ContactInfo : public FormGroup {
virtual string16 GetFieldText(const AutoFillType& type) const;
virtual void SetInfo(const AutoFillType& type, const string16& value);
+ private:
+ explicit ContactInfo(const ContactInfo& contact_info);
+ void operator=(const ContactInfo& info);
+
// Returns the full name, which can include up to the first, middle, middle
// initial, last name, and suffix.
string16 FullName() const;
- string16 first() const { return first_; }
- string16 middle() const { return middle_; }
- string16 last() const { return last_; }
+ // Returns the middle initial if |middle_| is non-empty. Returns an empty
+ // string otherwise.
string16 MiddleInitial() const;
- string16 suffix() const { return suffix_; }
- string16 email() const { return email_; }
- string16 company_name() const { return company_name_; }
- private:
- explicit ContactInfo(const ContactInfo& contact_info);
- void operator=(const ContactInfo& info);
+ const string16& first() const { return first_; }
+ const string16& middle() const { return middle_; }
+ const string16& last() const { return last_; }
+ const string16& suffix() const { return suffix_; }
+ const string16& email() const { return email_; }
+ const string16& company_name() const { return company_name_; }
// A helper function for FindInfoMatches that only handles matching the info
// with the requested field type.
diff --git a/chrome/browser/autofill/credit_card.cc b/chrome/browser/autofill/credit_card.cc
index 1d4ba55..8c6a3fd 100644
--- a/chrome/browser/autofill/credit_card.cc
+++ b/chrome/browser/autofill/credit_card.cc
@@ -203,65 +203,6 @@ void CreditCard::SetInfo(const AutoFillType& type, const string16& value) {
}
}
-string16 CreditCard::ExpirationMonthAsString() const {
- if (expiration_month_ == 0)
- return string16();
-
- string16 month = IntToString16(expiration_month_);
- if (expiration_month_ >= 10)
- return month;
-
- string16 zero = ASCIIToUTF16("0");
- zero.append(month);
- return zero;
-}
-
-string16 CreditCard::Expiration4DigitYearAsString() const {
- if (expiration_year_ == 0)
- return string16();
-
- return IntToString16(Expiration4DigitYear());
-}
-
-string16 CreditCard::Expiration2DigitYearAsString() const {
- if (expiration_year_ == 0)
- return string16();
-
- return IntToString16(Expiration2DigitYear());
-}
-
-void CreditCard::SetExpirationMonthFromString(const string16& text) {
- int month;
- if (!ConvertDate(text, &month))
- return;
-
- set_expiration_month(month);
-}
-
-void CreditCard::SetExpirationYearFromString(const string16& text) {
- int year;
- if (!ConvertDate(text, &year))
- return;
-
- set_expiration_year(year);
-}
-
-void CreditCard::set_expiration_month(int expiration_month) {
- if (expiration_month < 0 || expiration_month > 12)
- return;
-
- expiration_month_ = expiration_month;
-}
-
-void CreditCard::set_expiration_year(int expiration_year) {
- if (expiration_year != 0 &&
- (expiration_year < 2006 || expiration_year > 10000)) {
- return;
- }
-
- expiration_year_ = expiration_year;
-}
-
string16 CreditCard::PreviewSummary() const {
string16 preview;
if (number().empty())
@@ -327,6 +268,65 @@ bool CreditCard::operator!=(const CreditCard& creditcard) const {
return !operator==(creditcard);
}
+string16 CreditCard::ExpirationMonthAsString() const {
+ if (expiration_month_ == 0)
+ return string16();
+
+ string16 month = IntToString16(expiration_month_);
+ if (expiration_month_ >= 10)
+ return month;
+
+ string16 zero = ASCIIToUTF16("0");
+ zero.append(month);
+ return zero;
+}
+
+string16 CreditCard::Expiration4DigitYearAsString() const {
+ if (expiration_year_ == 0)
+ return string16();
+
+ return IntToString16(Expiration4DigitYear());
+}
+
+string16 CreditCard::Expiration2DigitYearAsString() const {
+ if (expiration_year_ == 0)
+ return string16();
+
+ return IntToString16(Expiration2DigitYear());
+}
+
+void CreditCard::SetExpirationMonthFromString(const string16& text) {
+ int month;
+ if (!ConvertDate(text, &month))
+ return;
+
+ set_expiration_month(month);
+}
+
+void CreditCard::SetExpirationYearFromString(const string16& text) {
+ int year;
+ if (!ConvertDate(text, &year))
+ return;
+
+ set_expiration_year(year);
+}
+
+void CreditCard::set_expiration_month(int expiration_month) {
+ if (expiration_month < 0 || expiration_month > 12)
+ return;
+
+ expiration_month_ = expiration_month;
+}
+
+void CreditCard::set_expiration_year(int expiration_year) {
+ if (expiration_year != 0 &&
+ (expiration_year < 2006 || expiration_year > 10000)) {
+ return;
+ }
+
+ expiration_year_ = expiration_year;
+}
+
bool CreditCard::FindInfoMatchesHelper(const AutoFillFieldType& field_type,
const string16& info,
string16* match) const {
diff --git a/chrome/browser/autofill/credit_card.h b/chrome/browser/autofill/credit_card.h
index c1cd0cf..ec1bd6e 100644
--- a/chrome/browser/autofill/credit_card.h
+++ b/chrome/browser/autofill/credit_card.h
@@ -28,8 +28,35 @@ class CreditCard : public FormGroup {
virtual string16 GetFieldText(const AutoFillType& type) const;
virtual string16 GetPreviewText(const AutoFillType& type) const;
virtual void SetInfo(const AutoFillType& type, const string16& value);
- string16 Label() const { return label_; }
+ const string16& Label() const { return label_; }
+ // Credit card preview summary, for example: ******1234, Exp: 01/2020
+ string16 PreviewSummary() const;
+
+ const string16& billing_address() const { return billing_address_; }
+ const string16& shipping_address() const { return shipping_address_; }
+ int unique_id() const { return unique_id_; }
+
+ // The caller should verify that the corresponding AutoFillProfile exists. If
+ // the shipping address should be the same as the billing address, send in an
+ // empty string to set_shipping_address.
+ void set_billing_address(const string16& address) {
+ billing_address_ = address;
+ }
+ void set_shipping_address(const string16& address) {
+ shipping_address_ = address;
+ }
+ void set_unique_id(int id) { unique_id_ = id; }
+
+ // For use in STL containers.
+ void operator=(const CreditCard&);
+
+ // Used by tests.
+ bool operator==(const CreditCard& creditcard) const;
+ bool operator!=(const CreditCard& creditcard) const;
+ void set_label(const string16& label) { label_ = label; }
+
+ private:
// The month and year are zero if not present.
int Expiration4DigitYear() const { return expiration_year_; }
int Expiration2DigitYear() const { return expiration_year_ % 100; }
@@ -43,16 +70,13 @@ class CreditCard : public FormGroup {
// Sets |expiration_year_| to the integer conversion of |text|.
void SetExpirationYearFromString(const string16& text);
- string16 number() const { return number_; }
- string16 name_on_card() const { return name_on_card_; }
- string16 type() const { return type_; }
- string16 verification_code() const { return verification_code_; }
- string16 last_four_digits() const { return last_four_digits_; }
+ const string16& number() const { return number_; }
+ const string16& name_on_card() const { return name_on_card_; }
+ const string16& type() const { return type_; }
+ const string16& verification_code() const { return verification_code_; }
+ const string16& last_four_digits() const { return last_four_digits_; }
int expiration_month() const { return expiration_month_; }
int expiration_year() const { return expiration_year_; }
- string16 billing_address() const { return billing_address_; }
- string16 shipping_address() const { return shipping_address_; }
- int unique_id() const { return unique_id_; }
void set_number(const string16& number) { number_ = number; }
void set_name_on_card(const string16& name_on_card) {
@@ -65,35 +89,12 @@ class CreditCard : public FormGroup {
void set_last_four_digits(const string16& last_four_digits) {
last_four_digits_ = last_four_digits;
}
- void set_unique_id(int id) { unique_id_ = id; }
-
- // The caller should verify that the corresponding AutoFillProfile exists. If
- // the shipping address should be the same as the billing address, send in an
- // empty string to set_shipping_address.
- void set_billing_address(const string16& address) {
- billing_address_ = address;
- }
- void set_shipping_address(const string16& address) {
- shipping_address_ = address;
- }
// These setters verify that the month and year are within appropriate
// ranges.
void set_expiration_month(int expiration_month);
void set_expiration_year(int expiration_year);
- // Credit card preview summary, for example: ******1234, Exp: 01/2020
- string16 PreviewSummary() const;
-
- // For use in STL containers.
- void operator=(const CreditCard&);
-
- // Used by tests.
- bool operator==(const CreditCard& creditcard) const;
- bool operator!=(const CreditCard& creditcard) const;
- void set_label(const string16& label) { label_ = label; }
-
- private:
// A helper function for FindInfoMatches that only handles matching the info
// with the requested field type.
bool FindInfoMatchesHelper(const AutoFillFieldType& field_type,
diff --git a/chrome/browser/autofill/credit_card_unittest.cc b/chrome/browser/autofill/credit_card_unittest.cc
index 7dab4ff..72b2a993 100644
--- a/chrome/browser/autofill/credit_card_unittest.cc
+++ b/chrome/browser/autofill/credit_card_unittest.cc
@@ -9,20 +9,10 @@
namespace {
-// Unit tests for autofill |CreditCard| class.
-class CreditCardTest : public testing::Test {
- protected:
- CreditCardTest() {
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(CreditCardTest);
-};
-
// Tests credit card summary string generation. This test simulates a variety
// of different possible summary strings. Variations occur based on the
// existence of credit card number, month, and year fields.
-TEST_F(CreditCardTest, PreviewSummaryString) {
+TEST(CreditCardTest, PreviewSummaryString) {
// Case 0: empty credit card.
CreditCard credit_card0(string16(), 0);
string16 summary0 = credit_card0.PreviewSummary();
diff --git a/chrome/browser/autofill/form_group.h b/chrome/browser/autofill/form_group.h
index d48402f..e14a040 100644
--- a/chrome/browser/autofill/form_group.h
+++ b/chrome/browser/autofill/form_group.h
@@ -49,7 +49,7 @@ class FormGroup {
// Returns the label for this FormGroup item. This should be overridden for
// form group items that implement a label.
- virtual string16 Label() const { return string16(); }
+ virtual const string16& Label() const { return EmptyString16(); }
};
#endif // CHROME_BROWSER_AUTOFILL_FORM_GROUP_H_
diff --git a/chrome/browser/autofill/phone_number.h b/chrome/browser/autofill/phone_number.h
index 0850a94..c7cfc59 100644
--- a/chrome/browser/autofill/phone_number.h
+++ b/chrome/browser/autofill/phone_number.h
@@ -26,10 +26,16 @@ class PhoneNumber : public FormGroup {
virtual string16 GetFieldText(const AutoFillType& type) const;
virtual void SetInfo(const AutoFillType& type, const string16& value);
- string16 country_code() const { return country_code_; }
- string16 city_code() const { return city_code_; }
- string16 number() const { return number_; }
- string16 extension() const { return extension_; }
+ protected:
+ explicit PhoneNumber(const PhoneNumber& phone_number);
+
+ private:
+ void operator=(const PhoneNumber& phone_number);
+
+ const string16& country_code() const { return country_code_; }
+ const string16& city_code() const { return city_code_; }
+ const string16& number() const { return number_; }
+ const string16& extension() const { return extension_; }
string16 CityAndNumber() const { return city_code_ + number_; }
// Returns the entire phone number as a string, without punctuation.
@@ -42,10 +48,6 @@ class PhoneNumber : public FormGroup {
void set_number(const string16& number);
void set_extension(const string16& extension) { extension_ = extension; }
- protected:
- explicit PhoneNumber(const PhoneNumber& phone_number);
- void operator=(const PhoneNumber& phone_number);
-
// A helper function for FindInfoMatches that only handles matching the info
// with the requested field type.
bool FindInfoMatchesHelper(const FieldTypeSubGroup& subgroup,
@@ -54,11 +56,11 @@ class PhoneNumber : public FormGroup {
// The numbers will be digits only (no punctuation), so any call to the IsX()
// functions should first call StripPunctuation on the text.
- virtual bool IsNumber(const string16& text) const;
- virtual bool IsCityCode(const string16& text) const;
- virtual bool IsCountryCode(const string16& text) const;
- virtual bool IsCityAndNumber(const string16& text) const;
- virtual bool IsWholeNumber(const string16& text) const;
+ bool IsNumber(const string16& text) const;
+ bool IsCityCode(const string16& text) const;
+ bool IsCountryCode(const string16& text) const;
+ bool IsCityAndNumber(const string16& text) const;
+ bool IsWholeNumber(const string16& text) const;
// The following functions should return the field type for each part of the
// phone number. Currently, these are either fax or home phone number types.