Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: components/autofill/core/browser/autofill_field.cc

Issue 442403002: Adjust displayed phone number for prefix/suffix case. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove duplicate documentation. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 field_data->value =
284 // fill accordingly. 284 AutofillField::GetPhoneNumberValue(field, number, *field_data);
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
299 field_data->value = value;
300 } 285 }
301 286
302 // Set |field_data|'s value to |number|, or possibly an appropriate substring 287 // Set |field_data|'s value to |number|, or possibly an appropriate substring
303 // of |number| for cases where credit card number splits across multiple HTML 288 // of |number| for cases where credit card number splits across multiple HTML
304 // form input fields. 289 // form input fields.
305 // The |field| specifies the |credit_card_number_offset_| to the substring 290 // The |field| specifies the |credit_card_number_offset_| to the substring
306 // within credit card number. 291 // within credit card number.
307 void FillCreditCardNumberField(const AutofillField& field, 292 void FillCreditCardNumberField(const AutofillField& field,
308 const base::string16& number, 293 const base::string16& number,
309 FormFieldData* field_data) { 294 FormFieldData* field_data) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 return true; 493 return true;
509 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { 494 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
510 FillCreditCardNumberField(field, value, field_data); 495 FillCreditCardNumberField(field, value, field_data);
511 return true; 496 return true;
512 } 497 }
513 498
514 field_data->value = value; 499 field_data->value = value;
515 return true; 500 return true;
516 } 501 }
517 502
503 base::string16 AutofillField::GetPhoneNumberValue(
504 const AutofillField& field,
505 const base::string16& number,
506 const FormFieldData& field_data) {
507 // Check to see if the size field matches the "prefix" or "suffix" size.
508 // If so, return the appropriate substring.
509 if (number.length() !=
510 PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) {
511 return number;
512 }
513
514 if (field.phone_part() == AutofillField::PHONE_PREFIX ||
515 field_data.max_length == PhoneNumber::kPrefixLength) {
516 return
517 number.substr(PhoneNumber::kPrefixOffset, PhoneNumber::kPrefixLength);
518 }
519
520 if (field.phone_part() == AutofillField::PHONE_SUFFIX ||
521 field_data.max_length == PhoneNumber::kSuffixLength) {
522 return
523 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength);
524 }
525
526 return number;
527 }
528
518 } // namespace autofill 529 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_field.h ('k') | components/autofill/core/browser/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698