Commit 10987379 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[WebView/WebLayer Autofill] Trigger form submission on navigation


Renderer-side autofill sometimes sends the browser a notification that
a form was *likely* submitted. WebView/WebLayer autofill currently
handles this case as follows:
- It records the fact that the event was received.
- If a new form is seen by the renderer while the current form is still
  active in the browser, it considers the current form as having been
  submitted and informs the Android Autofill framework.

This CL modifies this flow in order to support followup work that will
reset the current form on navigation. The logic is now as follows:
- When a navigation occurs, WV/WL Autofill's browser-side code checks
  whether (a) it has previously received a "form likely submitted" event
  from the renderer and (b) the current form has not subsequently been
  reset. If so, it considers the current form as having been submitted
  and informs the Android Autofill framework.

Without this change, the followup work that resets the current form on
navigation would break this flow entirely, as (naturally) a new form is
seen by the renderer only *after* a navigation occurs.

The practical impact of this change is that commit of a successful
autofill session will occur sooner: on the navigation resulting from
the successful submission rather than the next time that a form is seen
(which can be arbitrarily later). This seems like a good thing.

Bug: 1117563
Change-Id: I33dfa27b4bbf7e246e62273d3598eb0f30f1f722
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424144
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMichael Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809710}
parent 302f2133
...@@ -1238,12 +1238,13 @@ public class AwAutofillTest { ...@@ -1238,12 +1238,13 @@ public class AwAutofillTest {
} }
/** /**
* This test is verifying the session is still alive after navigation. * This test is verifying that a navigation occurring while there is a probably-submitted
* form will trigger commit of the current autofill session.
*/ */
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testSessionAliveAfterNavigation() throws Throwable { public void testNavigationAfterProbableSubmitResultsInSessionCommit() throws Throwable {
int cnt = 0; int cnt = 0;
final String data = "<!DOCTYPE html>" final String data = "<!DOCTYPE html>"
+ "<html>" + "<html>"
......
...@@ -337,25 +337,7 @@ void AutofillProviderAndroid::OnDidFillAutofillFormData( ...@@ -337,25 +337,7 @@ void AutofillProviderAndroid::OnDidFillAutofillFormData(
void AutofillProviderAndroid::OnFormsSeen(AutofillHandlerProxy* handler, void AutofillProviderAndroid::OnFormsSeen(AutofillHandlerProxy* handler,
const std::vector<FormData>& forms, const std::vector<FormData>& forms,
const base::TimeTicks) { const base::TimeTicks timestamp) {}
handler_for_testing_ = handler->GetWeakPtr();
if (!check_submission_)
return;
if (handler != handler_.get())
return;
if (form_.get() == nullptr)
return;
for (auto const& form : forms) {
if (form_->SimilarFormAs(form))
return;
}
// The form_ disappeared after it was submitted, we consider the submission
// succeeded.
FireSuccessfulSubmission(pending_submission_source_);
}
void AutofillProviderAndroid::OnHidePopup(AutofillHandlerProxy* handler) { void AutofillProviderAndroid::OnHidePopup(AutofillHandlerProxy* handler) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -372,6 +354,12 @@ void AutofillProviderAndroid::OnHidePopup(AutofillHandlerProxy* handler) { ...@@ -372,6 +354,12 @@ void AutofillProviderAndroid::OnHidePopup(AutofillHandlerProxy* handler) {
void AutofillProviderAndroid::Reset(AutofillHandlerProxy* handler) { void AutofillProviderAndroid::Reset(AutofillHandlerProxy* handler) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (handler == handler_.get()) { if (handler == handler_.get()) {
// If we previously received a notification from the renderer that the form
// was likely submitted and no event caused a reset of state in the interim,
// we consider this navigation to be resulting from the submission.
if (check_submission_ && form_.get())
FireSuccessfulSubmission(pending_submission_source_);
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null()) if (obj.is_null())
......
...@@ -118,8 +118,6 @@ class AutofillProviderAndroid : public AutofillProvider { ...@@ -118,8 +118,6 @@ class AutofillProviderAndroid : public AutofillProvider {
// Valid only if check_submission_ is true. // Valid only if check_submission_ is true.
mojom::SubmissionSource pending_submission_source_; mojom::SubmissionSource pending_submission_source_;
base::WeakPtr<AutofillHandlerProxy> handler_for_testing_;
DISALLOW_COPY_AND_ASSIGN(AutofillProviderAndroid); DISALLOW_COPY_AND_ASSIGN(AutofillProviderAndroid);
}; };
} // namespace autofill } // namespace autofill
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment