| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/win/registry.h" | 9 #include "base/win/registry.h" |
| 10 #include "chrome/browser/autofill/autofill_profile.h" | 10 #include "chrome/browser/autofill/autofill_profile.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 continue; | 130 continue; |
| 131 RegToFieldMap::const_iterator it = reg_to_field.find(value_name); | 131 RegToFieldMap::const_iterator it = reg_to_field.find(value_name); |
| 132 if (it == reg_to_field.end()) | 132 if (it == reg_to_field.end()) |
| 133 continue; // This field is not imported. | 133 continue; // This field is not imported. |
| 134 string16 field_value = ReadAndDecryptValue(key, value_name.c_str()); | 134 string16 field_value = ReadAndDecryptValue(key, value_name.c_str()); |
| 135 if (!field_value.empty()) { | 135 if (!field_value.empty()) { |
| 136 has_non_empty_fields = true; | 136 has_non_empty_fields = true; |
| 137 if (it->second == CREDIT_CARD_NUMBER) { | 137 if (it->second == CREDIT_CARD_NUMBER) { |
| 138 field_value = DecryptCCNumber(field_value); | 138 field_value = DecryptCCNumber(field_value); |
| 139 } | 139 } |
| 140 profile->SetInfo(AutofillType(it->second), field_value); | 140 profile->SetInfo(it->second, field_value); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 return has_non_empty_fields; | 143 return has_non_empty_fields; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Imports profiles from the IE toolbar and stores them. Asynchronous | 146 // Imports profiles from the IE toolbar and stores them. Asynchronous |
| 147 // if PersonalDataManager has not been loaded yet. Deletes itself on completion. | 147 // if PersonalDataManager has not been loaded yet. Deletes itself on completion. |
| 148 class AutoFillImporter : public PersonalDataManager::Observer { | 148 class AutoFillImporter : public PersonalDataManager::Observer { |
| 149 public: | 149 public: |
| 150 explicit AutoFillImporter(PersonalDataManager* personal_data_manager) | 150 explicit AutoFillImporter(PersonalDataManager* personal_data_manager) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 kProfileKey); | 202 kProfileKey); |
| 203 for (; iterator_profiles.Valid(); ++iterator_profiles) { | 203 for (; iterator_profiles.Valid(); ++iterator_profiles) { |
| 204 std::wstring key_name(kProfileKey); | 204 std::wstring key_name(kProfileKey); |
| 205 key_name.append(L"\\"); | 205 key_name.append(L"\\"); |
| 206 key_name.append(iterator_profiles.Name()); | 206 key_name.append(iterator_profiles.Name()); |
| 207 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); | 207 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); |
| 208 AutofillProfile profile; | 208 AutofillProfile profile; |
| 209 if (ImportSingleProfile(&profile, &key, reg_to_field)) { | 209 if (ImportSingleProfile(&profile, &key, reg_to_field)) { |
| 210 // Combine phones into whole phone #. | 210 // Combine phones into whole phone #. |
| 211 string16 phone; | 211 string16 phone; |
| 212 phone = profile.GetFieldText(AutofillType(PHONE_HOME_COUNTRY_CODE)); | 212 phone = profile.GetFieldText(PHONE_HOME_COUNTRY_CODE); |
| 213 phone.append(profile.GetFieldText(AutofillType(PHONE_HOME_CITY_CODE))); | 213 phone.append(profile.GetFieldText(PHONE_HOME_CITY_CODE)); |
| 214 phone.append(profile.GetFieldText(AutofillType(PHONE_HOME_NUMBER))); | 214 phone.append(profile.GetFieldText(PHONE_HOME_NUMBER)); |
| 215 profile.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), phone); | 215 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, phone); |
| 216 phone = profile.GetFieldText(AutofillType(PHONE_FAX_COUNTRY_CODE)); | 216 phone = profile.GetFieldText(PHONE_FAX_COUNTRY_CODE); |
| 217 phone.append(profile.GetFieldText(AutofillType(PHONE_FAX_CITY_CODE))); | 217 phone.append(profile.GetFieldText(PHONE_FAX_CITY_CODE)); |
| 218 phone.append(profile.GetFieldText(AutofillType(PHONE_FAX_NUMBER))); | 218 phone.append(profile.GetFieldText(PHONE_FAX_NUMBER)); |
| 219 profile.SetInfo(AutofillType(PHONE_FAX_WHOLE_NUMBER), phone); | 219 profile.SetInfo(PHONE_FAX_WHOLE_NUMBER, phone); |
| 220 profiles->push_back(profile); | 220 profiles->push_back(profile); |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 string16 password_hash; | 223 string16 password_hash; |
| 224 string16 salt; | 224 string16 salt; |
| 225 RegKey cc_key(HKEY_CURRENT_USER, kCreditCardKey, KEY_READ); | 225 RegKey cc_key(HKEY_CURRENT_USER, kCreditCardKey, KEY_READ); |
| 226 if (cc_key.Valid()) { | 226 if (cc_key.Valid()) { |
| 227 password_hash = ReadAndDecryptValue(&cc_key, kPasswordHashValue); | 227 password_hash = ReadAndDecryptValue(&cc_key, kPasswordHashValue); |
| 228 salt = ReadAndDecryptValue(&cc_key, kSaltValue); | 228 salt = ReadAndDecryptValue(&cc_key, kSaltValue); |
| 229 } | 229 } |
| 230 | 230 |
| 231 // We import CC profiles only if they are not password protected. | 231 // We import CC profiles only if they are not password protected. |
| 232 if (password_hash.empty() && IsEmptySalt(salt)) { | 232 if (password_hash.empty() && IsEmptySalt(salt)) { |
| 233 base::win::RegistryKeyIterator iterator_cc(HKEY_CURRENT_USER, | 233 base::win::RegistryKeyIterator iterator_cc(HKEY_CURRENT_USER, |
| 234 kCreditCardKey); | 234 kCreditCardKey); |
| 235 for (; iterator_cc.Valid(); ++iterator_cc) { | 235 for (; iterator_cc.Valid(); ++iterator_cc) { |
| 236 std::wstring key_name(kCreditCardKey); | 236 std::wstring key_name(kCreditCardKey); |
| 237 key_name.append(L"\\"); | 237 key_name.append(L"\\"); |
| 238 key_name.append(iterator_cc.Name()); | 238 key_name.append(iterator_cc.Name()); |
| 239 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); | 239 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); |
| 240 CreditCard credit_card; | 240 CreditCard credit_card; |
| 241 if (ImportSingleProfile(&credit_card, &key, reg_to_field)) { | 241 if (ImportSingleProfile(&credit_card, &key, reg_to_field)) { |
| 242 string16 cc_number = credit_card.GetFieldText( | 242 string16 cc_number = credit_card.GetFieldText(CREDIT_CARD_NUMBER); |
| 243 AutofillType(CREDIT_CARD_NUMBER)); | |
| 244 if (!cc_number.empty()) | 243 if (!cc_number.empty()) |
| 245 credit_cards->push_back(credit_card); | 244 credit_cards->push_back(credit_card); |
| 246 } | 245 } |
| 247 } | 246 } |
| 248 } | 247 } |
| 249 return (profiles->size() + credit_cards->size()) > 0; | 248 return (profiles->size() + credit_cards->size()) > 0; |
| 250 } | 249 } |
| 251 | 250 |
| 252 bool ImportAutofillDataWin(PersonalDataManager* pdm) { | 251 bool ImportAutofillDataWin(PersonalDataManager* pdm) { |
| 253 // In incognito mode we do not have PDM - and we should not import anything. | 252 // In incognito mode we do not have PDM - and we should not import anything. |
| 254 if (!pdm) | 253 if (!pdm) |
| 255 return false; | 254 return false; |
| 256 AutoFillImporter *importer = new AutoFillImporter(pdm); | 255 AutoFillImporter *importer = new AutoFillImporter(pdm); |
| 257 // importer will self delete. | 256 // importer will self delete. |
| 258 return importer->ImportProfiles(); | 257 return importer->ImportProfiles(); |
| 259 } | 258 } |
| 260 | 259 |
| OLD | NEW |