| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/passwords/password_manager_presenter.h" | 5 #include "chrome/browser/ui/passwords/password_manager_presenter.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 password_duplicates_.clear(); | 175 password_duplicates_.clear(); |
| 176 password_exception_list_.clear(); | 176 password_exception_list_.clear(); |
| 177 password_exception_duplicates_.clear(); | 177 password_exception_duplicates_.clear(); |
| 178 | 178 |
| 179 populater_.Populate(); | 179 populater_.Populate(); |
| 180 exception_populater_.Populate(); | 180 exception_populater_.Populate(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void PasswordManagerPresenter::RemoveSavedPassword(size_t index) { | 183 void PasswordManagerPresenter::RemoveSavedPassword(size_t index) { |
| 184 if (index >= password_list_.size()) { | 184 if (index >= password_list_.size()) { |
| 185 // |index| out of bounds might come from a compromised renderer, don't let | 185 // |index| out of bounds might come from a compromised renderer |
| 186 // it crash the browser. http://crbug.com/362054 | 186 // (http://crbug.com/362054), or the user removed a password while a request |
| 187 NOTREACHED(); | 187 // to the store is in progress (i.e. |password_list_| is empty). |
| 188 // Don't let it crash the browser. |
| 188 return; | 189 return; |
| 189 } | 190 } |
| 190 PasswordStore* store = GetPasswordStore(); | 191 PasswordStore* store = GetPasswordStore(); |
| 191 if (!store) | 192 if (!store) |
| 192 return; | 193 return; |
| 193 | 194 |
| 194 RemoveDuplicates(*password_list_[index], languages_, &password_duplicates_, | 195 RemoveDuplicates(*password_list_[index], languages_, &password_duplicates_, |
| 195 store, true); | 196 store, true); |
| 196 store->RemoveLogin(*password_list_[index]); | 197 store->RemoveLogin(*password_list_[index]); |
| 197 content::RecordAction( | 198 content::RecordAction( |
| 198 base::UserMetricsAction("PasswordManager_RemoveSavedPassword")); | 199 base::UserMetricsAction("PasswordManager_RemoveSavedPassword")); |
| 199 } | 200 } |
| 200 | 201 |
| 201 void PasswordManagerPresenter::RemovePasswordException(size_t index) { | 202 void PasswordManagerPresenter::RemovePasswordException(size_t index) { |
| 202 if (index >= password_exception_list_.size()) { | 203 if (index >= password_exception_list_.size()) { |
| 203 // |index| out of bounds might come from a compromised renderer, don't let | 204 // |index| out of bounds might come from a compromised renderer |
| 204 // it crash the browser. http://crbug.com/362054 | 205 // (http://crbug.com/362054), or the user removed a password exception while |
| 205 NOTREACHED(); | 206 // a request to the store is in progress (i.e. |password_exception_list_| |
| 207 // is empty). Don't let it crash the browser. |
| 206 return; | 208 return; |
| 207 } | 209 } |
| 208 PasswordStore* store = GetPasswordStore(); | 210 PasswordStore* store = GetPasswordStore(); |
| 209 if (!store) | 211 if (!store) |
| 210 return; | 212 return; |
| 211 RemoveDuplicates(*password_exception_list_[index], languages_, | 213 RemoveDuplicates(*password_exception_list_[index], languages_, |
| 212 &password_exception_duplicates_, store, false); | 214 &password_exception_duplicates_, store, false); |
| 213 store->RemoveLogin(*password_exception_list_[index]); | 215 store->RemoveLogin(*password_exception_list_[index]); |
| 214 content::RecordAction( | 216 content::RecordAction( |
| 215 base::UserMetricsAction("PasswordManager_RemovePasswordException")); | 217 base::UserMetricsAction("PasswordManager_RemovePasswordException")); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void PasswordManagerPresenter::RequestShowPassword(size_t index) { | 220 void PasswordManagerPresenter::RequestShowPassword(size_t index) { |
| 219 #if !defined(OS_ANDROID) // This is never called on Android. | 221 #if !defined(OS_ANDROID) // This is never called on Android. |
| 220 if (index >= password_list_.size()) { | 222 if (index >= password_list_.size()) { |
| 221 // |index| out of bounds might come from a compromised renderer, don't let | 223 // |index| out of bounds might come from a compromised renderer |
| 222 // it crash the browser. http://crbug.com/362054 | 224 // (http://crbug.com/362054), or the user requested to show a password while |
| 223 NOTREACHED(); | 225 // a request to the store is in progress (i.e. |password_list_| |
| 226 // is empty). Don't let it crash the browser. |
| 224 return; | 227 return; |
| 225 } | 228 } |
| 226 if ((base::TimeTicks::Now() - last_authentication_time_) > | 229 if ((base::TimeTicks::Now() - last_authentication_time_) > |
| 227 base::TimeDelta::FromSeconds(60)) { | 230 base::TimeDelta::FromSeconds(60)) { |
| 228 bool authenticated = true; | 231 bool authenticated = true; |
| 229 #if defined(OS_WIN) | 232 #if defined(OS_WIN) |
| 230 authenticated = password_manager_util_win::AuthenticateUser( | 233 authenticated = password_manager_util_win::AuthenticateUser( |
| 231 password_view_->GetNativeWindow()); | 234 password_view_->GetNativeWindow()); |
| 232 #elif defined(OS_MACOSX) | 235 #elif defined(OS_MACOSX) |
| 233 authenticated = password_manager_util_mac::AuthenticateUser(); | 236 authenticated = password_manager_util_mac::AuthenticateUser(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 258 index, | 261 index, |
| 259 origin_url, | 262 origin_url, |
| 260 base::UTF16ToUTF8(password_list_[index]->username_value), | 263 base::UTF16ToUTF8(password_list_[index]->username_value), |
| 261 password_list_[index]->password_value); | 264 password_list_[index]->password_value); |
| 262 #endif | 265 #endif |
| 263 } | 266 } |
| 264 | 267 |
| 265 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( | 268 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( |
| 266 size_t index) { | 269 size_t index) { |
| 267 if (index >= password_list_.size()) { | 270 if (index >= password_list_.size()) { |
| 268 // |index| out of bounds might come from a compromised renderer, don't let | 271 // |index| out of bounds might come from a compromised renderer |
| 269 // it crash the browser. http://crbug.com/362054 | 272 // (http://crbug.com/362054), or the user requested to get a password while |
| 270 NOTREACHED(); | 273 // a request to the store is in progress (i.e. |password_list_| |
| 274 // is empty). Don't let it crash the browser. |
| 271 return NULL; | 275 return NULL; |
| 272 } | 276 } |
| 273 return password_list_[index].get(); | 277 return password_list_[index].get(); |
| 274 } | 278 } |
| 275 | 279 |
| 276 const autofill::PasswordForm* PasswordManagerPresenter::GetPasswordException( | 280 const autofill::PasswordForm* PasswordManagerPresenter::GetPasswordException( |
| 277 size_t index) { | 281 size_t index) { |
| 278 if (index >= password_exception_list_.size()) { | 282 if (index >= password_exception_list_.size()) { |
| 279 // |index| out of bounds might come from a compromised renderer, don't let | 283 // |index| out of bounds might come from a compromised renderer |
| 280 // it crash the browser. http://crbug.com/362054 | 284 // (http://crbug.com/362054), or the user requested to get a password |
| 281 NOTREACHED(); | 285 // exception while a request to the store is in progress (i.e. |
| 286 // |password_exception_list_| is empty). Don't let it crash the browser. |
| 282 return NULL; | 287 return NULL; |
| 283 } | 288 } |
| 284 return password_exception_list_[index].get(); | 289 return password_exception_list_[index].get(); |
| 285 } | 290 } |
| 286 | 291 |
| 287 void PasswordManagerPresenter::SetPasswordList() { | 292 void PasswordManagerPresenter::SetPasswordList() { |
| 288 password_view_->SetPasswordList(password_list_); | 293 password_view_->SetPasswordList(password_list_); |
| 289 } | 294 } |
| 290 | 295 |
| 291 void PasswordManagerPresenter::SetPasswordExceptionList() { | 296 void PasswordManagerPresenter::SetPasswordExceptionList() { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 378 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
| 374 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { | 379 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { |
| 375 page_->password_exception_list_ = | 380 page_->password_exception_list_ = |
| 376 password_manager_util::ConvertScopedVector(std::move(results)); | 381 password_manager_util::ConvertScopedVector(std::move(results)); |
| 377 page_->SortEntriesAndHideDuplicates( | 382 page_->SortEntriesAndHideDuplicates( |
| 378 page_->languages_, &page_->password_exception_list_, | 383 page_->languages_, &page_->password_exception_list_, |
| 379 &page_->password_exception_duplicates_, | 384 &page_->password_exception_duplicates_, |
| 380 false /* don't use username and password*/); | 385 false /* don't use username and password*/); |
| 381 page_->SetPasswordExceptionList(); | 386 page_->SetPasswordExceptionList(); |
| 382 } | 387 } |
| OLD | NEW |