diff options
-rw-r--r-- | core/java/android/webkit/WebChromeClient.java | 10 | ||||
-rw-r--r-- | core/java/android/webkit/WebSettings.java | 7 | ||||
-rw-r--r-- | core/java/android/webkit/WebTextView.java | 35 | ||||
-rw-r--r-- | core/java/android/webkit/WebView.java | 18 | ||||
-rwxr-xr-x | core/res/res/values/strings.xml | 4 |
5 files changed, 67 insertions, 7 deletions
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 @@ <!-- 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]--> |