OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/browser/form_group.h" | 5 #include "components/autofill/browser/autofill_data_model.h" |
6 | |
7 #include <algorithm> | |
8 #include <iterator> | |
9 | 6 |
10 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
11 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" |
12 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
13 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
14 #include "components/autofill/browser/autofill_country.h" | 12 #include "components/autofill/browser/autofill_country.h" |
| 13 #include "components/autofill/browser/autofill_field.h" |
15 #include "components/autofill/browser/state_names.h" | 14 #include "components/autofill/browser/state_names.h" |
16 #include "components/autofill/browser/validation.h" | 15 #include "components/autofill/browser/validation.h" |
17 #include "components/autofill/common/form_field_data.h" | 16 #include "components/autofill/common/form_field_data.h" |
18 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
20 | 19 |
21 namespace autofill { | 20 namespace autofill { |
22 namespace { | 21 namespace { |
23 | 22 |
24 const char* const kMonthsAbbreviated[] = { | 23 const char* const kMonthsAbbreviated[] = { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 113 |
115 // For American Express, also try filling as "AmEx". | 114 // For American Express, also try filling as "AmEx". |
116 if (value == l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX)) | 115 if (value == l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX)) |
117 return FillCreditCardTypeSelectControl(ASCIIToUTF16("AmEx"), field); | 116 return FillCreditCardTypeSelectControl(ASCIIToUTF16("AmEx"), field); |
118 | 117 |
119 return false; | 118 return false; |
120 } | 119 } |
121 | 120 |
122 } // namespace | 121 } // namespace |
123 | 122 |
124 std::string FormGroup::GetGUID() const { | 123 AutofillDataModel::AutofillDataModel(const std::string& guid) : guid_(guid) {} |
125 NOTREACHED(); | 124 AutofillDataModel::~AutofillDataModel() {} |
126 return std::string(); | |
127 } | |
128 | 125 |
129 void FormGroup::GetMatchingTypes(const base::string16& text, | 126 void AutofillDataModel::FillSelectControl(AutofillFieldType type, |
130 const std::string& app_locale, | 127 const std::string& app_locale, |
131 FieldTypeSet* matching_types) const { | 128 FormFieldData* field) const { |
132 if (text.empty()) { | |
133 matching_types->insert(EMPTY_TYPE); | |
134 return; | |
135 } | |
136 | |
137 FieldTypeSet types; | |
138 GetSupportedTypes(&types); | |
139 for (FieldTypeSet::const_iterator type = types.begin(); | |
140 type != types.end(); ++type) { | |
141 // TODO(isherman): Matches are case-sensitive for now. Let's keep an eye on | |
142 // this and decide whether there are compelling reasons to add case- | |
143 // insensitivity. | |
144 if (GetInfo(*type, app_locale) == text) | |
145 matching_types->insert(*type); | |
146 } | |
147 } | |
148 | |
149 void FormGroup::GetNonEmptyTypes(const std::string& app_locale, | |
150 FieldTypeSet* non_empty_types) const { | |
151 FieldTypeSet types; | |
152 GetSupportedTypes(&types); | |
153 for (FieldTypeSet::const_iterator type = types.begin(); | |
154 type != types.end(); ++type) { | |
155 if (!GetInfo(*type, app_locale).empty()) | |
156 non_empty_types->insert(*type); | |
157 } | |
158 } | |
159 | |
160 base::string16 FormGroup::GetInfo(AutofillFieldType type, | |
161 const std::string& app_locale) const { | |
162 return GetRawInfo(type); | |
163 } | |
164 | |
165 bool FormGroup::SetInfo(AutofillFieldType type, | |
166 const base::string16& value, | |
167 const std::string& app_locale) { | |
168 SetRawInfo(type, value); | |
169 return true; | |
170 } | |
171 | |
172 void FormGroup::FillFormField(const AutofillField& field, | |
173 size_t variant, | |
174 const std::string& app_locale, | |
175 FormFieldData* field_data) const { | |
176 NOTREACHED(); | |
177 } | |
178 | |
179 void FormGroup::FillSelectControl(AutofillFieldType type, | |
180 const std::string& app_locale, | |
181 FormFieldData* field) const { | |
182 DCHECK(field); | 129 DCHECK(field); |
183 DCHECK_EQ("select-one", field->form_control_type); | 130 DCHECK_EQ("select-one", field->form_control_type); |
184 DCHECK_EQ(field->option_values.size(), field->option_contents.size()); | 131 DCHECK_EQ(field->option_values.size(), field->option_contents.size()); |
185 | 132 |
186 base::string16 field_text = GetInfo(type, app_locale); | 133 base::string16 field_text = GetInfo(type, app_locale); |
187 base::string16 field_text_lower = StringToLowerASCII(field_text); | 134 base::string16 field_text_lower = StringToLowerASCII(field_text); |
188 if (field_text.empty()) | 135 if (field_text.empty()) |
189 return; | 136 return; |
190 | 137 |
191 base::string16 value; | 138 base::string16 value; |
(...skipping 27 matching lines...) Expand all Loading... |
219 } else if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR) { | 166 } else if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR) { |
220 // Attempt to fill the year as a 2-digit year. This compensates for the | 167 // Attempt to fill the year as a 2-digit year. This compensates for the |
221 // fact that our heuristics do not always correctly detect when a website | 168 // fact that our heuristics do not always correctly detect when a website |
222 // requests a 2-digit rather than a 4-digit year. | 169 // requests a 2-digit rather than a 4-digit year. |
223 FillSelectControl(CREDIT_CARD_EXP_2_DIGIT_YEAR, app_locale, field); | 170 FillSelectControl(CREDIT_CARD_EXP_2_DIGIT_YEAR, app_locale, field); |
224 } else if (type == CREDIT_CARD_TYPE) { | 171 } else if (type == CREDIT_CARD_TYPE) { |
225 FillCreditCardTypeSelectControl(field_text, field); | 172 FillCreditCardTypeSelectControl(field_text, field); |
226 } | 173 } |
227 } | 174 } |
228 | 175 |
229 bool FormGroup::FillCountrySelectControl(const std::string& app_locale, | 176 bool AutofillDataModel::FillCountrySelectControl( |
230 FormFieldData* field_data) const { | 177 const std::string& app_locale, |
| 178 FormFieldData* field_data) const { |
231 return false; | 179 return false; |
232 } | 180 } |
233 | 181 |
234 } // namespace autofill | 182 } // namespace autofill |
OLD | NEW |