OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/registry.h" | |
9 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/win/registry.h" |
10 #include "chrome/browser/autofill/autofill_profile.h" | 10 #include "chrome/browser/autofill/autofill_profile.h" |
11 #include "chrome/browser/autofill/credit_card.h" | 11 #include "chrome/browser/autofill/credit_card.h" |
12 #include "chrome/browser/autofill/field_types.h" | 12 #include "chrome/browser/autofill/field_types.h" |
13 #include "chrome/browser/autofill/personal_data_manager.h" | 13 #include "chrome/browser/autofill/personal_data_manager.h" |
14 #include "chrome/browser/sync/util/data_encryption.h" | 14 #include "chrome/browser/sync/util/data_encryption.h" |
15 | 15 |
| 16 using base::win::RegKey; |
| 17 |
16 // Forward declaration. This function is not in unnamed namespace as it | 18 // Forward declaration. This function is not in unnamed namespace as it |
17 // is referenced in the unittest. | 19 // is referenced in the unittest. |
18 bool ImportCurrentUserProfiles(std::vector<AutoFillProfile>* profiles, | 20 bool ImportCurrentUserProfiles(std::vector<AutoFillProfile>* profiles, |
19 std::vector<CreditCard>* credit_cards); | 21 std::vector<CreditCard>* credit_cards); |
20 namespace { | 22 namespace { |
21 | 23 |
22 #if defined(GOOGLE_CHROME_BUILD) | 24 #if defined(GOOGLE_CHROME_BUILD) |
23 #include "chrome/browser/autofill/internal/autofill_ie_toolbar_decryption.h" | 25 #include "chrome/browser/autofill/internal/autofill_ie_toolbar_decryption.h" |
24 #else // defined(GOOGLE_CHROME_BUILD) | 26 #else // defined(GOOGLE_CHROME_BUILD) |
25 inline std::wstring DecryptCCNumber(const std::wstring& data) { | 27 inline std::wstring DecryptCCNumber(const std::wstring& data) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 DCHECK(profiles); | 172 DCHECK(profiles); |
171 DCHECK(credit_cards); | 173 DCHECK(credit_cards); |
172 | 174 |
173 // Create a map of possible fields for a quick access. | 175 // Create a map of possible fields for a quick access. |
174 RegToFieldMap reg_to_field; | 176 RegToFieldMap reg_to_field; |
175 for (size_t i = 0; i < arraysize(profile_reg_values); ++i) { | 177 for (size_t i = 0; i < arraysize(profile_reg_values); ++i) { |
176 reg_to_field[std::wstring(profile_reg_values[i].reg_value_name)] = | 178 reg_to_field[std::wstring(profile_reg_values[i].reg_value_name)] = |
177 profile_reg_values[i].field_type; | 179 profile_reg_values[i].field_type; |
178 } | 180 } |
179 | 181 |
180 RegistryKeyIterator iterator_profiles(HKEY_CURRENT_USER, kProfileKey); | 182 base::win::RegistryKeyIterator iterator_profiles(HKEY_CURRENT_USER, |
| 183 kProfileKey); |
181 for (; iterator_profiles.Valid(); ++iterator_profiles) { | 184 for (; iterator_profiles.Valid(); ++iterator_profiles) { |
182 std::wstring key_name(kProfileKey); | 185 std::wstring key_name(kProfileKey); |
183 key_name.append(L"\\"); | 186 key_name.append(L"\\"); |
184 key_name.append(iterator_profiles.Name()); | 187 key_name.append(iterator_profiles.Name()); |
185 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); | 188 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); |
186 AutoFillProfile profile; | 189 AutoFillProfile profile; |
187 if (ImportSingleProfile(&profile, &key, reg_to_field)) { | 190 if (ImportSingleProfile(&profile, &key, reg_to_field)) { |
188 // Combine phones into whole phone #. | 191 // Combine phones into whole phone #. |
189 string16 phone; | 192 string16 phone; |
190 phone = profile.GetFieldText(AutoFillType(PHONE_HOME_COUNTRY_CODE)); | 193 phone = profile.GetFieldText(AutoFillType(PHONE_HOME_COUNTRY_CODE)); |
(...skipping 10 matching lines...) Expand all Loading... |
201 string16 password_hash; | 204 string16 password_hash; |
202 string16 salt; | 205 string16 salt; |
203 RegKey cc_key(HKEY_CURRENT_USER, kCreditCardKey, KEY_READ); | 206 RegKey cc_key(HKEY_CURRENT_USER, kCreditCardKey, KEY_READ); |
204 if (cc_key.Valid()) { | 207 if (cc_key.Valid()) { |
205 password_hash = ReadAndDecryptValue(&cc_key, kPasswordHashValue); | 208 password_hash = ReadAndDecryptValue(&cc_key, kPasswordHashValue); |
206 salt = ReadAndDecryptValue(&cc_key, kSaltValue); | 209 salt = ReadAndDecryptValue(&cc_key, kSaltValue); |
207 } | 210 } |
208 | 211 |
209 // We import CC profiles only if they are not password protected. | 212 // We import CC profiles only if they are not password protected. |
210 if (password_hash.empty() && IsEmptySalt(salt)) { | 213 if (password_hash.empty() && IsEmptySalt(salt)) { |
211 RegistryKeyIterator iterator_cc(HKEY_CURRENT_USER, kCreditCardKey); | 214 base::win::RegistryKeyIterator iterator_cc(HKEY_CURRENT_USER, |
| 215 kCreditCardKey); |
212 for (; iterator_cc.Valid(); ++iterator_cc) { | 216 for (; iterator_cc.Valid(); ++iterator_cc) { |
213 std::wstring key_name(kCreditCardKey); | 217 std::wstring key_name(kCreditCardKey); |
214 key_name.append(L"\\"); | 218 key_name.append(L"\\"); |
215 key_name.append(iterator_cc.Name()); | 219 key_name.append(iterator_cc.Name()); |
216 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); | 220 RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_READ); |
217 CreditCard credit_card; | 221 CreditCard credit_card; |
218 if (ImportSingleProfile(&credit_card, &key, reg_to_field)) { | 222 if (ImportSingleProfile(&credit_card, &key, reg_to_field)) { |
219 string16 cc_number = credit_card.GetFieldText( | 223 string16 cc_number = credit_card.GetFieldText( |
220 AutoFillType(CREDIT_CARD_NUMBER)); | 224 AutoFillType(CREDIT_CARD_NUMBER)); |
221 | 225 |
222 if (!cc_number.empty()) { | 226 if (!cc_number.empty()) { |
223 // No additional password, and CC# is not empty, decrypt CC#. | 227 // No additional password, and CC# is not empty, decrypt CC#. |
224 cc_number = DecryptCCNumber(cc_number); | 228 cc_number = DecryptCCNumber(cc_number); |
225 } | 229 } |
226 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), cc_number); | 230 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), cc_number); |
227 if (!cc_number.empty()) | 231 if (!cc_number.empty()) |
228 credit_cards->push_back(credit_card); | 232 credit_cards->push_back(credit_card); |
229 } | 233 } |
230 } | 234 } |
231 } | 235 } |
232 return (profiles->size() + credit_cards->size()) > 0; | 236 return (profiles->size() + credit_cards->size()) > 0; |
233 } | 237 } |
234 | 238 |
235 bool ImportAutofillDataWin(PersonalDataManager* pdm) { | 239 bool ImportAutofillDataWin(PersonalDataManager* pdm) { |
236 AutoFillImporter *importer = new AutoFillImporter(pdm); | 240 AutoFillImporter *importer = new AutoFillImporter(pdm); |
237 // importer will self delete. | 241 // importer will self delete. |
238 return importer->ImportProfiles(); | 242 return importer->ImportProfiles(); |
239 } | 243 } |
240 | 244 |
OLD | NEW |