| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "webkit/glue/password_form_dom_manager.h" | 14 #include "webkit/glue/password_form_dom_manager.h" |
| 15 | 15 |
| 16 using base::Time; | 16 using base::Time; |
| 17 using webkit_glue::PasswordForm; | 17 using webkit_glue::PasswordForm; |
| 18 using webkit_glue::PasswordFormMap; | 18 using webkit_glue::PasswordFormMap; |
| 19 | 19 |
| 20 PasswordFormManager::PasswordFormManager(Profile* profile, | 20 PasswordFormManager::PasswordFormManager(Profile* profile, |
| 21 PasswordManager* password_manager, | 21 PasswordManager* password_manager, |
| 22 const PasswordForm& observed_form, | 22 const PasswordForm& observed_form, |
| 23 bool ssl_valid) | 23 bool ssl_valid) |
| 24 : best_matches_deleter_(&best_matches_), | 24 : best_matches_deleter_(&best_matches_), |
| 25 observed_form_(observed_form), | 25 observed_form_(observed_form), |
| 26 is_new_login_(true), | 26 is_new_login_(true), |
| 27 password_manager_(password_manager), | 27 password_manager_(password_manager), |
| 28 pending_login_query_(0), | 28 pending_login_query_(PasswordStore::kInvalidHandle), |
| 29 preferred_match_(NULL), | 29 preferred_match_(NULL), |
| 30 state_(PRE_MATCHING_PHASE), | 30 state_(PRE_MATCHING_PHASE), |
| 31 profile_(profile), | 31 profile_(profile), |
| 32 manager_action_(kManagerActionNone), | 32 manager_action_(kManagerActionNone), |
| 33 user_action_(kUserActionNone), | 33 user_action_(kUserActionNone), |
| 34 submit_result_(kSubmitResultNotSubmitted) { | 34 submit_result_(kSubmitResultNotSubmitted) { |
| 35 DCHECK(profile_); | 35 DCHECK(profile_); |
| 36 if (observed_form_.origin.is_valid()) | 36 if (observed_form_.origin.is_valid()) |
| 37 base::SplitString(observed_form_.origin.path(), '/', &form_path_tokens_); | 37 base::SplitString(observed_form_.origin.path(), '/', &form_path_tokens_); |
| 38 observed_form_.ssl_valid = ssl_valid; | 38 observed_form_.ssl_valid = ssl_valid; |
| 39 } | 39 } |
| 40 | 40 |
| 41 PasswordFormManager::~PasswordFormManager() { | 41 PasswordFormManager::~PasswordFormManager() { |
| 42 CancelLoginsQuery(); | |
| 43 UMA_HISTOGRAM_ENUMERATION("PasswordManager.ActionsTaken", | 42 UMA_HISTOGRAM_ENUMERATION("PasswordManager.ActionsTaken", |
| 44 GetActionsTaken(), | 43 GetActionsTaken(), |
| 45 kMaxNumActionsTaken); | 44 kMaxNumActionsTaken); |
| 46 } | 45 } |
| 47 | 46 |
| 48 int PasswordFormManager::GetActionsTaken() { | 47 int PasswordFormManager::GetActionsTaken() { |
| 49 return user_action_ + kUserActionMax * (manager_action_ + | 48 return user_action_ + kUserActionMax * (manager_action_ + |
| 50 kManagerActionMax * submit_result_); | 49 kManagerActionMax * submit_result_); |
| 51 }; | 50 }; |
| 52 | 51 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 DCHECK(!profile_->IsOffTheRecord()); | 189 DCHECK(!profile_->IsOffTheRecord()); |
| 191 | 190 |
| 192 if (IsNewLogin()) | 191 if (IsNewLogin()) |
| 193 SaveAsNewLogin(true); | 192 SaveAsNewLogin(true); |
| 194 else | 193 else |
| 195 UpdateLogin(); | 194 UpdateLogin(); |
| 196 } | 195 } |
| 197 | 196 |
| 198 void PasswordFormManager::FetchMatchingLoginsFromPasswordStore() { | 197 void PasswordFormManager::FetchMatchingLoginsFromPasswordStore() { |
| 199 DCHECK_EQ(state_, PRE_MATCHING_PHASE); | 198 DCHECK_EQ(state_, PRE_MATCHING_PHASE); |
| 200 DCHECK(!pending_login_query_); | 199 DCHECK(!PasswordStore::handle_is_valid(pending_login_query_)); |
| 201 state_ = MATCHING_PHASE; | 200 state_ = MATCHING_PHASE; |
| 202 PasswordStore* password_store = | 201 PasswordStore* password_store = |
| 203 profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); | 202 profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); |
| 204 if (!password_store) { | 203 if (!password_store) { |
| 205 NOTREACHED(); | 204 NOTREACHED(); |
| 206 return; | 205 return; |
| 207 } | 206 } |
| 208 pending_login_query_ = password_store->GetLogins(observed_form_, this); | 207 pending_login_query_ = password_store->GetLogins(observed_form_, this); |
| 209 } | 208 } |
| 210 | 209 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 preferred_match_->action.GetWithEmptyPath(); | 298 preferred_match_->action.GetWithEmptyPath(); |
| 300 if (wait_for_username) | 299 if (wait_for_username) |
| 301 manager_action_ = kManagerActionNone; | 300 manager_action_ = kManagerActionNone; |
| 302 else | 301 else |
| 303 manager_action_ = kManagerActionAutofilled; | 302 manager_action_ = kManagerActionAutofilled; |
| 304 password_manager_->Autofill(observed_form_, best_matches_, | 303 password_manager_->Autofill(observed_form_, best_matches_, |
| 305 preferred_match_, wait_for_username); | 304 preferred_match_, wait_for_username); |
| 306 } | 305 } |
| 307 | 306 |
| 308 void PasswordFormManager::OnPasswordStoreRequestDone( | 307 void PasswordFormManager::OnPasswordStoreRequestDone( |
| 309 int handle, const std::vector<PasswordForm*>& result) { | 308 PasswordStore::Handle handle, |
| 309 const std::vector<PasswordForm*>& result) { |
| 310 DCHECK_EQ(state_, MATCHING_PHASE); | 310 DCHECK_EQ(state_, MATCHING_PHASE); |
| 311 DCHECK_EQ(pending_login_query_, handle); | 311 DCHECK_EQ(pending_login_query_, handle); |
| 312 | 312 |
| 313 if (result.empty()) { | 313 if (result.empty()) { |
| 314 state_ = POST_MATCHING_PHASE; | 314 state_ = POST_MATCHING_PHASE; |
| 315 return; | 315 return; |
| 316 } | 316 } |
| 317 | 317 |
| 318 OnRequestDone(handle, result); | 318 OnRequestDone(handle, result); |
| 319 pending_login_query_ = PasswordStore::kInvalidHandle; |
| 319 } | 320 } |
| 320 | 321 |
| 321 bool PasswordFormManager::IgnoreResult(const PasswordForm& form) const { | 322 bool PasswordFormManager::IgnoreResult(const PasswordForm& form) const { |
| 322 // Ignore change password forms until we have some change password | 323 // Ignore change password forms until we have some change password |
| 323 // functionality | 324 // functionality |
| 324 if (observed_form_.old_password_element.length() != 0) { | 325 if (observed_form_.old_password_element.length() != 0) { |
| 325 return true; | 326 return true; |
| 326 } | 327 } |
| 327 // Don't match an invalid SSL form with one saved under secure | 328 // Don't match an invalid SSL form with one saved under secure |
| 328 // circumstances. | 329 // circumstances. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 // TODO(timsteele): Bug 1188626 - expire the master copies. | 414 // TODO(timsteele): Bug 1188626 - expire the master copies. |
| 414 PasswordForm copy(pending_credentials_); | 415 PasswordForm copy(pending_credentials_); |
| 415 copy.origin = observed_form_.origin; | 416 copy.origin = observed_form_.origin; |
| 416 copy.action = observed_form_.action; | 417 copy.action = observed_form_.action; |
| 417 password_store->AddLogin(copy); | 418 password_store->AddLogin(copy); |
| 418 } else { | 419 } else { |
| 419 password_store->UpdateLogin(pending_credentials_); | 420 password_store->UpdateLogin(pending_credentials_); |
| 420 } | 421 } |
| 421 } | 422 } |
| 422 | 423 |
| 423 void PasswordFormManager::CancelLoginsQuery() { | |
| 424 PasswordStore* password_store = | |
| 425 profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); | |
| 426 if (!password_store) { | |
| 427 // Can be NULL in unit tests. | |
| 428 return; | |
| 429 } | |
| 430 password_store->CancelLoginsQuery(pending_login_query_); | |
| 431 } | |
| 432 | |
| 433 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { | 424 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { |
| 434 DCHECK_EQ(state_, MATCHING_PHASE); | 425 DCHECK_EQ(state_, MATCHING_PHASE); |
| 435 // For scoring of candidate login data: | 426 // For scoring of candidate login data: |
| 436 // The most important element that should match is the origin, followed by | 427 // The most important element that should match is the origin, followed by |
| 437 // the action, the password name, the submit button name, and finally the | 428 // the action, the password name, the submit button name, and finally the |
| 438 // username input field name. | 429 // username input field name. |
| 439 // Exact origin match gives an addition of 32 (1 << 5) + # of matching url | 430 // Exact origin match gives an addition of 32 (1 << 5) + # of matching url |
| 440 // dirs. | 431 // dirs. |
| 441 // Partial match gives an addition of 16 (1 << 4) + # matching url dirs | 432 // Partial match gives an addition of 16 (1 << 4) + # matching url dirs |
| 442 // That way, a partial match cannot trump an exact match even if | 433 // That way, a partial match cannot trump an exact match even if |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 return score; | 470 return score; |
| 480 } | 471 } |
| 481 | 472 |
| 482 void PasswordFormManager::SubmitPassed() { | 473 void PasswordFormManager::SubmitPassed() { |
| 483 submit_result_ = kSubmitResultPassed; | 474 submit_result_ = kSubmitResultPassed; |
| 484 } | 475 } |
| 485 | 476 |
| 486 void PasswordFormManager::SubmitFailed() { | 477 void PasswordFormManager::SubmitFailed() { |
| 487 submit_result_ = kSubmitResultFailed; | 478 submit_result_ = kSubmitResultFailed; |
| 488 } | 479 } |
| OLD | NEW |