Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57914381 authored by Ben Murdoch's avatar Ben Murdoch
Browse files

Offer the user the option to configure an AutoFill profile.

When the user selects a form field that is part of a form that can
be autofilled, inform the embedder that this is the case to give
them the opportunity to configure a profile if they the user has
not done so already. A Message is also provided
to the embedder that when sent will trigger the form to be filled
with the profile that the embedder set up.

Change-Id: Ica995e5b1ed92a3ec3e356401b261740d9f90e57
parent 1c24e957
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -330,4 +330,14 @@ public class WebChromeClient {
     */
    public void setInstallableWebApp() { }

    /**
     * Tell the client that the page being viewed has an autofillable
     * form and the user would like to set a profile up.
     * @param msg A Message to send once the user has successfully
     *      set up a profile and to inform the WebTextView it should
     *      now autofill using that new profile.
     * @hide
     */
    public void setupAutoFill(Message msg) { }

}
+7 −0
Original line number Diff line number Diff line
@@ -1626,6 +1626,13 @@ public class WebSettings {
        }
    }

    /**
     * @hide
     */
    public synchronized AutoFillProfile getAutoFillProfile() {
        return mAutoFillProfile;
    }

    int getDoubleTapToastCount() {
        return mDoubleTapToastCount;
    }
+33 −2
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.text.BoringLayout.Metrics;
import android.text.DynamicLayout;
import android.text.Editable;
@@ -129,6 +131,7 @@ import junit.framework.Assert;

    private boolean mAutoFillable; // Is this textview part of an autofillable form?
    private int mQueryId;
    private boolean mAutoFillProfileIsSet;

    // Types used with setType.  Keep in sync with CachedInput.h
    private static final int NORMAL_TEXT_FIELD = 0;
@@ -140,6 +143,9 @@ import junit.framework.Assert;
    private static final int TELEPHONE = 6;
    private static final int URL = 7;

    private static final int AUTOFILL_FORM = 100;
    private Handler mHandler;

    /**
     * Create a new WebTextView.
     * @param   context The Context for this WebTextView.
@@ -163,6 +169,18 @@ import junit.framework.Assert;
        setTextColor(DebugFlags.DRAW_WEBTEXTVIEW ? Color.RED : Color.BLACK);
        // This helps to align the text better with the text in the web page.
        setIncludeFontPadding(false);

        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                case AUTOFILL_FORM:
                    mWebView.autoFillForm(mQueryId);
                    break;
                }
            }
        };

    }

    public void setAutoFillable(int queryId) {
@@ -801,8 +819,17 @@ import junit.framework.Assert;
                    if (id == 0 && position == 0) {
                        // Blank out the text box while we wait for WebCore to fill the form.
                        replaceText("");
                        WebSettings settings = mWebView.getSettings();
                        if (mAutoFillProfileIsSet) {
                            // Call a webview method to tell WebCore to autofill the form.
                            mWebView.autoFillForm(mQueryId);
                        } else {
                            // There is no autofill profile setup yet and the user has
                            // elected to try and set one up. Call through to the
                            // embedder to action that.
                            mWebView.getWebChromeClient().setupAutoFill(
                                    mHandler.obtainMessage(AUTOFILL_FORM));
                        }
                    }
                }
            });
@@ -1124,4 +1151,8 @@ import junit.framework.Assert;
    /* package */ void updateCachedTextfield() {
        mWebView.updateCachedTextfield(getText().toString());
    }

    /* package */ void setAutoFillProfileIsSet(boolean autoFillProfileIsSet) {
        mAutoFillProfileIsSet = autoFillProfileIsSet;
    }
}
+14 −4
Original line number Diff line number Diff line
@@ -4051,10 +4051,20 @@ public class WebView extends AbsoluteLayout
                // Note that code inside the adapter click handler in WebTextView depends
                // on the AutoFill item being at the top of the drop down list. If you change
                // the order, make sure to do it there too!
                WebSettings settings = getSettings();
                if (settings != null && settings.getAutoFillProfile() != null) {
                    pastEntries.add(getResources().getText(
                            com.android.internal.R.string.autofill_this_form).toString() +
                            " " +
                            mAutoFillData.getPreviewString());
                    mWebTextView.setAutoFillProfileIsSet(true);
                } else {
                    // There is no autofill profile set up yet, so add an option that
                    // will invite the user to set their profile up.
                    pastEntries.add(getResources().getText(
                            com.android.internal.R.string.setup_autofill).toString());
                    mWebTextView.setAutoFillProfileIsSet(false);
                }
            }

            pastEntries.addAll(mDatabase.getFormData(mUrl, mName));
+3 −1
Original line number Diff line number Diff line
@@ -1824,8 +1824,10 @@
    <!-- Toast for double-tap -->
    <string name="double_tap_toast">Tip: double-tap to zoom in and out.</string>

    <!-- Text to show in the auto complete drop down list on a text view when the browser can auto fill the entire form -->
    <!-- Text to show in the auto complete drop down list on a text view when the WebView can auto fill the entire form, and the user has configured an AutoFill profile [CHAR-LIMIT=8] -->
    <string name="autofill_this_form">AutoFill</string>
    <!-- Text to show in the auto complete drop down list on a text view when the WebView can auto fill the entire form but the user has not configured an AutoFill profile [CHAR-LIMIT=16] -->
    <string name="setup_autofill">Setup AutoFill</string>

    <!-- String used to separate FirstName and LastName when writing out a local name
         e.g. John<separator>Smith [CHAR-LIMIT=NONE]-->