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/personal_data_manager.h" | 5 #include "chrome/browser/autofill/personal_data_manager.h" |
6 | 6 |
7 #import <AddressBook/AddressBook.h> | 7 #import <AddressBook/AddressBook.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 182 } |
183 | 183 |
184 // Fills in telephone numbers. Each of these are special cases. | 184 // Fills in telephone numbers. Each of these are special cases. |
185 // We match four cases: home/tel, home/fax, work/tel, work/fax. | 185 // We match four cases: home/tel, home/fax, work/tel, work/fax. |
186 // Note, we traverse in reverse order so that top values in address book | 186 // Note, we traverse in reverse order so that top values in address book |
187 // take priority. | 187 // take priority. |
188 void AuxiliaryProfilesImpl::GetAddressBookPhoneNumbers( | 188 void AuxiliaryProfilesImpl::GetAddressBookPhoneNumbers( |
189 ABPerson* me, | 189 ABPerson* me, |
190 NSString* addressLabelRaw, | 190 NSString* addressLabelRaw, |
191 AutofillProfile* profile) { | 191 AutofillProfile* profile) { |
192 string16 number; | |
193 string16 city_code; | |
194 string16 country_code; | |
195 | |
196 ABMultiValue* phoneNumbers = [me valueForProperty:kABPhoneProperty]; | 192 ABMultiValue* phoneNumbers = [me valueForProperty:kABPhoneProperty]; |
197 for (NSUInteger k = 0, phoneCount = [phoneNumbers count]; | 193 for (NSUInteger k = 0, phoneCount = [phoneNumbers count]; |
198 k < phoneCount; k++) { | 194 k < phoneCount; k++) { |
199 NSUInteger reverseK = phoneCount - k - 1; | 195 NSUInteger reverseK = phoneCount - k - 1; |
200 NSString* phoneLabelRaw = [phoneNumbers labelAtIndex:reverseK]; | 196 NSString* phoneLabelRaw = [phoneNumbers labelAtIndex:reverseK]; |
201 if ([addressLabelRaw isEqualToString:kABAddressHomeLabel] && | 197 if ([addressLabelRaw isEqualToString:kABAddressHomeLabel] && |
202 [phoneLabelRaw isEqualToString:kABPhoneHomeLabel]) { | 198 [phoneLabelRaw isEqualToString:kABPhoneHomeLabel]) { |
203 string16 homePhone = base::SysNSStringToUTF16( | 199 string16 homePhone = base::SysNSStringToUTF16( |
204 [phoneNumbers valueAtIndex:reverseK]); | 200 [phoneNumbers valueAtIndex:reverseK]); |
205 PhoneNumber::ParsePhoneNumber( | 201 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, homePhone); |
206 homePhone, &number, &city_code, &country_code); | |
207 profile->SetInfo(PHONE_HOME_NUMBER, number); | |
208 profile->SetInfo(PHONE_HOME_CITY_CODE, city_code); | |
209 profile->SetInfo(PHONE_HOME_COUNTRY_CODE, country_code); | |
210 } else if ([addressLabelRaw isEqualToString:kABAddressHomeLabel] && | 202 } else if ([addressLabelRaw isEqualToString:kABAddressHomeLabel] && |
211 [phoneLabelRaw isEqualToString:kABPhoneHomeFAXLabel]) { | 203 [phoneLabelRaw isEqualToString:kABPhoneHomeFAXLabel]) { |
212 string16 homeFax = base::SysNSStringToUTF16( | 204 string16 homeFax = base::SysNSStringToUTF16( |
213 [phoneNumbers valueAtIndex:reverseK]); | 205 [phoneNumbers valueAtIndex:reverseK]); |
214 PhoneNumber::ParsePhoneNumber(homeFax, | 206 profile->SetInfo(PHONE_FAX_WHOLE_NUMBER, homeFax); |
215 &number, &city_code, &country_code); | |
216 profile->SetInfo(PHONE_FAX_NUMBER, number); | |
217 profile->SetInfo(PHONE_FAX_CITY_CODE, city_code); | |
218 profile->SetInfo(PHONE_FAX_COUNTRY_CODE, country_code); | |
219 } else if ([addressLabelRaw isEqualToString:kABAddressWorkLabel] && | 207 } else if ([addressLabelRaw isEqualToString:kABAddressWorkLabel] && |
220 [phoneLabelRaw isEqualToString:kABPhoneWorkLabel]) { | 208 [phoneLabelRaw isEqualToString:kABPhoneWorkLabel]) { |
221 string16 workPhone = base::SysNSStringToUTF16( | 209 string16 workPhone = base::SysNSStringToUTF16( |
222 [phoneNumbers valueAtIndex:reverseK]); | 210 [phoneNumbers valueAtIndex:reverseK]); |
223 PhoneNumber::ParsePhoneNumber(workPhone, | 211 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, workPhone); |
224 &number, &city_code, &country_code); | |
225 profile->SetInfo(PHONE_HOME_NUMBER, number); | |
226 profile->SetInfo(PHONE_HOME_CITY_CODE, city_code); | |
227 profile->SetInfo(PHONE_HOME_COUNTRY_CODE, country_code); | |
228 } else if ([addressLabelRaw isEqualToString:kABAddressWorkLabel] && | 212 } else if ([addressLabelRaw isEqualToString:kABAddressWorkLabel] && |
229 [phoneLabelRaw isEqualToString:kABPhoneWorkFAXLabel]) { | 213 [phoneLabelRaw isEqualToString:kABPhoneWorkFAXLabel]) { |
230 string16 workFax = base::SysNSStringToUTF16( | 214 string16 workFax = base::SysNSStringToUTF16( |
231 [phoneNumbers valueAtIndex:reverseK]); | 215 [phoneNumbers valueAtIndex:reverseK]); |
232 PhoneNumber::ParsePhoneNumber(workFax, | 216 profile->SetInfo(PHONE_FAX_WHOLE_NUMBER, workFax); |
233 &number, &city_code, &country_code); | |
234 profile->SetInfo(PHONE_FAX_NUMBER, number); | |
235 profile->SetInfo(PHONE_FAX_CITY_CODE, city_code); | |
236 profile->SetInfo(PHONE_FAX_COUNTRY_CODE, country_code); | |
237 } | 217 } |
238 } | 218 } |
| 219 profile->NormalizePhones(); |
239 } | 220 } |
240 | 221 |
241 } // namespace | 222 } // namespace |
242 | 223 |
243 // Populate |auxiliary_profiles_| with the Address Book data. | 224 // Populate |auxiliary_profiles_| with the Address Book data. |
244 void PersonalDataManager::LoadAuxiliaryProfiles() const { | 225 void PersonalDataManager::LoadAuxiliaryProfiles() const { |
245 AuxiliaryProfilesImpl impl(&auxiliary_profiles_); | 226 AuxiliaryProfilesImpl impl(&auxiliary_profiles_); |
246 impl.GetAddressBookMeCard(); | 227 impl.GetAddressBookMeCard(); |
247 } | 228 } |
OLD | NEW |