| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/autofill/select_control_handler.h" | 5 #include "chrome/browser/autofill/select_control_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 SetSelectControlValue(ASCIIToUTF16(kMonthsFull[index]), field) || | 192 SetSelectControlValue(ASCIIToUTF16(kMonthsFull[index]), field) || |
| 193 SetSelectControlValue(ASCIIToUTF16(kMonthsNumeric[index]), field); | 193 SetSelectControlValue(ASCIIToUTF16(kMonthsNumeric[index]), field); |
| 194 return filled; | 194 return filled; |
| 195 } | 195 } |
| 196 | 196 |
| 197 } // namespace | 197 } // namespace |
| 198 | 198 |
| 199 namespace autofill { | 199 namespace autofill { |
| 200 | 200 |
| 201 void FillSelectControl(const FormGroup& form_group, | 201 void FillSelectControl(const FormGroup& form_group, |
| 202 AutofillType type, | 202 AutofillFieldType type, |
| 203 webkit_glue::FormField* field) { | 203 webkit_glue::FormField* field) { |
| 204 DCHECK(field); | 204 DCHECK(field); |
| 205 DCHECK_EQ(ASCIIToUTF16("select-one"), field->form_control_type); | 205 DCHECK_EQ(ASCIIToUTF16("select-one"), field->form_control_type); |
| 206 | 206 |
| 207 string16 field_text = form_group.GetFieldText(type); | 207 string16 field_text = form_group.GetFieldText(type); |
| 208 if (field_text.empty()) | 208 if (field_text.empty()) |
| 209 return; | 209 return; |
| 210 | 210 |
| 211 string16 value; | 211 string16 value; |
| 212 for (size_t i = 0; i < field->option_strings.size(); ++i) { | 212 for (size_t i = 0; i < field->option_strings.size(); ++i) { |
| 213 if (field_text == field->option_strings[i]) { | 213 if (field_text == field->option_strings[i]) { |
| 214 // An exact match, use it. | 214 // An exact match, use it. |
| 215 value = field_text; | 215 value = field_text; |
| 216 break; | 216 break; |
| 217 } | 217 } |
| 218 | 218 |
| 219 if (StringToLowerASCII(field->option_strings[i]) == | 219 if (StringToLowerASCII(field->option_strings[i]) == |
| 220 StringToLowerASCII(field_text)) { | 220 StringToLowerASCII(field_text)) { |
| 221 // A match, but not in the same case. Save it in case an exact match is | 221 // A match, but not in the same case. Save it in case an exact match is |
| 222 // not found. | 222 // not found. |
| 223 value = field->option_strings[i]; | 223 value = field->option_strings[i]; |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| 227 if (!value.empty()) { | 227 if (!value.empty()) { |
| 228 field->value = value; | 228 field->value = value; |
| 229 return; | 229 return; |
| 230 } | 230 } |
| 231 | 231 |
| 232 if (type.field_type() == ADDRESS_HOME_STATE || | 232 if (type == ADDRESS_HOME_STATE || type == ADDRESS_BILLING_STATE) |
| 233 type.field_type() == ADDRESS_BILLING_STATE) { | |
| 234 FillStateSelectControl(field_text, field); | 233 FillStateSelectControl(field_text, field); |
| 235 } else if (type.field_type() == ADDRESS_HOME_COUNTRY || | 234 else if (type == ADDRESS_HOME_COUNTRY || type == ADDRESS_BILLING_COUNTRY) |
| 236 type.field_type() == ADDRESS_BILLING_COUNTRY) { | |
| 237 FillCountrySelectControl(form_group, field); | 235 FillCountrySelectControl(form_group, field); |
| 238 } else if (type.field_type() == CREDIT_CARD_EXP_MONTH) { | 236 else if (type == CREDIT_CARD_EXP_MONTH) |
| 239 FillExpirationMonthSelectControl(field_text, field); | 237 FillExpirationMonthSelectControl(field_text, field); |
| 240 } | |
| 241 | 238 |
| 242 return; | 239 return; |
| 243 } | 240 } |
| 244 | 241 |
| 245 } // namespace autofill | 242 } // namespace autofill |
| OLD | NEW |