Relax form autocomplete conditions
Use the URL host and path rather than the complete url to store
form autocomplete data. This helps in the situation that a site
uses some dynamic query string on the page that contains the form.
Also set the autoocmplete threshold to 1 so that we don't flick the
autocomplete options up and down as you type the first few characters.
Bug: 5265606
Change-Id: I7b372400062ae34f70a78b786007910dc179b101
diff --git a/core/java/android/webkit/BrowserFrame.java b/core/java/android/webkit/BrowserFrame.java
index 49b4f66..309857d 100644
--- a/core/java/android/webkit/BrowserFrame.java
+++ b/core/java/android/webkit/BrowserFrame.java
@@ -422,9 +422,9 @@
final WebHistoryItem h = mCallbackProxy.getBackForwardList()
.getCurrentItem();
if (h != null) {
- String currentUrl = h.getUrl();
- if (currentUrl != null) {
- mDatabase.setFormData(currentUrl, data);
+ String url = WebTextView.urlForAutoCompleteData(h.getUrl());
+ if (url != null) {
+ mDatabase.setFormData(url, data);
}
}
}
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index 2a79caa..217ad7c 100644
--- a/core/java/android/webkit/WebTextView.java
+++ b/core/java/android/webkit/WebTextView.java
@@ -60,6 +60,8 @@
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import junit.framework.Assert;
@@ -1044,6 +1046,7 @@
break;
}
setHint(null);
+ setThreshold(1);
if (single) {
mWebView.requestLabel(mWebView.nativeFocusCandidateFramePointer(),
mNodePointer);
@@ -1077,4 +1080,16 @@
/* package */ void setAutoFillProfileIsSet(boolean autoFillProfileIsSet) {
mAutoFillProfileIsSet = autoFillProfileIsSet;
}
+
+ static String urlForAutoCompleteData(String urlString) {
+ // Remove any fragment or query string.
+ URL url = null;
+ try {
+ url = new URL(urlString);
+ } catch (MalformedURLException e) {
+ Log.e(LOGTAG, "Unable to parse URL "+url);
+ }
+
+ return url != null ? url.getProtocol() + "://" + url.getHost() + url.getPath() : null;
+ }
}
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 7ba93da0..47abbc2 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -4826,7 +4826,7 @@
public RequestFormData(String name, String url, Message msg,
boolean autoFillable, boolean autoComplete) {
mName = name;
- mUrl = url;
+ mUrl = WebTextView.urlForAutoCompleteData(url);
mUpdateMessage = msg;
mAutoFillable = autoFillable;
mAutoComplete = autoComplete;