| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", | 118 "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 // Returns true if the value was successfully set, meaning |value| was found in | 121 // Returns true if the value was successfully set, meaning |value| was found in |
| 122 // the list of select options in |field|. | 122 // the list of select options in |field|. |
| 123 bool SetSelectControlValue(const string16& value, | 123 bool SetSelectControlValue(const string16& value, |
| 124 webkit_glue::FormField* field) { | 124 webkit_glue::FormField* field) { |
| 125 string16 value_lowercase = StringToLowerASCII(value); | 125 string16 value_lowercase = StringToLowerASCII(value); |
| 126 | 126 |
| 127 for (std::vector<string16>::const_iterator iter = | 127 for (std::vector<string16>::const_iterator iter = |
| 128 field->option_strings().begin(); | 128 field->option_strings.begin(); |
| 129 iter != field->option_strings().end(); ++iter) { | 129 iter != field->option_strings.end(); ++iter) { |
| 130 if (value_lowercase == StringToLowerASCII(*iter)) { | 130 if (value_lowercase == StringToLowerASCII(*iter)) { |
| 131 field->set_value(*iter); | 131 field->value = *iter; |
| 132 return true; | 132 return true; |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 return false; | 136 return false; |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool FillStateSelectControl(const string16& value, | 139 bool FillStateSelectControl(const string16& value, |
| 140 webkit_glue::FormField* field) { | 140 webkit_glue::FormField* field) { |
| 141 string16 abbrev, full; | 141 string16 abbrev, full; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool FillCountrySelectControl(const FormGroup& form_group, | 160 bool FillCountrySelectControl(const FormGroup& form_group, |
| 161 webkit_glue::FormField* field) { | 161 webkit_glue::FormField* field) { |
| 162 const AutoFillProfile& profile = | 162 const AutoFillProfile& profile = |
| 163 static_cast<const AutoFillProfile&>(form_group); | 163 static_cast<const AutoFillProfile&>(form_group); |
| 164 std::string country_code = profile.CountryCode(); | 164 std::string country_code = profile.CountryCode(); |
| 165 std::string app_locale = AutofillCountry::ApplicationLocale(); | 165 std::string app_locale = AutofillCountry::ApplicationLocale(); |
| 166 | 166 |
| 167 for (std::vector<string16>::const_iterator iter = | 167 for (std::vector<string16>::const_iterator iter = |
| 168 field->option_strings().begin(); | 168 field->option_strings.begin(); |
| 169 iter != field->option_strings().end(); | 169 iter != field->option_strings.end(); |
| 170 ++iter) { | 170 ++iter) { |
| 171 // Canonicalize each <option> value to a country code, and compare to the | 171 // Canonicalize each <option> value to a country code, and compare to the |
| 172 // target country code. | 172 // target country code. |
| 173 if (country_code == AutofillCountry::GetCountryCode(*iter, app_locale)) { | 173 if (country_code == AutofillCountry::GetCountryCode(*iter, app_locale)) { |
| 174 field->set_value(*iter); | 174 field->value = *iter; |
| 175 return true; | 175 return true; |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 return false; | 179 return false; |
| 180 } | 180 } |
| 181 | 181 |
| 182 bool FillExpirationMonthSelectControl(const string16& value, | 182 bool FillExpirationMonthSelectControl(const string16& value, |
| 183 webkit_glue::FormField* field) { | 183 webkit_glue::FormField* field) { |
| 184 int index = 0; | 184 int index = 0; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 AutofillType 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->set_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.field_type() == ADDRESS_HOME_STATE || |
| 233 type.field_type() == ADDRESS_BILLING_STATE) { | 233 type.field_type() == ADDRESS_BILLING_STATE) { |
| 234 FillStateSelectControl(field_text, field); | 234 FillStateSelectControl(field_text, field); |
| 235 } else if (type.field_type() == ADDRESS_HOME_COUNTRY || | 235 } else if (type.field_type() == ADDRESS_HOME_COUNTRY || |
| 236 type.field_type() == ADDRESS_BILLING_COUNTRY) { | 236 type.field_type() == ADDRESS_BILLING_COUNTRY) { |
| 237 FillCountrySelectControl(form_group, field); | 237 FillCountrySelectControl(form_group, field); |
| 238 } else if (type.field_type() == CREDIT_CARD_EXP_MONTH) { | 238 } else if (type.field_type() == CREDIT_CARD_EXP_MONTH) { |
| 239 FillExpirationMonthSelectControl(field_text, field); | 239 FillExpirationMonthSelectControl(field_text, field); |
| 240 } | 240 } |
| 241 | 241 |
| 242 return; | 242 return; |
| 243 } | 243 } |
| 244 | 244 |
| 245 } // namespace autofill | 245 } // namespace autofill |
| OLD | NEW |