From 57914381a80c9f19cf5227b4af9e822fa0c74ea9 Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Tue, 16 Nov 2010 11:50:39 +0000 Subject: 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 --- core/java/android/webkit/WebChromeClient.java | 10 ++++++++ core/java/android/webkit/WebSettings.java | 7 ++++++ core/java/android/webkit/WebTextView.java | 35 +++++++++++++++++++++++++-- core/java/android/webkit/WebView.java | 18 +++++++++++--- core/res/res/values/strings.xml | 4 ++- 5 files changed, 67 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/java/android/webkit/WebChromeClient.java b/core/java/android/webkit/WebChromeClient.java index b2ba7e2..755366c 100644 --- a/core/java/android/webkit/WebChromeClient.java +++ b/core/java/android/webkit/WebChromeClient.java @@ -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) { } + } diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java index f4caa74..98e6ab8 100644 --- a/core/java/android/webkit/WebSettings.java +++ b/core/java/android/webkit/WebSettings.java @@ -1626,6 +1626,13 @@ public class WebSettings { } } + /** + * @hide + */ + public synchronized AutoFillProfile getAutoFillProfile() { + return mAutoFillProfile; + } + int getDoubleTapToastCount() { return mDoubleTapToastCount; } diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index fafb6be..e1a5c2d 100644 --- a/core/java/android/webkit/WebTextView.java +++ b/core/java/android/webkit/WebTextView.java @@ -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(""); - // Call a webview method to tell WebCore to autofill the form. - mWebView.autoFillForm(mQueryId); + 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; + } } diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 602975f..376b1d0 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -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! - pastEntries.add(getResources().getText( - com.android.internal.R.string.autofill_this_form).toString() + - " " + - mAutoFillData.getPreviewString()); + 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)); diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index c8a5de8..0c3361d 100755 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -1824,8 +1824,10 @@ Tip: double-tap to zoom in and out. - + AutoFill + + Setup AutoFill -- cgit v1.1