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