Chromium Code Reviews| Index: components/autofill/android/java/src/org/chromium/components/autofill/AutofillProvider.java |
| diff --git a/components/autofill/android/java/src/org/chromium/components/autofill/AutofillProvider.java b/components/autofill/android/java/src/org/chromium/components/autofill/AutofillProvider.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ce8a0ea9f5ac9a312b4d4468a0bc7ebb7cd0858e |
| --- /dev/null |
| +++ b/components/autofill/android/java/src/org/chromium/components/autofill/AutofillProvider.java |
| @@ -0,0 +1,116 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.components.autofill; |
| + |
| +import android.util.SparseArray; |
| +import android.view.ViewStructure; |
| + |
| +import org.chromium.base.annotations.CalledByNative; |
| +import org.chromium.base.annotations.JNINamespace; |
| + |
| +/** |
| + * This class defines interface of AutofillProvider, it doesn't use chrome's |
| + * autofill service or suggestion UI, instead, uses third party autofill service |
| + * by knowing of format structure and user's input. |
| + * |
| + * AutofillProvider handles one autofill session at time, each call of |
|
sgurun-gerrit only
2017/04/28 01:46:39
is this limitation per WebContents? what if there
Roger McFarlane (Chromium)
2017/04/28 20:28:27
What is the scope of a session?
How does this wor
michaelbai
2017/04/28 20:52:00
Yes, It is driven by user, more specifically, A ne
michaelbai
2017/04/28 20:52:00
Each WebView has its own AutofillProvider, since e
|
| + * queryFormFieldAutofill cancels previous session and starts a new one, the |
| + * calling of other methods shall associate with current session. |
| + */ |
| +@JNINamespace("autofill") |
| +public abstract class AutofillProvider { |
| + private long mNativeAutofillProviderAndroid; |
| + |
| + public AutofillProvider() {} |
| + |
| + public long getNativeAutofillProviderAndroid() { |
| + if (mNativeAutofillProviderAndroid == 0) { |
| + mNativeAutofillProviderAndroid = nativeCreateNativePeer(); |
| + } |
| + return mNativeAutofillProviderAndroid; |
| + } |
| + |
| + /** |
| + * Invoked when autofill value is available, AutofillProvider shall fill the |
| + * form by provided values. |
| + * |
| + * @param values the array of autofill values, the key is virtual id of form |
| + * field. |
| + */ |
| + public abstract void autofill(final SparseArray<String> values); |
| + |
| + /** |
| + * Invoked when autofill service needs the form structure. |
| + * |
| + * @param structure see View.onProvideAutofillVirtualStructure() |
| + * @param flags |
| + */ |
| + public abstract void onProvideAutoFillVirtualStructure(ViewStructure structure, int flags); |
| + |
| + /** |
| + * Invoked when filling form is need. AutofillProvider shall ask autofill |
| + * service for the value to fill the form. |
| + * |
| + * @param formData the form needs to fill. |
| + * @param focus the index of focus field in formData |
| + * @param x the boundary of focus field. |
| + * @param y the boundary of focus field. |
| + * @param width the boundary of focus field. |
| + * @param height the boundary of focus field. |
| + */ |
| + @CalledByNative |
| + protected abstract void queryFormFieldAutofill( |
| + FormData formData, int focus, int x, int y, int width, int height); |
| + |
| + /** |
| + * Invoked when text field is changed. |
| + * |
| + * @param index index of field in current form. |
| + */ |
| + @CalledByNative |
| + protected abstract void onTextFieldDidChange(int index); |
| + |
| + /** |
| + * Invoked when current form will be submitted. |
| + */ |
| + @CalledByNative |
| + protected abstract void onWillSubmitForm(); |
| + |
| + /** |
| + * Invoked when focus field changed. |
| + * |
| + * @param focusOnForm whether focus is still on form. |
| + * @param focusItem the index of field has focus |
| + * @param x the boundary of focus field. |
| + * @param y the boundary of focus field. |
| + * @param width the boundary of focus field. |
| + * @param height the boundary of focus field. |
| + */ |
| + @CalledByNative |
| + protected abstract void onFocusChanged( |
| + boolean focusOnForm, int focusItem, int x, int y, int width, int height); |
| + |
| + /** |
| + * Send form to renderer for filling. |
| + * |
| + * @param formData the form to fill. |
| + */ |
| + protected void autofill(FormData formData) { |
| + nativeOnAutofillAvailable(mNativeAutofillProviderAndroid, formData); |
| + } |
| + |
| + /** |
| + * Invoked when native peer is destroyed. |
| + */ |
| + @CalledByNative |
| + private void onNativeDestroyed() { |
| + mNativeAutofillProviderAndroid = 0; |
| + } |
| + |
| + private native long nativeCreateNativePeer(); |
| + |
| + private native void nativeOnAutofillAvailable( |
| + long nativeAutofillProviderAndroid, FormData formData); |
| +} |