Invite the user to set up AutoFill

If the user has not set up an AutoFill profile but has the
feature enabled and they start to fill out a form that we
have determined as "autofillable" then offer to take them
to the profile editor to set up their profile.

Change-Id: Ia44c7036ef616d4ea826e541471dd916262488f2
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index e0b15b4..41e7356 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -47,6 +47,7 @@
 import android.os.Message;
 import android.os.PowerManager;
 import android.os.PowerManager.WakeLock;
+import android.preference.PreferenceActivity;
 import android.provider.Browser;
 import android.provider.BrowserContract;
 import android.provider.BrowserContract.History;
@@ -114,6 +115,8 @@
     // activity requestCode
     final static int PREFERENCES_PAGE = 3;
     final static int FILE_SELECTED = 4;
+    final static int AUTOFILL_SETUP = 5;
+
     private final static int WAKELOCK_TIMEOUT = 5 * 60 * 1000; // 5 minutes
 
     // As the ids are dynamically created, we can't guarantee that they will
@@ -143,6 +146,8 @@
     private PageDialogsHandler mPageDialogsHandler;
     private NetworkStateHandler mNetworkHandler;
 
+    private Message mAutoFillSetupMessage;
+
     private boolean mShouldShowErrorConsole;
 
     private SystemAllowGeolocationOrigins mSystemAllowGeolocationOrigins;
@@ -1050,6 +1055,15 @@
                 mUploadHandler.onResult(resultCode, intent);
                 mUploadHandler = null;
                 break;
+            case AUTOFILL_SETUP:
+                // Determine whether a profile was actually set up or not
+                // and if so, send the message back to the WebTextView to
+                // fill the form with the new profile.
+                if (getSettings().getAutoFillProfile() != null) {
+                    mAutoFillSetupMessage.sendToTarget();
+                    mAutoFillSetupMessage = null;
+                }
+                break;
             default:
                 break;
         }
@@ -2409,4 +2423,14 @@
         return mMenuIsDown;
     }
 
+    public void setupAutoFill(Message message) {
+        // Open the settings activity at the AutoFill profile fragment so that
+        // the user can create a new profile. When they return, we will dispatch
+        // the message so that we can autofill the form using their new profile.
+        Intent intent = new Intent(mActivity, BrowserPreferencesPage.class);
+        intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
+                AutoFillSettingsFragment.class.getName());
+        mAutoFillSetupMessage = message;
+        mActivity.startActivityForResult(intent, AUTOFILL_SETUP);
+    }
 }