Chromium Code Reviews| 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" |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 | 273 |
| 274 return false; | 274 return false; |
| 275 } | 275 } |
| 276 | 276 |
| 277 // Set |field_data|'s value to |number|, or possibly an appropriate substring of | 277 // Set |field_data|'s value to |number|, or possibly an appropriate substring of |
| 278 // |number|. The |field| specifies the type of the phone and whether this is a | 278 // |number|. The |field| specifies the type of the phone and whether this is a |
| 279 // phone prefix or suffix. | 279 // phone prefix or suffix. |
| 280 void FillPhoneNumberField(const AutofillField& field, | 280 void FillPhoneNumberField(const AutofillField& field, |
| 281 const base::string16& number, | 281 const base::string16& number, |
| 282 FormFieldData* field_data) { | 282 FormFieldData* field_data) { |
| 283 // Check to see if the size field matches the "prefix" or "suffix" sizes and | 283 base::string16 value; |
| 284 // fill accordingly. | 284 AutofillField::GetPhoneNumberValue(field, number, field_data, &value); |
| 285 base::string16 value = number; | |
| 286 if (number.length() == | |
| 287 PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { | |
| 288 if (field.phone_part() == AutofillField::PHONE_PREFIX || | |
| 289 field_data->max_length == PhoneNumber::kPrefixLength) { | |
| 290 value = number.substr(PhoneNumber::kPrefixOffset, | |
| 291 PhoneNumber::kPrefixLength); | |
| 292 } else if (field.phone_part() == AutofillField::PHONE_SUFFIX || | |
| 293 field_data->max_length == PhoneNumber::kSuffixLength) { | |
| 294 value = number.substr(PhoneNumber::kSuffixOffset, | |
| 295 PhoneNumber::kSuffixLength); | |
| 296 } | |
| 297 } | |
| 298 | 285 |
| 299 field_data->value = value; | 286 field_data->value = value; |
|
Ilya Sherman
2014/09/03 00:55:49
nit: You can shorten this to
AutofillField::Ge
ziran.sun
2014/09/04 13:10:25
Done.
| |
| 300 } | 287 } |
| 301 | 288 |
| 302 // Fills in the select control |field| with |value|. If an exact match is not | 289 // Fills in the select control |field| with |value|. If an exact match is not |
| 303 // found, falls back to alternate filling strategies based on the |type|. | 290 // found, falls back to alternate filling strategies based on the |type|. |
| 304 bool FillSelectControl(const AutofillType& type, | 291 bool FillSelectControl(const AutofillType& type, |
| 305 const base::string16& value, | 292 const base::string16& value, |
| 306 const std::string& app_locale, | 293 const std::string& app_locale, |
| 307 FormFieldData* field) { | 294 FormFieldData* field) { |
| 308 DCHECK_EQ("select-one", field->form_control_type); | 295 DCHECK_EQ("select-one", field->form_control_type); |
| 309 | 296 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 return FillMonthControl(value, field_data); | 473 return FillMonthControl(value, field_data); |
| 487 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { | 474 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { |
| 488 FillStreetAddress(value, address_language_code, field_data); | 475 FillStreetAddress(value, address_language_code, field_data); |
| 489 return true; | 476 return true; |
| 490 } | 477 } |
| 491 | 478 |
| 492 field_data->value = value; | 479 field_data->value = value; |
| 493 return true; | 480 return true; |
| 494 } | 481 } |
| 495 | 482 |
| 483 // Get value for phone number. The value could be |number|, or possibly an | |
| 484 // appropriate substring of |number| if it's for phone prefix or suffix field. | |
| 485 void AutofillField::GetPhoneNumberValue(const AutofillField& field, | |
| 486 const base::string16& number, | |
| 487 FormFieldData* field_data, | |
| 488 base::string16* value) { | |
| 489 // Check to see if the size field matches the "prefix" or "suffix" sizes and | |
| 490 // substract the value accordingly. | |
|
Ilya Sherman
2014/09/03 00:55:49
nit: Let's update this to something like "Check to
ziran.sun
2014/09/04 13:10:25
Done.
| |
| 491 *value = number; | |
| 492 if (number.length() == | |
| 493 PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { | |
|
Ilya Sherman
2014/09/03 00:55:49
nit: Please indent this line by four more spaces.
ziran.sun
2014/09/04 13:10:25
Done.
| |
| 494 if (field.phone_part() == AutofillField::PHONE_PREFIX || | |
| 495 field_data->max_length == PhoneNumber::kPrefixLength) { | |
| 496 *value = | |
| 497 number.substr(PhoneNumber::kPrefixOffset, PhoneNumber::kPrefixLength); | |
| 498 } else if (field.phone_part() == AutofillField::PHONE_SUFFIX || | |
| 499 field_data->max_length == PhoneNumber::kSuffixLength) { | |
| 500 *value = | |
| 501 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); | |
| 502 } | |
| 503 } | |
| 504 } | |
| 505 | |
| 496 } // namespace autofill | 506 } // namespace autofill |
| OLD | NEW |