| 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/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/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/password_manager/password_store_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "components/autofill/content/browser/autofill_driver_impl.h" |
| 17 #include "components/autofill/core/browser/form_structure.h" |
| 16 #include "components/autofill/core/browser/validation.h" | 18 #include "components/autofill/core/browser/validation.h" |
| 17 #include "components/autofill/core/common/autofill_messages.h" | 19 #include "components/autofill/core/common/autofill_messages.h" |
| 18 #include "components/autofill/core/common/password_form.h" | 20 #include "components/autofill/core/common/password_form.h" |
| 19 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 21 | 23 |
| 24 using autofill::FormStructure; |
| 22 using autofill::PasswordForm; | 25 using autofill::PasswordForm; |
| 23 using autofill::PasswordFormMap; | 26 using autofill::PasswordFormMap; |
| 24 using base::Time; | 27 using base::Time; |
| 25 | 28 |
| 26 PasswordFormManager::PasswordFormManager(Profile* profile, | 29 PasswordFormManager::PasswordFormManager(Profile* profile, |
| 27 PasswordManager* password_manager, | 30 PasswordManager* password_manager, |
| 28 content::WebContents* web_contents, | 31 content::WebContents* web_contents, |
| 29 const PasswordForm& observed_form, | 32 const PasswordForm& observed_form, |
| 30 bool ssl_valid) | 33 bool ssl_valid) |
| 31 : best_matches_deleter_(&best_matches_), | 34 : best_matches_deleter_(&best_matches_), |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 482 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
| 480 profile_, Profile::IMPLICIT_ACCESS).get(); | 483 profile_, Profile::IMPLICIT_ACCESS).get(); |
| 481 if (!password_store) { | 484 if (!password_store) { |
| 482 NOTREACHED(); | 485 NOTREACHED(); |
| 483 return; | 486 return; |
| 484 } | 487 } |
| 485 | 488 |
| 486 // Update metadata. | 489 // Update metadata. |
| 487 ++pending_credentials_.times_used; | 490 ++pending_credentials_.times_used; |
| 488 | 491 |
| 492 // Check to see if this form is a candidate for password generation. |
| 493 CheckForAccountCreationForm(pending_credentials_, observed_form_); |
| 494 |
| 489 UpdatePreferredLoginState(password_store); | 495 UpdatePreferredLoginState(password_store); |
| 490 | 496 |
| 491 // Remove alternate usernames. At this point we assume that we have found | 497 // Remove alternate usernames. At this point we assume that we have found |
| 492 // the right username. | 498 // the right username. |
| 493 pending_credentials_.other_possible_usernames.clear(); | 499 pending_credentials_.other_possible_usernames.clear(); |
| 494 | 500 |
| 495 // Update the new preferred login. | 501 // Update the new preferred login. |
| 496 if (!selected_username_.empty()) { | 502 if (!selected_username_.empty()) { |
| 497 // An other possible username is selected. We set this selected username | 503 // An other possible username is selected. We set this selected username |
| 498 // as the real username. The PasswordStore API isn't designed to update | 504 // as the real username. The PasswordStore API isn't designed to update |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 for (size_t i = 0; i < it->second->other_possible_usernames.size(); ++i) { | 542 for (size_t i = 0; i < it->second->other_possible_usernames.size(); ++i) { |
| 537 if (it->second->other_possible_usernames[i] == username) { | 543 if (it->second->other_possible_usernames[i] == username) { |
| 538 pending_credentials_ = *it->second; | 544 pending_credentials_ = *it->second; |
| 539 return true; | 545 return true; |
| 540 } | 546 } |
| 541 } | 547 } |
| 542 } | 548 } |
| 543 return false; | 549 return false; |
| 544 } | 550 } |
| 545 | 551 |
| 552 void PasswordFormManager::CheckForAccountCreationForm( |
| 553 const PasswordForm& pending, const PasswordForm& observed) { |
| 554 // We check to see if the saved form_data is the same as the observed |
| 555 // form_data, which should never be true for passwords saved on account |
| 556 // creation forms. This check is only made the first time a password is used |
| 557 // to cut down on false positives. Specifically a site may have multiple login |
| 558 // forms with different markup, which might look similar to a signup form. |
| 559 if (pending.times_used == 1) { |
| 560 FormStructure pending_structure(pending.form_data); |
| 561 FormStructure observed_structure(observed.form_data); |
| 562 if (pending_structure.FormSignature() != |
| 563 observed_structure.FormSignature()) { |
| 564 autofill::AutofillDriverImpl* driver = |
| 565 autofill::AutofillDriverImpl::FromWebContents(web_contents_); |
| 566 if (driver && driver->autofill_manager()) { |
| 567 // Note that this doesn't guarantee that the upload succeeded, only that |
| 568 // |pending.form_data| is considered uploadable. |
| 569 bool success = driver->autofill_manager()->UploadPasswordGenerationForm( |
| 570 pending.form_data); |
| 571 UMA_HISTOGRAM_BOOLEAN("PasswordGeneration.UploadStarted", success); |
| 572 } |
| 573 } |
| 574 } |
| 575 } |
| 576 |
| 546 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { | 577 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { |
| 547 DCHECK_EQ(state_, MATCHING_PHASE); | 578 DCHECK_EQ(state_, MATCHING_PHASE); |
| 548 // For scoring of candidate login data: | 579 // For scoring of candidate login data: |
| 549 // The most important element that should match is the origin, followed by | 580 // The most important element that should match is the origin, followed by |
| 550 // the action, the password name, the submit button name, and finally the | 581 // the action, the password name, the submit button name, and finally the |
| 551 // username input field name. | 582 // username input field name. |
| 552 // Exact origin match gives an addition of 64 (1 << 6) + # of matching url | 583 // Exact origin match gives an addition of 64 (1 << 6) + # of matching url |
| 553 // dirs. | 584 // dirs. |
| 554 // Partial match gives an addition of 32 (1 << 5) + # matching url dirs | 585 // Partial match gives an addition of 32 (1 << 5) + # matching url dirs |
| 555 // That way, a partial match cannot trump an exact match even if | 586 // That way, a partial match cannot trump an exact match even if |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 633 |
| 603 void PasswordFormManager::SubmitFailed() { | 634 void PasswordFormManager::SubmitFailed() { |
| 604 submit_result_ = kSubmitResultFailed; | 635 submit_result_ = kSubmitResultFailed; |
| 605 } | 636 } |
| 606 | 637 |
| 607 void PasswordFormManager::SendNotBlacklistedToRenderer() { | 638 void PasswordFormManager::SendNotBlacklistedToRenderer() { |
| 608 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); | 639 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); |
| 609 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), | 640 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), |
| 610 observed_form_)); | 641 observed_form_)); |
| 611 } | 642 } |
| OLD | NEW |