| 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 "chrome/browser/autofill/phone_number.h" | 5 #include "chrome/browser/autofill/phone_number.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 PhoneNumber::PhoneNumber(const PhoneNumber& number) : FormGroup() { | 53 PhoneNumber::PhoneNumber(const PhoneNumber& number) : FormGroup() { |
| 54 *this = number; | 54 *this = number; |
| 55 } | 55 } |
| 56 | 56 |
| 57 PhoneNumber::~PhoneNumber() {} | 57 PhoneNumber::~PhoneNumber() {} |
| 58 | 58 |
| 59 PhoneNumber& PhoneNumber::operator=(const PhoneNumber& number) { | 59 PhoneNumber& PhoneNumber::operator=(const PhoneNumber& number) { |
| 60 if (this == &number) | 60 if (this == &number) |
| 61 return *this; | 61 return *this; |
| 62 |
| 62 phone_group_ = number.phone_group_; | 63 phone_group_ = number.phone_group_; |
| 63 number_ = number.number_; | 64 number_ = number.number_; |
| 64 profile_ = number.profile_; | 65 profile_ = number.profile_; |
| 65 cached_parsed_phone_ = number.cached_parsed_phone_; | 66 cached_parsed_phone_ = number.cached_parsed_phone_; |
| 66 return *this; | 67 return *this; |
| 67 } | 68 } |
| 68 | 69 |
| 69 void PhoneNumber::GetSupportedTypes(FieldTypeSet* supported_types) const { | 70 void PhoneNumber::GetSupportedTypes(FieldTypeSet* supported_types) const { |
| 70 supported_types->insert(GetWholeNumberType()); | 71 supported_types->insert(GetWholeNumberType()); |
| 71 supported_types->insert(GetNumberType()); | 72 supported_types->insert(GetNumberType()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return NormalizePhone(); | 144 return NormalizePhone(); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void PhoneNumber::GetMatchingTypes(const string16& text, | 147 void PhoneNumber::GetMatchingTypes(const string16& text, |
| 147 FieldTypeSet* matching_types) const { | 148 FieldTypeSet* matching_types) const { |
| 148 string16 stripped_text = text; | 149 string16 stripped_text = text; |
| 149 StripPunctuation(&stripped_text); | 150 StripPunctuation(&stripped_text); |
| 150 FormGroup::GetMatchingTypes(stripped_text, matching_types); | 151 FormGroup::GetMatchingTypes(stripped_text, matching_types); |
| 151 | 152 |
| 152 // For US numbers, also compare to the three-digit prefix and the four-digit | 153 // For US numbers, also compare to the three-digit prefix and the four-digit |
| 153 // suffix, since websites often split numbers into these two fields. | 154 // suffix, since web sites often split numbers into these two fields. |
| 154 string16 number = GetCanonicalizedInfo(GetNumberType()); | 155 string16 number = GetCanonicalizedInfo(GetNumberType()); |
| 155 if (locale() == "US" && number.size() == (kPrefixLength + kSuffixLength)) { | 156 if (locale() == "US" && number.size() == (kPrefixLength + kSuffixLength)) { |
| 156 string16 prefix = number.substr(kPrefixOffset, kPrefixLength); | 157 string16 prefix = number.substr(kPrefixOffset, kPrefixLength); |
| 157 string16 suffix = number.substr(kSuffixOffset, kSuffixLength); | 158 string16 suffix = number.substr(kSuffixOffset, kSuffixLength); |
| 158 if (text == prefix || text == suffix) | 159 if (text == prefix || text == suffix) |
| 159 matching_types->insert(GetNumberType()); | 160 matching_types->insert(GetNumberType()); |
| 160 } | 161 } |
| 161 | 162 |
| 162 string16 whole_number = GetCanonicalizedInfo(GetWholeNumberType()); | 163 string16 whole_number = GetCanonicalizedInfo(GetWholeNumberType()); |
| 163 if (!whole_number.empty() && | 164 if (!whole_number.empty() && |
| (...skipping 20 matching lines...) Expand all Loading... |
| 184 | 185 |
| 185 return profile_->CountryCode(); | 186 return profile_->CountryCode(); |
| 186 } | 187 } |
| 187 | 188 |
| 188 void PhoneNumber::UpdateCacheIfNeeded() const { | 189 void PhoneNumber::UpdateCacheIfNeeded() const { |
| 189 if (!number_.empty() && cached_parsed_phone_.GetLocale() != locale()) | 190 if (!number_.empty() && cached_parsed_phone_.GetLocale() != locale()) |
| 190 cached_parsed_phone_ = autofill_i18n::PhoneObject(number_, locale()); | 191 cached_parsed_phone_ = autofill_i18n::PhoneObject(number_, locale()); |
| 191 } | 192 } |
| 192 | 193 |
| 193 AutofillFieldType PhoneNumber::GetNumberType() const { | 194 AutofillFieldType PhoneNumber::GetNumberType() const { |
| 194 if (phone_group_ == AutofillType::PHONE_HOME) | 195 return PHONE_HOME_NUMBER; |
| 195 return PHONE_HOME_NUMBER; | |
| 196 else if (phone_group_ == AutofillType::PHONE_FAX) | |
| 197 return PHONE_FAX_NUMBER; | |
| 198 else | |
| 199 NOTREACHED(); | |
| 200 return UNKNOWN_TYPE; | |
| 201 } | 196 } |
| 202 | 197 |
| 203 AutofillFieldType PhoneNumber::GetCityCodeType() const { | 198 AutofillFieldType PhoneNumber::GetCityCodeType() const { |
| 204 if (phone_group_ == AutofillType::PHONE_HOME) | 199 return PHONE_HOME_CITY_CODE; |
| 205 return PHONE_HOME_CITY_CODE; | |
| 206 else if (phone_group_ == AutofillType::PHONE_FAX) | |
| 207 return PHONE_FAX_CITY_CODE; | |
| 208 else | |
| 209 NOTREACHED(); | |
| 210 return UNKNOWN_TYPE; | |
| 211 } | 200 } |
| 212 | 201 |
| 213 AutofillFieldType PhoneNumber::GetCountryCodeType() const { | 202 AutofillFieldType PhoneNumber::GetCountryCodeType() const { |
| 214 if (phone_group_ == AutofillType::PHONE_HOME) | 203 return PHONE_HOME_COUNTRY_CODE; |
| 215 return PHONE_HOME_COUNTRY_CODE; | |
| 216 else if (phone_group_ == AutofillType::PHONE_FAX) | |
| 217 return PHONE_FAX_COUNTRY_CODE; | |
| 218 else | |
| 219 NOTREACHED(); | |
| 220 return UNKNOWN_TYPE; | |
| 221 } | 204 } |
| 222 | 205 |
| 223 AutofillFieldType PhoneNumber::GetCityAndNumberType() const { | 206 AutofillFieldType PhoneNumber::GetCityAndNumberType() const { |
| 224 if (phone_group_ == AutofillType::PHONE_HOME) | 207 return PHONE_HOME_CITY_AND_NUMBER; |
| 225 return PHONE_HOME_CITY_AND_NUMBER; | |
| 226 else if (phone_group_ == AutofillType::PHONE_FAX) | |
| 227 return PHONE_FAX_CITY_AND_NUMBER; | |
| 228 else | |
| 229 NOTREACHED(); | |
| 230 return UNKNOWN_TYPE; | |
| 231 } | 208 } |
| 232 | 209 |
| 233 AutofillFieldType PhoneNumber::GetWholeNumberType() const { | 210 AutofillFieldType PhoneNumber::GetWholeNumberType() const { |
| 234 if (phone_group_ == AutofillType::PHONE_HOME) | 211 return PHONE_HOME_WHOLE_NUMBER; |
| 235 return PHONE_HOME_WHOLE_NUMBER; | |
| 236 else if (phone_group_ == AutofillType::PHONE_FAX) | |
| 237 return PHONE_FAX_WHOLE_NUMBER; | |
| 238 else | |
| 239 NOTREACHED(); | |
| 240 return UNKNOWN_TYPE; | |
| 241 } | 212 } |
| 242 | 213 |
| 243 PhoneNumber::PhoneCombineHelper::PhoneCombineHelper( | 214 PhoneNumber::PhoneCombineHelper::PhoneCombineHelper( |
| 244 AutofillType::FieldTypeGroup phone_group) | 215 AutofillType::FieldTypeGroup phone_group) |
| 245 : phone_group_(phone_group) { | 216 : phone_group_(phone_group) { |
| 246 } | 217 } |
| 247 | 218 |
| 248 PhoneNumber::PhoneCombineHelper::~PhoneCombineHelper() { | 219 PhoneNumber::PhoneCombineHelper::~PhoneCombineHelper() { |
| 249 } | 220 } |
| 250 | 221 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 country_, city_, phone_, | 262 country_, city_, phone_, |
| 292 locale, | 263 locale, |
| 293 (country_.empty() ? | 264 (country_.empty() ? |
| 294 autofill_i18n::NATIONAL : autofill_i18n::INTERNATIONAL), | 265 autofill_i18n::NATIONAL : autofill_i18n::INTERNATIONAL), |
| 295 value); | 266 value); |
| 296 } | 267 } |
| 297 | 268 |
| 298 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { | 269 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { |
| 299 return phone_.empty() && whole_number_.empty(); | 270 return phone_.empty() && whole_number_.empty(); |
| 300 } | 271 } |
| OLD | NEW |