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

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

Issue 397233002: Use language-specific street address line separators (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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"
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/components_strings.h" 17 #include "grit/components_strings.h"
18 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h"
19 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h"
18 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
19 21
20 using base::ASCIIToUTF16; 22 using base::ASCIIToUTF16;
21 using base::StringToInt; 23 using base::StringToInt;
22 24
23 namespace autofill { 25 namespace autofill {
24 namespace { 26 namespace {
25 27
26 const char* const kMonthsAbbreviated[] = { 28 const char* const kMonthsAbbreviated[] = {
27 NULL, // Padding so index 1 = month 1 = January. 29 NULL, // Padding so index 1 = month 1 = January.
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 return false; 349 return false;
348 350
349 // HTML5 input="month" expects zero-padded months. 351 // HTML5 input="month" expects zero-padded months.
350 if (month.size() == 1) 352 if (month.size() == 1)
351 month = ASCIIToUTF16("0") + month; 353 month = ASCIIToUTF16("0") + month;
352 354
353 field->value = year + ASCIIToUTF16("-") + month; 355 field->value = year + ASCIIToUTF16("-") + month;
354 return true; 356 return true;
355 } 357 }
356 358
357 // Fills |field| with the street address in |value|. Translates newlines into 359 // Fills |field| with the street address in |value|. Translates newlines into
358 // equivalent separators when necessary, i.e. when filling a single-line field. 360 // equivalent separators when necessary, i.e. when filling a single-line field.
359 void FillStreetAddress(const base::string16& value, 361 void FillStreetAddress(const base::string16& value,
362 const std::string& value_language_code,
360 FormFieldData* field) { 363 FormFieldData* field) {
361 if (field->form_control_type == "textarea") { 364 if (field->form_control_type == "textarea") {
362 field->value = value; 365 field->value = value;
363 return; 366 return;
364 } 367 }
365 368
366 const base::string16& separator = 369 ::i18n::addressinput::AddressData address_data;
367 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_SEPARATOR); 370 address_data.language_code = value_language_code;
368 base::ReplaceChars(value, base::ASCIIToUTF16("\n"), separator, &field->value); 371 base::SplitString(base::UTF16ToUTF8(value), '\n', &address_data.address_line);
372 std::string line;
373 ::i18n::addressinput::GetStreetAddressLinesAsSingleLine(address_data, &line);
374 field->value = base::UTF8ToUTF16(line);
369 } 375 }
370 376
371 std::string Hash32Bit(const std::string& str) { 377 std::string Hash32Bit(const std::string& str) {
372 std::string hash_bin = base::SHA1HashString(str); 378 std::string hash_bin = base::SHA1HashString(str);
373 DCHECK_EQ(20U, hash_bin.length()); 379 DCHECK_EQ(20U, hash_bin.length());
374 380
375 uint32 hash32 = ((hash_bin[0] & 0xFF) << 24) | 381 uint32 hash32 = ((hash_bin[0] & 0xFF) << 24) |
376 ((hash_bin[1] & 0xFF) << 16) | 382 ((hash_bin[1] & 0xFF) << 16) |
377 ((hash_bin[2] & 0xFF) << 8) | 383 ((hash_bin[2] & 0xFF) << 8) |
378 (hash_bin[3] & 0xFF); 384 (hash_bin[3] & 0xFF);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 return Hash32Bit(field_string); 461 return Hash32Bit(field_string);
456 } 462 }
457 463
458 bool AutofillField::IsFieldFillable() const { 464 bool AutofillField::IsFieldFillable() const {
459 return should_autocomplete && !Type().IsUnknown(); 465 return should_autocomplete && !Type().IsUnknown();
460 } 466 }
461 467
462 // static 468 // static
463 bool AutofillField::FillFormField(const AutofillField& field, 469 bool AutofillField::FillFormField(const AutofillField& field,
464 const base::string16& value, 470 const base::string16& value,
471 const std::string& value_language_code,
Evan Stade 2014/07/17 17:25:31 s/value_language_code/address_language_code
please use gerrit instead 2014/07/17 23:42:10 Done.
465 const std::string& app_locale, 472 const std::string& app_locale,
466 FormFieldData* field_data) { 473 FormFieldData* field_data) {
467 AutofillType type = field.Type(); 474 AutofillType type = field.Type();
468 475
469 if (type.GetStorableType() == PHONE_HOME_NUMBER) { 476 if (type.GetStorableType() == PHONE_HOME_NUMBER) {
470 FillPhoneNumberField(field, value, field_data); 477 FillPhoneNumberField(field, value, field_data);
471 return true; 478 return true;
472 } else if (field_data->form_control_type == "select-one") { 479 } else if (field_data->form_control_type == "select-one") {
473 return FillSelectControl(type, value, app_locale, field_data); 480 return FillSelectControl(type, value, app_locale, field_data);
474 } else if (field_data->form_control_type == "month") { 481 } else if (field_data->form_control_type == "month") {
475 return FillMonthControl(value, field_data); 482 return FillMonthControl(value, field_data);
476 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { 483 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) {
477 FillStreetAddress(value, field_data); 484 FillStreetAddress(value, value_language_code, field_data);
478 return true; 485 return true;
479 } 486 }
480 487
481 field_data->value = value; 488 field_data->value = value;
482 return true; 489 return true;
483 } 490 }
484 491
485 } // namespace autofill 492 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698