OLD | NEW |
1 // Copyright 2013 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/core/browser/autofill_data_model.h" | 5 #include "components/autofill/core/browser/autofill_data_model.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "components/autofill/core/browser/autofill_country.h" | 12 #include "components/autofill/core/browser/autofill_country.h" |
13 #include "components/autofill/core/browser/autofill_field.h" | 13 #include "components/autofill/core/browser/autofill_field.h" |
| 14 #include "components/autofill/core/browser/autofill_type.h" |
14 #include "components/autofill/core/browser/state_names.h" | 15 #include "components/autofill/core/browser/state_names.h" |
15 #include "components/autofill/core/browser/validation.h" | 16 #include "components/autofill/core/browser/validation.h" |
16 #include "components/autofill/core/common/form_field_data.h" | 17 #include "components/autofill/core/common/form_field_data.h" |
17 #include "grit/component_strings.h" | 18 #include "grit/component_strings.h" |
18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
21 namespace autofill { | 22 namespace autofill { |
22 namespace { | 23 namespace { |
23 | 24 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 117 } |
117 | 118 |
118 } // namespace | 119 } // namespace |
119 | 120 |
120 AutofillDataModel::AutofillDataModel(const std::string& guid, | 121 AutofillDataModel::AutofillDataModel(const std::string& guid, |
121 const std::string& origin) | 122 const std::string& origin) |
122 : guid_(guid), | 123 : guid_(guid), |
123 origin_(origin) {} | 124 origin_(origin) {} |
124 AutofillDataModel::~AutofillDataModel() {} | 125 AutofillDataModel::~AutofillDataModel() {} |
125 | 126 |
126 void AutofillDataModel::FillSelectControl(AutofillFieldType type, | 127 void AutofillDataModel::FillSelectControl(const AutofillType& type, |
127 const std::string& app_locale, | 128 const std::string& app_locale, |
128 FormFieldData* field) const { | 129 FormFieldData* field) const { |
129 DCHECK(field); | 130 DCHECK(field); |
130 DCHECK_EQ("select-one", field->form_control_type); | 131 DCHECK_EQ("select-one", field->form_control_type); |
131 DCHECK_EQ(field->option_values.size(), field->option_contents.size()); | 132 DCHECK_EQ(field->option_values.size(), field->option_contents.size()); |
132 | 133 |
133 base::string16 field_text = GetInfo(type, app_locale); | 134 base::string16 field_text = GetInfo(type, app_locale); |
134 base::string16 field_text_lower = StringToLowerASCII(field_text); | 135 base::string16 field_text_lower = StringToLowerASCII(field_text); |
135 if (field_text.empty()) | 136 if (field_text.empty()) |
136 return; | 137 return; |
(...skipping 13 matching lines...) Expand all Loading... |
150 // not found. | 151 // not found. |
151 value = field->option_values[i]; | 152 value = field->option_values[i]; |
152 } | 153 } |
153 } | 154 } |
154 | 155 |
155 if (!value.empty()) { | 156 if (!value.empty()) { |
156 field->value = value; | 157 field->value = value; |
157 return; | 158 return; |
158 } | 159 } |
159 | 160 |
160 if (type == ADDRESS_HOME_STATE || type == ADDRESS_BILLING_STATE) { | 161 ServerFieldType server_type = type.server_type(); |
| 162 if (server_type == ADDRESS_HOME_STATE || |
| 163 server_type == ADDRESS_BILLING_STATE) { |
161 FillStateSelectControl(field_text, field); | 164 FillStateSelectControl(field_text, field); |
162 } else if (type == ADDRESS_HOME_COUNTRY || type == ADDRESS_BILLING_COUNTRY) { | 165 } else if (server_type == ADDRESS_HOME_COUNTRY || |
| 166 server_type == ADDRESS_BILLING_COUNTRY) { |
163 FillCountrySelectControl(app_locale, field); | 167 FillCountrySelectControl(app_locale, field); |
164 } else if (type == CREDIT_CARD_EXP_MONTH) { | 168 } else if (server_type == CREDIT_CARD_EXP_MONTH) { |
165 FillExpirationMonthSelectControl(field_text, field); | 169 FillExpirationMonthSelectControl(field_text, field); |
166 } else if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR) { | 170 } else if (server_type == CREDIT_CARD_EXP_4_DIGIT_YEAR) { |
167 // Attempt to fill the year as a 2-digit year. This compensates for the | 171 // Attempt to fill the year as a 2-digit year. This compensates for the |
168 // fact that our heuristics do not always correctly detect when a website | 172 // fact that our heuristics do not always correctly detect when a website |
169 // requests a 2-digit rather than a 4-digit year. | 173 // requests a 2-digit rather than a 4-digit year. |
170 FillSelectControl(CREDIT_CARD_EXP_2_DIGIT_YEAR, app_locale, field); | 174 FillSelectControl(AutofillType(CREDIT_CARD_EXP_2_DIGIT_YEAR), app_locale, |
171 } else if (type == CREDIT_CARD_TYPE) { | 175 field); |
| 176 } else if (server_type == CREDIT_CARD_TYPE) { |
172 FillCreditCardTypeSelectControl(field_text, field); | 177 FillCreditCardTypeSelectControl(field_text, field); |
173 } | 178 } |
174 } | 179 } |
175 | 180 |
176 bool AutofillDataModel::FillCountrySelectControl( | 181 bool AutofillDataModel::FillCountrySelectControl( |
177 const std::string& app_locale, | 182 const std::string& app_locale, |
178 FormFieldData* field_data) const { | 183 FormFieldData* field_data) const { |
179 return false; | 184 return false; |
180 } | 185 } |
181 | 186 |
182 bool AutofillDataModel::IsVerified() const { | 187 bool AutofillDataModel::IsVerified() const { |
183 return !origin_.empty() && !GURL(origin_).is_valid(); | 188 return !origin_.empty() && !GURL(origin_).is_valid(); |
184 } | 189 } |
185 | 190 |
186 } // namespace autofill | 191 } // namespace autofill |
OLD | NEW |