| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/password_manager/password_store_win.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "chrome/browser/password_manager/ie7_password.h" | |
| 10 #include "chrome/browser/password_manager/password_manager.h" | |
| 11 #include "chrome/browser/profile.h" | |
| 12 | |
| 13 using std::map; | |
| 14 using std::vector; | |
| 15 | |
| 16 PasswordStoreWin::PasswordStoreWin(WebDataService* web_data_service) | |
| 17 : PasswordStoreDefault(web_data_service) { | |
| 18 } | |
| 19 | |
| 20 void PasswordStoreWin::OnWebDataServiceRequestDone( | |
| 21 WebDataService::Handle h, const WDTypedResult *result) { | |
| 22 // Look up this handle in our request map to get the original | |
| 23 // GetLoginsRequest. | |
| 24 PendingRequestMap::const_iterator it(pending_requests_.find(h)); | |
| 25 DCHECK(it != pending_requests_.end()); | |
| 26 | |
| 27 GetLoginsRequest* request = (*it).second; | |
| 28 pending_requests_.erase(h); | |
| 29 | |
| 30 DCHECK(result); | |
| 31 if (!result) | |
| 32 return; | |
| 33 | |
| 34 switch (result->GetType()) { | |
| 35 case PASSWORD_RESULT: { | |
| 36 // This is a response from WebDataService::GetLogins. | |
| 37 const WDResult<std::vector<PasswordForm*> >* r = | |
| 38 static_cast<const WDResult<std::vector<PasswordForm*> >*>(result); | |
| 39 std::vector<PasswordForm*> result_value = r->GetValue(); | |
| 40 | |
| 41 if (result_value.size()) { | |
| 42 // If we found some results then return them now. | |
| 43 NotifyConsumer(request, result_value); | |
| 44 return; | |
| 45 } else { | |
| 46 // Otherwise try finding IE7 logins. | |
| 47 IE7PasswordInfo info; | |
| 48 std::wstring url = ASCIIToWide(request->form.origin.spec()); | |
| 49 info.url_hash = ie7_password::GetUrlHash(url); | |
| 50 | |
| 51 WebDataService::Handle web_data_handle = | |
| 52 web_data_service_->GetIE7Login(info, this); | |
| 53 pending_requests_.insert(PendingRequestMap::value_type( | |
| 54 web_data_handle, request)); | |
| 55 } | |
| 56 break; | |
| 57 } | |
| 58 | |
| 59 case PASSWORD_IE7_RESULT: { | |
| 60 // This is a response from WebDataService::GetIE7Login. | |
| 61 PasswordForm* ie7_form = GetIE7Result(result, request->form); | |
| 62 | |
| 63 std::vector<PasswordForm*> forms; | |
| 64 if (ie7_form) | |
| 65 forms.push_back(ie7_form); | |
| 66 | |
| 67 NotifyConsumer(request, forms); | |
| 68 break; | |
| 69 } | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 PasswordForm* PasswordStoreWin::GetIE7Result(const WDTypedResult *result, | |
| 74 const PasswordForm& form) { | |
| 75 const WDResult<IE7PasswordInfo>* r = | |
| 76 static_cast<const WDResult<IE7PasswordInfo>*>(result); | |
| 77 IE7PasswordInfo info = r->GetValue(); | |
| 78 | |
| 79 if (!info.encrypted_data.empty()) { | |
| 80 // We got a result. | |
| 81 // Delete the entry. If it's good we will add it to the real saved password | |
| 82 // table. | |
| 83 web_data_service_->RemoveIE7Login(info); | |
| 84 std::wstring username; | |
| 85 std::wstring password; | |
| 86 std::wstring url = ASCIIToWide(form.origin.spec()); | |
| 87 if (!ie7_password::DecryptPassword(url, info.encrypted_data, | |
| 88 &username, &password)) { | |
| 89 return NULL; | |
| 90 } | |
| 91 | |
| 92 PasswordForm* auto_fill = new PasswordForm(form); | |
| 93 auto_fill->username_value = username; | |
| 94 auto_fill->password_value = password; | |
| 95 auto_fill->preferred = true; | |
| 96 auto_fill->ssl_valid = form.origin.SchemeIsSecure(); | |
| 97 auto_fill->date_created = info.date_created; | |
| 98 // Add this PasswordForm to the saved password table. | |
| 99 AddLogin(*auto_fill); | |
| 100 return auto_fill; | |
| 101 } | |
| 102 return NULL; | |
| 103 } | |
| OLD | NEW |