| 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 "components/autofill/renderer/password_autofill_agent.h" | 5 #include "components/autofill/renderer/password_autofill_agent.h" |
| 6 | 6 |
| 7 #include <vector> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 11 #include "components/autofill/common/autofill_messages.h" | 13 #include "components/autofill/common/autofill_messages.h" |
| 12 #include "components/autofill/common/form_field_data.h" | 14 #include "components/autofill/common/form_field_data.h" |
| 13 #include "components/autofill/common/password_form_fill_data.h" | 15 #include "components/autofill/common/password_form_fill_data.h" |
| 14 #include "components/autofill/renderer/form_autofill_util.h" | 16 #include "components/autofill/renderer/form_autofill_util.h" |
| 15 #include "content/public/common/password_form.h" | 17 #include "content/public/common/password_form.h" |
| 16 #include "content/public/renderer/password_form_conversion_utils.h" | 18 #include "content/public/renderer/password_form_conversion_utils.h" |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 form_data)); | 481 form_data)); |
| 480 } | 482 } |
| 481 } | 483 } |
| 482 | 484 |
| 483 //////////////////////////////////////////////////////////////////////////////// | 485 //////////////////////////////////////////////////////////////////////////////// |
| 484 // PasswordAutofillAgent, private: | 486 // PasswordAutofillAgent, private: |
| 485 | 487 |
| 486 void PasswordAutofillAgent::GetSuggestions( | 488 void PasswordAutofillAgent::GetSuggestions( |
| 487 const PasswordFormFillData& fill_data, | 489 const PasswordFormFillData& fill_data, |
| 488 const base::string16& input, | 490 const base::string16& input, |
| 489 std::vector<base::string16>* suggestions) { | 491 std::vector<base::string16>* suggestions, |
| 490 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) | 492 std::vector<base::string16>* realms) { |
| 493 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) { |
| 491 suggestions->push_back(fill_data.basic_data.fields[0].value); | 494 suggestions->push_back(fill_data.basic_data.fields[0].value); |
| 495 realms->push_back(fill_data.preferred_realm); |
| 496 } |
| 492 | 497 |
| 493 for (PasswordFormFillData::LoginCollection::const_iterator iter = | 498 for (PasswordFormFillData::LoginCollection::const_iterator iter = |
| 494 fill_data.additional_logins.begin(); | 499 fill_data.additional_logins_realms.begin(); |
| 495 iter != fill_data.additional_logins.end(); ++iter) { | 500 iter != fill_data.additional_logins_realms.end(); ++iter) { |
| 496 if (StartsWith(iter->first, input, false)) | 501 if (StartsWith(iter->first, input, false)) { |
| 497 suggestions->push_back(iter->first); | 502 suggestions->push_back(iter->first); |
| 503 realms->push_back(iter->second); |
| 504 } |
| 498 } | 505 } |
| 499 | 506 |
| 500 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = | 507 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = |
| 501 fill_data.other_possible_usernames.begin(); | 508 fill_data.other_possible_usernames.begin(); |
| 502 iter != fill_data.other_possible_usernames.end(); ++iter) { | 509 iter != fill_data.other_possible_usernames.end(); ++iter) { |
| 503 for (size_t i = 0; i < iter->second.size(); ++i) { | 510 for (size_t i = 0; i < iter->second.size(); ++i) { |
| 504 if (StartsWith(iter->second[i], input, false)) { | 511 if (StartsWith(iter->second[i], input, false)) { |
| 505 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN; | 512 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN; |
| 506 suggestions->push_back(iter->second[i]); | 513 suggestions->push_back(iter->second[i]); |
| 507 } | 514 } |
| 508 } | 515 } |
| 509 } | 516 } |
| 510 } | 517 } |
| 511 | 518 |
| 512 bool PasswordAutofillAgent::ShowSuggestionPopup( | 519 bool PasswordAutofillAgent::ShowSuggestionPopup( |
| 513 const PasswordFormFillData& fill_data, | 520 const PasswordFormFillData& fill_data, |
| 514 const WebKit::WebInputElement& user_input) { | 521 const WebKit::WebInputElement& user_input) { |
| 515 WebKit::WebFrame* frame = user_input.document().frame(); | 522 WebKit::WebFrame* frame = user_input.document().frame(); |
| 516 if (!frame) | 523 if (!frame) |
| 517 return false; | 524 return false; |
| 518 | 525 |
| 519 WebKit::WebView* webview = frame->view(); | 526 WebKit::WebView* webview = frame->view(); |
| 520 if (!webview) | 527 if (!webview) |
| 521 return false; | 528 return false; |
| 522 | 529 |
| 523 std::vector<base::string16> suggestions; | 530 std::vector<base::string16> suggestions; |
| 524 GetSuggestions(fill_data, user_input.value(), &suggestions); | 531 std::vector<base::string16> suggestions_realms; |
| 532 GetSuggestions(fill_data, |
| 533 user_input.value(), |
| 534 &suggestions, |
| 535 &suggestions_realms); |
| 525 | 536 |
| 526 if (disable_popup_) { | 537 if (disable_popup_) { |
| 527 FormData form; | 538 FormData form; |
| 528 FormFieldData field; | 539 FormFieldData field; |
| 529 FindFormAndFieldForInputElement( | 540 FindFormAndFieldForInputElement( |
| 530 user_input, &form, &field, REQUIRE_NONE); | 541 user_input, &form, &field, REQUIRE_NONE); |
| 531 | 542 |
| 532 WebKit::WebInputElement selected_element = user_input; | 543 WebKit::WebInputElement selected_element = user_input; |
| 533 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); | 544 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); |
| 534 | 545 |
| 535 float scale = web_view_->pageScaleFactor(); | 546 float scale = web_view_->pageScaleFactor(); |
| 536 gfx::RectF bounding_box_scaled(bounding_box.x() * scale, | 547 gfx::RectF bounding_box_scaled(bounding_box.x() * scale, |
| 537 bounding_box.y() * scale, | 548 bounding_box.y() * scale, |
| 538 bounding_box.width() * scale, | 549 bounding_box.width() * scale, |
| 539 bounding_box.height() * scale); | 550 bounding_box.height() * scale); |
| 540 Send(new AutofillHostMsg_ShowPasswordSuggestions(routing_id(), | 551 Send(new AutofillHostMsg_ShowPasswordSuggestions(routing_id(), |
| 541 field, | 552 field, |
| 542 bounding_box_scaled, | 553 bounding_box_scaled, |
| 543 suggestions)); | 554 suggestions, |
| 555 suggestions_realms)); |
| 544 return !suggestions.empty(); | 556 return !suggestions.empty(); |
| 545 } | 557 } |
| 546 | 558 |
| 547 | 559 |
| 548 if (suggestions.empty()) { | 560 if (suggestions.empty()) { |
| 549 webview->hidePopups(); | 561 webview->hidePopups(); |
| 550 return false; | 562 return false; |
| 551 } | 563 } |
| 552 | 564 |
| 553 std::vector<base::string16> labels(suggestions.size()); | 565 std::vector<base::string16> labels(suggestions.size()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 571 base::string16 password; | 583 base::string16 password; |
| 572 | 584 |
| 573 // Look for any suitable matches to current field text. | 585 // Look for any suitable matches to current field text. |
| 574 if (DoUsernamesMatch(fill_data.basic_data.fields[0].value, current_username, | 586 if (DoUsernamesMatch(fill_data.basic_data.fields[0].value, current_username, |
| 575 exact_username_match)) { | 587 exact_username_match)) { |
| 576 username = fill_data.basic_data.fields[0].value; | 588 username = fill_data.basic_data.fields[0].value; |
| 577 password = fill_data.basic_data.fields[1].value; | 589 password = fill_data.basic_data.fields[1].value; |
| 578 } else { | 590 } else { |
| 579 // Scan additional logins for a match. | 591 // Scan additional logins for a match. |
| 580 PasswordFormFillData::LoginCollection::const_iterator iter; | 592 PasswordFormFillData::LoginCollection::const_iterator iter; |
| 581 for (iter = fill_data.additional_logins.begin(); | 593 for (iter = fill_data.additional_logins_passwords.begin(); |
| 582 iter != fill_data.additional_logins.end(); ++iter) { | 594 iter != fill_data.additional_logins_passwords.end(); ++iter) { |
| 583 if (DoUsernamesMatch(iter->first, current_username, | 595 if (DoUsernamesMatch(iter->first, current_username, |
| 584 exact_username_match)) { | 596 exact_username_match)) { |
| 585 username = iter->first; | 597 username = iter->first; |
| 586 password = iter->second; | 598 password = iter->second; |
| 587 break; | 599 break; |
| 588 } | 600 } |
| 589 } | 601 } |
| 590 | 602 |
| 591 // Check possible usernames. | 603 // Check possible usernames. |
| 592 if (username.empty() && password.empty()) { | 604 if (username.empty() && password.empty()) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 689 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
| 678 if (iter == login_to_password_info_.end()) | 690 if (iter == login_to_password_info_.end()) |
| 679 return false; | 691 return false; |
| 680 | 692 |
| 681 *found_input = input; | 693 *found_input = input; |
| 682 *found_password = iter->second; | 694 *found_password = iter->second; |
| 683 return true; | 695 return true; |
| 684 } | 696 } |
| 685 | 697 |
| 686 } // namespace autofill | 698 } // namespace autofill |
| OLD | NEW |