From 0348440e4ad665f9fa7ed73a5c6b533e183a9e1f Mon Sep 17 00:00:00 2001 From: Steve Block Date: Fri, 26 Mar 2010 09:10:58 +0000 Subject: [PATCH 1/2] 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 --- core/java/android/webkit/CallbackProxy.java | 37 ++++++++----------- core/java/android/webkit/HttpAuthHandler.java | 2 +- core/java/android/webkit/WebViewClient.java | 16 -------- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/core/java/android/webkit/CallbackProxy.java b/core/java/android/webkit/CallbackProxy.java index 188ab2ac5f8b1..8af2492b1cdf4 100644 --- a/core/java/android/webkit/CallbackProxy.java +++ b/core/java/android/webkit/CallbackProxy.java @@ -736,14 +736,12 @@ class CallbackProxy extends Handler { } 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 @@ class CallbackProxy extends Handler { 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 @@ class CallbackProxy extends Handler { 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 6a8d88d582962..ed85da604744b 100644 --- a/core/java/android/webkit/HttpAuthHandler.java +++ b/core/java/android/webkit/HttpAuthHandler.java @@ -269,7 +269,7 @@ public class HttpAuthHandler extends Handler { } /** - * 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 4ac660e685132..02c721009b103 100644 --- a/core/java/android/webkit/WebViewClient.java +++ b/core/java/android/webkit/WebViewClient.java @@ -196,22 +196,6 @@ public class WebViewClient { handler.cancel(); } - /** - * 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 From 2bb2553a20f33a2587ea33619d6be92343101eba Mon Sep 17 00:00:00 2001 From: Steve Block Date: Thu, 25 Mar 2010 14:48:13 +0000 Subject: [PATCH 2/2] Cherry pick from master. Fixes DumpRenderTree to re-use HTTP authentication credentials This is required for layout test http/tests/appcache/auth.html Bug: 2098423 Change-Id: Ic9531e3c23a2fa9ebfab70cde3172550f572a404 --- .../src/com/android/dumprendertree/FileFilter.java | 1 - .../src/com/android/dumprendertree/TestShellActivity.java | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/FileFilter.java b/tests/DumpRenderTree/src/com/android/dumprendertree/FileFilter.java index d10e382cba707..77fd3ed16cf4c 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/FileFilter.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/FileFilter.java @@ -82,7 +82,6 @@ public class FileFilter { // This first block of tests are for HTML5 features, for which Android // should pass all tests. They are skipped only temporarily. // TODO: Fix these failing tests and remove them from this list. - ignoreResultList.add("http/tests/appcache/auth.html"); // DumpRenderTree throws exception when authentication fails ignoreResultList.add("http/tests/appcache/empty-manifest.html"); // flaky ignoreResultList.add("http/tests/appcache/foreign-iframe-main.html"); // flaky - skips states ignoreResultList.add("http/tests/appcache/manifest-with-empty-file.html"); // flaky diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java index 24f58b2284869..81d5b0862f0d1 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java @@ -515,6 +515,13 @@ public class TestShellActivity extends Activity implements LayoutTestController @Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { + if (handler.useHttpAuthUsernamePassword() && view != null) { + String[] credentials = view.getHttpAuthUsernamePassword(host, realm); + if (credentials != null && credentials.length == 2) { + handler.proceed(credentials[0], credentials[1]); + return; + } + } handler.cancel(); }