Request <label> info only when accessing a textfield.

Previously, we were storing the label info each time we build the
navigation cache.

Requires a change to external/webkit.
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index cd2d26a..b6891b1 100644
--- a/core/java/android/webkit/WebTextView.java
+++ b/core/java/android/webkit/WebTextView.java
@@ -814,7 +814,6 @@
                         | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES
                         | EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
                 setImeOptions(EditorInfo.IME_ACTION_NONE);
-                setHint(null);
                 break;
             case 2: // PASSWORD
                 inPassword = true;
@@ -843,9 +842,11 @@
             default:
                 break;
         }
+        setHint(null);
         if (single) {
+            mWebView.requestLabel(mWebView.nativeFocusCandidateFramePointer(),
+                    mNodePointer);
             maxLength = mWebView.nativeFocusCandidateMaxLength();
-            setHint(mWebView.nativeFocusCandidateLabel());
             if (type != 2 /* PASSWORD */) {
                 String name = mWebView.nativeFocusCandidateName();
                 if (name != null && name.length() > 0) {
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 583195a..bf8ab7d 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -499,6 +499,7 @@
     static final int DOM_FOCUS_CHANGED                  = 31;
     static final int IMMEDIATE_REPAINT_MSG_ID           = 32;
     static final int SET_ROOT_LAYER_MSG_ID              = 33;
+    static final int RETURN_LABEL                       = 34;
 
     static final String[] HandlerDebugString = {
         "REMEMBER_PASSWORD", //              = 1;
@@ -533,7 +534,8 @@
         "HIDE_FULLSCREEN", //                = 30;
         "DOM_FOCUS_CHANGED", //              = 31;
         "IMMEDIATE_REPAINT_MSG_ID", //       = 32;
-        "SET_ROOT_LAYER_MSG_ID" //           = 33;
+        "SET_ROOT_LAYER_MSG_ID", //          = 33;
+        "RETURN_LABEL" //                    = 34;
     };
 
     // If the site doesn't use the viewport meta tag to specify the viewport,
@@ -3308,6 +3310,17 @@
         }
     }
 
+    /**
+     * Pass a message to find out the <label> associated with the <input>
+     * identified by nodePointer
+     * @param framePointer Pointer to the frame containing the <input> node
+     * @param nodePointer Pointer to the node for which a <label> is desired.
+     */
+    /* package */ void requestLabel(int framePointer, int nodePointer) {
+        mWebViewCore.sendMessage(EventHub.REQUEST_LABEL, framePointer,
+                nodePointer);
+    }
+
     /*
      * This class runs the layers animations in their own thread,
      * so that we do not slow down the UI.
@@ -5361,7 +5374,7 @@
             // exclude INVAL_RECT_MSG_ID since it is frequently output
             if (DebugFlags.WEB_VIEW && msg.what != INVAL_RECT_MSG_ID) {
                 Log.v(LOGTAG, msg.what < REMEMBER_PASSWORD || msg.what
-                        > SET_ROOT_LAYER_MSG_ID ? Integer.toString(msg.what)
+                        > RETURN_LABEL ? Integer.toString(msg.what)
                         : HandlerDebugString[msg.what - REMEMBER_PASSWORD]);
             }
             if (mWebViewCore == null) {
@@ -5592,6 +5605,20 @@
                                 tData.mEnd);
                     }
                     break;
+                case RETURN_LABEL:
+                    if (inEditingMode()
+                            && mWebTextView.isSameTextField(msg.arg1)) {
+                        mWebTextView.setHint((String) msg.obj);
+                        InputMethodManager imm
+                                = InputMethodManager.peekInstance();
+                        // The hint is propagated to the IME in
+                        // onCreateInputConnection.  If the IME is already
+                        // active, restart it so that its hint text is updated.
+                        if (imm != null && imm.isActive(mWebTextView)) {
+                            imm.restartInput(mWebTextView);
+                        }
+                    }
+                    break;
                 case MOVE_OUT_OF_PLUGIN:
                     navHandledKey(msg.arg1, 1, false, 0, true);
                     break;
@@ -6350,12 +6377,11 @@
     private native void     nativeDumpDisplayTree(String urlOrNull);
     private native int      nativeFindAll(String findLower, String findUpper);
     private native void     nativeFindNext(boolean forward);
-    private native int      nativeFocusCandidateFramePointer();
+    /* package */ native int      nativeFocusCandidateFramePointer();
     private native boolean  nativeFocusCandidateIsPassword();
     private native boolean  nativeFocusCandidateIsPlugin();
     private native boolean  nativeFocusCandidateIsRtlText();
     private native boolean  nativeFocusCandidateIsTextInput();
-    /* package */ native String   nativeFocusCandidateLabel();
     /* package */ native int      nativeFocusCandidateMaxLength();
     /* package */ native String   nativeFocusCandidateName();
     private native Rect     nativeFocusCandidateNodeBounds();
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 2de25e8..1ef37e6 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -746,6 +746,7 @@
     }
 
         static final String[] HandlerDebugString = {
+            "REQUEST_LABEL", // 97
             "UPDATE_FRAME_CACHE_IF_LOADING", // = 98
             "SCROLL_TEXT_INPUT", // = 99
             "LOAD_URL", // = 100;
@@ -799,6 +800,7 @@
 
     class EventHub {
         // Message Ids
+        static final int REQUEST_LABEL = 97;
         static final int UPDATE_FRAME_CACHE_IF_LOADING = 98;
         static final int SCROLL_TEXT_INPUT = 99;
         static final int LOAD_URL = 100;
@@ -911,11 +913,11 @@
                 @Override
                 public void handleMessage(Message msg) {
                     if (DebugFlags.WEB_VIEW_CORE) {
-                        Log.v(LOGTAG, (msg.what < UPDATE_FRAME_CACHE_IF_LOADING
+                        Log.v(LOGTAG, (msg.what < REQUEST_LABEL
                                 || msg.what
                                 > VALID_NODE_BOUNDS ? Integer.toString(msg.what)
                                 : HandlerDebugString[msg.what
-                                        - UPDATE_FRAME_CACHE_IF_LOADING])
+                                        - REQUEST_LABEL])
                                 + " arg1=" + msg.arg1 + " arg2=" + msg.arg2
                                 + " obj=" + msg.obj);
                     }
@@ -936,6 +938,19 @@
                             }
                             break;
 
+                        case REQUEST_LABEL:
+                            if (mWebView != null) {
+                                int nodePointer = msg.arg2;
+                                String label = nativeRequestLabel(msg.arg1,
+                                        nodePointer);
+                                if (label != null && label.length() > 0) {
+                                    Message.obtain(mWebView.mPrivateHandler,
+                                            WebView.RETURN_LABEL, nodePointer,
+                                            0, label).sendToTarget();
+                                }
+                            }
+                            break;
+
                         case UPDATE_FRAME_CACHE_IF_LOADING:
                             nativeUpdateFrameCacheIfLoading();
                             break;
@@ -2201,7 +2216,7 @@
     }
 
     private native void nativeUpdateFrameCacheIfLoading();
-
+    private native String nativeRequestLabel(int framePtr, int nodePtr);
     /**
      * Scroll the focused textfield to (xPercent, y) in document space
      */