| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/address.h" | 5 #include "components/autofill/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" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 void Address::GetSupportedTypes(FieldTypeSet* supported_types) const { | 45 void Address::GetSupportedTypes(FieldTypeSet* supported_types) const { |
| 46 supported_types->insert(ADDRESS_HOME_LINE1); | 46 supported_types->insert(ADDRESS_HOME_LINE1); |
| 47 supported_types->insert(ADDRESS_HOME_LINE2); | 47 supported_types->insert(ADDRESS_HOME_LINE2); |
| 48 supported_types->insert(ADDRESS_HOME_CITY); | 48 supported_types->insert(ADDRESS_HOME_CITY); |
| 49 supported_types->insert(ADDRESS_HOME_STATE); | 49 supported_types->insert(ADDRESS_HOME_STATE); |
| 50 supported_types->insert(ADDRESS_HOME_ZIP); | 50 supported_types->insert(ADDRESS_HOME_ZIP); |
| 51 supported_types->insert(ADDRESS_HOME_COUNTRY); | 51 supported_types->insert(ADDRESS_HOME_COUNTRY); |
| 52 } | 52 } |
| 53 | 53 |
| 54 string16 Address::GetRawInfo(AutofillFieldType type) const { | 54 base::string16 Address::GetRawInfo(AutofillFieldType type) const { |
| 55 type = AutofillType::GetEquivalentFieldType(type); | 55 type = AutofillType::GetEquivalentFieldType(type); |
| 56 if (type == ADDRESS_HOME_LINE1) | 56 if (type == ADDRESS_HOME_LINE1) |
| 57 return line1_; | 57 return line1_; |
| 58 | 58 |
| 59 if (type == ADDRESS_HOME_LINE2) | 59 if (type == ADDRESS_HOME_LINE2) |
| 60 return line2_; | 60 return line2_; |
| 61 | 61 |
| 62 if (type == ADDRESS_HOME_CITY) | 62 if (type == ADDRESS_HOME_CITY) |
| 63 return city_; | 63 return city_; |
| 64 | 64 |
| 65 if (type == ADDRESS_HOME_STATE) | 65 if (type == ADDRESS_HOME_STATE) |
| 66 return state_; | 66 return state_; |
| 67 | 67 |
| 68 if (type == ADDRESS_HOME_ZIP) | 68 if (type == ADDRESS_HOME_ZIP) |
| 69 return zip_code_; | 69 return zip_code_; |
| 70 | 70 |
| 71 if (type == ADDRESS_HOME_COUNTRY) | 71 if (type == ADDRESS_HOME_COUNTRY) |
| 72 return country_code_; | 72 return country_code_; |
| 73 | 73 |
| 74 return string16(); | 74 return base::string16(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void Address::SetRawInfo(AutofillFieldType type, const string16& value) { | 77 void Address::SetRawInfo(AutofillFieldType type, const base::string16& value) { |
| 78 type = AutofillType::GetEquivalentFieldType(type); | 78 type = AutofillType::GetEquivalentFieldType(type); |
| 79 if (type == ADDRESS_HOME_LINE1) { | 79 if (type == ADDRESS_HOME_LINE1) { |
| 80 line1_ = value; | 80 line1_ = value; |
| 81 } else if (type == ADDRESS_HOME_LINE2) { | 81 } else if (type == ADDRESS_HOME_LINE2) { |
| 82 line2_ = value; | 82 line2_ = value; |
| 83 } else if (type == ADDRESS_HOME_CITY) { | 83 } else if (type == ADDRESS_HOME_CITY) { |
| 84 city_ = value; | 84 city_ = value; |
| 85 } else if (type == ADDRESS_HOME_STATE) { | 85 } else if (type == ADDRESS_HOME_STATE) { |
| 86 state_ = value; | 86 state_ = value; |
| 87 } else if (type == ADDRESS_HOME_COUNTRY) { | 87 } else if (type == ADDRESS_HOME_COUNTRY) { |
| 88 DCHECK(value.empty() || value.length() == 2u); | 88 DCHECK(value.empty() || value.length() == 2u); |
| 89 country_code_ = value; | 89 country_code_ = value; |
| 90 } else if (type == ADDRESS_HOME_ZIP) { | 90 } else if (type == ADDRESS_HOME_ZIP) { |
| 91 zip_code_ = value; | 91 zip_code_ = value; |
| 92 } else { | 92 } else { |
| 93 NOTREACHED(); | 93 NOTREACHED(); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 string16 Address::GetInfo(AutofillFieldType type, | 97 base::string16 Address::GetInfo(AutofillFieldType type, |
| 98 const std::string& app_locale) const { | 98 const std::string& app_locale) const { |
| 99 type = AutofillType::GetEquivalentFieldType(type); | 99 type = AutofillType::GetEquivalentFieldType(type); |
| 100 if (type == ADDRESS_HOME_COUNTRY && !country_code_.empty()) | 100 if (type == ADDRESS_HOME_COUNTRY && !country_code_.empty()) |
| 101 return AutofillCountry(UTF16ToASCII(country_code_), app_locale).name(); | 101 return AutofillCountry(UTF16ToASCII(country_code_), app_locale).name(); |
| 102 | 102 |
| 103 return GetRawInfo(type); | 103 return GetRawInfo(type); |
| 104 } | 104 } |
| 105 | 105 |
| 106 bool Address::SetInfo(AutofillFieldType type, | 106 bool Address::SetInfo(AutofillFieldType type, |
| 107 const string16& value, | 107 const base::string16& value, |
| 108 const std::string& app_locale) { | 108 const std::string& app_locale) { |
| 109 type = AutofillType::GetEquivalentFieldType(type); | 109 type = AutofillType::GetEquivalentFieldType(type); |
| 110 if (type == ADDRESS_HOME_COUNTRY && !value.empty()) { | 110 if (type == ADDRESS_HOME_COUNTRY && !value.empty()) { |
| 111 country_code_ = | 111 country_code_ = |
| 112 ASCIIToUTF16(AutofillCountry::GetCountryCode(value, app_locale)); | 112 ASCIIToUTF16(AutofillCountry::GetCountryCode(value, app_locale)); |
| 113 return !country_code_.empty(); | 113 return !country_code_.empty(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 SetRawInfo(type, value); | 116 SetRawInfo(type, value); |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void Address::GetMatchingTypes(const string16& text, | 120 void Address::GetMatchingTypes(const base::string16& text, |
| 121 const std::string& app_locale, | 121 const std::string& app_locale, |
| 122 FieldTypeSet* matching_types) const { | 122 FieldTypeSet* matching_types) const { |
| 123 FormGroup::GetMatchingTypes(text, app_locale, matching_types); | 123 FormGroup::GetMatchingTypes(text, app_locale, matching_types); |
| 124 | 124 |
| 125 // Check to see if the |text| canonicalized as a country name is a match. | 125 // Check to see if the |text| canonicalized as a country name is a match. |
| 126 std::string country_code = AutofillCountry::GetCountryCode(text, app_locale); | 126 std::string country_code = AutofillCountry::GetCountryCode(text, app_locale); |
| 127 if (!country_code.empty() && country_code_ == ASCIIToUTF16(country_code)) | 127 if (!country_code.empty() && country_code_ == ASCIIToUTF16(country_code)) |
| 128 matching_types->insert(ADDRESS_HOME_COUNTRY); | 128 matching_types->insert(ADDRESS_HOME_COUNTRY); |
| 129 } | 129 } |
| OLD | NEW |