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

Unified 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: Nits 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/content/renderer/password_autofill_agent.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/content/renderer/password_autofill_agent.cc
diff --git a/components/autofill/content/renderer/password_autofill_agent.cc b/components/autofill/content/renderer/password_autofill_agent.cc
index 034ec424e217c1eef3224a1517f957713f62cebd..02770f56bf1a750b2e38522881e75a62750f75ee 100644
--- a/components/autofill/content/renderer/password_autofill_agent.cc
+++ b/components/autofill/content/renderer/password_autofill_agent.cc
@@ -189,10 +189,15 @@ PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view)
: content::RenderViewObserver(render_view),
usernames_usage_(NOTHING_TO_AUTOFILL),
web_view_(render_view->GetWebView()),
+ gesture_handler_(new AutofillWebUserGestureHandler(this)),
+ user_gesture_occurred_(false),
weak_ptr_factory_(this) {
+ blink::WebUserGestureIndicator::setHandler(gesture_handler_.get());
}
PasswordAutofillAgent::~PasswordAutofillAgent() {
+ DCHECK(gesture_handler_.get());
+ blink::WebUserGestureIndicator::setHandler(NULL);
}
bool PasswordAutofillAgent::TextFieldDidEndEditing(
@@ -492,6 +497,11 @@ void PasswordAutofillAgent::DidStartProvisionalLoad(blink::WebFrame* frame) {
}
// Clear the whole map during main frame navigation.
provisionally_saved_forms_.clear();
+
+ // We are navigating, se we need to wait for a new user gesture before
+ // filling in passwords.
+ user_gesture_occurred_ = false;
+ gesture_handler_->clearElements();
}
}
@@ -728,7 +738,16 @@ bool PasswordAutofillAgent::FillUserNameAndPassword(
return false;
}
- password_element->setValue(password);
+ // If a user gesture has not occurred, we setup a handler to listen for the
+ // next user gesture, at which point we then fill in the password. This is to
+ // make sure that we do not fill in the DOM with a password until we believe
+ // the user is intentionally interacting with the page.
+ if (!user_gesture_occurred_) {
+ gesture_handler_->addElement(*password_element);
+ password_element->setSuggestedValue(password);
+ } else {
+ password_element->setValue(password);
+ }
SetElementAutofilled(password_element, true);
return true;
}
@@ -801,4 +820,23 @@ bool PasswordAutofillAgent::FindLoginInfo(const blink::WebNode& node,
return true;
}
+void PasswordAutofillAgent::AutofillWebUserGestureHandler::onGesture() {
+ agent_->set_user_gesture_occurred(true);
+
+ std::vector<blink::WebInputElement>::iterator iter;
+ for (iter = elements_.begin(); iter != elements_.end(); ++iter) {
+ if (!iter->isNull() && !iter->suggestedValue().isNull())
+ iter->setValue(iter->suggestedValue());
+ }
+
+ elements_.clear();
+}
+
+PasswordAutofillAgent::AutofillWebUserGestureHandler::
+ AutofillWebUserGestureHandler(PasswordAutofillAgent* agent)
+ : agent_(agent) {}
+
+PasswordAutofillAgent::AutofillWebUserGestureHandler::
+ ~AutofillWebUserGestureHandler() {}
+
} // namespace autofill
« no previous file with comments | « components/autofill/content/renderer/password_autofill_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698