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_field.h" | 5 #include "components/autofill/core/browser/autofill_field.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "components/autofill/core/browser/autofill_country.h" | 13 #include "components/autofill/core/browser/autofill_country.h" |
14 #include "components/autofill/core/browser/autofill_type.h" | 14 #include "components/autofill/core/browser/autofill_type.h" |
15 #include "components/autofill/core/browser/phone_number.h" | 15 #include "components/autofill/core/browser/phone_number.h" |
16 #include "components/autofill/core/browser/state_names.h" | 16 #include "components/autofill/core/browser/state_names.h" |
17 #include "grit/component_strings.h" | 17 #include "grit/component_strings.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 | 19 |
| 20 using base::ASCIIToUTF16; |
20 using base::StringToInt; | 21 using base::StringToInt; |
21 | 22 |
22 namespace autofill { | 23 namespace autofill { |
23 namespace { | 24 namespace { |
24 | 25 |
25 const char* const kMonthsAbbreviated[] = { | 26 const char* const kMonthsAbbreviated[] = { |
26 NULL, // Padding so index 1 = month 1 = January. | 27 NULL, // Padding so index 1 = month 1 = January. |
27 "Jan", "Feb", "Mar", "Apr", "May", "Jun", | 28 "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
28 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", | 29 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", |
29 }; | 30 }; |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 return AutofillType(server_type_); | 372 return AutofillType(server_type_); |
372 | 373 |
373 return AutofillType(heuristic_type_); | 374 return AutofillType(heuristic_type_); |
374 } | 375 } |
375 | 376 |
376 bool AutofillField::IsEmpty() const { | 377 bool AutofillField::IsEmpty() const { |
377 return value.empty(); | 378 return value.empty(); |
378 } | 379 } |
379 | 380 |
380 std::string AutofillField::FieldSignature() const { | 381 std::string AutofillField::FieldSignature() const { |
381 std::string field_name = UTF16ToUTF8(name); | 382 std::string field_name = base::UTF16ToUTF8(name); |
382 std::string field_string = field_name + "&" + form_control_type; | 383 std::string field_string = field_name + "&" + form_control_type; |
383 return Hash32Bit(field_string); | 384 return Hash32Bit(field_string); |
384 } | 385 } |
385 | 386 |
386 bool AutofillField::IsFieldFillable() const { | 387 bool AutofillField::IsFieldFillable() const { |
387 return !Type().IsUnknown(); | 388 return !Type().IsUnknown(); |
388 } | 389 } |
389 | 390 |
390 // static | 391 // static |
391 void AutofillField::FillFormField(const AutofillField& field, | 392 void AutofillField::FillFormField(const AutofillField& field, |
392 const base::string16& value, | 393 const base::string16& value, |
393 const std::string& app_locale, | 394 const std::string& app_locale, |
394 FormFieldData* field_data) { | 395 FormFieldData* field_data) { |
395 AutofillType type = field.Type(); | 396 AutofillType type = field.Type(); |
396 | 397 |
397 if (type.GetStorableType() == PHONE_HOME_NUMBER) | 398 if (type.GetStorableType() == PHONE_HOME_NUMBER) |
398 FillPhoneNumberField(field, value, field_data); | 399 FillPhoneNumberField(field, value, field_data); |
399 else if (field_data->form_control_type == "select-one") | 400 else if (field_data->form_control_type == "select-one") |
400 FillSelectControl(type, value, app_locale, field_data); | 401 FillSelectControl(type, value, app_locale, field_data); |
401 else if (field_data->form_control_type == "month") | 402 else if (field_data->form_control_type == "month") |
402 FillMonthControl(value, field_data); | 403 FillMonthControl(value, field_data); |
403 else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) | 404 else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) |
404 FillStreetAddress(value, field_data); | 405 FillStreetAddress(value, field_data); |
405 else | 406 else |
406 field_data->value = value; | 407 field_data->value = value; |
407 } | 408 } |
408 | 409 |
409 } // namespace autofill | 410 } // namespace autofill |
OLD | NEW |