| 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_form_manager.h" | |
| 6 | |
| 7 #include "base/string_util.h" | |
| 8 #include "chrome/browser/password_manager/ie7_password.h" | |
| 9 #include "chrome/browser/password_manager/password_manager.h" | |
| 10 #include "chrome/browser/profile.h" | |
| 11 | |
| 12 void PasswordFormManager::FetchMatchingIE7LoginFromWebDatabase() { | |
| 13 DCHECK_EQ(state_, PRE_MATCHING_PHASE); | |
| 14 DCHECK(!pending_login_query_); | |
| 15 state_ = MATCHING_PHASE; | |
| 16 WebDataService* web_data_service = | |
| 17 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | |
| 18 if (!web_data_service) { | |
| 19 NOTREACHED(); | |
| 20 return; | |
| 21 } | |
| 22 | |
| 23 IE7PasswordInfo info; | |
| 24 std::wstring url = ASCIIToWide(observed_form_.origin.spec()); | |
| 25 info.url_hash = ie7_password::GetUrlHash(url); | |
| 26 pending_login_query_ = web_data_service->GetIE7Login(info, this); | |
| 27 } | |
| 28 | |
| 29 void PasswordFormManager::OnIE7RequestDone(WebDataService::Handle h, | |
| 30 const WDTypedResult* result) { | |
| 31 // Get the result from the database into a usable form. | |
| 32 const WDResult<IE7PasswordInfo>* r = | |
| 33 static_cast<const WDResult<IE7PasswordInfo>*>(result); | |
| 34 IE7PasswordInfo result_value = r->GetValue(); | |
| 35 | |
| 36 state_ = POST_MATCHING_PHASE; | |
| 37 | |
| 38 if (!result_value.encrypted_data.empty()) { | |
| 39 // We got a result. | |
| 40 // Delete the entry. If it's good we will add it to the real saved password | |
| 41 // table. | |
| 42 WebDataService* web_data_service = | |
| 43 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | |
| 44 if (!web_data_service) { | |
| 45 NOTREACHED(); | |
| 46 return; | |
| 47 } | |
| 48 web_data_service->RemoveIE7Login(result_value); | |
| 49 | |
| 50 std::wstring username; | |
| 51 std::wstring password; | |
| 52 std::wstring url = ASCIIToWide(observed_form_.origin.spec()); | |
| 53 if (!ie7_password::DecryptPassword(url, result_value.encrypted_data, | |
| 54 &username, &password)) { | |
| 55 return; | |
| 56 } | |
| 57 | |
| 58 PasswordForm* auto_fill = new PasswordForm(observed_form_); | |
| 59 auto_fill->username_value = username; | |
| 60 auto_fill->password_value = password; | |
| 61 auto_fill->preferred = true; | |
| 62 auto_fill->ssl_valid = observed_form_.origin.SchemeIsSecure(); | |
| 63 auto_fill->date_created = result_value.date_created; | |
| 64 // Add this PasswordForm to the saved password table. | |
| 65 web_data_service->AddLogin(*auto_fill); | |
| 66 | |
| 67 if (IgnoreResult(*auto_fill)) { | |
| 68 delete auto_fill; | |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 best_matches_[auto_fill->username_value] = auto_fill; | |
| 73 preferred_match_ = auto_fill; | |
| 74 password_manager_->Autofill(observed_form_, best_matches_, | |
| 75 preferred_match_); | |
| 76 } | |
| 77 } | |
| OLD | NEW |