Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: components/autofill/content/renderer/password_autofill_agent.cc

Issue 83023017: Basic autofill into password value on user gesture only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes from gcasto Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 gestureHandler_(new AutofillWebUserGestureHandler(this)),
193 user_gesture_occurred_(false),
192 weak_ptr_factory_(this) { 194 weak_ptr_factory_(this) {
195 blink::WebUserGestureIndicator::setHandler(gestureHandler_);
193 } 196 }
194 197
195 PasswordAutofillAgent::~PasswordAutofillAgent() { 198 PasswordAutofillAgent::~PasswordAutofillAgent() {
199 DCHECK(gestureHandler_);
200 blink::WebUserGestureIndicator::setHandler(NULL);
201 delete gestureHandler_;
196 } 202 }
197 203
198 bool PasswordAutofillAgent::TextFieldDidEndEditing( 204 bool PasswordAutofillAgent::TextFieldDidEndEditing(
199 const blink::WebInputElement& element) { 205 const blink::WebInputElement& element) {
200 LoginToPasswordInfoMap::const_iterator iter = 206 LoginToPasswordInfoMap::const_iterator iter =
201 login_to_password_info_.find(element); 207 login_to_password_info_.find(element);
202 if (iter == login_to_password_info_.end()) 208 if (iter == login_to_password_info_.end())
203 return false; 209 return false;
204 210
205 const PasswordFormFillData& fill_data = 211 const PasswordFormFillData& fill_data =
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 blink::WebFrame* form_frame = CurrentOrChildFrameWithSavedForms(frame); 491 blink::WebFrame* form_frame = CurrentOrChildFrameWithSavedForms(frame);
486 if (!blink::WebUserGestureIndicator::isProcessingUserGesture() && 492 if (!blink::WebUserGestureIndicator::isProcessingUserGesture() &&
487 provisionally_saved_forms_[form_frame].get()) { 493 provisionally_saved_forms_[form_frame].get()) {
488 Send(new AutofillHostMsg_PasswordFormSubmitted( 494 Send(new AutofillHostMsg_PasswordFormSubmitted(
489 routing_id(), 495 routing_id(),
490 *provisionally_saved_forms_[form_frame])); 496 *provisionally_saved_forms_[form_frame]));
491 provisionally_saved_forms_.erase(form_frame); 497 provisionally_saved_forms_.erase(form_frame);
492 } 498 }
493 // Clear the whole map during main frame navigation. 499 // Clear the whole map during main frame navigation.
494 provisionally_saved_forms_.clear(); 500 provisionally_saved_forms_.clear();
501
502 // We are navigating, se we need to wait for a new user gesture before
503 // filling in passwords.
504 user_gesture_occurred_ = false;
505 gestureHandler_->clearElements();
495 } 506 }
496 } 507 }
497 508
498 void PasswordAutofillAgent::OnFillPasswordForm( 509 void PasswordAutofillAgent::OnFillPasswordForm(
499 const PasswordFormFillData& form_data) { 510 const PasswordFormFillData& form_data) {
500 if (usernames_usage_ == NOTHING_TO_AUTOFILL) { 511 if (usernames_usage_ == NOTHING_TO_AUTOFILL) {
501 if (form_data.other_possible_usernames.size()) 512 if (form_data.other_possible_usernames.size())
502 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_PRESENT; 513 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_PRESENT;
503 else if (usernames_usage_ == NOTHING_TO_AUTOFILL) 514 else if (usernames_usage_ == NOTHING_TO_AUTOFILL)
504 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_ABSENT; 515 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_ABSENT;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 if (set_selection) { 732 if (set_selection) {
722 username_element->setSelectionRange(current_username.length(), 733 username_element->setSelectionRange(current_username.length(),
723 username.length()); 734 username.length());
724 } 735 }
725 } else if (current_username != username) { 736 } else if (current_username != username) {
726 // If the username can't be filled and it doesn't match a saved password 737 // If the username can't be filled and it doesn't match a saved password
727 // as is, don't autofill a password. 738 // as is, don't autofill a password.
728 return false; 739 return false;
729 } 740 }
730 741
731 password_element->setValue(password); 742 // If a user gesture has not occurred, we setup a handler to listen for the
743 // next user gesture, at which point we then fill in the password. This is to
744 // make sure that we do not fill in the DOM with a password until we believe
745 // the user is intentionally interacting with the page.
746 if (!user_gesture_occurred_) {
747 gestureHandler_->addElement(*password_element);
748 password_element->setSuggestedValue(password);
749 } else {
750 password_element->setValue(password);
751 }
732 SetElementAutofilled(password_element, true); 752 SetElementAutofilled(password_element, true);
733 return true; 753 return true;
734 } 754 }
735 755
736 void PasswordAutofillAgent::PerformInlineAutocomplete( 756 void PasswordAutofillAgent::PerformInlineAutocomplete(
737 const blink::WebInputElement& username_input, 757 const blink::WebInputElement& username_input,
738 const blink::WebInputElement& password_input, 758 const blink::WebInputElement& password_input,
739 const PasswordFormFillData& fill_data) { 759 const PasswordFormFillData& fill_data) {
740 DCHECK(!fill_data.wait_for_username); 760 DCHECK(!fill_data.wait_for_username);
741 761
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 blink::WebInputElement input = element.to<blink::WebInputElement>(); 814 blink::WebInputElement input = element.to<blink::WebInputElement>();
795 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); 815 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input);
796 if (iter == login_to_password_info_.end()) 816 if (iter == login_to_password_info_.end())
797 return false; 817 return false;
798 818
799 *found_input = input; 819 *found_input = input;
800 *found_password = iter->second; 820 *found_password = iter->second;
801 return true; 821 return true;
802 } 822 }
803 823
824 void PasswordAutofillAgent::AutofillWebUserGestureHandler::onGesture() {
825 agent_->set_user_gesture_occurred(true);
826
827 std::vector<blink::WebInputElement>::iterator iter;
828 for (iter = elements_.begin(); iter != elements_.end(); ++iter) {
829 if (!(*iter).isNull() && !(*iter).suggestedValue().isNull())
Garrett Casto 2013/12/04 00:25:31 "(*iter)." -> "iter->"
jww 2013/12/04 00:45:11 Done.
830 (*iter).setValue((*iter).suggestedValue());
831 }
832
833 elements_.clear();
834 }
835
836 PasswordAutofillAgent::AutofillWebUserGestureHandler::
837 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent)
838 : agent_(agent) {}
839
840 PasswordAutofillAgent::AutofillWebUserGestureHandler::
841 ~AutofillWebUserGestureHandler() {}
842
804 } // namespace autofill 843 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698