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

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

Issue 381613005: [Autofill] Autofill fails to fill credit card number when split across fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated review comments. Created 6 years, 4 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } else if (field.phone_part() == AutofillField::PHONE_SUFFIX || 291 } else if (field.phone_part() == AutofillField::PHONE_SUFFIX ||
292 field_data->max_length == PhoneNumber::kSuffixLength) { 292 field_data->max_length == PhoneNumber::kSuffixLength) {
293 value = number.substr(PhoneNumber::kSuffixOffset, 293 value = number.substr(PhoneNumber::kSuffixOffset,
294 PhoneNumber::kSuffixLength); 294 PhoneNumber::kSuffixLength);
295 } 295 }
296 } 296 }
297 297
298 field_data->value = value; 298 field_data->value = value;
299 } 299 }
300 300
301 // Set |field_data|'s value to |cc_number|, or possibly an appropriate substring
302 // of |cc_number| for cases where credit card number splits across multiple HTML
303 // form input fields.
304 // The |field| specifies the |credit_card_number_start_index_| to the substring
305 // within credit card number.
306 void FillCreditCardNumberField(const AutofillField& field,
307 const base::string16& cc_number,
Ilya Sherman 2014/08/12 04:23:41 nit: Please don't use the abbreviation "cc". Inst
Pritam Nikam 2014/08/12 14:00:37 Done.
308 FormFieldData* field_data) {
309 base::string16 value = cc_number;
310
311 // |filed|'s max_length truncates credit card number to fit within.
Ilya Sherman 2014/08/12 04:23:41 nit: "filed" -> "field"
Pritam Nikam 2014/08/12 14:00:37 Done.
312 if (field.credit_card_number_start_index() &&
Ilya Sherman 2014/08/12 04:23:41 There's no need to check whether the start index i
Pritam Nikam 2014/08/12 14:00:37 Done.
313 field.credit_card_number_start_index() < value.length())
314 value =
315 value.substr(field.credit_card_number_start_index(),
316 value.length() - field.credit_card_number_start_index());
Ilya Sherman 2014/08/12 04:23:41 You can shorten this by dropping the second argume
Pritam Nikam 2014/08/12 14:00:37 Done.
317
318 field_data->value = value;
319 }
320
301 // Fills in the select control |field| with |value|. If an exact match is not 321 // Fills in the select control |field| with |value|. If an exact match is not
302 // found, falls back to alternate filling strategies based on the |type|. 322 // found, falls back to alternate filling strategies based on the |type|.
303 bool FillSelectControl(const AutofillType& type, 323 bool FillSelectControl(const AutofillType& type,
304 const base::string16& value, 324 const base::string16& value,
305 const std::string& app_locale, 325 const std::string& app_locale,
306 FormFieldData* field) { 326 FormFieldData* field) {
307 DCHECK_EQ("select-one", field->form_control_type); 327 DCHECK_EQ("select-one", field->form_control_type);
308 328
309 // Guard against corrupted values passed over IPC. 329 // Guard against corrupted values passed over IPC.
310 if (field->option_values.size() != field->option_contents.size()) 330 if (field->option_values.size() != field->option_contents.size())
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return base::UintToString(hash32); 409 return base::UintToString(hash32);
390 } 410 }
391 411
392 } // namespace 412 } // namespace
393 413
394 AutofillField::AutofillField() 414 AutofillField::AutofillField()
395 : server_type_(NO_SERVER_DATA), 415 : server_type_(NO_SERVER_DATA),
396 heuristic_type_(UNKNOWN_TYPE), 416 heuristic_type_(UNKNOWN_TYPE),
397 html_type_(HTML_TYPE_UNKNOWN), 417 html_type_(HTML_TYPE_UNKNOWN),
398 html_mode_(HTML_MODE_NONE), 418 html_mode_(HTML_MODE_NONE),
399 phone_part_(IGNORED) { 419 phone_part_(IGNORED),
420 credit_card_number_start_index_(0) {
400 } 421 }
401 422
402 AutofillField::AutofillField(const FormFieldData& field, 423 AutofillField::AutofillField(const FormFieldData& field,
403 const base::string16& unique_name) 424 const base::string16& unique_name)
404 : FormFieldData(field), 425 : FormFieldData(field),
405 unique_name_(unique_name), 426 unique_name_(unique_name),
406 server_type_(NO_SERVER_DATA), 427 server_type_(NO_SERVER_DATA),
407 heuristic_type_(UNKNOWN_TYPE), 428 heuristic_type_(UNKNOWN_TYPE),
408 html_type_(HTML_TYPE_UNKNOWN), 429 html_type_(HTML_TYPE_UNKNOWN),
409 html_mode_(HTML_MODE_NONE), 430 html_mode_(HTML_MODE_NONE),
410 phone_part_(IGNORED) { 431 phone_part_(IGNORED),
432 credit_card_number_start_index_(0) {
411 } 433 }
412 434
413 AutofillField::~AutofillField() {} 435 AutofillField::~AutofillField() {
436 }
414 437
415 void AutofillField::set_heuristic_type(ServerFieldType type) { 438 void AutofillField::set_heuristic_type(ServerFieldType type) {
416 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && 439 if (type >= 0 && type < MAX_VALID_FIELD_TYPE &&
417 type != FIELD_WITH_DEFAULT_VALUE) { 440 type != FIELD_WITH_DEFAULT_VALUE) {
418 heuristic_type_ = type; 441 heuristic_type_ = type;
419 } else { 442 } else {
420 NOTREACHED(); 443 NOTREACHED();
421 // This case should not be reachable; but since this has potential 444 // This case should not be reachable; but since this has potential
422 // implications on data uploaded to the server, better safe than sorry. 445 // implications on data uploaded to the server, better safe than sorry.
423 heuristic_type_ = UNKNOWN_TYPE; 446 heuristic_type_ = UNKNOWN_TYPE;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 if (type.GetStorableType() == PHONE_HOME_NUMBER) { 502 if (type.GetStorableType() == PHONE_HOME_NUMBER) {
480 FillPhoneNumberField(field, value, field_data); 503 FillPhoneNumberField(field, value, field_data);
481 return true; 504 return true;
482 } else if (field_data->form_control_type == "select-one") { 505 } else if (field_data->form_control_type == "select-one") {
483 return FillSelectControl(type, value, app_locale, field_data); 506 return FillSelectControl(type, value, app_locale, field_data);
484 } else if (field_data->form_control_type == "month") { 507 } else if (field_data->form_control_type == "month") {
485 return FillMonthControl(value, field_data); 508 return FillMonthControl(value, field_data);
486 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { 509 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) {
487 FillStreetAddress(value, address_language_code, field_data); 510 FillStreetAddress(value, address_language_code, field_data);
488 return true; 511 return true;
512 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
513 FillCreditCardNumberField(field, value, field_data);
514 return true;
489 } 515 }
490 516
491 field_data->value = value; 517 field_data->value = value;
492 return true; 518 return true;
493 } 519 }
494 520
495 } // namespace autofill 521 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698