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

Side by Side Diff: components/autofill/core/browser/address.cc

Issue 2829903004: Reland: Normalize shipping address for merchant on Desktop. (Closed)
Patch Set: Make android code use the new impl Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/i18n/case_conversion.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "components/autofill/core/browser/autofill_country.h" 15 #include "components/autofill/core/browser/autofill_country.h"
16 #include "components/autofill/core/browser/autofill_data_util.h"
15 #include "components/autofill/core/browser/autofill_field.h" 17 #include "components/autofill/core/browser/autofill_field.h"
16 #include "components/autofill/core/browser/autofill_profile.h" 18 #include "components/autofill/core/browser/autofill_profile.h"
17 #include "components/autofill/core/browser/autofill_profile_comparator.h" 19 #include "components/autofill/core/browser/autofill_profile_comparator.h"
18 #include "components/autofill/core/browser/autofill_type.h" 20 #include "components/autofill/core/browser/autofill_type.h"
19 #include "components/autofill/core/browser/country_names.h" 21 #include "components/autofill/core/browser/country_names.h"
20 #include "components/autofill/core/browser/state_names.h" 22 #include "components/autofill/core/browser/state_names.h"
21 #include "components/autofill/core/common/autofill_l10n_util.h" 23 #include "components/autofill/core/common/autofill_l10n_util.h"
22 24
23 namespace autofill { 25 namespace autofill {
24 26
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 case ADDRESS_HOME_CITY: 129 case ADDRESS_HOME_CITY:
128 city_ = value; 130 city_ = value;
129 break; 131 break;
130 132
131 case ADDRESS_HOME_STATE: 133 case ADDRESS_HOME_STATE:
132 state_ = value; 134 state_ = value;
133 break; 135 break;
134 136
135 case ADDRESS_HOME_COUNTRY: 137 case ADDRESS_HOME_COUNTRY:
136 DCHECK(value.empty() || 138 DCHECK(value.empty() ||
137 (value.length() == 2u && base::IsStringASCII(value))); 139 data_util::IsValidCountryCode(base::i18n::ToUpper(value)));
138 country_code_ = base::UTF16ToASCII(value); 140 country_code_ = base::ToUpperASCII(base::UTF16ToASCII(value));
139 break; 141 break;
140 142
141 case ADDRESS_HOME_ZIP: 143 case ADDRESS_HOME_ZIP:
142 zip_code_ = value; 144 zip_code_ = value;
143 break; 145 break;
144 146
145 case ADDRESS_HOME_SORTING_CODE: 147 case ADDRESS_HOME_SORTING_CODE:
146 sorting_code_ = value; 148 sorting_code_ = value;
147 break; 149 break;
148 150
(...skipping 17 matching lines...) Expand all
166 if (storable_type == ADDRESS_HOME_COUNTRY && !country_code_.empty()) 168 if (storable_type == ADDRESS_HOME_COUNTRY && !country_code_.empty())
167 return AutofillCountry(country_code_, app_locale).name(); 169 return AutofillCountry(country_code_, app_locale).name();
168 170
169 return GetRawInfo(storable_type); 171 return GetRawInfo(storable_type);
170 } 172 }
171 173
172 bool Address::SetInfo(const AutofillType& type, 174 bool Address::SetInfo(const AutofillType& type,
173 const base::string16& value, 175 const base::string16& value,
174 const std::string& app_locale) { 176 const std::string& app_locale) {
175 if (type.html_type() == HTML_TYPE_COUNTRY_CODE) { 177 if (type.html_type() == HTML_TYPE_COUNTRY_CODE) {
176 if (!value.empty() && (value.size() != 2u || !base::IsStringASCII(value))) { 178 if (!data_util::IsValidCountryCode(base::i18n::ToUpper(value))) {
177 country_code_ = std::string(); 179 country_code_ = std::string();
178 return false; 180 return false;
179 } 181 }
180 182
181 country_code_ = base::ToUpperASCII(base::UTF16ToASCII(value)); 183 country_code_ = base::ToUpperASCII(base::UTF16ToASCII(value));
182 return true; 184 return true;
183 } else if (type.html_type() == HTML_TYPE_FULL_ADDRESS) { 185 } else if (type.html_type() == HTML_TYPE_FULL_ADDRESS) {
184 // Parsing a full address is too hard. 186 // Parsing a full address is too hard.
185 return false; 187 return false;
186 } 188 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 supported_types->insert(ADDRESS_HOME_COUNTRY); 253 supported_types->insert(ADDRESS_HOME_COUNTRY);
252 } 254 }
253 255
254 void Address::TrimStreetAddress() { 256 void Address::TrimStreetAddress() {
255 while (!street_address_.empty() && street_address_.back().empty()) { 257 while (!street_address_.empty() && street_address_.back().empty()) {
256 street_address_.pop_back(); 258 street_address_.pop_back();
257 } 259 }
258 } 260 }
259 261
260 } // namespace autofill 262 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698