Chromium Code Reviews| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, |
| 150 const std::string& app_locale, | 150 const std::string& app_locale, |
| 151 ServerFieldTypeSet* matching_types) const { | 151 ServerFieldTypeSet* matching_types) const { |
| 152 // Strip the common phone number non numerical characters before calling the | |
| 153 // base matching type function. For example, the |text| "(514) 121-1523" | |
| 154 // would become the stripped text "5141211523". | |
|
Mathieu
2016/01/27 18:48:35
Mention that FormGroup::GetMatchingTypes will only
sebsg
2016/01/27 20:00:43
Done.
| |
| 152 base::string16 stripped_text = text; | 155 base::string16 stripped_text = text; |
| 153 base::RemoveChars(stripped_text, base::ASCIIToUTF16(" .()-"), &stripped_text); | 156 base::RemoveChars(stripped_text, base::ASCIIToUTF16(" .()-"), &stripped_text); |
| 154 FormGroup::GetMatchingTypes(stripped_text, app_locale, matching_types); | 157 FormGroup::GetMatchingTypes(stripped_text, app_locale, matching_types); |
| 155 | 158 |
| 156 // For US numbers, also compare to the three-digit prefix and the four-digit | 159 // 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. | 160 // suffix, since web sites often split numbers into these two fields. |
| 158 base::string16 number = GetInfo(AutofillType(PHONE_HOME_NUMBER), app_locale); | 161 base::string16 number = GetInfo(AutofillType(PHONE_HOME_NUMBER), app_locale); |
| 159 if (GetRegion(*profile_, app_locale) == "US" && | 162 if (GetRegion(*profile_, app_locale) == "US" && |
| 160 number.size() == (kPrefixLength + kSuffixLength)) { | 163 number.size() == (kPrefixLength + kSuffixLength)) { |
| 161 base::string16 prefix = number.substr(kPrefixOffset, kPrefixLength); | 164 base::string16 prefix = number.substr(kPrefixOffset, kPrefixLength); |
| 162 base::string16 suffix = number.substr(kSuffixOffset, kSuffixLength); | 165 base::string16 suffix = number.substr(kSuffixOffset, kSuffixLength); |
| 163 if (text == prefix || text == suffix) | 166 if (text == prefix || text == suffix) |
| 164 matching_types->insert(PHONE_HOME_NUMBER); | 167 matching_types->insert(PHONE_HOME_NUMBER); |
| 165 } | 168 } |
| 166 | 169 |
| 170 // TODO(crbug.com/581391): Investigate the use of phonenumberutil when | |
|
Mathieu
2016/01/27 18:48:35
*PhoneNumberUtil
sebsg
2016/01/27 20:00:43
Done.
| |
| 171 // matching phone numbers for upload. | |
| 172 // Normalizes the |text| based on the app_locale before comparing it to the | |
| 173 // whole number. For example, the number from France "33 2 49 19 70 70" would | |
|
Mathieu
2016/01/27 18:48:35
*the France number and *the US number
sebsg
2016/01/27 20:00:43
Done.
| |
| 174 // be normalized to "+33249197070" whereas the number from the US | |
| 175 // "+1 (234) 567-8901" would be normalized to "12345678901". | |
| 167 base::string16 whole_number = | 176 base::string16 whole_number = |
| 168 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), app_locale); | 177 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), app_locale); |
| 169 if (!whole_number.empty()) { | 178 if (!whole_number.empty()) { |
| 170 base::string16 normalized_number = | 179 base::string16 normalized_number = |
| 171 i18n::NormalizePhoneNumber(text, GetRegion(*profile_, app_locale)); | 180 i18n::NormalizePhoneNumber(text, GetRegion(*profile_, app_locale)); |
| 172 if (normalized_number == whole_number) | 181 if (normalized_number == whole_number) |
| 173 matching_types->insert(PHONE_HOME_WHOLE_NUMBER); | 182 matching_types->insert(PHONE_HOME_WHOLE_NUMBER); |
|
Mathieu
2016/01/27 18:48:35
I think there's a case where we could be doubly ad
sebsg
2016/01/27 20:00:43
Done.
| |
| 174 } | 183 } |
| 184 | |
| 185 // If both PHONE_HOME_CITY_AND_NUMBER and PHONE_HOME_WHOLE_NUMBER are matched, | |
| 186 // it means there is no country code in the profile's phone number.In that | |
|
Mathieu
2016/01/27 18:48:35
nit: space after .
sebsg
2016/01/27 20:00:43
Done.
| |
| 187 // case, we should only return PHONE_HOME_CITY_AND_NUMBER because it's more | |
| 188 // precise. | |
| 189 ServerFieldTypeSet::iterator whole_number_iterator = | |
| 190 matching_types->find(PHONE_HOME_WHOLE_NUMBER); | |
| 191 if (whole_number_iterator != matching_types->end() && | |
| 192 matching_types->find(PHONE_HOME_CITY_AND_NUMBER) != | |
| 193 matching_types->end()) { | |
| 194 matching_types->erase(whole_number_iterator); | |
| 195 } | |
| 175 } | 196 } |
| 176 | 197 |
| 177 void PhoneNumber::UpdateCacheIfNeeded(const std::string& app_locale) const { | 198 void PhoneNumber::UpdateCacheIfNeeded(const std::string& app_locale) const { |
| 178 std::string region = GetRegion(*profile_, app_locale); | 199 std::string region = GetRegion(*profile_, app_locale); |
| 179 if (!number_.empty() && cached_parsed_phone_.region() != region) | 200 if (!number_.empty() && cached_parsed_phone_.region() != region) |
| 180 cached_parsed_phone_ = i18n::PhoneObject(number_, region); | 201 cached_parsed_phone_ = i18n::PhoneObject(number_, region); |
| 181 } | 202 } |
| 182 | 203 |
| 183 PhoneNumber::PhoneCombineHelper::PhoneCombineHelper() { | 204 PhoneNumber::PhoneCombineHelper::PhoneCombineHelper() { |
| 184 } | 205 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 | 252 |
| 232 return i18n::ConstructPhoneNumber( | 253 return i18n::ConstructPhoneNumber( |
| 233 country_, city_, phone_, GetRegion(profile, app_locale), value); | 254 country_, city_, phone_, GetRegion(profile, app_locale), value); |
| 234 } | 255 } |
| 235 | 256 |
| 236 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { | 257 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { |
| 237 return phone_.empty() && whole_number_.empty(); | 258 return phone_.empty() && whole_number_.empty(); |
| 238 } | 259 } |
| 239 | 260 |
| 240 } // namespace autofill | 261 } // namespace autofill |
| OLD | NEW |