| 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/autofill_ie_toolbar_import_win.h" | 5 #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } profile_reg_values[] = { | 94 } profile_reg_values[] = { |
| 95 { NAME_FIRST, L"name_first" }, | 95 { NAME_FIRST, L"name_first" }, |
| 96 { NAME_MIDDLE, L"name_middle" }, | 96 { NAME_MIDDLE, L"name_middle" }, |
| 97 { NAME_LAST, L"name_last" }, | 97 { NAME_LAST, L"name_last" }, |
| 98 { NAME_SUFFIX, L"name_suffix" }, | 98 { NAME_SUFFIX, L"name_suffix" }, |
| 99 { EMAIL_ADDRESS, L"email" }, | 99 { EMAIL_ADDRESS, L"email" }, |
| 100 { COMPANY_NAME, L"company_name" }, | 100 { COMPANY_NAME, L"company_name" }, |
| 101 { PHONE_HOME_NUMBER, L"phone_home_number" }, | 101 { PHONE_HOME_NUMBER, L"phone_home_number" }, |
| 102 { PHONE_HOME_CITY_CODE, L"phone_home_city_code" }, | 102 { PHONE_HOME_CITY_CODE, L"phone_home_city_code" }, |
| 103 { PHONE_HOME_COUNTRY_CODE, L"phone_home_country_code" }, | 103 { PHONE_HOME_COUNTRY_CODE, L"phone_home_country_code" }, |
| 104 { PHONE_FAX_NUMBER, L"phone_fax_number" }, | |
| 105 { PHONE_FAX_CITY_CODE, L"phone_fax_city_code" }, | |
| 106 { PHONE_FAX_COUNTRY_CODE, L"phone_fax_country_code" }, | |
| 107 { ADDRESS_HOME_LINE1, L"address_home_line1" }, | 104 { ADDRESS_HOME_LINE1, L"address_home_line1" }, |
| 108 { ADDRESS_HOME_LINE2, L"address_home_line2" }, | 105 { ADDRESS_HOME_LINE2, L"address_home_line2" }, |
| 109 { ADDRESS_HOME_CITY, L"address_home_city" }, | 106 { ADDRESS_HOME_CITY, L"address_home_city" }, |
| 110 { ADDRESS_HOME_STATE, L"address_home_state" }, | 107 { ADDRESS_HOME_STATE, L"address_home_state" }, |
| 111 { ADDRESS_HOME_ZIP, L"address_home_zip" }, | 108 { ADDRESS_HOME_ZIP, L"address_home_zip" }, |
| 112 { ADDRESS_HOME_COUNTRY, L"address_home_country" }, | 109 { ADDRESS_HOME_COUNTRY, L"address_home_country" }, |
| 113 { ADDRESS_BILLING_LINE1, L"address_billing_line1" }, | 110 { ADDRESS_BILLING_LINE1, L"address_billing_line1" }, |
| 114 { ADDRESS_BILLING_LINE2, L"address_billing_line2" }, | 111 { ADDRESS_BILLING_LINE2, L"address_billing_line2" }, |
| 115 { ADDRESS_BILLING_CITY, L"address_billing_city" }, | 112 { ADDRESS_BILLING_CITY, L"address_billing_city" }, |
| 116 { ADDRESS_BILLING_STATE, L"address_billing_state" }, | 113 { ADDRESS_BILLING_STATE, L"address_billing_state" }, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 129 bool ImportSingleProfile(FormGroup* profile, | 126 bool ImportSingleProfile(FormGroup* profile, |
| 130 RegKey* key, | 127 RegKey* key, |
| 131 const RegToFieldMap& reg_to_field ) { | 128 const RegToFieldMap& reg_to_field ) { |
| 132 DCHECK(profile != NULL); | 129 DCHECK(profile != NULL); |
| 133 if (!key->Valid()) | 130 if (!key->Valid()) |
| 134 return false; | 131 return false; |
| 135 | 132 |
| 136 bool has_non_empty_fields = false; | 133 bool has_non_empty_fields = false; |
| 137 | 134 |
| 138 // Phones need to be rebuilt. | 135 // Phones need to be rebuilt. |
| 139 PhoneNumber::PhoneCombineHelper home(AutofillType::PHONE_HOME); | 136 PhoneNumber::PhoneCombineHelper phone; |
| 140 PhoneNumber::PhoneCombineHelper fax(AutofillType::PHONE_FAX); | |
| 141 | 137 |
| 142 for (uint32 value_index = 0; value_index < key->ValueCount(); ++value_index) { | 138 for (uint32 value_index = 0; value_index < key->ValueCount(); ++value_index) { |
| 143 std::wstring value_name; | 139 std::wstring value_name; |
| 144 if (key->ReadName(value_index, &value_name) != ERROR_SUCCESS) | 140 if (key->ReadName(value_index, &value_name) != ERROR_SUCCESS) |
| 145 continue; | 141 continue; |
| 146 RegToFieldMap::const_iterator it = reg_to_field.find(value_name); | 142 RegToFieldMap::const_iterator it = reg_to_field.find(value_name); |
| 147 if (it == reg_to_field.end()) | 143 if (it == reg_to_field.end()) |
| 148 continue; // This field is not imported. | 144 continue; // This field is not imported. |
| 149 string16 field_value = ReadAndDecryptValue(key, value_name.c_str()); | 145 string16 field_value = ReadAndDecryptValue(key, value_name.c_str()); |
| 150 if (!field_value.empty()) { | 146 if (!field_value.empty()) { |
| 151 has_non_empty_fields = true; | 147 has_non_empty_fields = true; |
| 152 if (it->second == CREDIT_CARD_NUMBER) { | 148 if (it->second == CREDIT_CARD_NUMBER) |
| 153 field_value = DecryptCCNumber(field_value); | 149 field_value = DecryptCCNumber(field_value); |
| 154 } | 150 |
| 155 // We need to store phone data in the variables, before building the whole | 151 // We need to store phone data in |phone| before building the whole number |
| 156 // number at the end. The rest of the fields are set "as is". | 152 // at the end. The rest of the fields are set "as is". |
| 157 if (!home.SetInfo(it->second, field_value) && | 153 if (!phone.SetInfo(it->second, field_value)) |
| 158 !fax.SetInfo(it->second, field_value)) { | |
| 159 profile->SetInfo(it->second, field_value); | 154 profile->SetInfo(it->second, field_value); |
| 160 } | |
| 161 } | 155 } |
| 162 } | 156 } |
| 163 // Now re-construct the phones if needed. | 157 // Now re-construct the phones if needed. |
| 164 string16 constructed_number; | 158 string16 constructed_number; |
| 165 if (!home.IsEmpty() && | 159 if (!phone.IsEmpty() && |
| 166 home.ParseNumber(std::string("US"), &constructed_number)) { | 160 phone.ParseNumber(std::string("US"), &constructed_number)) { |
| 167 profile->SetCanonicalizedInfo(PHONE_HOME_WHOLE_NUMBER, constructed_number); | 161 profile->SetCanonicalizedInfo(PHONE_HOME_WHOLE_NUMBER, constructed_number); |
| 168 } | 162 } |
| 169 if (!fax.IsEmpty() && | |
| 170 fax.ParseNumber(std::string("US"), &constructed_number)) { | |
| 171 profile->SetCanonicalizedInfo(PHONE_FAX_WHOLE_NUMBER, constructed_number); | |
| 172 } | |
| 173 | 163 |
| 174 return has_non_empty_fields; | 164 return has_non_empty_fields; |
| 175 } | 165 } |
| 176 | 166 |
| 177 // Imports profiles from the IE toolbar and stores them. Asynchronous | 167 // Imports profiles from the IE toolbar and stores them. Asynchronous |
| 178 // if PersonalDataManager has not been loaded yet. Deletes itself on completion. | 168 // if PersonalDataManager has not been loaded yet. Deletes itself on completion. |
| 179 class AutofillImporter : public PersonalDataManagerObserver { | 169 class AutofillImporter : public PersonalDataManagerObserver { |
| 180 public: | 170 public: |
| 181 explicit AutofillImporter(PersonalDataManager* personal_data_manager) | 171 explicit AutofillImporter(PersonalDataManager* personal_data_manager) |
| 182 : personal_data_manager_(personal_data_manager) { | 172 : personal_data_manager_(personal_data_manager) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 266 |
| 277 bool ImportAutofillDataWin(PersonalDataManager* pdm) { | 267 bool ImportAutofillDataWin(PersonalDataManager* pdm) { |
| 278 // In incognito mode we do not have PDM - and we should not import anything. | 268 // In incognito mode we do not have PDM - and we should not import anything. |
| 279 if (!pdm) | 269 if (!pdm) |
| 280 return false; | 270 return false; |
| 281 AutofillImporter *importer = new AutofillImporter(pdm); | 271 AutofillImporter *importer = new AutofillImporter(pdm); |
| 282 // importer will self delete. | 272 // importer will self delete. |
| 283 return importer->ImportProfiles(); | 273 return importer->ImportProfiles(); |
| 284 } | 274 } |
| 285 | 275 |
| OLD | NEW |