| 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 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
| 22 #include "chrome/browser/sync/profile_sync_service_factory.h" | 22 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 23 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 23 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 24 #include "chrome/browser/ui/passwords/password_ui_view.h" | 24 #include "chrome/browser/ui/passwords/password_ui_view.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "components/autofill/core/common/password_form.h" | 28 #include "components/autofill/core/common/password_form.h" |
| 29 #include "components/browser_sync/browser/profile_sync_service.h" | 29 #include "components/browser_sync/browser/profile_sync_service.h" |
| 30 #include "components/password_manager/core/browser/affiliation_utils.h" | 30 #include "components/password_manager/core/browser/affiliation_utils.h" |
| 31 #include "components/password_manager/core/browser/import/password_importer.h" |
| 31 #include "components/password_manager/core/browser/password_manager_util.h" | 32 #include "components/password_manager/core/browser/password_manager_util.h" |
| 32 #include "components/password_manager/core/browser/password_ui_utils.h" | 33 #include "components/password_manager/core/browser/password_ui_utils.h" |
| 33 #include "components/password_manager/core/common/password_manager_pref_names.h" | 34 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 34 #include "components/password_manager/sync/browser/password_sync_util.h" | 35 #include "components/password_manager/sync/browser/password_sync_util.h" |
| 35 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
| 37 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
| 37 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 38 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 40 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 39 | 41 |
| 40 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 41 #include "chrome/browser/password_manager/password_manager_util_win.h" | 43 #include "chrome/browser/password_manager/password_manager_util_win.h" |
| 42 #elif defined(OS_MACOSX) | 44 #elif defined(OS_MACOSX) |
| 43 #include "chrome/browser/password_manager/password_manager_util_mac.h" | 45 #include "chrome/browser/password_manager/password_manager_util_mac.h" |
| 44 #endif | 46 #endif |
| 45 | 47 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 216 |
| 215 void PasswordManagerPresenter::RequestShowPassword(size_t index) { | 217 void PasswordManagerPresenter::RequestShowPassword(size_t index) { |
| 216 #if !defined(OS_ANDROID) // This is never called on Android. | 218 #if !defined(OS_ANDROID) // This is never called on Android. |
| 217 if (index >= password_list_.size()) { | 219 if (index >= password_list_.size()) { |
| 218 // |index| out of bounds might come from a compromised renderer | 220 // |index| out of bounds might come from a compromised renderer |
| 219 // (http://crbug.com/362054), or the user requested to show a password while | 221 // (http://crbug.com/362054), or the user requested to show a password while |
| 220 // a request to the store is in progress (i.e. |password_list_| | 222 // a request to the store is in progress (i.e. |password_list_| |
| 221 // is empty). Don't let it crash the browser. | 223 // is empty). Don't let it crash the browser. |
| 222 return; | 224 return; |
| 223 } | 225 } |
| 224 if ((base::TimeTicks::Now() - last_authentication_time_) > | 226 |
| 225 base::TimeDelta::FromSeconds(60)) { | 227 if (!IsUserAuthenticated()) { |
| 226 bool authenticated = true; | 228 return; |
| 227 #if defined(OS_WIN) | |
| 228 authenticated = password_manager_util_win::AuthenticateUser( | |
| 229 password_view_->GetNativeWindow()); | |
| 230 #elif defined(OS_MACOSX) | |
| 231 authenticated = password_manager_util_mac::AuthenticateUser(); | |
| 232 #endif | |
| 233 if (authenticated) | |
| 234 last_authentication_time_ = base::TimeTicks::Now(); | |
| 235 else | |
| 236 return; | |
| 237 } | 229 } |
| 238 | 230 |
| 239 sync_driver::SyncService* sync_service = nullptr; | 231 sync_driver::SyncService* sync_service = nullptr; |
| 240 if (ProfileSyncServiceFactory::HasProfileSyncService( | 232 if (ProfileSyncServiceFactory::HasProfileSyncService( |
| 241 password_view_->GetProfile())) { | 233 password_view_->GetProfile())) { |
| 242 sync_service = | 234 sync_service = |
| 243 ProfileSyncServiceFactory::GetForProfile(password_view_->GetProfile()); | 235 ProfileSyncServiceFactory::GetForProfile(password_view_->GetProfile()); |
| 244 } | 236 } |
| 245 if (password_manager::sync_util::IsSyncAccountCredential( | 237 if (password_manager::sync_util::IsSyncAccountCredential( |
| 246 *password_list_[index], sync_service, | 238 *password_list_[index], sync_service, |
| 247 SigninManagerFactory::GetForProfile(password_view_->GetProfile()))) { | 239 SigninManagerFactory::GetForProfile(password_view_->GetProfile()))) { |
| 248 content::RecordAction( | 240 content::RecordAction( |
| 249 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); | 241 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); |
| 250 } | 242 } |
| 251 | 243 |
| 252 // Call back the front end to reveal the password. | 244 // Call back the front end to reveal the password. |
| 253 std::string origin_url = password_manager::GetHumanReadableOrigin( | 245 std::string origin_url = password_manager::GetHumanReadableOrigin( |
| 254 *password_list_[index]); | 246 *password_list_[index]); |
| 255 password_view_->ShowPassword( | 247 password_view_->ShowPassword( |
| 256 index, | 248 index, |
| 257 origin_url, | 249 origin_url, |
| 258 base::UTF16ToUTF8(password_list_[index]->username_value), | 250 base::UTF16ToUTF8(password_list_[index]->username_value), |
| 259 password_list_[index]->password_value); | 251 password_list_[index]->password_value); |
| 260 #endif | 252 #endif |
| 261 } | 253 } |
| 262 | 254 |
| 255 std::vector<scoped_ptr<autofill::PasswordForm>> |
| 256 PasswordManagerPresenter::GetAllPasswords() { |
| 257 std::vector<scoped_ptr<autofill::PasswordForm>> ret_val; |
| 258 |
| 259 for (const auto& form : password_list_) { |
| 260 ret_val.push_back(make_scoped_ptr(new autofill::PasswordForm(*form))); |
| 261 } |
| 262 |
| 263 return ret_val; |
| 264 } |
| 265 |
| 263 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( | 266 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( |
| 264 size_t index) { | 267 size_t index) { |
| 265 if (index >= password_list_.size()) { | 268 if (index >= password_list_.size()) { |
| 266 // |index| out of bounds might come from a compromised renderer | 269 // |index| out of bounds might come from a compromised renderer |
| 267 // (http://crbug.com/362054), or the user requested to get a password while | 270 // (http://crbug.com/362054), or the user requested to get a password while |
| 268 // a request to the store is in progress (i.e. |password_list_| | 271 // a request to the store is in progress (i.e. |password_list_| |
| 269 // is empty). Don't let it crash the browser. | 272 // is empty). Don't let it crash the browser. |
| 270 return NULL; | 273 return NULL; |
| 271 } | 274 } |
| 272 return password_list_[index].get(); | 275 return password_list_[index].get(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 for (auto& pair : pairs) { | 320 for (auto& pair : pairs) { |
| 318 if (pair.first != previous_key) { | 321 if (pair.first != previous_key) { |
| 319 list->push_back(std::move(pair.second)); | 322 list->push_back(std::move(pair.second)); |
| 320 previous_key = pair.first; | 323 previous_key = pair.first; |
| 321 } else { | 324 } else { |
| 322 duplicates->insert(std::make_pair(previous_key, std::move(pair.second))); | 325 duplicates->insert(std::make_pair(previous_key, std::move(pair.second))); |
| 323 } | 326 } |
| 324 } | 327 } |
| 325 } | 328 } |
| 326 | 329 |
| 330 bool PasswordManagerPresenter::IsUserAuthenticated() { |
| 331 #if defined(OS_ANDROID) |
| 332 NOTREACHED(); |
| 333 #endif |
| 334 if (base::TimeTicks::Now() - last_authentication_time_ > |
| 335 base::TimeDelta::FromSeconds(60)) { |
| 336 bool authenticated = true; |
| 337 #if defined(OS_WIN) |
| 338 authenticated = password_manager_util_win::AuthenticateUser( |
| 339 password_view_->GetNativeWindow()); |
| 340 #elif defined(OS_MACOSX) |
| 341 authenticated = password_manager_util_mac::AuthenticateUser(); |
| 342 #endif |
| 343 if (authenticated) |
| 344 last_authentication_time_ = base::TimeTicks::Now(); |
| 345 return authenticated; |
| 346 } |
| 347 return true; |
| 348 } |
| 349 |
| 327 PasswordManagerPresenter::ListPopulater::ListPopulater( | 350 PasswordManagerPresenter::ListPopulater::ListPopulater( |
| 328 PasswordManagerPresenter* page) : page_(page) { | 351 PasswordManagerPresenter* page) : page_(page) { |
| 329 } | 352 } |
| 330 | 353 |
| 331 PasswordManagerPresenter::ListPopulater::~ListPopulater() { | 354 PasswordManagerPresenter::ListPopulater::~ListPopulater() { |
| 332 } | 355 } |
| 333 | 356 |
| 334 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater( | 357 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater( |
| 335 PasswordManagerPresenter* page) : ListPopulater(page) { | 358 PasswordManagerPresenter* page) : ListPopulater(page) { |
| 336 } | 359 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 395 |
| 373 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 396 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
| 374 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { | 397 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { |
| 375 page_->password_exception_list_ = | 398 page_->password_exception_list_ = |
| 376 password_manager_util::ConvertScopedVector(std::move(results)); | 399 password_manager_util::ConvertScopedVector(std::move(results)); |
| 377 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_, | 400 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_, |
| 378 &page_->password_exception_duplicates_, | 401 &page_->password_exception_duplicates_, |
| 379 false /* don't use username and password*/); | 402 false /* don't use username and password*/); |
| 380 page_->SetPasswordExceptionList(); | 403 page_->SetPasswordExceptionList(); |
| 381 } | 404 } |
| OLD | NEW |