| 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_form_manager.h" | 5 #include "chrome/browser/password_manager/password_form_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "chrome/browser/password_manager/password_manager.h" | 12 #include "chrome/browser/password_manager/password_manager.h" |
| 13 #include "chrome/browser/password_manager/password_store.h" | 13 #include "chrome/browser/password_manager/password_store.h" |
| 14 #include "chrome/browser/password_manager/password_store_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "webkit/forms/password_form_dom_manager.h" | 16 #include "webkit/forms/password_form_dom_manager.h" |
| 16 | 17 |
| 17 using base::Time; | 18 using base::Time; |
| 18 using webkit::forms::PasswordForm; | 19 using webkit::forms::PasswordForm; |
| 19 using webkit::forms::PasswordFormMap; | 20 using webkit::forms::PasswordFormMap; |
| 20 | 21 |
| 21 PasswordFormManager::PasswordFormManager(Profile* profile, | 22 PasswordFormManager::PasswordFormManager(Profile* profile, |
| 22 PasswordManager* password_manager, | 23 PasswordManager* password_manager, |
| 23 const PasswordForm& observed_form, | 24 const PasswordForm& observed_form, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // Configure the form about to be saved for blacklist status. | 108 // Configure the form about to be saved for blacklist status. |
| 108 pending_credentials_.preferred = true; | 109 pending_credentials_.preferred = true; |
| 109 pending_credentials_.blacklisted_by_user = true; | 110 pending_credentials_.blacklisted_by_user = true; |
| 110 pending_credentials_.username_value.clear(); | 111 pending_credentials_.username_value.clear(); |
| 111 pending_credentials_.password_value.clear(); | 112 pending_credentials_.password_value.clear(); |
| 112 | 113 |
| 113 // Retroactively forget existing matches for this form, so we NEVER prompt or | 114 // Retroactively forget existing matches for this form, so we NEVER prompt or |
| 114 // autofill it again. | 115 // autofill it again. |
| 115 if (!best_matches_.empty()) { | 116 if (!best_matches_.empty()) { |
| 116 PasswordFormMap::const_iterator iter; | 117 PasswordFormMap::const_iterator iter; |
| 117 PasswordStore* password_store = | 118 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
| 118 profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); | 119 profile_, Profile::EXPLICIT_ACCESS); |
| 119 if (!password_store) { | 120 if (!password_store) { |
| 120 NOTREACHED(); | 121 NOTREACHED(); |
| 121 return; | 122 return; |
| 122 } | 123 } |
| 123 for (iter = best_matches_.begin(); iter != best_matches_.end(); ++iter) { | 124 for (iter = best_matches_.begin(); iter != best_matches_.end(); ++iter) { |
| 124 // We want to remove existing matches for this form so that the exact | 125 // We want to remove existing matches for this form so that the exact |
| 125 // origin match with |blackisted_by_user == true| is the only result that | 126 // origin match with |blackisted_by_user == true| is the only result that |
| 126 // shows up in the future for this origin URL. However, we don't want to | 127 // shows up in the future for this origin URL. However, we don't want to |
| 127 // delete logins that were actually saved on a different page (hence with | 128 // delete logins that were actually saved on a different page (hence with |
| 128 // different origin URL) and just happened to match this form because of | 129 // different origin URL) and just happened to match this form because of |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 if (IsNewLogin()) | 193 if (IsNewLogin()) |
| 193 SaveAsNewLogin(true); | 194 SaveAsNewLogin(true); |
| 194 else | 195 else |
| 195 UpdateLogin(); | 196 UpdateLogin(); |
| 196 } | 197 } |
| 197 | 198 |
| 198 void PasswordFormManager::FetchMatchingLoginsFromPasswordStore() { | 199 void PasswordFormManager::FetchMatchingLoginsFromPasswordStore() { |
| 199 DCHECK_EQ(state_, PRE_MATCHING_PHASE); | 200 DCHECK_EQ(state_, PRE_MATCHING_PHASE); |
| 200 DCHECK(!pending_login_query_); | 201 DCHECK(!pending_login_query_); |
| 201 state_ = MATCHING_PHASE; | 202 state_ = MATCHING_PHASE; |
| 202 PasswordStore* password_store = | 203 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
| 203 profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); | 204 profile_, Profile::EXPLICIT_ACCESS); |
| 204 if (!password_store) { | 205 if (!password_store) { |
| 205 NOTREACHED(); | 206 NOTREACHED(); |
| 206 return; | 207 return; |
| 207 } | 208 } |
| 208 pending_login_query_ = password_store->GetLogins(observed_form_, this); | 209 pending_login_query_ = password_store->GetLogins(observed_form_, this); |
| 209 } | 210 } |
| 210 | 211 |
| 211 bool PasswordFormManager::HasCompletedMatching() { | 212 bool PasswordFormManager::HasCompletedMatching() { |
| 212 return state_ == POST_MATCHING_PHASE; | 213 return state_ == POST_MATCHING_PHASE; |
| 213 } | 214 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 void PasswordFormManager::SaveAsNewLogin(bool reset_preferred_login) { | 341 void PasswordFormManager::SaveAsNewLogin(bool reset_preferred_login) { |
| 341 DCHECK_EQ(state_, POST_MATCHING_PHASE); | 342 DCHECK_EQ(state_, POST_MATCHING_PHASE); |
| 342 DCHECK(IsNewLogin()); | 343 DCHECK(IsNewLogin()); |
| 343 // The new_form is being used to sign in, so it is preferred. | 344 // The new_form is being used to sign in, so it is preferred. |
| 344 DCHECK(pending_credentials_.preferred); | 345 DCHECK(pending_credentials_.preferred); |
| 345 // new_form contains the same basic data as observed_form_ (because its the | 346 // new_form contains the same basic data as observed_form_ (because its the |
| 346 // same form), but with the newly added credentials. | 347 // same form), but with the newly added credentials. |
| 347 | 348 |
| 348 DCHECK(!profile_->IsOffTheRecord()); | 349 DCHECK(!profile_->IsOffTheRecord()); |
| 349 | 350 |
| 350 PasswordStore* password_store = | 351 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
| 351 profile_->GetPasswordStore(Profile::IMPLICIT_ACCESS); | 352 profile_, Profile::IMPLICIT_ACCESS); |
| 352 if (!password_store) { | 353 if (!password_store) { |
| 353 NOTREACHED(); | 354 NOTREACHED(); |
| 354 return; | 355 return; |
| 355 } | 356 } |
| 356 | 357 |
| 357 pending_credentials_.date_created = Time::Now(); | 358 pending_credentials_.date_created = Time::Now(); |
| 358 password_store->AddLogin(pending_credentials_); | 359 password_store->AddLogin(pending_credentials_); |
| 359 | 360 |
| 360 if (reset_preferred_login) { | 361 if (reset_preferred_login) { |
| 361 UpdatePreferredLoginState(password_store); | 362 UpdatePreferredLoginState(password_store); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 381 void PasswordFormManager::UpdateLogin() { | 382 void PasswordFormManager::UpdateLogin() { |
| 382 DCHECK_EQ(state_, POST_MATCHING_PHASE); | 383 DCHECK_EQ(state_, POST_MATCHING_PHASE); |
| 383 DCHECK(preferred_match_); | 384 DCHECK(preferred_match_); |
| 384 // If we're doing an Update, we either autofilled correctly and need to | 385 // If we're doing an Update, we either autofilled correctly and need to |
| 385 // update the stats, or the user typed in a new password for autofilled | 386 // update the stats, or the user typed in a new password for autofilled |
| 386 // username, or the user selected one of the non-preferred matches, | 387 // username, or the user selected one of the non-preferred matches, |
| 387 // thus requiring a swap of preferred bits. | 388 // thus requiring a swap of preferred bits. |
| 388 DCHECK(!IsNewLogin() && pending_credentials_.preferred); | 389 DCHECK(!IsNewLogin() && pending_credentials_.preferred); |
| 389 DCHECK(!profile_->IsOffTheRecord()); | 390 DCHECK(!profile_->IsOffTheRecord()); |
| 390 | 391 |
| 391 PasswordStore* password_store = | 392 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
| 392 profile_->GetPasswordStore(Profile::IMPLICIT_ACCESS); | 393 profile_, Profile::IMPLICIT_ACCESS); |
| 393 if (!password_store) { | 394 if (!password_store) { |
| 394 NOTREACHED(); | 395 NOTREACHED(); |
| 395 return; | 396 return; |
| 396 } | 397 } |
| 397 | 398 |
| 398 UpdatePreferredLoginState(password_store); | 399 UpdatePreferredLoginState(password_store); |
| 399 | 400 |
| 400 // Update the new preferred login. | 401 // Update the new preferred login. |
| 401 // Note origin.spec().length > signon_realm.length implies the origin has a | 402 // Note origin.spec().length > signon_realm.length implies the origin has a |
| 402 // path, since signon_realm is a prefix of origin for HTML password forms. | 403 // path, since signon_realm is a prefix of origin for HTML password forms. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 return score; | 475 return score; |
| 475 } | 476 } |
| 476 | 477 |
| 477 void PasswordFormManager::SubmitPassed() { | 478 void PasswordFormManager::SubmitPassed() { |
| 478 submit_result_ = kSubmitResultPassed; | 479 submit_result_ = kSubmitResultPassed; |
| 479 } | 480 } |
| 480 | 481 |
| 481 void PasswordFormManager::SubmitFailed() { | 482 void PasswordFormManager::SubmitFailed() { |
| 482 submit_result_ = kSubmitResultFailed; | 483 submit_result_ = kSubmitResultFailed; |
| 483 } | 484 } |
| OLD | NEW |