Cherry pick from master.

This change forwards to the WebView HTTP authentication credentials that
are supplied to an XHR from JavaScript. This allows the WebView to store these
credentials for use with later requests.

This is a re-working of https://android-git.corp.google.com/g/46430

Bug: 2544330
Change-Id: I3f04433b00233d7b7bf4f7e3471d8d15d8817f93
diff --git a/core/java/android/webkit/CallbackProxy.java b/core/java/android/webkit/CallbackProxy.java
index 188ab2a..8af2492 100644
--- a/core/java/android/webkit/CallbackProxy.java
+++ b/core/java/android/webkit/CallbackProxy.java
@@ -736,14 +736,12 @@
                 }
                 break;
             case AUTH_CREDENTIALS:
-                if (mWebViewClient != null) {
-                    String host = msg.getData().getString("host");
-                    String realm = msg.getData().getString("realm");
-                    username = msg.getData().getString("username");
-                    password = msg.getData().getString("password");
-                    mWebViewClient.onReceivedHttpAuthCredentials(
-                            mWebView, host, realm, username, password);
-                }
+                String host = msg.getData().getString("host");
+                String realm = msg.getData().getString("realm");
+                username = msg.getData().getString("username");
+                password = msg.getData().getString("password");
+                mWebView.setHttpAuthUsernamePassword(
+                        host, realm, username, password);
                 break;
         }
     }
@@ -929,19 +927,6 @@
         sendMessage(msg);
     }
 
-    public void onReceivedHttpAuthCredentials(String host, String realm,
-            String username, String password) {
-        if (mWebViewClient == null) {
-            return;
-        }
-        Message msg = obtainMessage(AUTH_CREDENTIALS);
-        msg.getData().putString("host", host);
-        msg.getData().putString("realm", realm);
-        msg.getData().putString("username", username);
-        msg.getData().putString("password", password);
-        sendMessage(msg);
-    }
-
     /**
      * @hide - hide this because it contains a parameter of type SslError.
      * SslError is located in a hidden package.
@@ -1078,6 +1063,16 @@
         return false;
     }
 
+    public void onReceivedHttpAuthCredentials(String host, String realm,
+            String username, String password) {
+        Message msg = obtainMessage(AUTH_CREDENTIALS);
+        msg.getData().putString("host", host);
+        msg.getData().putString("realm", realm);
+        msg.getData().putString("username", username);
+        msg.getData().putString("password", password);
+        sendMessage(msg);
+    }
+
     //--------------------------------------------------------------------------
     // WebChromeClient methods
     //--------------------------------------------------------------------------
diff --git a/core/java/android/webkit/HttpAuthHandler.java b/core/java/android/webkit/HttpAuthHandler.java
index 6a8d88d..ed85da6 100644
--- a/core/java/android/webkit/HttpAuthHandler.java
+++ b/core/java/android/webkit/HttpAuthHandler.java
@@ -269,7 +269,7 @@
     }
 
     /**
-     * Informs the proxy of a new set of credentials.
+     * Informs the WebView of a new set of credentials.
      * @hide Pending API council review
      */
     public static void onReceivedCredentials(LoadListener loader,
diff --git a/core/java/android/webkit/WebViewClient.java b/core/java/android/webkit/WebViewClient.java
index 4ac660e..02c7210 100644
--- a/core/java/android/webkit/WebViewClient.java
+++ b/core/java/android/webkit/WebViewClient.java
@@ -197,22 +197,6 @@
     }
 
     /**
-     * Notify the host application that authentication credentials have been
-     * supplied from Script.
-     * The default behavior is to do nothing.
-     * @hide Pending API council review
-     *
-     * @param view The WebView that is initiating the callback.
-     * @param host The host requiring authentication.
-     * @param realm A description to help store user credentials for future
-     * @param username The username
-     * @param password The password
-     */
-    public void onReceivedHttpAuthCredentials(WebView view, String host,
-            String realm, String username, String password) {
-    }
-
-    /**
      * Give the host application a chance to handle the key event synchronously.
      * e.g. menu shortcut key events need to be filtered this way. If return
      * true, WebView will not handle the key event. If return false, WebView