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

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

Issue 22040002: [Autofill] Add a separate enumeration for HTML field type hints. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add docs Created 7 years, 4 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 | Annotate | Revision Log
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/phone_number.h" 5 #include "components/autofill/core/browser/phone_number.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 void PhoneNumber::GetSupportedTypes(NativeFieldTypeSet* supported_types) const { 68 void PhoneNumber::GetSupportedTypes(NativeFieldTypeSet* supported_types) const {
69 supported_types->insert(PHONE_HOME_WHOLE_NUMBER); 69 supported_types->insert(PHONE_HOME_WHOLE_NUMBER);
70 supported_types->insert(PHONE_HOME_NUMBER); 70 supported_types->insert(PHONE_HOME_NUMBER);
71 supported_types->insert(PHONE_HOME_CITY_CODE); 71 supported_types->insert(PHONE_HOME_CITY_CODE);
72 supported_types->insert(PHONE_HOME_CITY_AND_NUMBER); 72 supported_types->insert(PHONE_HOME_CITY_AND_NUMBER);
73 supported_types->insert(PHONE_HOME_COUNTRY_CODE); 73 supported_types->insert(PHONE_HOME_COUNTRY_CODE);
74 } 74 }
75 75
76 base::string16 PhoneNumber::GetRawInfo(NativeFieldType type) const { 76 base::string16 PhoneNumber::GetRawInfo(NativeFieldType type) const {
77 type = AutofillType::GetEquivalentFieldType(type); 77 // TODO(isherman): Is GetEquivalentNativeType even necessary?
78 if (type == PHONE_HOME_WHOLE_NUMBER) 78 if (AutofillType(type).GetEquivalentNativeType() == PHONE_HOME_WHOLE_NUMBER)
79 return number_; 79 return number_;
80 80
81 // Only the whole number is available as raw data. All of the other types are 81 // Only the whole number is available as raw data. All of the other types are
82 // parsed from this raw info, and parsing requires knowledge of the phone 82 // parsed from this raw info, and parsing requires knowledge of the phone
83 // number's region, which is only available via GetInfo(). 83 // number's region, which is only available via GetInfo().
84 return base::string16(); 84 return base::string16();
85 } 85 }
86 86
87 void PhoneNumber::SetRawInfo(NativeFieldType type, 87 void PhoneNumber::SetRawInfo(NativeFieldType type,
88 const base::string16& value) { 88 const base::string16& value) {
89 type = AutofillType::GetEquivalentFieldType(type); 89 // TODO(isherman): Is GetEquivalentNativeType even necessary?
90 if (type != PHONE_HOME_CITY_AND_NUMBER && 90 type = AutofillType(type).GetEquivalentNativeType();
91 type != PHONE_HOME_WHOLE_NUMBER) { 91 if (type != PHONE_HOME_CITY_AND_NUMBER && type != PHONE_HOME_WHOLE_NUMBER) {
92 // Only full phone numbers should be set directly. The remaining field 92 // Only full phone numbers should be set directly. The remaining field
93 // field types are read-only. 93 // field types are read-only.
94 return; 94 return;
95 } 95 }
96 96
97 number_ = value; 97 number_ = value;
98 98
99 // Invalidate the cached number. 99 // Invalidate the cached number.
100 cached_parsed_phone_ = i18n::PhoneObject(); 100 cached_parsed_phone_ = i18n::PhoneObject();
101 } 101 }
102 102
103 // Normalize phones if |type| is a whole number: 103 // Normalize phones if |type| is a whole number:
104 // (650)2345678 -> 6502345678 104 // (650)2345678 -> 6502345678
105 // 1-800-FLOWERS -> 18003569377 105 // 1-800-FLOWERS -> 18003569377
106 // If the phone cannot be normalized, returns the stored value verbatim. 106 // If the phone cannot be normalized, returns the stored value verbatim.
107 base::string16 PhoneNumber::GetInfo(const AutofillType& type, 107 base::string16 PhoneNumber::GetInfo(const AutofillType& type,
108 const std::string& app_locale) const { 108 const std::string& app_locale) const {
109 NativeFieldType native_type = 109 NativeFieldType native_type = type.GetEquivalentNativeType();
110 AutofillType::GetEquivalentFieldType(type.native_type());
111 UpdateCacheIfNeeded(app_locale); 110 UpdateCacheIfNeeded(app_locale);
112 111
113 // Queries for whole numbers will return the non-normalized number if 112 // Queries for whole numbers will return the non-normalized number if
114 // normalization for the number fails. All other field types require 113 // normalization for the number fails. All other field types require
115 // normalization. 114 // normalization.
116 if (native_type != PHONE_HOME_WHOLE_NUMBER && 115 if (native_type != PHONE_HOME_WHOLE_NUMBER &&
117 !cached_parsed_phone_.IsValidNumber()) 116 !cached_parsed_phone_.IsValidNumber())
118 return base::string16(); 117 return base::string16();
119 118
120 switch (native_type) { 119 switch (native_type) {
(...skipping 15 matching lines...) Expand all
136 135
137 default: 136 default:
138 NOTREACHED(); 137 NOTREACHED();
139 return base::string16(); 138 return base::string16();
140 } 139 }
141 } 140 }
142 141
143 bool PhoneNumber::SetInfo(const AutofillType& type, 142 bool PhoneNumber::SetInfo(const AutofillType& type,
144 const base::string16& value, 143 const base::string16& value,
145 const std::string& app_locale) { 144 const std::string& app_locale) {
146 NativeFieldType native_type = 145 NativeFieldType native_type = type.GetEquivalentNativeType();
147 AutofillType::GetEquivalentFieldType(type.native_type());
148 SetRawInfo(native_type, value); 146 SetRawInfo(native_type, value);
149 147
150 if (number_.empty()) 148 if (number_.empty())
151 return true; 149 return true;
152 150
153 // Store a formatted (i.e., pretty printed) version of the number. 151 // Store a formatted (i.e., pretty printed) version of the number.
154 UpdateCacheIfNeeded(app_locale); 152 UpdateCacheIfNeeded(app_locale);
155 number_ = cached_parsed_phone_.GetFormattedNumber(); 153 number_ = cached_parsed_phone_.GetFormattedNumber();
156 return !number_.empty(); 154 return !number_.empty();
157 } 155 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (!number_.empty() && cached_parsed_phone_.region() != region) 187 if (!number_.empty() && cached_parsed_phone_.region() != region)
190 cached_parsed_phone_ = i18n::PhoneObject(number_, region); 188 cached_parsed_phone_ = i18n::PhoneObject(number_, region);
191 } 189 }
192 190
193 PhoneNumber::PhoneCombineHelper::PhoneCombineHelper() { 191 PhoneNumber::PhoneCombineHelper::PhoneCombineHelper() {
194 } 192 }
195 193
196 PhoneNumber::PhoneCombineHelper::~PhoneCombineHelper() { 194 PhoneNumber::PhoneCombineHelper::~PhoneCombineHelper() {
197 } 195 }
198 196
199 bool PhoneNumber::PhoneCombineHelper::SetInfo(const AutofillType& field_type, 197 bool PhoneNumber::PhoneCombineHelper::SetInfo(const AutofillType& type,
200 const base::string16& value) { 198 const base::string16& value) {
201 NativeFieldType native_field_type = 199 NativeFieldType native_field_type = type.GetEquivalentNativeType();
202 AutofillType::GetEquivalentFieldType(field_type.native_type());
203 if (native_field_type == PHONE_HOME_COUNTRY_CODE) { 200 if (native_field_type == PHONE_HOME_COUNTRY_CODE) {
204 country_ = value; 201 country_ = value;
205 return true; 202 return true;
206 } 203 }
207 204
208 if (native_field_type == PHONE_HOME_CITY_CODE) { 205 if (native_field_type == PHONE_HOME_CITY_CODE) {
209 city_ = value; 206 city_ = value;
210 return true; 207 return true;
211 } 208 }
212 209
(...skipping 29 matching lines...) Expand all
242 239
243 return i18n::ConstructPhoneNumber( 240 return i18n::ConstructPhoneNumber(
244 country_, city_, phone_, GetRegion(profile, app_locale), value); 241 country_, city_, phone_, GetRegion(profile, app_locale), value);
245 } 242 }
246 243
247 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { 244 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const {
248 return phone_.empty() && whole_number_.empty(); 245 return phone_.empty() && whole_number_.empty();
249 } 246 }
250 247
251 } // namespace autofill 248 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698