| 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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 password_forms)); | 374 password_forms)); |
| 375 } else { | 375 } else { |
| 376 Send(new AutofillHostMsg_PasswordFormsParsed(routing_id(), password_forms)); | 376 Send(new AutofillHostMsg_PasswordFormsParsed(routing_id(), password_forms)); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 | 379 |
| 380 bool PasswordAutofillAgent::OnMessageReceived(const IPC::Message& message) { | 380 bool PasswordAutofillAgent::OnMessageReceived(const IPC::Message& message) { |
| 381 bool handled = true; | 381 bool handled = true; |
| 382 IPC_BEGIN_MESSAGE_MAP(PasswordAutofillAgent, message) | 382 IPC_BEGIN_MESSAGE_MAP(PasswordAutofillAgent, message) |
| 383 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordForm, OnFillPasswordForm) | 383 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordForm, OnFillPasswordForm) |
| 384 IPC_MESSAGE_HANDLER(AutofillMsg_RemovePasswordSuggestion, |
| 385 OnRemovePasswordSuggestion) |
| 384 IPC_MESSAGE_UNHANDLED(handled = false) | 386 IPC_MESSAGE_UNHANDLED(handled = false) |
| 385 IPC_END_MESSAGE_MAP() | 387 IPC_END_MESSAGE_MAP() |
| 386 return handled; | 388 return handled; |
| 387 } | 389 } |
| 388 | 390 |
| 389 void PasswordAutofillAgent::DidStartLoading() { | 391 void PasswordAutofillAgent::DidStartLoading() { |
| 390 if (usernames_usage_ != NOTHING_TO_AUTOFILL) { | 392 if (usernames_usage_ != NOTHING_TO_AUTOFILL) { |
| 391 UMA_HISTOGRAM_ENUMERATION("PasswordManager.OtherPossibleUsernamesUsage", | 393 UMA_HISTOGRAM_ENUMERATION("PasswordManager.OtherPossibleUsernamesUsage", |
| 392 usernames_usage_, OTHER_POSSIBLE_USERNAMES_MAX); | 394 usernames_usage_, OTHER_POSSIBLE_USERNAMES_MAX); |
| 393 usernames_usage_ = NOTHING_TO_AUTOFILL; | 395 usernames_usage_ = NOTHING_TO_AUTOFILL; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 FormData form; | 550 FormData form; |
| 549 FormFieldData field; | 551 FormFieldData field; |
| 550 FindFormAndFieldForInputElement( | 552 FindFormAndFieldForInputElement( |
| 551 username_element, &form, &field, REQUIRE_NONE); | 553 username_element, &form, &field, REQUIRE_NONE); |
| 552 Send(new AutofillHostMsg_AddPasswordFormMapping( | 554 Send(new AutofillHostMsg_AddPasswordFormMapping( |
| 553 routing_id(), | 555 routing_id(), |
| 554 field, | 556 field, |
| 555 form_data)); | 557 form_data)); |
| 556 } | 558 } |
| 557 } | 559 } |
| 560 void PasswordAutofillAgent::OnRemovePasswordSuggestion( |
| 561 const PasswordForm& password_form) { |
| 562 |
| 563 std::vector<PasswordForm> updated_password_forms; |
| 564 |
| 565 LoginToPasswordInfoMap::iterator iter; |
| 566 for (iter = login_to_password_info_.begin(); |
| 567 iter != login_to_password_info_.end();) { |
| 568 scoped_ptr<PasswordForm> new_password_form( |
| 569 CreatePasswordForm(iter->second.password_field.form())); |
| 570 if (new_password_form.get()) { |
| 571 login_to_password_info_.erase(iter++); |
| 572 updated_password_forms.push_back(*new_password_form); |
| 573 } else { |
| 574 ++iter; |
| 575 } |
| 576 } |
| 577 |
| 578 Send(new AutofillHostMsg_RemovePasswordSuggestion( |
| 579 routing_id(), password_form, updated_password_forms)); |
| 580 } |
| 558 | 581 |
| 559 //////////////////////////////////////////////////////////////////////////////// | 582 //////////////////////////////////////////////////////////////////////////////// |
| 560 // PasswordAutofillAgent, private: | 583 // PasswordAutofillAgent, private: |
| 561 | 584 |
| 562 void PasswordAutofillAgent::GetSuggestions( | 585 void PasswordAutofillAgent::GetSuggestions( |
| 563 const PasswordFormFillData& fill_data, | 586 const PasswordFormFillData& fill_data, |
| 564 const base::string16& input, | 587 const base::string16& input, |
| 565 std::vector<base::string16>* suggestions, | 588 std::vector<base::string16>* suggestions, |
| 566 std::vector<base::string16>* realms) { | 589 std::vector<base::string16>* realms) { |
| 567 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) { | 590 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 std::vector<base::string16> suggestions; | 628 std::vector<base::string16> suggestions; |
| 606 std::vector<base::string16> realms; | 629 std::vector<base::string16> realms; |
| 607 GetSuggestions(fill_data, user_input.value(), &suggestions, &realms); | 630 GetSuggestions(fill_data, user_input.value(), &suggestions, &realms); |
| 608 DCHECK_EQ(suggestions.size(), realms.size()); | 631 DCHECK_EQ(suggestions.size(), realms.size()); |
| 609 | 632 |
| 610 FormData form; | 633 FormData form; |
| 611 FormFieldData field; | 634 FormFieldData field; |
| 612 FindFormAndFieldForInputElement( | 635 FindFormAndFieldForInputElement( |
| 613 user_input, &form, &field, REQUIRE_NONE); | 636 user_input, &form, &field, REQUIRE_NONE); |
| 614 | 637 |
| 638 scoped_ptr<PasswordForm> password_form = |
| 639 CreatePasswordForm(user_input.form()); |
| 640 DCHECK(password_form); |
| 641 |
| 615 blink::WebInputElement selected_element = user_input; | 642 blink::WebInputElement selected_element = user_input; |
| 616 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); | 643 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); |
| 617 | 644 |
| 618 float scale = web_view_->pageScaleFactor(); | 645 float scale = web_view_->pageScaleFactor(); |
| 619 gfx::RectF bounding_box_scaled(bounding_box.x() * scale, | 646 gfx::RectF bounding_box_scaled(bounding_box.x() * scale, |
| 620 bounding_box.y() * scale, | 647 bounding_box.y() * scale, |
| 621 bounding_box.width() * scale, | 648 bounding_box.width() * scale, |
| 622 bounding_box.height() * scale); | 649 bounding_box.height() * scale); |
| 623 Send(new AutofillHostMsg_ShowPasswordSuggestions(routing_id(), | 650 Send(new AutofillHostMsg_ShowPasswordSuggestions(routing_id(), |
| 624 field, | 651 field, |
| 652 *password_form, |
| 625 bounding_box_scaled, | 653 bounding_box_scaled, |
| 626 suggestions, | 654 suggestions, |
| 627 realms)); | 655 realms)); |
| 628 return !suggestions.empty(); | 656 return !suggestions.empty(); |
| 629 } | 657 } |
| 630 | 658 |
| 631 void PasswordAutofillAgent::FillFormOnPasswordRecieved( | 659 void PasswordAutofillAgent::FillFormOnPasswordRecieved( |
| 632 const PasswordFormFillData& fill_data, | 660 const PasswordFormFillData& fill_data, |
| 633 blink::WebInputElement username_element, | 661 blink::WebInputElement username_element, |
| 634 blink::WebInputElement password_element) { | 662 blink::WebInputElement password_element) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 } | 852 } |
| 825 | 853 |
| 826 PasswordAutofillAgent::AutofillWebUserGestureHandler:: | 854 PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
| 827 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) | 855 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) |
| 828 : agent_(agent) {} | 856 : agent_(agent) {} |
| 829 | 857 |
| 830 PasswordAutofillAgent::AutofillWebUserGestureHandler:: | 858 PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
| 831 ~AutofillWebUserGestureHandler() {} | 859 ~AutofillWebUserGestureHandler() {} |
| 832 | 860 |
| 833 } // namespace autofill | 861 } // namespace autofill |
| OLD | NEW |