| 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" |
| 11 #include "chrome/browser/autofill/autofill_profile.h" | 11 #include "chrome/browser/autofill/autofill_profile.h" |
| 12 #include "chrome/browser/autofill/autofill_type.h" | 12 #include "chrome/browser/autofill/autofill_type.h" |
| 13 #include "chrome/browser/autofill/field_types.h" | 13 #include "chrome/browser/autofill/field_types.h" |
| 14 #include "chrome/browser/autofill/phone_number_i18n.h" | 14 #include "chrome/browser/autofill/phone_number_i18n.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const char16 kPhoneNumberSeparators[] = { ' ', '.', '(', ')', '-', 0 }; | 18 const char16 kPhoneNumberSeparators[] = { ' ', '.', '(', ')', '-', 0 }; |
| 19 | 19 |
| 20 // The number of digits in a phone number. | 20 // The number of digits in a phone number. |
| 21 const size_t kPhoneNumberLength = 7; | 21 const size_t kPhoneNumberLength = 7; |
| 22 | 22 |
| 23 // The number of digits in an area code. | 23 // The number of digits in an area code. |
| 24 const size_t kPhoneCityCodeLength = 3; | 24 const size_t kPhoneCityCodeLength = 3; |
| 25 | 25 |
| 26 const AutofillType::FieldTypeSubGroup kAutofillPhoneTypes[] = { | |
| 27 AutofillType::PHONE_NUMBER, | |
| 28 AutofillType::PHONE_CITY_CODE, | |
| 29 AutofillType::PHONE_COUNTRY_CODE, | |
| 30 AutofillType::PHONE_CITY_AND_NUMBER, | |
| 31 AutofillType::PHONE_WHOLE_NUMBER, | |
| 32 }; | |
| 33 | |
| 34 const int kAutofillPhoneLength = arraysize(kAutofillPhoneTypes); | |
| 35 | |
| 36 void StripPunctuation(string16* number) { | 26 void StripPunctuation(string16* number) { |
| 37 RemoveChars(*number, kPhoneNumberSeparators, number); | 27 RemoveChars(*number, kPhoneNumberSeparators, number); |
| 38 } | 28 } |
| 39 | 29 |
| 40 } // namespace | 30 } // namespace |
| 41 | 31 |
| 42 PhoneNumber::PhoneNumber(AutofillProfile* profile) | 32 PhoneNumber::PhoneNumber(AutofillProfile* profile) |
| 43 : profile_(profile) { | 33 : profile_(profile) { |
| 44 } | 34 } |
| 45 | 35 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 if (type == PHONE_HOME_CITY_AND_NUMBER) { | 79 if (type == PHONE_HOME_CITY_AND_NUMBER) { |
| 90 string16 city_and_local(cached_parsed_phone_.GetCityCode()); | 80 string16 city_and_local(cached_parsed_phone_.GetCityCode()); |
| 91 city_and_local.append(cached_parsed_phone_.GetNumber()); | 81 city_and_local.append(cached_parsed_phone_.GetNumber()); |
| 92 return city_and_local; | 82 return city_and_local; |
| 93 } | 83 } |
| 94 | 84 |
| 95 return string16(); | 85 return string16(); |
| 96 } | 86 } |
| 97 | 87 |
| 98 void PhoneNumber::SetInfo(AutofillFieldType type, const string16& value) { | 88 void PhoneNumber::SetInfo(AutofillFieldType type, const string16& value) { |
| 99 FieldTypeSubGroup subgroup = AutofillType(type).subgroup(); | 89 if (type != PHONE_HOME_CITY_AND_NUMBER && |
| 100 if (subgroup != AutofillType::PHONE_CITY_AND_NUMBER && | 90 type != PHONE_HOME_WHOLE_NUMBER) { |
| 101 subgroup != AutofillType::PHONE_WHOLE_NUMBER) { | |
| 102 // Only full phone numbers should be set directly. The remaining field | 91 // Only full phone numbers should be set directly. The remaining field |
| 103 // field types are read-only. | 92 // field types are read-only. |
| 104 return; | 93 return; |
| 105 } | 94 } |
| 106 | 95 |
| 107 number_ = value; | 96 number_ = value; |
| 108 cached_parsed_phone_ = autofill_i18n::PhoneObject(number_, locale()); | 97 cached_parsed_phone_ = autofill_i18n::PhoneObject(number_, locale()); |
| 109 } | 98 } |
| 110 | 99 |
| 111 // Normalize phones if |type| is a whole number: | 100 // Normalize phones if |type| is a whole number: |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 country_, city_, phone_, | 217 country_, city_, phone_, |
| 229 locale, | 218 locale, |
| 230 (country_.empty() ? | 219 (country_.empty() ? |
| 231 autofill_i18n::NATIONAL : autofill_i18n::INTERNATIONAL), | 220 autofill_i18n::NATIONAL : autofill_i18n::INTERNATIONAL), |
| 232 value); | 221 value); |
| 233 } | 222 } |
| 234 | 223 |
| 235 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { | 224 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { |
| 236 return phone_.empty() && whole_number_.empty(); | 225 return phone_.empty() && whole_number_.empty(); |
| 237 } | 226 } |
| OLD | NEW |