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 GetLoginsRequest* request = GetLoginsRequestForWebDataServiceRequest(h); |
| 25 DCHECK(request); |
| 26 // Remove our pending request, but make sure that we won't be destroyed until |
| 27 // we're done with this function. |
| 28 scoped_refptr<PasswordStoreWin> life_preserver(this); |
| 29 RemovePendingWebDataServiceRequest(h); |
| 30 |
| 31 DCHECK(result); |
| 32 if (!result) |
| 33 return; |
| 34 |
| 35 switch (result->GetType()) { |
| 36 case PASSWORD_RESULT: { |
| 37 // This is a response from WebDataService::GetLogins. |
| 38 const WDResult<std::vector<PasswordForm*> >* r = |
| 39 static_cast<const WDResult<std::vector<PasswordForm*> >*>(result); |
| 40 std::vector<PasswordForm*> result_value = r->GetValue(); |
| 41 |
| 42 if (result_value.size()) { |
| 43 // If we found some results then return them now. |
| 44 NotifyConsumer(request, result_value); |
| 45 return; |
| 46 } else { |
| 47 // Otherwise try finding IE7 logins. |
| 48 IE7PasswordInfo info; |
| 49 std::wstring url = ASCIIToWide(request->form.origin.spec()); |
| 50 info.url_hash = ie7_password::GetUrlHash(url); |
| 51 |
| 52 if (web_data_service_->IsRunning()) { |
| 53 WebDataService::Handle web_data_handle = |
| 54 web_data_service_->GetIE7Login(info, this); |
| 55 AddPendingWebDataServiceRequest(web_data_handle, request); |
| 56 } |
| 57 } |
| 58 break; |
| 59 } |
| 60 |
| 61 case PASSWORD_IE7_RESULT: { |
| 62 // This is a response from WebDataService::GetIE7Login. |
| 63 PasswordForm* ie7_form = GetIE7Result(result, request->form); |
| 64 |
| 65 std::vector<PasswordForm*> forms; |
| 66 if (ie7_form) |
| 67 forms.push_back(ie7_form); |
| 68 |
| 69 NotifyConsumer(request, forms); |
| 70 break; |
| 71 } |
| 72 } |
| 73 } |
| 74 |
| 75 PasswordForm* PasswordStoreWin::GetIE7Result(const WDTypedResult *result, |
| 76 const PasswordForm& form) { |
| 77 const WDResult<IE7PasswordInfo>* r = |
| 78 static_cast<const WDResult<IE7PasswordInfo>*>(result); |
| 79 IE7PasswordInfo info = r->GetValue(); |
| 80 |
| 81 if (!info.encrypted_data.empty()) { |
| 82 // We got a result. |
| 83 // Delete the entry. If it's good we will add it to the real saved password |
| 84 // table. |
| 85 web_data_service_->RemoveIE7Login(info); |
| 86 std::wstring username; |
| 87 std::wstring password; |
| 88 std::wstring url = ASCIIToWide(form.origin.spec()); |
| 89 if (!ie7_password::DecryptPassword(url, info.encrypted_data, |
| 90 &username, &password)) { |
| 91 return NULL; |
| 92 } |
| 93 |
| 94 PasswordForm* auto_fill = new PasswordForm(form); |
| 95 auto_fill->username_value = username; |
| 96 auto_fill->password_value = password; |
| 97 auto_fill->preferred = true; |
| 98 auto_fill->ssl_valid = form.origin.SchemeIsSecure(); |
| 99 auto_fill->date_created = info.date_created; |
| 100 // Add this PasswordForm to the saved password table. |
| 101 AddLogin(*auto_fill); |
| 102 return auto_fill; |
| 103 } |
| 104 return NULL; |
| 105 } |
OLD | NEW |