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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 } // namespace | 183 } // namespace |
184 | 184 |
185 //////////////////////////////////////////////////////////////////////////////// | 185 //////////////////////////////////////////////////////////////////////////////// |
186 // PasswordAutofillAgent, public: | 186 // PasswordAutofillAgent, public: |
187 | 187 |
188 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view) | 188 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view) |
189 : content::RenderViewObserver(render_view), | 189 : content::RenderViewObserver(render_view), |
190 usernames_usage_(NOTHING_TO_AUTOFILL), | 190 usernames_usage_(NOTHING_TO_AUTOFILL), |
191 web_view_(render_view->GetWebView()), | 191 web_view_(render_view->GetWebView()), |
| 192 gesture_handler_(new AutofillWebUserGestureHandler(this)), |
| 193 user_gesture_occurred_(false), |
192 weak_ptr_factory_(this) { | 194 weak_ptr_factory_(this) { |
| 195 blink::WebUserGestureIndicator::setHandler(gesture_handler_.get()); |
193 } | 196 } |
194 | 197 |
195 PasswordAutofillAgent::~PasswordAutofillAgent() { | 198 PasswordAutofillAgent::~PasswordAutofillAgent() { |
| 199 DCHECK(gesture_handler_.get()); |
| 200 blink::WebUserGestureIndicator::setHandler(NULL); |
196 } | 201 } |
197 | 202 |
198 bool PasswordAutofillAgent::TextFieldDidEndEditing( | 203 bool PasswordAutofillAgent::TextFieldDidEndEditing( |
199 const blink::WebInputElement& element) { | 204 const blink::WebInputElement& element) { |
200 LoginToPasswordInfoMap::const_iterator iter = | 205 LoginToPasswordInfoMap::const_iterator iter = |
201 login_to_password_info_.find(element); | 206 login_to_password_info_.find(element); |
202 if (iter == login_to_password_info_.end()) | 207 if (iter == login_to_password_info_.end()) |
203 return false; | 208 return false; |
204 | 209 |
205 const PasswordFormFillData& fill_data = | 210 const PasswordFormFillData& fill_data = |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 blink::WebFrame* form_frame = CurrentOrChildFrameWithSavedForms(frame); | 490 blink::WebFrame* form_frame = CurrentOrChildFrameWithSavedForms(frame); |
486 if (!blink::WebUserGestureIndicator::isProcessingUserGesture() && | 491 if (!blink::WebUserGestureIndicator::isProcessingUserGesture() && |
487 provisionally_saved_forms_[form_frame].get()) { | 492 provisionally_saved_forms_[form_frame].get()) { |
488 Send(new AutofillHostMsg_PasswordFormSubmitted( | 493 Send(new AutofillHostMsg_PasswordFormSubmitted( |
489 routing_id(), | 494 routing_id(), |
490 *provisionally_saved_forms_[form_frame])); | 495 *provisionally_saved_forms_[form_frame])); |
491 provisionally_saved_forms_.erase(form_frame); | 496 provisionally_saved_forms_.erase(form_frame); |
492 } | 497 } |
493 // Clear the whole map during main frame navigation. | 498 // Clear the whole map during main frame navigation. |
494 provisionally_saved_forms_.clear(); | 499 provisionally_saved_forms_.clear(); |
| 500 |
| 501 // We are navigating, se we need to wait for a new user gesture before |
| 502 // filling in passwords. |
| 503 user_gesture_occurred_ = false; |
| 504 gesture_handler_->clearElements(); |
495 } | 505 } |
496 } | 506 } |
497 | 507 |
498 void PasswordAutofillAgent::OnFillPasswordForm( | 508 void PasswordAutofillAgent::OnFillPasswordForm( |
499 const PasswordFormFillData& form_data) { | 509 const PasswordFormFillData& form_data) { |
500 if (usernames_usage_ == NOTHING_TO_AUTOFILL) { | 510 if (usernames_usage_ == NOTHING_TO_AUTOFILL) { |
501 if (form_data.other_possible_usernames.size()) | 511 if (form_data.other_possible_usernames.size()) |
502 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_PRESENT; | 512 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_PRESENT; |
503 else if (usernames_usage_ == NOTHING_TO_AUTOFILL) | 513 else if (usernames_usage_ == NOTHING_TO_AUTOFILL) |
504 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_ABSENT; | 514 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_ABSENT; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 if (set_selection) { | 731 if (set_selection) { |
722 username_element->setSelectionRange(current_username.length(), | 732 username_element->setSelectionRange(current_username.length(), |
723 username.length()); | 733 username.length()); |
724 } | 734 } |
725 } else if (current_username != username) { | 735 } else if (current_username != username) { |
726 // If the username can't be filled and it doesn't match a saved password | 736 // If the username can't be filled and it doesn't match a saved password |
727 // as is, don't autofill a password. | 737 // as is, don't autofill a password. |
728 return false; | 738 return false; |
729 } | 739 } |
730 | 740 |
731 password_element->setValue(password); | 741 // If a user gesture has not occurred, we setup a handler to listen for the |
| 742 // next user gesture, at which point we then fill in the password. This is to |
| 743 // make sure that we do not fill in the DOM with a password until we believe |
| 744 // the user is intentionally interacting with the page. |
| 745 if (!user_gesture_occurred_) { |
| 746 gesture_handler_->addElement(*password_element); |
| 747 password_element->setSuggestedValue(password); |
| 748 } else { |
| 749 password_element->setValue(password); |
| 750 } |
732 SetElementAutofilled(password_element, true); | 751 SetElementAutofilled(password_element, true); |
733 return true; | 752 return true; |
734 } | 753 } |
735 | 754 |
736 void PasswordAutofillAgent::PerformInlineAutocomplete( | 755 void PasswordAutofillAgent::PerformInlineAutocomplete( |
737 const blink::WebInputElement& username_input, | 756 const blink::WebInputElement& username_input, |
738 const blink::WebInputElement& password_input, | 757 const blink::WebInputElement& password_input, |
739 const PasswordFormFillData& fill_data) { | 758 const PasswordFormFillData& fill_data) { |
740 DCHECK(!fill_data.wait_for_username); | 759 DCHECK(!fill_data.wait_for_username); |
741 | 760 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 blink::WebInputElement input = element.to<blink::WebInputElement>(); | 813 blink::WebInputElement input = element.to<blink::WebInputElement>(); |
795 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 814 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
796 if (iter == login_to_password_info_.end()) | 815 if (iter == login_to_password_info_.end()) |
797 return false; | 816 return false; |
798 | 817 |
799 *found_input = input; | 818 *found_input = input; |
800 *found_password = iter->second; | 819 *found_password = iter->second; |
801 return true; | 820 return true; |
802 } | 821 } |
803 | 822 |
| 823 void PasswordAutofillAgent::AutofillWebUserGestureHandler::onGesture() { |
| 824 agent_->set_user_gesture_occurred(true); |
| 825 |
| 826 std::vector<blink::WebInputElement>::iterator iter; |
| 827 for (iter = elements_.begin(); iter != elements_.end(); ++iter) { |
| 828 if (!iter->isNull() && !iter->suggestedValue().isNull()) |
| 829 iter->setValue(iter->suggestedValue()); |
| 830 } |
| 831 |
| 832 elements_.clear(); |
| 833 } |
| 834 |
| 835 PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
| 836 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) |
| 837 : agent_(agent) {} |
| 838 |
| 839 PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
| 840 ~AutofillWebUserGestureHandler() {} |
| 841 |
804 } // namespace autofill | 842 } // namespace autofill |
OLD | NEW |