| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/content/renderer/password_autofill_agent.h" | 5 #include "components/autofill/content/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/content/renderer/form_autofill_util.h" | 16 #include "components/autofill/content/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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 form_data)); | 488 form_data)); |
| 487 } | 489 } |
| 488 } | 490 } |
| 489 | 491 |
| 490 //////////////////////////////////////////////////////////////////////////////// | 492 //////////////////////////////////////////////////////////////////////////////// |
| 491 // PasswordAutofillAgent, private: | 493 // PasswordAutofillAgent, private: |
| 492 | 494 |
| 493 void PasswordAutofillAgent::GetSuggestions( | 495 void PasswordAutofillAgent::GetSuggestions( |
| 494 const PasswordFormFillData& fill_data, | 496 const PasswordFormFillData& fill_data, |
| 495 const base::string16& input, | 497 const base::string16& input, |
| 496 std::vector<base::string16>* suggestions) { | 498 std::vector<base::string16>* suggestions, |
| 497 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) | 499 std::vector<base::string16>* realms) { |
| 500 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) { |
| 498 suggestions->push_back(fill_data.basic_data.fields[0].value); | 501 suggestions->push_back(fill_data.basic_data.fields[0].value); |
| 502 realms->push_back(fill_data.preferred_realm); |
| 503 } |
| 499 | 504 |
| 500 for (PasswordFormFillData::LoginCollection::const_iterator iter = | 505 for (PasswordFormFillData::LoginCollection::const_iterator iter = |
| 501 fill_data.additional_logins.begin(); | 506 fill_data.additional_logins.begin(); |
| 502 iter != fill_data.additional_logins.end(); ++iter) { | 507 iter != fill_data.additional_logins.end(); ++iter) { |
| 503 if (StartsWith(iter->first, input, false)) | 508 if (StartsWith(iter->first, input, false)) { |
| 504 suggestions->push_back(iter->first); | 509 suggestions->push_back(iter->first); |
| 510 realms->push_back(iter->second.realm); |
| 511 } |
| 505 } | 512 } |
| 506 | 513 |
| 507 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = | 514 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = |
| 508 fill_data.other_possible_usernames.begin(); | 515 fill_data.other_possible_usernames.begin(); |
| 509 iter != fill_data.other_possible_usernames.end(); ++iter) { | 516 iter != fill_data.other_possible_usernames.end(); ++iter) { |
| 510 for (size_t i = 0; i < iter->second.size(); ++i) { | 517 for (size_t i = 0; i < iter->second.size(); ++i) { |
| 511 if (StartsWith(iter->second[i], input, false)) { | 518 if (StartsWith(iter->second[i], input, false)) { |
| 512 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN; | 519 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN; |
| 513 suggestions->push_back(iter->second[i]); | 520 suggestions->push_back(iter->second[i]); |
| 514 } | 521 } |
| 515 } | 522 } |
| 516 } | 523 } |
| 517 } | 524 } |
| 518 | 525 |
| 519 bool PasswordAutofillAgent::ShowSuggestionPopup( | 526 bool PasswordAutofillAgent::ShowSuggestionPopup( |
| 520 const PasswordFormFillData& fill_data, | 527 const PasswordFormFillData& fill_data, |
| 521 const WebKit::WebInputElement& user_input) { | 528 const WebKit::WebInputElement& user_input) { |
| 522 WebKit::WebFrame* frame = user_input.document().frame(); | 529 WebKit::WebFrame* frame = user_input.document().frame(); |
| 523 if (!frame) | 530 if (!frame) |
| 524 return false; | 531 return false; |
| 525 | 532 |
| 526 WebKit::WebView* webview = frame->view(); | 533 WebKit::WebView* webview = frame->view(); |
| 527 if (!webview) | 534 if (!webview) |
| 528 return false; | 535 return false; |
| 529 | 536 |
| 530 std::vector<base::string16> suggestions; | 537 std::vector<base::string16> suggestions; |
| 531 GetSuggestions(fill_data, user_input.value(), &suggestions); | 538 std::vector<base::string16> suggestions_realms; |
| 539 GetSuggestions(fill_data, |
| 540 user_input.value(), |
| 541 &suggestions, |
| 542 &suggestions_realms); |
| 532 | 543 |
| 533 if (disable_popup_) { | 544 if (disable_popup_) { |
| 534 FormData form; | 545 FormData form; |
| 535 FormFieldData field; | 546 FormFieldData field; |
| 536 FindFormAndFieldForInputElement( | 547 FindFormAndFieldForInputElement( |
| 537 user_input, &form, &field, REQUIRE_NONE); | 548 user_input, &form, &field, REQUIRE_NONE); |
| 538 | 549 |
| 539 WebKit::WebInputElement selected_element = user_input; | 550 WebKit::WebInputElement selected_element = user_input; |
| 540 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); | 551 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); |
| 541 | 552 |
| 542 float scale = web_view_->pageScaleFactor(); | 553 float scale = web_view_->pageScaleFactor(); |
| 543 gfx::RectF bounding_box_scaled(bounding_box.x() * scale, | 554 gfx::RectF bounding_box_scaled(bounding_box.x() * scale, |
| 544 bounding_box.y() * scale, | 555 bounding_box.y() * scale, |
| 545 bounding_box.width() * scale, | 556 bounding_box.width() * scale, |
| 546 bounding_box.height() * scale); | 557 bounding_box.height() * scale); |
| 547 Send(new AutofillHostMsg_ShowPasswordSuggestions(routing_id(), | 558 Send(new AutofillHostMsg_ShowPasswordSuggestions(routing_id(), |
| 548 field, | 559 field, |
| 549 bounding_box_scaled, | 560 bounding_box_scaled, |
| 550 suggestions)); | 561 suggestions, |
| 562 suggestions_realms)); |
| 551 return !suggestions.empty(); | 563 return !suggestions.empty(); |
| 552 } | 564 } |
| 553 | 565 |
| 554 | 566 |
| 555 if (suggestions.empty()) { | 567 if (suggestions.empty()) { |
| 556 webview->hidePopups(); | 568 webview->hidePopups(); |
| 557 return false; | 569 return false; |
| 558 } | 570 } |
| 559 | 571 |
| 560 std::vector<base::string16> labels(suggestions.size()); | 572 std::vector<base::string16> labels(suggestions.size()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 583 username = fill_data.basic_data.fields[0].value; | 595 username = fill_data.basic_data.fields[0].value; |
| 584 password = fill_data.basic_data.fields[1].value; | 596 password = fill_data.basic_data.fields[1].value; |
| 585 } else { | 597 } else { |
| 586 // Scan additional logins for a match. | 598 // Scan additional logins for a match. |
| 587 PasswordFormFillData::LoginCollection::const_iterator iter; | 599 PasswordFormFillData::LoginCollection::const_iterator iter; |
| 588 for (iter = fill_data.additional_logins.begin(); | 600 for (iter = fill_data.additional_logins.begin(); |
| 589 iter != fill_data.additional_logins.end(); ++iter) { | 601 iter != fill_data.additional_logins.end(); ++iter) { |
| 590 if (DoUsernamesMatch(iter->first, current_username, | 602 if (DoUsernamesMatch(iter->first, current_username, |
| 591 exact_username_match)) { | 603 exact_username_match)) { |
| 592 username = iter->first; | 604 username = iter->first; |
| 593 password = iter->second; | 605 password = iter->second.password; |
| 594 break; | 606 break; |
| 595 } | 607 } |
| 596 } | 608 } |
| 597 | 609 |
| 598 // Check possible usernames. | 610 // Check possible usernames. |
| 599 if (username.empty() && password.empty()) { | 611 if (username.empty() && password.empty()) { |
| 600 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = | 612 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = |
| 601 fill_data.other_possible_usernames.begin(); | 613 fill_data.other_possible_usernames.begin(); |
| 602 iter != fill_data.other_possible_usernames.end(); ++iter) { | 614 iter != fill_data.other_possible_usernames.end(); ++iter) { |
| 603 for (size_t i = 0; i < iter->second.size(); ++i) { | 615 for (size_t i = 0; i < iter->second.size(); ++i) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 696 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
| 685 if (iter == login_to_password_info_.end()) | 697 if (iter == login_to_password_info_.end()) |
| 686 return false; | 698 return false; |
| 687 | 699 |
| 688 *found_input = input; | 700 *found_input = input; |
| 689 *found_password = iter->second; | 701 *found_password = iter->second; |
| 690 return true; | 702 return true; |
| 691 } | 703 } |
| 692 | 704 |
| 693 } // namespace autofill | 705 } // namespace autofill |
| OLD | NEW |