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

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: 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
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..f8fcfce455c8db836ac1ed7a1225af835b02b068 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,21 @@ void FillStreetAddress(const base::string16& value,
field->value = base::UTF8ToUTF16(line);
}
+// Fills |field| with the state in |value|. Checks for potential field that
+// expect the state abbreviation by looking at the maxlength attribute of the
+// |field|.
+void FillStateText(const base::string16& value, FormFieldData* field) {
+ if (field->max_length != 2) {
vabr (Chromium) 2016/03/16 16:38:45 The "2" here is related to the data used in GetAbb
sebsg 2016/03/16 23:41:01 Good idea, I also added a check to 0 (default valu
vabr (Chromium) 2016/03/17 09:03:37 Acknowledged, both your improvements SGTM.
+ // Fill the state value directly.
+ field->value = value;
+ } else {
+ // Fill with the state abbreviation.
+ base::string16 full, abbreviation;
+ state_names::GetNameAndAbbreviation(value, &full, &abbreviation);
vabr (Chromium) 2016/03/16 16:38:45 &full -> nullptr
sebsg 2016/03/16 23:41:01 Didn't think of that, thanks!
+ field->value = base::i18n::ToUpper(abbreviation);
+ }
+}
+
std::string Hash32Bit(const std::string& str) {
std::string hash_bin = base::SHA1HashString(str);
DCHECK_EQ(base::kSHA1Length, hash_bin.length());
@@ -566,6 +582,9 @@ 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) {
+ FillStateText(value, field_data);
+ return true;
}
field_data->value = value;

Powered by Google App Engine
This is Rietveld 408576698