| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 was_user_gesture_seen_ = false; | 617 was_user_gesture_seen_ = false; |
| 618 elements_.clear(); | 618 elements_.clear(); |
| 619 } | 619 } |
| 620 | 620 |
| 621 void PasswordAutofillAgent::PasswordValueGatekeeper::ShowValue( | 621 void PasswordAutofillAgent::PasswordValueGatekeeper::ShowValue( |
| 622 blink::WebInputElement* element) { | 622 blink::WebInputElement* element) { |
| 623 if (!element->isNull() && !element->suggestedValue().isEmpty()) | 623 if (!element->isNull() && !element->suggestedValue().isEmpty()) |
| 624 element->setValue(element->suggestedValue(), true); | 624 element->setValue(element->suggestedValue(), true); |
| 625 } | 625 } |
| 626 | 626 |
| 627 bool PasswordAutofillAgent::TextFieldDidEndEditing( | |
| 628 const blink::WebInputElement& element) { | |
| 629 WebInputToPasswordInfoMap::const_iterator iter = | |
| 630 web_input_to_password_info_.find(element); | |
| 631 if (iter == web_input_to_password_info_.end()) | |
| 632 return false; | |
| 633 | |
| 634 const PasswordInfo& password_info = iter->second; | |
| 635 // Don't let autofill overwrite an explicit change made by the user. | |
| 636 if (password_info.password_was_edited_last) | |
| 637 return false; | |
| 638 | |
| 639 const PasswordFormFillData& fill_data = password_info.fill_data; | |
| 640 | |
| 641 // If wait_for_username is false, we should have filled when the text changed. | |
| 642 if (!fill_data.wait_for_username) | |
| 643 return false; | |
| 644 | |
| 645 blink::WebInputElement password = password_info.password_field; | |
| 646 if (!IsElementEditable(password)) | |
| 647 return false; | |
| 648 | |
| 649 blink::WebInputElement username = element; // We need a non-const. | |
| 650 | |
| 651 // Do not set selection when ending an editing session, otherwise it can | |
| 652 // mess with focus. | |
| 653 FillUserNameAndPassword(&username, &password, fill_data, true, false, | |
| 654 &field_value_and_properties_map_, | |
| 655 base::Bind(&PasswordValueGatekeeper::RegisterElement, | |
| 656 base::Unretained(&gatekeeper_)), | |
| 657 nullptr); | |
| 658 return true; | |
| 659 } | |
| 660 | |
| 661 bool PasswordAutofillAgent::TextDidChangeInTextField( | 627 bool PasswordAutofillAgent::TextDidChangeInTextField( |
| 662 const blink::WebInputElement& element) { | 628 const blink::WebInputElement& element) { |
| 663 // TODO(vabr): Get a mutable argument instead. http://crbug.com/397083 | 629 // TODO(vabr): Get a mutable argument instead. http://crbug.com/397083 |
| 664 blink::WebInputElement mutable_element = element; // We need a non-const. | 630 blink::WebInputElement mutable_element = element; // We need a non-const. |
| 665 mutable_element.setAutofilled(false); | 631 mutable_element.setAutofilled(false); |
| 666 | 632 |
| 667 WebInputToPasswordInfoMap::iterator iter = | 633 WebInputToPasswordInfoMap::iterator iter = |
| 668 web_input_to_password_info_.find(element); | 634 web_input_to_password_info_.find(element); |
| 669 if (iter != web_input_to_password_info_.end()) { | 635 if (iter != web_input_to_password_info_.end()) { |
| 670 iter->second.password_was_edited_last = false; | 636 iter->second.password_was_edited_last = false; |
| 671 // If wait_for_username is true we will fill when the username loses focus. | |
| 672 if (iter->second.fill_data.wait_for_username) | |
| 673 return false; | |
| 674 } | 637 } |
| 675 | 638 |
| 676 // Show the popup with the list of available usernames. | 639 // Show the popup with the list of available usernames. |
| 677 return ShowSuggestions(element, false, false); | 640 return ShowSuggestions(element, false, false); |
| 678 } | 641 } |
| 679 | 642 |
| 680 void PasswordAutofillAgent::UpdateStateForTextChange( | 643 void PasswordAutofillAgent::UpdateStateForTextChange( |
| 681 const blink::WebInputElement& element) { | 644 const blink::WebInputElement& element) { |
| 682 // TODO(vabr): Get a mutable argument instead. http://crbug.com/397083 | 645 // TODO(vabr): Get a mutable argument instead. http://crbug.com/397083 |
| 683 blink::WebInputElement mutable_element = element; // We need a non-const. | 646 blink::WebInputElement mutable_element = element; // We need a non-const. |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 !(provisionally_saved_form_->password_value.empty() && | 1493 !(provisionally_saved_form_->password_value.empty() && |
| 1531 provisionally_saved_form_->new_password_value.empty()); | 1494 provisionally_saved_form_->new_password_value.empty()); |
| 1532 } | 1495 } |
| 1533 | 1496 |
| 1534 const mojom::AutofillDriverPtr& PasswordAutofillAgent::GetAutofillDriver() { | 1497 const mojom::AutofillDriverPtr& PasswordAutofillAgent::GetAutofillDriver() { |
| 1535 DCHECK(autofill_agent_); | 1498 DCHECK(autofill_agent_); |
| 1536 return autofill_agent_->GetAutofillDriver(); | 1499 return autofill_agent_->GetAutofillDriver(); |
| 1537 } | 1500 } |
| 1538 | 1501 |
| 1539 } // namespace autofill | 1502 } // namespace autofill |
| OLD | NEW |