| 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/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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 for (size_t i = 0; i < salt.length(); ++i) { | 50 for (size_t i = 0; i < salt.length(); ++i) { |
| 51 if (salt[i] != i + 1) | 51 if (salt[i] != i + 1) |
| 52 return false; | 52 return false; |
| 53 } | 53 } |
| 54 return true; | 54 return true; |
| 55 } | 55 } |
| 56 | 56 |
| 57 string16 ReadAndDecryptValue(RegKey* key, const wchar_t* value_name) { | 57 string16 ReadAndDecryptValue(RegKey* key, const wchar_t* value_name) { |
| 58 DWORD data_type = REG_BINARY; | 58 DWORD data_type = REG_BINARY; |
| 59 DWORD data_size = 0; | 59 DWORD data_size = 0; |
| 60 if (!key->ReadValue(value_name, NULL, &data_size, &data_type) || | 60 LONG result = key->ReadValue(value_name, NULL, &data_size, &data_type); |
| 61 !data_size || data_type != REG_BINARY) | 61 if ((result != ERROR_SUCCESS) || !data_size || data_type != REG_BINARY) |
| 62 return string16(); | 62 return string16(); |
| 63 std::vector<uint8> data; | 63 std::vector<uint8> data; |
| 64 data.resize(data_size); | 64 data.resize(data_size); |
| 65 if (key->ReadValue(value_name, &(data[0]), &data_size, &data_type)) { | 65 result = key->ReadValue(value_name, &(data[0]), &data_size, &data_type); |
| 66 if (result == ERROR_SUCCESS) { |
| 66 std::string out_data; | 67 std::string out_data; |
| 67 if (DecryptData(data, &out_data)) { | 68 if (DecryptData(data, &out_data)) { |
| 68 // The actual data is in UTF16 already. | 69 // The actual data is in UTF16 already. |
| 69 if (!(out_data.size() & 1) && (out_data.size() > 2) && | 70 if (!(out_data.size() & 1) && (out_data.size() > 2) && |
| 70 !out_data[out_data.size() - 1] && !out_data[out_data.size() - 2]) { | 71 !out_data[out_data.size() - 1] && !out_data[out_data.size() - 2]) { |
| 71 return string16( | 72 return string16( |
| 72 reinterpret_cast<const wchar_t *>(out_data.c_str())); | 73 reinterpret_cast<const wchar_t *>(out_data.c_str())); |
| 73 } | 74 } |
| 74 } | 75 } |
| 75 } | 76 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 RegKey* key, | 119 RegKey* key, |
| 119 const RegToFieldMap& reg_to_field ) { | 120 const RegToFieldMap& reg_to_field ) { |
| 120 DCHECK(profile != NULL); | 121 DCHECK(profile != NULL); |
| 121 if (!key->Valid()) | 122 if (!key->Valid()) |
| 122 return false; | 123 return false; |
| 123 | 124 |
| 124 bool has_non_empty_fields = false; | 125 bool has_non_empty_fields = false; |
| 125 | 126 |
| 126 for (uint32 value_index = 0; value_index < key->ValueCount(); ++value_index) { | 127 for (uint32 value_index = 0; value_index < key->ValueCount(); ++value_index) { |
| 127 std::wstring value_name; | 128 std::wstring value_name; |
| 128 if (!key->ReadName(value_index, &value_name)) | 129 if (key->ReadName(value_index, &value_name) != ERROR_SUCCESS) |
| 129 continue; | 130 continue; |
| 130 RegToFieldMap::const_iterator it = reg_to_field.find(value_name); | 131 RegToFieldMap::const_iterator it = reg_to_field.find(value_name); |
| 131 if (it == reg_to_field.end()) | 132 if (it == reg_to_field.end()) |
| 132 continue; // This field is not imported. | 133 continue; // This field is not imported. |
| 133 string16 field_value = ReadAndDecryptValue(key, value_name.c_str()); | 134 string16 field_value = ReadAndDecryptValue(key, value_name.c_str()); |
| 134 if (!field_value.empty()) { | 135 if (!field_value.empty()) { |
| 135 has_non_empty_fields = true; | 136 has_non_empty_fields = true; |
| 136 if (it->second == CREDIT_CARD_NUMBER) { | 137 if (it->second == CREDIT_CARD_NUMBER) { |
| 137 field_value = DecryptCCNumber(field_value); | 138 field_value = DecryptCCNumber(field_value); |
| 138 } | 139 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 251 |
| 251 bool ImportAutofillDataWin(PersonalDataManager* pdm) { | 252 bool ImportAutofillDataWin(PersonalDataManager* pdm) { |
| 252 // In incognito mode we do not have PDM - and we should not import anything. | 253 // In incognito mode we do not have PDM - and we should not import anything. |
| 253 if (!pdm) | 254 if (!pdm) |
| 254 return false; | 255 return false; |
| 255 AutoFillImporter *importer = new AutoFillImporter(pdm); | 256 AutoFillImporter *importer = new AutoFillImporter(pdm); |
| 256 // importer will self delete. | 257 // importer will self delete. |
| 257 return importer->ImportProfiles(); | 258 return importer->ImportProfiles(); |
| 258 } | 259 } |
| 259 | 260 |
| OLD | NEW |