OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/password_manager/password_store_win.h" | 5 #include "chrome/browser/password_manager/password_store_win.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 PasswordForm* form; | 48 PasswordForm* form; |
49 PasswordStoreWin::ConsumerCallbackRunner callback_runner; | 49 PasswordStoreWin::ConsumerCallbackRunner callback_runner; |
50 }; | 50 }; |
51 | 51 |
52 // Holds info associated with in-flight GetIE7Login requests. | 52 // Holds info associated with in-flight GetIE7Login requests. |
53 typedef std::map<WebDataService::Handle, RequestInfo> PendingRequestMap; | 53 typedef std::map<WebDataService::Handle, RequestInfo> PendingRequestMap; |
54 | 54 |
55 // Gets logins from IE7 if no others are found. Also copies them into | 55 // Gets logins from IE7 if no others are found. Also copies them into |
56 // Chrome's WebDatabase so we don't need to look next time. | 56 // Chrome's WebDatabase so we don't need to look next time. |
57 PasswordForm* GetIE7Result(const WDTypedResult* result, | 57 std::vector<autofill::PasswordForm*> GetIE7Results( |
58 const PasswordForm& form); | 58 const WDTypedResult* result, |
| 59 const PasswordForm& form); |
59 | 60 |
60 // WebDataServiceConsumer implementation. | 61 // WebDataServiceConsumer implementation. |
61 virtual void OnWebDataServiceRequestDone( | 62 virtual void OnWebDataServiceRequestDone( |
62 WebDataService::Handle handle, | 63 WebDataService::Handle handle, |
63 const WDTypedResult* result) OVERRIDE; | 64 const WDTypedResult* result) OVERRIDE; |
64 | 65 |
65 scoped_refptr<WebDataService> web_data_service_; | 66 scoped_refptr<WebDataService> web_data_service_; |
66 | 67 |
67 // This creates a cycle between us and PasswordStore. The cycle is broken | 68 // This creates a cycle between us and PasswordStore. The cycle is broken |
68 // from PasswordStoreWin::Shutdown, which deletes us. | 69 // from PasswordStoreWin::Shutdown, which deletes us. |
(...skipping 18 matching lines...) Expand all Loading... |
87 const PasswordForm& form, | 88 const PasswordForm& form, |
88 const PasswordStoreWin::ConsumerCallbackRunner& callback_runner) { | 89 const PasswordStoreWin::ConsumerCallbackRunner& callback_runner) { |
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
90 IE7PasswordInfo info; | 91 IE7PasswordInfo info; |
91 info.url_hash = ie7_password::GetUrlHash(UTF8ToWide(form.origin.spec())); | 92 info.url_hash = ie7_password::GetUrlHash(UTF8ToWide(form.origin.spec())); |
92 WebDataService::Handle handle = web_data_service_->GetIE7Login(info, this); | 93 WebDataService::Handle handle = web_data_service_->GetIE7Login(info, this); |
93 pending_requests_[handle] = | 94 pending_requests_[handle] = |
94 RequestInfo(new PasswordForm(form), callback_runner); | 95 RequestInfo(new PasswordForm(form), callback_runner); |
95 } | 96 } |
96 | 97 |
97 PasswordForm* PasswordStoreWin::DBHandler::GetIE7Result( | 98 std::vector<PasswordForm*> PasswordStoreWin::DBHandler::GetIE7Results( |
98 const WDTypedResult *result, | 99 const WDTypedResult *result, |
99 const PasswordForm& form) { | 100 const PasswordForm& form) { |
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 102 std::vector<PasswordForm*> matching_forms; |
101 | 103 |
102 const WDResult<IE7PasswordInfo>* r = | 104 const WDResult<IE7PasswordInfo>* r = |
103 static_cast<const WDResult<IE7PasswordInfo>*>(result); | 105 static_cast<const WDResult<IE7PasswordInfo>*>(result); |
104 IE7PasswordInfo info = r->GetValue(); | 106 IE7PasswordInfo info = r->GetValue(); |
105 | 107 |
106 if (!info.encrypted_data.empty()) { | 108 if (!info.encrypted_data.empty()) { |
107 // We got a result. | 109 // We got a result. |
108 // Delete the entry. If it's good we will add it to the real saved password | 110 // Delete the entry. If it's good we will add it to the real saved password |
109 // table. | 111 // table. |
110 web_data_service_->RemoveIE7Login(info); | 112 web_data_service_->RemoveIE7Login(info); |
111 std::wstring username; | 113 std::vector<ie7_password::DecryptedCredentials> credentials; |
112 std::wstring password; | |
113 std::wstring url = ASCIIToWide(form.origin.spec()); | 114 std::wstring url = ASCIIToWide(form.origin.spec()); |
114 if (!ie7_password::DecryptPassword(url, info.encrypted_data, | 115 if (ie7_password::DecryptPasswords(url, |
115 &username, &password)) { | 116 info.encrypted_data, |
116 return NULL; | 117 &credentials)) { |
| 118 for (size_t i = 0; i < credentials.size(); ++i) { |
| 119 PasswordForm* autofill = new PasswordForm(form); |
| 120 autofill->username_value = credentials[i].username; |
| 121 autofill->password_value = credentials[i].password; |
| 122 autofill->preferred = true; |
| 123 autofill->ssl_valid = form.origin.SchemeIsSecure(); |
| 124 autofill->date_created = info.date_created; |
| 125 matching_forms.push_back(autofill); |
| 126 // Add this PasswordForm to the saved password table. We're on the DB |
| 127 // thread already, so we use AddLoginImpl. |
| 128 password_store_->AddLoginImpl(*autofill); |
| 129 } |
117 } | 130 } |
118 | |
119 PasswordForm* autofill = new PasswordForm(form); | |
120 autofill->username_value = username; | |
121 autofill->password_value = password; | |
122 autofill->preferred = true; | |
123 autofill->ssl_valid = form.origin.SchemeIsSecure(); | |
124 autofill->date_created = info.date_created; | |
125 // Add this PasswordForm to the saved password table. We're on the DB thread | |
126 // already, so we use AddLoginImpl. | |
127 password_store_->AddLoginImpl(*autofill); | |
128 return autofill; | |
129 } | 131 } |
130 return NULL; | 132 return matching_forms; |
131 } | 133 } |
132 | 134 |
133 void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone( | 135 void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone( |
134 WebDataService::Handle handle, | 136 WebDataService::Handle handle, |
135 const WDTypedResult* result) { | 137 const WDTypedResult* result) { |
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
137 | 139 |
138 PendingRequestMap::iterator i = pending_requests_.find(handle); | 140 PendingRequestMap::iterator i = pending_requests_.find(handle); |
139 DCHECK(i != pending_requests_.end()); | 141 DCHECK(i != pending_requests_.end()); |
140 | 142 |
141 scoped_ptr<PasswordForm> form(i->second.form); | 143 scoped_ptr<PasswordForm> form(i->second.form); |
142 PasswordStoreWin::ConsumerCallbackRunner callback_runner( | 144 PasswordStoreWin::ConsumerCallbackRunner callback_runner( |
143 i->second.callback_runner); | 145 i->second.callback_runner); |
144 pending_requests_.erase(i); | 146 pending_requests_.erase(i); |
145 | 147 |
146 std::vector<autofill::PasswordForm*> matched_forms; | |
147 | |
148 if (!result) { | 148 if (!result) { |
149 // The WDS returns NULL if it is shutting down. Run callback with empty | 149 // The WDS returns NULL if it is shutting down. Run callback with empty |
150 // result. | 150 // result. |
151 callback_runner.Run(matched_forms); | 151 callback_runner.Run(std::vector<autofill::PasswordForm*>()); |
152 return; | 152 return; |
153 } | 153 } |
154 | 154 |
155 DCHECK_EQ(PASSWORD_IE7_RESULT, result->GetType()); | 155 DCHECK_EQ(PASSWORD_IE7_RESULT, result->GetType()); |
156 PasswordForm* ie7_form = GetIE7Result(result, *form); | 156 std::vector<autofill::PasswordForm*> matched_forms = |
157 | 157 GetIE7Results(result, *form); |
158 if (ie7_form) | |
159 matched_forms.push_back(ie7_form); | |
160 | 158 |
161 callback_runner.Run(matched_forms); | 159 callback_runner.Run(matched_forms); |
162 } | 160 } |
163 | 161 |
164 PasswordStoreWin::PasswordStoreWin(LoginDatabase* login_database, | 162 PasswordStoreWin::PasswordStoreWin(LoginDatabase* login_database, |
165 Profile* profile, | 163 Profile* profile, |
166 WebDataService* web_data_service) | 164 WebDataService* web_data_service) |
167 : PasswordStoreDefault(login_database, profile) { | 165 : PasswordStoreDefault(login_database, profile) { |
168 db_handler_.reset(new DBHandler(web_data_service, this)); | 166 db_handler_.reset(new DBHandler(web_data_service, this)); |
169 } | 167 } |
(...skipping 27 matching lines...) Expand all Loading... |
197 } | 195 } |
198 | 196 |
199 void PasswordStoreWin::GetLoginsImpl( | 197 void PasswordStoreWin::GetLoginsImpl( |
200 const PasswordForm& form, | 198 const PasswordForm& form, |
201 const ConsumerCallbackRunner& callback_runner) { | 199 const ConsumerCallbackRunner& callback_runner) { |
202 ConsumerCallbackRunner get_ie7_login = | 200 ConsumerCallbackRunner get_ie7_login = |
203 base::Bind(&PasswordStoreWin::GetIE7LoginIfNecessary, | 201 base::Bind(&PasswordStoreWin::GetIE7LoginIfNecessary, |
204 this, form, callback_runner); | 202 this, form, callback_runner); |
205 PasswordStoreDefault::GetLoginsImpl(form, get_ie7_login); | 203 PasswordStoreDefault::GetLoginsImpl(form, get_ie7_login); |
206 } | 204 } |
OLD | NEW |