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

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: Bug fixes Created 7 years, 1 month 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
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..32837dbce9276ef4f94247f9f6cdd73c09f79cee 100644
--- a/components/autofill/content/renderer/password_autofill_agent.cc
+++ b/components/autofill/content/renderer/password_autofill_agent.cc
@@ -27,6 +27,7 @@
#include "third_party/WebKit/public/web/WebNodeList.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
+#include "third_party/WebKit/public/web/WebUserGestureToken.h"
Garrett Casto 2013/12/02 23:49:12 Is this leftover from a previous version? Doesn't
jww 2013/12/03 06:29:59 Done.
#include "third_party/WebKit/public/web/WebView.h"
#include "ui/events/keycodes/keyboard_codes.h"
@@ -189,10 +190,16 @@ PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view)
: content::RenderViewObserver(render_view),
usernames_usage_(NOTHING_TO_AUTOFILL),
web_view_(render_view->GetWebView()),
- weak_ptr_factory_(this) {
+ weak_ptr_factory_(this),
+ gestureHandler_(new AutofillWebUserGestureHandler(this)),
+ userGestureOccurred_(false) {
+ blink::WebUserGestureIndicator::setHandler(gestureHandler_);
}
PasswordAutofillAgent::~PasswordAutofillAgent() {
+ DCHECK(gestureHandler_);
+ blink::WebUserGestureIndicator::setHandler(0);
Garrett Casto 2013/12/02 23:49:12 use NULL for this instead of 0, since we are talki
jww 2013/12/03 06:29:59 Done.
+ delete gestureHandler_;
}
bool PasswordAutofillAgent::TextFieldDidEndEditing(
@@ -728,7 +735,16 @@ bool PasswordAutofillAgent::FillUserNameAndPassword(
return false;
}
- password_element->setValue(password);
+ // We do not autofill into the DOM until a user gesture has occurred to make
+ // sure that the user is intentionally interacting with page. So if there
+ // isn't a user gesture occuring right now, we setup a handler here to wait
+ // for such a gesture to occur.
Garrett Casto 2013/12/02 23:49:12 Shouldn't this be "If a user gesture hasn't occurr
jww 2013/12/03 06:29:59 Done.
+ if (!userGestureOccurred_) {
+ gestureHandler_->addElement(new blink::WebInputElement(*password_element));
Garrett Casto 2013/12/02 23:49:12 I think that we can just keep a copy of the WebInp
jww 2013/12/03 06:29:59 Done.
+ password_element->setSuggestedValue(password);
+ } else {
+ password_element->setValue(password);
+ }
SetElementAutofilled(password_element, true);
return true;
}
@@ -801,4 +817,33 @@ bool PasswordAutofillAgent::FindLoginInfo(const blink::WebNode& node,
return true;
}
+void PasswordAutofillAgent::AutofillWebUserGestureHandler::onGesture() {
Garrett Casto 2013/12/02 23:49:12 To be clear, this gets called whenever there is a
jww 2013/12/03 06:29:59 Yup!
+ agent_->setUserGestureOccurred(true);
+
+ std::vector<blink::WebInputElement*>::iterator iter;
+ for (iter = elements_.begin(); iter != elements_.end(); ++iter) {
+ if (!(*iter)->isNull() && !(*iter)->suggestedValue().isNull()) {
+ DCHECK(!(*iter)->suggestedValue().isNull());
Garrett Casto 2013/12/02 23:49:12 I don't think that there is much value to DCHECK o
jww 2013/12/03 06:29:59 Done.
+ (*iter)->setValue((*iter)->suggestedValue());
+ }
+ delete (*iter);
+ }
+
+ elements_.clear();
+}
+
+PasswordAutofillAgent::AutofillWebUserGestureHandler::
+ AutofillWebUserGestureHandler(PasswordAutofillAgent* agent)
+ : agent_(agent) {}
+
+PasswordAutofillAgent::AutofillWebUserGestureHandler::
+ ~AutofillWebUserGestureHandler() {
+ std::vector<blink::WebInputElement*>::iterator iter;
Garrett Casto 2013/12/02 23:49:12 I don't think that this should be necessary to kee
jww 2013/12/03 06:29:59 Oh, awesome!
+ for (iter = elements_.begin(); iter != elements_.end(); ++iter) {
+ delete (*iter);
+ }
+
+ elements_.clear();
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698