[Autofill] Send Autofill upload when active form loses focus.
This is in addition to uploading on submission events. We now distinguish the two, with TODOs to have separate metrics and a bit in the payload. I will address the TODOs in subsequent CLs to keep complexity low.
The idea is to upload votes for any entered data (albeit lower quality, which we will distinguish on the server side).
Note: I moved OnFormsSeen and OnFormSubmitted because they were out of order with the .h
BUG=555015
TEST=AutofillManagerTest,FormAutocompleteTest
Review URL: https://codereview.chromium.org/1494373003
Cr-Commit-Position: refs/heads/master@{#363795}
diff --git a/components/autofill/content/renderer/autofill_agent.cc b/components/autofill/content/renderer/autofill_agent.cc
index afb8274..5d00761e 100644
--- a/components/autofill/content/renderer/autofill_agent.cc
+++ b/components/autofill/content/renderer/autofill_agent.cc
@@ -259,11 +259,24 @@
void AutofillAgent::FocusedNodeChanged(const WebNode& node) {
HidePopup();
- if (node.isNull() || !node.isElementNode())
+ if (node.isNull() || !node.isElementNode()) {
+ if (!last_interacted_form_.isNull()) {
+ // Focus moved away from the last interacted form to somewhere else on
+ // the page.
+ Send(new AutofillHostMsg_FocusNoLongerOnForm(routing_id()));
+ }
return;
+ }
WebElement web_element = node.toConst<WebElement>();
const WebInputElement* element = toWebInputElement(&web_element);
+ if (!element || (!last_interacted_form_.isNull() &&
+ last_interacted_form_ != element->form())) {
+ // The focused element is not part of the last interacted form (could be
+ // in a different form).
+ Send(new AutofillHostMsg_FocusNoLongerOnForm(routing_id()));
+ return;
+ }
if (!element || !element->isEnabled() || element->isReadOnly() ||
!element->isTextField())
@@ -523,7 +536,7 @@
if (!element_.form().isNull())
last_interacted_form_ = element_.form();
- Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(),
+ Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), form,
base::TimeTicks::Now()));
}