Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/win/registry.h" | 15 #include "base/win/registry.h" |
| 16 #include "chrome/browser/autofill/autofill_profile.h" | 16 #include "chrome/browser/autofill/autofill_profile.h" |
| 17 #include "chrome/browser/autofill/credit_card.h" | 17 #include "chrome/browser/autofill/credit_card.h" |
| 18 #include "chrome/browser/autofill/crypto/rc4_decryptor.h" | 18 #include "chrome/browser/autofill/crypto/rc4_decryptor.h" |
| 19 #include "chrome/browser/autofill/field_types.h" | 19 #include "chrome/browser/autofill/field_types.h" |
| 20 #include "chrome/browser/autofill/form_group.h" | 20 #include "chrome/browser/autofill/form_group.h" |
| 21 #include "chrome/browser/autofill/personal_data_manager.h" | 21 #include "chrome/browser/autofill/personal_data_manager.h" |
| 22 #include "chrome/browser/autofill/phone_number_i18n.h" | |
| 22 #include "chrome/browser/sync/util/data_encryption.h" | 23 #include "chrome/browser/sync/util/data_encryption.h" |
| 23 | 24 |
| 24 using base::win::RegKey; | 25 using base::win::RegKey; |
| 25 | 26 |
| 26 // Forward declaration. This function is not in unnamed namespace as it | 27 // Forward declaration. This function is not in unnamed namespace as it |
| 27 // is referenced in the unittest. | 28 // is referenced in the unittest. |
| 28 bool ImportCurrentUserProfiles(std::vector<AutofillProfile>* profiles, | 29 bool ImportCurrentUserProfiles(std::vector<AutofillProfile>* profiles, |
| 29 std::vector<CreditCard>* credit_cards); | 30 std::vector<CreditCard>* credit_cards); |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 | 125 |
| 125 bool ImportSingleProfile(FormGroup* profile, | 126 bool ImportSingleProfile(FormGroup* profile, |
| 126 RegKey* key, | 127 RegKey* key, |
| 127 const RegToFieldMap& reg_to_field ) { | 128 const RegToFieldMap& reg_to_field ) { |
| 128 DCHECK(profile != NULL); | 129 DCHECK(profile != NULL); |
| 129 if (!key->Valid()) | 130 if (!key->Valid()) |
| 130 return false; | 131 return false; |
| 131 | 132 |
| 132 bool has_non_empty_fields = false; | 133 bool has_non_empty_fields = false; |
| 133 | 134 |
| 135 // Phones need to be rebuild. | |
|
dhollowa
2011/05/13 18:55:35
nit: s/rebuild/rebuilt/
GeorgeY
2011/05/18 17:41:45
Done.
| |
| 136 string16 home, home_city, home_country; | |
| 137 string16 fax, fax_city, fax_country; | |
| 138 | |
| 134 for (uint32 value_index = 0; value_index < key->ValueCount(); ++value_index) { | 139 for (uint32 value_index = 0; value_index < key->ValueCount(); ++value_index) { |
| 135 std::wstring value_name; | 140 std::wstring value_name; |
| 136 if (key->ReadName(value_index, &value_name) != ERROR_SUCCESS) | 141 if (key->ReadName(value_index, &value_name) != ERROR_SUCCESS) |
| 137 continue; | 142 continue; |
| 138 RegToFieldMap::const_iterator it = reg_to_field.find(value_name); | 143 RegToFieldMap::const_iterator it = reg_to_field.find(value_name); |
| 139 if (it == reg_to_field.end()) | 144 if (it == reg_to_field.end()) |
| 140 continue; // This field is not imported. | 145 continue; // This field is not imported. |
| 141 string16 field_value = ReadAndDecryptValue(key, value_name.c_str()); | 146 string16 field_value = ReadAndDecryptValue(key, value_name.c_str()); |
| 142 if (!field_value.empty()) { | 147 if (!field_value.empty()) { |
| 143 has_non_empty_fields = true; | 148 has_non_empty_fields = true; |
| 144 if (it->second == CREDIT_CARD_NUMBER) { | 149 if (it->second == CREDIT_CARD_NUMBER) { |
| 145 field_value = DecryptCCNumber(field_value); | 150 field_value = DecryptCCNumber(field_value); |
| 146 } | 151 } |
| 147 profile->SetInfo(it->second, field_value); | 152 switch (it->second) { |
|
dhollowa
2011/05/13 18:55:35
This is getting pretty hard to read with |SetInfo|
GeorgeY
2011/05/18 17:41:45
Simplified it
| |
| 153 case PHONE_HOME_CITY_CODE: | |
| 154 home_city = field_value; | |
| 155 break; | |
| 156 case PHONE_HOME_COUNTRY_CODE: | |
| 157 home_country = field_value; | |
| 158 break; | |
| 159 case PHONE_HOME_CITY_AND_NUMBER: | |
| 160 case PHONE_HOME_NUMBER: | |
| 161 home = field_value; | |
| 162 break; | |
| 163 case PHONE_FAX_CITY_CODE: | |
| 164 fax_city = field_value; | |
| 165 break; | |
| 166 case PHONE_FAX_COUNTRY_CODE: | |
| 167 fax_country = field_value; | |
| 168 break; | |
| 169 case PHONE_FAX_NUMBER: | |
| 170 case PHONE_FAX_CITY_AND_NUMBER: | |
| 171 fax = field_value; | |
| 172 break; | |
| 173 default: | |
| 174 profile->SetInfo(it->second, field_value); | |
| 175 break; | |
| 176 } | |
| 148 } | 177 } |
| 149 } | 178 } |
| 179 string16 constructed_number; | |
| 180 if (!home.empty() && autofill_i18n::ConstructPhoneNumber( | |
| 181 home_country, home_city, home, std::string("US"), | |
| 182 (home_country.empty() ? | |
| 183 autofill_i18n::NATIONAL : autofill_i18n::INTERNATIONAL), | |
| 184 &constructed_number)) { | |
| 185 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, constructed_number); | |
| 186 } | |
| 187 if (!fax.empty() && autofill_i18n::ConstructPhoneNumber( | |
| 188 fax_country, fax_city, fax, std::string("US"), | |
| 189 (fax_country.empty() ? | |
| 190 autofill_i18n::NATIONAL : autofill_i18n::INTERNATIONAL), | |
| 191 &constructed_number)) { | |
| 192 profile->SetInfo(PHONE_FAX_WHOLE_NUMBER, constructed_number); | |
| 193 } | |
| 194 | |
| 150 return has_non_empty_fields; | 195 return has_non_empty_fields; |
| 151 } | 196 } |
| 152 | 197 |
| 153 // Imports profiles from the IE toolbar and stores them. Asynchronous | 198 // Imports profiles from the IE toolbar and stores them. Asynchronous |
| 154 // if PersonalDataManager has not been loaded yet. Deletes itself on completion. | 199 // if PersonalDataManager has not been loaded yet. Deletes itself on completion. |
| 155 class AutofillImporter : public PersonalDataManager::Observer { | 200 class AutofillImporter : public PersonalDataManager::Observer { |
| 156 public: | 201 public: |
| 157 explicit AutofillImporter(PersonalDataManager* personal_data_manager) | 202 explicit AutofillImporter(PersonalDataManager* personal_data_manager) |
| 158 : personal_data_manager_(personal_data_manager) { | 203 : personal_data_manager_(personal_data_manager) { |
| 159 personal_data_manager_->SetObserver(this); | 204 personal_data_manager_->SetObserver(this); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 base::win::RegistryKeyIterator iterator_profiles(HKEY_CURRENT_USER, | 253 base::win::RegistryKeyIterator iterator_profiles(HKEY_CURRENT_USER, |
| 209 kProfileKey); | 254 kProfileKey); |
| 210 for (; iterator_profiles.Valid(); ++iterator_profiles) { | 255 for (; iterator_profiles.Valid(); ++iterator_profiles) { |
| 211 std::wstring key_name(kProfileKey); | 256 std::wstring key_name(kProfileKey); |
| 212 key_name.append(L"\\"); | 257 key_name.append(L"\\"); |
| 213 key_name.append(iterator_profiles.Name()); | 258 key_name.append(iterator_profiles.Name()); |
| 214 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); | 259 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); |
| 215 AutofillProfile profile; | 260 AutofillProfile profile; |
| 216 if (ImportSingleProfile(&profile, &key, reg_to_field)) { | 261 if (ImportSingleProfile(&profile, &key, reg_to_field)) { |
| 217 // Combine phones into whole phone #. | 262 // Combine phones into whole phone #. |
| 218 string16 phone; | |
| 219 phone = profile.GetInfo(PHONE_HOME_COUNTRY_CODE); | |
| 220 phone.append(profile.GetInfo(PHONE_HOME_CITY_CODE)); | |
| 221 phone.append(profile.GetInfo(PHONE_HOME_NUMBER)); | |
| 222 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, phone); | |
| 223 phone = profile.GetInfo(PHONE_FAX_COUNTRY_CODE); | |
| 224 phone.append(profile.GetInfo(PHONE_FAX_CITY_CODE)); | |
| 225 phone.append(profile.GetInfo(PHONE_FAX_NUMBER)); | |
| 226 profile.SetInfo(PHONE_FAX_WHOLE_NUMBER, phone); | |
| 227 profiles->push_back(profile); | 263 profiles->push_back(profile); |
| 228 } | 264 } |
| 229 } | 265 } |
| 230 string16 password_hash; | 266 string16 password_hash; |
| 231 string16 salt; | 267 string16 salt; |
| 232 RegKey cc_key(HKEY_CURRENT_USER, kCreditCardKey, KEY_READ); | 268 RegKey cc_key(HKEY_CURRENT_USER, kCreditCardKey, KEY_READ); |
| 233 if (cc_key.Valid()) { | 269 if (cc_key.Valid()) { |
| 234 password_hash = ReadAndDecryptValue(&cc_key, kPasswordHashValue); | 270 password_hash = ReadAndDecryptValue(&cc_key, kPasswordHashValue); |
| 235 salt = ReadAndDecryptValue(&cc_key, kSaltValue); | 271 salt = ReadAndDecryptValue(&cc_key, kSaltValue); |
| 236 } | 272 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 257 | 293 |
| 258 bool ImportAutofillDataWin(PersonalDataManager* pdm) { | 294 bool ImportAutofillDataWin(PersonalDataManager* pdm) { |
| 259 // In incognito mode we do not have PDM - and we should not import anything. | 295 // In incognito mode we do not have PDM - and we should not import anything. |
| 260 if (!pdm) | 296 if (!pdm) |
| 261 return false; | 297 return false; |
| 262 AutofillImporter *importer = new AutofillImporter(pdm); | 298 AutofillImporter *importer = new AutofillImporter(pdm); |
| 263 // importer will self delete. | 299 // importer will self delete. |
| 264 return importer->ImportProfiles(); | 300 return importer->ImportProfiles(); |
| 265 } | 301 } |
| 266 | 302 |
| OLD | NEW |