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

Unified Diff: components/autofill/core/browser/autofill_field.cc

Issue 1811543002: [Autofill] Fill text state fields that have a max length of 2 with the state abbreviation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments and made code more robust Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_field_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/browser/autofill_field.cc
diff --git a/components/autofill/core/browser/autofill_field.cc b/components/autofill/core/browser/autofill_field.cc
index 7ec8ebefa5498b816026a07126cc464a92de25e5..ed30aee96f5e49a4f5e19efc91f8e5fcff493548 100644
--- a/components/autofill/core/browser/autofill_field.cc
+++ b/components/autofill/core/browser/autofill_field.cc
@@ -7,6 +7,7 @@
#include <stdint.h>
#include "base/command_line.h"
+#include "base/i18n/case_conversion.h"
#include "base/i18n/string_search.h"
#include "base/logging.h"
#include "base/metrics/field_trial.h"
@@ -414,6 +415,27 @@ void FillStreetAddress(const base::string16& value,
field->value = base::UTF8ToUTF16(line);
}
+// Returns whether the |field| was filled with the state in |value| or its
+// abbreviation. First looks if |value| fits directly in the field, then looks
+// if the abbreviation of |value| fits. Does not fill if neither |value| or its
+// abbreviation are too long for the field.
+bool FillStateText(const base::string16& value, FormFieldData* field) {
+ if (field->max_length == 0 || field->max_length >= value.size()) {
+ // Fill the state value directly.
+ field->value = value;
+ return true;
+ } else {
+ // Fill with the state abbreviation.
+ base::string16 abbreviation;
+ state_names::GetNameAndAbbreviation(value, nullptr, &abbreviation);
+ if (abbreviation.size() != 0 && field->max_length >= abbreviation.size()) {
vabr (Chromium) 2016/03/17 09:03:37 optional nit: "!abbreviation.empty()" instead of "
sebsg 2016/03/17 14:46:08 Done.
+ field->value = base::i18n::ToUpper(abbreviation);
+ return true;
+ }
+ }
+ return false;
+}
+
std::string Hash32Bit(const std::string& str) {
std::string hash_bin = base::SHA1HashString(str);
DCHECK_EQ(base::kSHA1Length, hash_bin.length());
@@ -566,6 +588,8 @@ bool AutofillField::FillFormField(const AutofillField& field,
} else if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
FillCreditCardNumberField(field, value, field_data);
return true;
+ } else if (type.GetStorableType() == ADDRESS_HOME_STATE) {
+ return FillStateText(value, field_data);
}
field_data->value = value;
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698