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/phone_number.h" | 5 #include "components/autofill/core/browser/phone_number.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/core/browser/autofill_country.h" | 10 #include "components/autofill/core/browser/autofill_country.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 if (base::ContainsOnlyChars(number_, base::ASCIIToUTF16("+0123456789"))) { | 139 if (base::ContainsOnlyChars(number_, base::ASCIIToUTF16("+0123456789"))) { |
140 number_ = cached_parsed_phone_.GetFormattedNumber(); | 140 number_ = cached_parsed_phone_.GetFormattedNumber(); |
141 } else if (i18n::NormalizePhoneNumber( | 141 } else if (i18n::NormalizePhoneNumber( |
142 number_, GetRegion(*profile_, app_locale)).empty()) { | 142 number_, GetRegion(*profile_, app_locale)).empty()) { |
143 // The number doesn't make sense for this region; clear it. | 143 // The number doesn't make sense for this region; clear it. |
144 number_.clear(); | 144 number_.clear(); |
145 } | 145 } |
146 return !number_.empty(); | 146 return !number_.empty(); |
147 } | 147 } |
148 | 148 |
149 void PhoneNumber::GetMatchingTypes(const base::string16& text, | 149 void PhoneNumber::GetMatchingTypes(const base::string16& text, |
Mathieu
2016/01/25 20:32:16
Since you have the context in your head, please en
sebsg
2016/01/26 21:31:07
Done.
| |
150 const std::string& app_locale, | 150 const std::string& app_locale, |
151 ServerFieldTypeSet* matching_types) const { | 151 ServerFieldTypeSet* matching_types) const { |
152 base::string16 stripped_text = text; | 152 base::string16 stripped_text = text; |
153 base::RemoveChars(stripped_text, base::ASCIIToUTF16(" .()-"), &stripped_text); | 153 base::RemoveChars(stripped_text, base::ASCIIToUTF16(" .()-"), &stripped_text); |
154 FormGroup::GetMatchingTypes(stripped_text, app_locale, matching_types); | 154 FormGroup::GetMatchingTypes(stripped_text, app_locale, matching_types); |
155 | 155 |
156 // For US numbers, also compare to the three-digit prefix and the four-digit | 156 // For US numbers, also compare to the three-digit prefix and the four-digit |
157 // suffix, since web sites often split numbers into these two fields. | 157 // suffix, since web sites often split numbers into these two fields. |
158 base::string16 number = GetInfo(AutofillType(PHONE_HOME_NUMBER), app_locale); | 158 base::string16 number = GetInfo(AutofillType(PHONE_HOME_NUMBER), app_locale); |
159 if (GetRegion(*profile_, app_locale) == "US" && | 159 if (GetRegion(*profile_, app_locale) == "US" && |
160 number.size() == (kPrefixLength + kSuffixLength)) { | 160 number.size() == (kPrefixLength + kSuffixLength)) { |
161 base::string16 prefix = number.substr(kPrefixOffset, kPrefixLength); | 161 base::string16 prefix = number.substr(kPrefixOffset, kPrefixLength); |
162 base::string16 suffix = number.substr(kSuffixOffset, kSuffixLength); | 162 base::string16 suffix = number.substr(kSuffixOffset, kSuffixLength); |
163 if (text == prefix || text == suffix) | 163 if (text == prefix || text == suffix) |
164 matching_types->insert(PHONE_HOME_NUMBER); | 164 matching_types->insert(PHONE_HOME_NUMBER); |
165 } | 165 } |
166 | 166 |
167 // To match whole phone numbers with the "+" in front of the country code. | |
Mathieu
2016/01/25 20:32:16
is the + always present?
sebsg
2016/01/26 21:31:07
I put a better comment.
| |
167 base::string16 whole_number = | 168 base::string16 whole_number = |
168 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), app_locale); | 169 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), app_locale); |
169 if (!whole_number.empty()) { | 170 if (!whole_number.empty()) { |
170 base::string16 normalized_number = | 171 base::string16 normalized_number = |
171 i18n::NormalizePhoneNumber(text, GetRegion(*profile_, app_locale)); | 172 i18n::NormalizePhoneNumber(text, GetRegion(*profile_, app_locale)); |
172 if (normalized_number == whole_number) | 173 if (normalized_number == whole_number) { |
Mathieu
2016/01/25 20:32:16
revert change to add {}
sebsg
2016/01/26 21:31:07
Done.
| |
173 matching_types->insert(PHONE_HOME_WHOLE_NUMBER); | 174 matching_types->insert(PHONE_HOME_WHOLE_NUMBER); |
175 } | |
176 } | |
177 | |
178 // If both PHONE_HOME_CITY_AND_NUMBER and PHONE_HOME_WHOLE_NUMBER, it means | |
Mathieu
2016/01/25 20:32:16
nit: sentence is missing a few words
sebsg
2016/01/26 21:31:07
Done.
| |
179 // there is no country code and we should only return | |
180 // PHONE_HOME_CITY_AND_NUMBER. | |
181 ServerFieldTypeSet::iterator whole_number_iterator = | |
182 matching_types->find(PHONE_HOME_WHOLE_NUMBER); | |
183 if (whole_number_iterator != matching_types->end() && | |
184 matching_types->find(PHONE_HOME_CITY_AND_NUMBER) != | |
185 matching_types->end()) { | |
186 matching_types->erase(whole_number_iterator); | |
174 } | 187 } |
175 } | 188 } |
176 | 189 |
177 void PhoneNumber::UpdateCacheIfNeeded(const std::string& app_locale) const { | 190 void PhoneNumber::UpdateCacheIfNeeded(const std::string& app_locale) const { |
178 std::string region = GetRegion(*profile_, app_locale); | 191 std::string region = GetRegion(*profile_, app_locale); |
179 if (!number_.empty() && cached_parsed_phone_.region() != region) | 192 if (!number_.empty() && cached_parsed_phone_.region() != region) |
180 cached_parsed_phone_ = i18n::PhoneObject(number_, region); | 193 cached_parsed_phone_ = i18n::PhoneObject(number_, region); |
181 } | 194 } |
182 | 195 |
183 PhoneNumber::PhoneCombineHelper::PhoneCombineHelper() { | 196 PhoneNumber::PhoneCombineHelper::PhoneCombineHelper() { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 | 244 |
232 return i18n::ConstructPhoneNumber( | 245 return i18n::ConstructPhoneNumber( |
233 country_, city_, phone_, GetRegion(profile, app_locale), value); | 246 country_, city_, phone_, GetRegion(profile, app_locale), value); |
234 } | 247 } |
235 | 248 |
236 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { | 249 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { |
237 return phone_.empty() && whole_number_.empty(); | 250 return phone_.empty() && whole_number_.empty(); |
238 } | 251 } |
239 | 252 |
240 } // namespace autofill | 253 } // namespace autofill |
OLD | NEW |