Commit 1ea45968 authored by Matthias Körber's avatar Matthias Körber Committed by Commit Bot

[Autofill][Lepzig] Provides capabilities to vote for new types.

The types are not fillable because there are no heuristics and no server
classifications for those types.

Change-Id: I129aa69d1c18b190359c2519ada7d30a7bba3549
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343329
Commit-Queue: Matthias Körber <koerber@google.com>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796162}
parent 097893d8
......@@ -165,6 +165,18 @@ std::unique_ptr<EntityData> CreateEntityDataFromAutofillProfile(
specifics->set_address_home_line2(
TruncateUTF8(UTF16ToUTF8(entry.GetRawInfo(ADDRESS_HOME_LINE2))));
// The following entries are only popluated by Sync.
specifics->set_address_home_thoroughfare_name(
UTF16ToUTF8(entry.GetRawInfo(ADDRESS_HOME_STREET_NAME)));
specifics->set_address_home_dependent_thoroughfare_name(
UTF16ToUTF8(entry.GetRawInfo(ADDRESS_HOME_DEPENDENT_STREET_NAME)));
specifics->set_address_home_subpremise_name(
UTF16ToUTF8(entry.GetRawInfo(ADDRESS_HOME_FLOOR)));
specifics->set_address_home_premise_name(
UTF16ToUTF8(entry.GetRawInfo(ADDRESS_HOME_PREMISE_NAME)));
specifics->set_address_home_thoroughfare_number(
UTF16ToUTF8(entry.GetRawInfo(ADDRESS_HOME_HOUSE_NUMBER)));
return entity_data;
}
......@@ -315,6 +327,35 @@ std::unique_ptr<AutofillProfile> CreateAutofillProfileFromSpecifics(
UTF8ToUTF16(specifics.address_home_line2()));
}
profile->SetRawInfoWithVerificationStatus(
ADDRESS_HOME_STREET_NAME,
UTF8ToUTF16(specifics.address_home_thoroughfare_name()),
ConvertSpecificsToProfileVerificationStatus(
specifics.address_home_thoroughfare_name_status()));
profile->SetRawInfoWithVerificationStatus(
ADDRESS_HOME_DEPENDENT_STREET_NAME,
UTF8ToUTF16(specifics.address_home_dependent_thoroughfare_name()),
ConvertSpecificsToProfileVerificationStatus(
specifics.address_home_dependent_thoroughfare_name_status()));
profile->SetRawInfoWithVerificationStatus(
ADDRESS_HOME_HOUSE_NUMBER,
UTF8ToUTF16(specifics.address_home_thoroughfare_number()),
ConvertSpecificsToProfileVerificationStatus(
specifics.address_home_thoroughfare_number_status()));
profile->SetRawInfoWithVerificationStatus(
ADDRESS_HOME_PREMISE_NAME,
UTF8ToUTF16(specifics.address_home_premise_name()),
ConvertSpecificsToProfileVerificationStatus(
specifics.address_home_premise_name_status()));
profile->SetRawInfoWithVerificationStatus(
ADDRESS_HOME_FLOOR, UTF8ToUTF16(specifics.address_home_subpremise_name()),
ConvertSpecificsToProfileVerificationStatus(
specifics.address_home_subpremise_name_status()));
// This has to be the last one, otherwise setting the raw info may change it.
profile->set_is_client_validity_states_updated(
specifics.is_client_validity_states_updated());
......
......@@ -77,6 +77,13 @@ AutofillProfile ConstructCompleteProfile() {
profile.SetRawInfo(ADDRESS_HOME_SORTING_CODE, ASCIIToUTF16("CEDEX"));
profile.SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY,
ASCIIToUTF16("Santa Clara"));
profile.SetRawInfo(ADDRESS_HOME_STREET_NAME, ASCIIToUTF16("Street Name"));
profile.SetRawInfo(ADDRESS_HOME_DEPENDENT_STREET_NAME,
ASCIIToUTF16("Dependent Street Name"));
profile.SetRawInfo(ADDRESS_HOME_HOUSE_NUMBER, ASCIIToUTF16("House Number"));
profile.SetRawInfo(ADDRESS_HOME_FLOOR, ASCIIToUTF16("Floor"));
profile.SetRawInfo(ADDRESS_HOME_PREMISE_NAME, ASCIIToUTF16("Premise"));
profile.set_language_code("en");
profile.SetClientValidityFromBitfieldValue(1984);
profile.set_is_client_validity_states_updated(true);
......@@ -137,6 +144,12 @@ AutofillProfileSpecifics ConstructCompleteSpecifics() {
specifics.set_address_home_street_address(
"123 Fake St.\n"
"Apt. 42");
specifics.set_address_home_thoroughfare_name("Street Name");
specifics.set_address_home_dependent_thoroughfare_name(
"Dependent Street Name");
specifics.set_address_home_thoroughfare_number("House Number");
specifics.set_address_home_subpremise_name("Floor");
specifics.set_address_home_premise_name("Premise");
specifics.set_company_name("Google, Inc.");
specifics.set_address_home_city("Mountain View");
......
......@@ -98,6 +98,23 @@ base::string16 Address::GetRawInfo(ServerFieldType type) const {
case ADDRESS_HOME_APT_NUM:
return base::string16();
// The following tokens are used for creating new type votes but should not
// be filled into fields.
case ADDRESS_HOME_STREET_NAME:
return street_name_;
case ADDRESS_HOME_HOUSE_NUMBER:
return house_number_;
case ADDRESS_HOME_DEPENDENT_STREET_NAME:
return dependent_street_name_;
case ADDRESS_HOME_PREMISE_NAME:
return premise_name_;
case ADDRESS_HOME_FLOOR:
return floor_;
default:
NOTREACHED() << "Unrecognized type: " << type;
return base::string16();
......@@ -109,9 +126,13 @@ void Address::SetRawInfoWithVerificationStatus(ServerFieldType type,
VerificationStatus status) {
DCHECK_EQ(ADDRESS_HOME, AutofillType(type).group());
switch (type) {
// If any of the address lines change, the structured tokens must be
// reset.
case ADDRESS_HOME_LINE1:
if (street_address_.empty())
street_address_.resize(1);
if (street_address_[0] != value)
ResetStructuredTokes();
street_address_[0] = value;
TrimStreetAddress();
break;
......@@ -119,6 +140,8 @@ void Address::SetRawInfoWithVerificationStatus(ServerFieldType type,
case ADDRESS_HOME_LINE2:
if (street_address_.size() < 2)
street_address_.resize(2);
if (street_address_[1] != value)
ResetStructuredTokes();
street_address_[1] = value;
TrimStreetAddress();
break;
......@@ -126,6 +149,8 @@ void Address::SetRawInfoWithVerificationStatus(ServerFieldType type,
case ADDRESS_HOME_LINE3:
if (street_address_.size() < 3)
street_address_.resize(3);
if (street_address_[2] != value)
ResetStructuredTokes();
street_address_[2] = value;
TrimStreetAddress();
break;
......@@ -157,9 +182,37 @@ void Address::SetRawInfoWithVerificationStatus(ServerFieldType type,
break;
case ADDRESS_HOME_STREET_ADDRESS:
street_address_ =
base::SplitString(value, base::ASCIIToUTF16("\n"),
base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
// If the street address changes, the structured tokens must be reset.
if (base::SplitString(value, base::ASCIIToUTF16("\n"),
base::TRIM_WHITESPACE,
base::SPLIT_WANT_ALL) != street_address_) {
ResetStructuredTokes();
street_address_ =
base::SplitString(value, base::ASCIIToUTF16("\n"),
base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
}
break;
// The following types are used to create type votes but should not be
// filled into fields.
case ADDRESS_HOME_STREET_NAME:
street_name_ = value;
break;
case ADDRESS_HOME_DEPENDENT_STREET_NAME:
dependent_street_name_ = value;
break;
case ADDRESS_HOME_HOUSE_NUMBER:
house_number_ = value;
break;
case ADDRESS_HOME_PREMISE_NAME:
premise_name_ = value;
break;
case ADDRESS_HOME_FLOOR:
floor_ = value;
break;
default:
......@@ -167,6 +220,14 @@ void Address::SetRawInfoWithVerificationStatus(ServerFieldType type,
}
}
void Address::ResetStructuredTokes() {
street_name_.clear();
dependent_street_name_.clear();
house_number_.clear();
premise_name_.clear();
floor_.clear();
}
void Address::GetMatchingTypes(const base::string16& text,
const std::string& app_locale,
ServerFieldTypeSet* matching_types) const {
......@@ -211,6 +272,15 @@ void Address::GetSupportedTypes(ServerFieldTypeSet* supported_types) const {
supported_types->insert(ADDRESS_HOME_ZIP);
supported_types->insert(ADDRESS_HOME_SORTING_CODE);
supported_types->insert(ADDRESS_HOME_COUNTRY);
// If those types are not added, no votes will be generated.
if (base::FeatureList::IsEnabled(
features::kAutofillAddressEnhancementVotes)) {
supported_types->insert(ADDRESS_HOME_STREET_NAME);
supported_types->insert(ADDRESS_HOME_DEPENDENT_STREET_NAME);
supported_types->insert(ADDRESS_HOME_HOUSE_NUMBER);
supported_types->insert(ADDRESS_HOME_PREMISE_NAME);
supported_types->insert(ADDRESS_HOME_FLOOR);
}
}
base::string16 Address::GetInfoImpl(const AutofillType& type,
......
......@@ -35,6 +35,8 @@ class Address : public FormGroup {
const std::string& locale,
ServerFieldTypeSet* matching_types) const override;
void ResetStructuredTokes();
private:
// FormGroup:
void GetSupportedTypes(ServerFieldTypeSet* supported_types) const override;
......@@ -60,6 +62,14 @@ class Address : public FormGroup {
// geographically contiguous. The canonical example is CEDEX in France.
base::string16 sorting_code_;
// The following entries are only popluated by Sync and
// used to create type votes, but are not used for filling fields.
base::string16 street_name_;
base::string16 dependent_street_name_;
base::string16 house_number_;
base::string16 premise_name_;
base::string16 floor_;
// The ISO 3166 2-letter country code, or an empty string if there is no
// country data specified for this address.
std::string country_code_;
......
......@@ -146,10 +146,14 @@ AutofillProfile ConstructCompleteProfile() {
profile.set_use_count(7);
profile.set_use_date(base::Time::FromTimeT(1423182152));
profile.SetRawInfo(NAME_HONORIFIC_PREFIX, ASCIIToUTF16(""));
profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John K. Doe, Jr."));
profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
profile.SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("K."));
profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Doe"));
profile.SetRawInfo(NAME_LAST_FIRST, ASCIIToUTF16("D"));
profile.SetRawInfo(NAME_LAST_CONJUNCTION, ASCIIToUTF16("o"));
profile.SetRawInfo(NAME_LAST_SECOND, ASCIIToUTF16("e"));
profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("user@example.com"));
profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1.800.555.1234"));
......@@ -168,6 +172,12 @@ AutofillProfile ConstructCompleteProfile() {
profile.SetRawInfo(ADDRESS_HOME_SORTING_CODE, ASCIIToUTF16("CEDEX"));
profile.SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY,
ASCIIToUTF16("Santa Clara"));
profile.SetRawInfo(ADDRESS_HOME_STREET_NAME, ASCIIToUTF16("Street Name"));
profile.SetRawInfo(ADDRESS_HOME_DEPENDENT_STREET_NAME,
ASCIIToUTF16("Dependent Street Name"));
profile.SetRawInfo(ADDRESS_HOME_HOUSE_NUMBER, ASCIIToUTF16("House Number"));
profile.SetRawInfo(ADDRESS_HOME_FLOOR, ASCIIToUTF16("Floor"));
profile.SetRawInfo(ADDRESS_HOME_PREMISE_NAME, ASCIIToUTF16("Premise"));
profile.set_language_code("en");
profile.SetClientValidityFromBitfieldValue(kValidityStateBitfield);
return profile;
......@@ -183,10 +193,39 @@ AutofillProfileSpecifics ConstructCompleteSpecifics() {
specifics.set_use_count(7);
specifics.set_use_date(1423182152);
specifics.add_name_honorific("");
specifics.add_name_first("John");
specifics.add_name_middle("K.");
specifics.add_name_last("Doe");
specifics.add_name_full("John K. Doe, Jr.");
specifics.add_name_last_first("D");
specifics.add_name_last_conjunction("o");
specifics.add_name_last_second("e");
specifics.add_name_honorific_status(
sync_pb::
AutofillProfileSpecifics_VerificationStatus_VERIFICATION_STATUS_UNSPECIFIED);
specifics.add_name_first_status(
sync_pb::
AutofillProfileSpecifics_VerificationStatus_VERIFICATION_STATUS_UNSPECIFIED);
specifics.add_name_middle_status(
sync_pb::
AutofillProfileSpecifics_VerificationStatus_VERIFICATION_STATUS_UNSPECIFIED);
specifics.add_name_last_status(
sync_pb::
AutofillProfileSpecifics_VerificationStatus_VERIFICATION_STATUS_UNSPECIFIED);
specifics.add_name_full_status(
sync_pb::
AutofillProfileSpecifics_VerificationStatus_VERIFICATION_STATUS_UNSPECIFIED);
specifics.add_name_last_first_status(
sync_pb::
AutofillProfileSpecifics_VerificationStatus_VERIFICATION_STATUS_UNSPECIFIED);
specifics.add_name_last_conjunction_status(
sync_pb::
AutofillProfileSpecifics_VerificationStatus_VERIFICATION_STATUS_UNSPECIFIED);
specifics.add_name_last_second_status(
sync_pb::
AutofillProfileSpecifics_VerificationStatus_VERIFICATION_STATUS_UNSPECIFIED);
specifics.add_email_address("user@example.com");
......@@ -206,8 +245,15 @@ AutofillProfileSpecifics ConstructCompleteSpecifics() {
specifics.set_address_home_sorting_code("CEDEX");
specifics.set_address_home_dependent_locality("Santa Clara");
specifics.set_address_home_language_code("en");
specifics.set_validity_state_bitfield(kValidityStateBitfield);
specifics.set_address_home_thoroughfare_name("Street Name");
specifics.set_address_home_dependent_thoroughfare_name(
"Dependent Street Name");
specifics.set_address_home_thoroughfare_number("House Number");
specifics.set_address_home_subpremise_name("Floor");
specifics.set_address_home_premise_name("Premise");
specifics.set_validity_state_bitfield(kValidityStateBitfield);
return specifics;
}
......
......@@ -20,6 +20,10 @@
namespace autofill {
namespace features {
// Controls if Autofill sends votes for the new address types.
const base::Feature kAutofillAddressEnhancementVotes{
"kAutofillAddressEnhancementVotes", base::FEATURE_DISABLED_BY_DEFAULT};
// Controls whether the AddressNormalizer is supplied. If available, it may be
// used to normalize address and will incur fetching rules from the server.
const base::Feature kAutofillAddressNormalizer{
......
......@@ -21,6 +21,7 @@ namespace autofill {
namespace features {
// All features in alphabetical order.
extern const base::Feature kAutofillAddressEnhancementVotes;
extern const base::Feature kAutofillAddressNormalizer;
extern const base::Feature kAutofillAllowHtmlTypeCountryCodesWithFullNames;
extern const base::Feature kAutofillAllowNonHttpActivation;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment