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_util.h" | 10 #include "base/string_util.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 // Make sure the important fields stay the same as the initially observed or | 183 // Make sure the important fields stay the same as the initially observed or |
184 // autofilled ones, as they may have changed if the user experienced a login | 184 // autofilled ones, as they may have changed if the user experienced a login |
185 // failure. | 185 // failure. |
186 // Look for these credentials in the list containing auto-fill entries. | 186 // Look for these credentials in the list containing auto-fill entries. |
187 PasswordFormMap::const_iterator it = | 187 PasswordFormMap::const_iterator it = |
188 best_matches_.find(credentials.username_value); | 188 best_matches_.find(credentials.username_value); |
189 if (it != best_matches_.end()) { | 189 if (it != best_matches_.end()) { |
190 // The user signed in with a login we autofilled. | 190 // The user signed in with a login we autofilled. |
191 pending_credentials_ = *it->second; | 191 pending_credentials_ = *it->second; |
192 is_new_login_ = false; | 192 |
| 193 // PSL origin matches should always be new logins, since we want to store |
| 194 // them so they can automatically be filled in later. |
| 195 is_new_login_ = pending_credentials_.is_psl_origin_match; |
193 | 196 |
194 // Check to see if we're using a known username but a new password. | 197 // Check to see if we're using a known username but a new password. |
195 if (pending_credentials_.password_value != credentials.password_value) | 198 if (pending_credentials_.password_value != credentials.password_value) |
196 user_action_ = kUserActionOverride; | 199 user_action_ = kUserActionOverride; |
197 } else if (action == ALLOW_OTHER_POSSIBLE_USERNAMES && | 200 } else if (action == ALLOW_OTHER_POSSIBLE_USERNAMES && |
198 UpdatePendingCredentialsIfOtherPossibleUsername( | 201 UpdatePendingCredentialsIfOtherPossibleUsername( |
199 credentials.username_value)) { | 202 credentials.username_value)) { |
200 // |pending_credentials_| is now set. Note we don't update | 203 // |pending_credentials_| is now set. Note we don't update |
201 // |pending_credentials_.username_value| to |credentials.username_value| | 204 // |pending_credentials_.username_value| to |credentials.username_value| |
202 // yet because we need to keep the original username to modify the stored | 205 // yet because we need to keep the original username to modify the stored |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 // Check to see if the user told us to ignore this site in the past. | 333 // Check to see if the user told us to ignore this site in the past. |
331 if (preferred_match_->blacklisted_by_user) { | 334 if (preferred_match_->blacklisted_by_user) { |
332 manager_action_ = kManagerActionBlacklisted; | 335 manager_action_ = kManagerActionBlacklisted; |
333 return; | 336 return; |
334 } | 337 } |
335 | 338 |
336 // If not blacklisted, send a message to allow password generation. | 339 // If not blacklisted, send a message to allow password generation. |
337 SendNotBlacklistedToRenderer(); | 340 SendNotBlacklistedToRenderer(); |
338 | 341 |
339 // Proceed to autofill. | 342 // Proceed to autofill. |
340 // Note that we provide the choices but don't actually prefill a value if | 343 // Note that we provide the choices but don't actually prefill a value if: |
341 // either: (1) we are in Incognito mode, or (2) the ACTION paths don't match. | 344 // (1) we are in Incognito mode, (2) the ACTION paths don't match, |
| 345 // or (3) if it matched using PSL domain matching. |
342 bool wait_for_username = | 346 bool wait_for_username = |
343 profile_->IsOffTheRecord() || | 347 profile_->IsOffTheRecord() || |
344 observed_form_.action.GetWithEmptyPath() != | 348 observed_form_.action.GetWithEmptyPath() != |
345 preferred_match_->action.GetWithEmptyPath(); | 349 preferred_match_->action.GetWithEmptyPath() || |
| 350 preferred_match_->is_psl_origin_match; |
346 if (wait_for_username) | 351 if (wait_for_username) |
347 manager_action_ = kManagerActionNone; | 352 manager_action_ = kManagerActionNone; |
348 else | 353 else |
349 manager_action_ = kManagerActionAutofilled; | 354 manager_action_ = kManagerActionAutofilled; |
350 password_manager_->Autofill(observed_form_, best_matches_, | 355 password_manager_->Autofill(observed_form_, best_matches_, |
351 *preferred_match_, wait_for_username); | 356 *preferred_match_, wait_for_username); |
352 } | 357 } |
353 | 358 |
354 void PasswordFormManager::OnPasswordStoreRequestDone( | 359 void PasswordFormManager::OnPasswordStoreRequestDone( |
355 CancelableRequestProvider::Handle handle, | 360 CancelableRequestProvider::Handle handle, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 } | 526 } |
522 return false; | 527 return false; |
523 } | 528 } |
524 | 529 |
525 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { | 530 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { |
526 DCHECK_EQ(state_, MATCHING_PHASE); | 531 DCHECK_EQ(state_, MATCHING_PHASE); |
527 // For scoring of candidate login data: | 532 // For scoring of candidate login data: |
528 // The most important element that should match is the origin, followed by | 533 // The most important element that should match is the origin, followed by |
529 // the action, the password name, the submit button name, and finally the | 534 // the action, the password name, the submit button name, and finally the |
530 // username input field name. | 535 // username input field name. |
531 // Exact origin match gives an addition of 32 (1 << 5) + # of matching url | 536 // Exact origin match gives an addition of 64 (1 << 6) + # of matching url |
532 // dirs. | 537 // dirs. |
533 // Partial match gives an addition of 16 (1 << 4) + # matching url dirs | 538 // Partial match gives an addition of 32 (1 << 5) + # matching url dirs |
534 // That way, a partial match cannot trump an exact match even if | 539 // That way, a partial match cannot trump an exact match even if |
535 // the partial one matches all other attributes (action, elements) (and | 540 // the partial one matches all other attributes (action, elements) (and |
536 // regardless of the matching depth in the URL path). | 541 // regardless of the matching depth in the URL path). |
| 542 // If PSL origin match was not used, it gives an addition of 16 (1 << 4). |
537 int score = 0; | 543 int score = 0; |
538 if (candidate.origin == observed_form_.origin) { | 544 if (candidate.origin == observed_form_.origin) { |
539 // This check is here for the most common case which | 545 // This check is here for the most common case which |
540 // is we have a single match in the db for the given host, | 546 // is we have a single match in the db for the given host, |
541 // so we don't generally need to walk the entire URL path (the else | 547 // so we don't generally need to walk the entire URL path (the else |
542 // clause). | 548 // clause). |
543 score += (1 << 5) + static_cast<int>(form_path_tokens_.size()); | 549 score += (1 << 6) + static_cast<int>(form_path_tokens_.size()); |
544 } else { | 550 } else { |
545 // Walk the origin URL paths one directory at a time to see how | 551 // Walk the origin URL paths one directory at a time to see how |
546 // deep the two match. | 552 // deep the two match. |
547 std::vector<std::string> candidate_path_tokens; | 553 std::vector<std::string> candidate_path_tokens; |
548 base::SplitString(candidate.origin.path(), '/', &candidate_path_tokens); | 554 base::SplitString(candidate.origin.path(), '/', &candidate_path_tokens); |
549 size_t depth = 0; | 555 size_t depth = 0; |
550 size_t max_dirs = std::min(form_path_tokens_.size(), | 556 size_t max_dirs = std::min(form_path_tokens_.size(), |
551 candidate_path_tokens.size()); | 557 candidate_path_tokens.size()); |
552 while ((depth < max_dirs) && (form_path_tokens_[depth] == | 558 while ((depth < max_dirs) && (form_path_tokens_[depth] == |
553 candidate_path_tokens[depth])) { | 559 candidate_path_tokens[depth])) { |
554 depth++; | 560 depth++; |
555 score++; | 561 score++; |
556 } | 562 } |
557 // do we have a partial match? | 563 // do we have a partial match? |
558 score += (depth > 0) ? 1 << 4 : 0; | 564 score += (depth > 0) ? 1 << 5 : 0; |
559 } | 565 } |
560 if (observed_form_.scheme == PasswordForm::SCHEME_HTML) { | 566 if (observed_form_.scheme == PasswordForm::SCHEME_HTML) { |
| 567 if (!candidate.is_psl_origin_match) |
| 568 score += 1 << 4; |
561 if (candidate.action == observed_form_.action) | 569 if (candidate.action == observed_form_.action) |
562 score += 1 << 3; | 570 score += 1 << 3; |
563 if (candidate.password_element == observed_form_.password_element) | 571 if (candidate.password_element == observed_form_.password_element) |
564 score += 1 << 2; | 572 score += 1 << 2; |
565 if (candidate.submit_element == observed_form_.submit_element) | 573 if (candidate.submit_element == observed_form_.submit_element) |
566 score += 1 << 1; | 574 score += 1 << 1; |
567 if (candidate.username_element == observed_form_.username_element) | 575 if (candidate.username_element == observed_form_.username_element) |
568 score += 1 << 0; | 576 score += 1 << 0; |
569 } | 577 } |
570 | 578 |
571 return score; | 579 return score; |
572 } | 580 } |
573 | 581 |
574 void PasswordFormManager::SubmitPassed() { | 582 void PasswordFormManager::SubmitPassed() { |
575 submit_result_ = kSubmitResultPassed; | 583 submit_result_ = kSubmitResultPassed; |
576 } | 584 } |
577 | 585 |
578 void PasswordFormManager::SubmitFailed() { | 586 void PasswordFormManager::SubmitFailed() { |
579 submit_result_ = kSubmitResultFailed; | 587 submit_result_ = kSubmitResultFailed; |
580 } | 588 } |
581 | 589 |
582 void PasswordFormManager::SendNotBlacklistedToRenderer() { | 590 void PasswordFormManager::SendNotBlacklistedToRenderer() { |
583 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); | 591 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); |
584 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), | 592 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), |
585 observed_form_)); | 593 observed_form_)); |
586 } | 594 } |
OLD | NEW |