| OLD | NEW |
| 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/address.h" | 5 #include "components/autofill/core/browser/address.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.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_field.h" | 14 #include "components/autofill/core/browser/autofill_field.h" |
| 15 #include "components/autofill/core/browser/autofill_type.h" | 15 #include "components/autofill/core/browser/autofill_type.h" |
| 16 #include "components/autofill/core/browser/field_types.h" | |
| 17 | 16 |
| 18 namespace { | 17 namespace { |
| 19 | 18 |
| 20 const char16 kAddressSplitChars[] = {'-', ',', '#', '.', ' ', 0}; | 19 const char16 kAddressSplitChars[] = {'-', ',', '#', '.', ' ', 0}; |
| 21 | 20 |
| 22 } // namespace | 21 } // namespace |
| 23 | 22 |
| 24 namespace autofill { | 23 namespace autofill { |
| 25 | 24 |
| 26 Address::Address() {} | 25 Address::Address() {} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 37 | 36 |
| 38 line1_ = address.line1_; | 37 line1_ = address.line1_; |
| 39 line2_ = address.line2_; | 38 line2_ = address.line2_; |
| 40 city_ = address.city_; | 39 city_ = address.city_; |
| 41 state_ = address.state_; | 40 state_ = address.state_; |
| 42 country_code_ = address.country_code_; | 41 country_code_ = address.country_code_; |
| 43 zip_code_ = address.zip_code_; | 42 zip_code_ = address.zip_code_; |
| 44 return *this; | 43 return *this; |
| 45 } | 44 } |
| 46 | 45 |
| 47 void Address::GetSupportedTypes(FieldTypeSet* supported_types) const { | 46 base::string16 Address::GetRawInfo(ServerFieldType type) const { |
| 48 supported_types->insert(ADDRESS_HOME_LINE1); | |
| 49 supported_types->insert(ADDRESS_HOME_LINE2); | |
| 50 supported_types->insert(ADDRESS_HOME_CITY); | |
| 51 supported_types->insert(ADDRESS_HOME_STATE); | |
| 52 supported_types->insert(ADDRESS_HOME_ZIP); | |
| 53 supported_types->insert(ADDRESS_HOME_COUNTRY); | |
| 54 } | |
| 55 | |
| 56 base::string16 Address::GetRawInfo(AutofillFieldType type) const { | |
| 57 type = AutofillType::GetEquivalentFieldType(type); | 47 type = AutofillType::GetEquivalentFieldType(type); |
| 58 if (type == ADDRESS_HOME_LINE1) | 48 if (type == ADDRESS_HOME_LINE1) |
| 59 return line1_; | 49 return line1_; |
| 60 | 50 |
| 61 if (type == ADDRESS_HOME_LINE2) | 51 if (type == ADDRESS_HOME_LINE2) |
| 62 return line2_; | 52 return line2_; |
| 63 | 53 |
| 64 if (type == ADDRESS_HOME_CITY) | 54 if (type == ADDRESS_HOME_CITY) |
| 65 return city_; | 55 return city_; |
| 66 | 56 |
| 67 if (type == ADDRESS_HOME_STATE) | 57 if (type == ADDRESS_HOME_STATE) |
| 68 return state_; | 58 return state_; |
| 69 | 59 |
| 70 if (type == ADDRESS_HOME_ZIP) | 60 if (type == ADDRESS_HOME_ZIP) |
| 71 return zip_code_; | 61 return zip_code_; |
| 72 | 62 |
| 73 if (type == ADDRESS_HOME_COUNTRY) | 63 if (type == ADDRESS_HOME_COUNTRY) |
| 74 return country_code_; | 64 return country_code_; |
| 75 | 65 |
| 76 return base::string16(); | 66 return base::string16(); |
| 77 } | 67 } |
| 78 | 68 |
| 79 void Address::SetRawInfo(AutofillFieldType type, const base::string16& value) { | 69 void Address::SetRawInfo(ServerFieldType type, const base::string16& value) { |
| 80 type = AutofillType::GetEquivalentFieldType(type); | 70 type = AutofillType::GetEquivalentFieldType(type); |
| 81 if (type == ADDRESS_HOME_LINE1) { | 71 if (type == ADDRESS_HOME_LINE1) { |
| 82 line1_ = value; | 72 line1_ = value; |
| 83 } else if (type == ADDRESS_HOME_LINE2) { | 73 } else if (type == ADDRESS_HOME_LINE2) { |
| 84 line2_ = value; | 74 line2_ = value; |
| 85 } else if (type == ADDRESS_HOME_CITY) { | 75 } else if (type == ADDRESS_HOME_CITY) { |
| 86 city_ = value; | 76 city_ = value; |
| 87 } else if (type == ADDRESS_HOME_STATE) { | 77 } else if (type == ADDRESS_HOME_STATE) { |
| 88 state_ = value; | 78 state_ = value; |
| 89 } else if (type == ADDRESS_HOME_COUNTRY) { | 79 } else if (type == ADDRESS_HOME_COUNTRY) { |
| 90 DCHECK(value.empty() || value.length() == 2u); | 80 DCHECK(value.empty() || value.length() == 2u); |
| 91 country_code_ = value; | 81 country_code_ = value; |
| 92 } else if (type == ADDRESS_HOME_ZIP) { | 82 } else if (type == ADDRESS_HOME_ZIP) { |
| 93 zip_code_ = value; | 83 zip_code_ = value; |
| 94 } else { | 84 } else { |
| 95 NOTREACHED(); | 85 NOTREACHED(); |
| 96 } | 86 } |
| 97 } | 87 } |
| 98 | 88 |
| 99 base::string16 Address::GetInfo(AutofillFieldType type, | 89 base::string16 Address::GetInfo(const AutofillType& type, |
| 100 const std::string& app_locale) const { | 90 const std::string& app_locale) const { |
| 101 type = AutofillType::GetEquivalentFieldType(type); | 91 ServerFieldType server_type = |
| 102 if (type == ADDRESS_HOME_COUNTRY && !country_code_.empty()) | 92 AutofillType::GetEquivalentFieldType(type.server_type()); |
| 93 if (server_type == ADDRESS_HOME_COUNTRY && !country_code_.empty()) |
| 103 return AutofillCountry(UTF16ToASCII(country_code_), app_locale).name(); | 94 return AutofillCountry(UTF16ToASCII(country_code_), app_locale).name(); |
| 104 | 95 |
| 105 return GetRawInfo(type); | 96 return GetRawInfo(server_type); |
| 106 } | 97 } |
| 107 | 98 |
| 108 bool Address::SetInfo(AutofillFieldType type, | 99 bool Address::SetInfo(const AutofillType& type, |
| 109 const base::string16& value, | 100 const base::string16& value, |
| 110 const std::string& app_locale) { | 101 const std::string& app_locale) { |
| 111 type = AutofillType::GetEquivalentFieldType(type); | 102 ServerFieldType server_type = |
| 112 if (type == ADDRESS_HOME_COUNTRY && !value.empty()) { | 103 AutofillType::GetEquivalentFieldType(type.server_type()); |
| 104 if (server_type == ADDRESS_HOME_COUNTRY && !value.empty()) { |
| 113 country_code_ = | 105 country_code_ = |
| 114 ASCIIToUTF16(AutofillCountry::GetCountryCode(value, app_locale)); | 106 ASCIIToUTF16(AutofillCountry::GetCountryCode(value, app_locale)); |
| 115 return !country_code_.empty(); | 107 return !country_code_.empty(); |
| 116 } | 108 } |
| 117 | 109 |
| 118 SetRawInfo(type, value); | 110 SetRawInfo(server_type, value); |
| 119 return true; | 111 return true; |
| 120 } | 112 } |
| 121 | 113 |
| 122 void Address::GetMatchingTypes(const base::string16& text, | 114 void Address::GetMatchingTypes(const base::string16& text, |
| 123 const std::string& app_locale, | 115 const std::string& app_locale, |
| 124 FieldTypeSet* matching_types) const { | 116 ServerFieldTypeSet* matching_types) const { |
| 125 FormGroup::GetMatchingTypes(text, app_locale, matching_types); | 117 FormGroup::GetMatchingTypes(text, app_locale, matching_types); |
| 126 | 118 |
| 127 // Check to see if the |text| canonicalized as a country name is a match. | 119 // Check to see if the |text| canonicalized as a country name is a match. |
| 128 std::string country_code = AutofillCountry::GetCountryCode(text, app_locale); | 120 std::string country_code = AutofillCountry::GetCountryCode(text, app_locale); |
| 129 if (!country_code.empty() && country_code_ == ASCIIToUTF16(country_code)) | 121 if (!country_code.empty() && country_code_ == ASCIIToUTF16(country_code)) |
| 130 matching_types->insert(ADDRESS_HOME_COUNTRY); | 122 matching_types->insert(ADDRESS_HOME_COUNTRY); |
| 131 } | 123 } |
| 132 | 124 |
| 125 void Address::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { |
| 126 supported_types->insert(ADDRESS_HOME_LINE1); |
| 127 supported_types->insert(ADDRESS_HOME_LINE2); |
| 128 supported_types->insert(ADDRESS_HOME_CITY); |
| 129 supported_types->insert(ADDRESS_HOME_STATE); |
| 130 supported_types->insert(ADDRESS_HOME_ZIP); |
| 131 supported_types->insert(ADDRESS_HOME_COUNTRY); |
| 132 } |
| 133 |
| 133 } // namespace autofill | 134 } // namespace autofill |
| OLD | NEW |