summaryrefslogtreecommitdiffstats
path: root/WebKit/android/jni/WebCoreFrameBridge.cpp
diff options
context:
space:
mode:
authorIain Merrick <husky@google.com>2010-08-23 17:35:30 +0100
committerIain Merrick <husky@google.com>2010-09-20 12:14:03 +0100
commitd4ff0cc91b5eb975d563f355f9f4c7358e0e2c06 (patch)
tree69dda182d1890032def251c6888fcfb97d4d5135 /WebKit/android/jni/WebCoreFrameBridge.cpp
parentf8230805249e7f0956d00204d2e610208efe5ad9 (diff)
downloadexternal_webkit-d4ff0cc91b5eb975d563f355f9f4c7358e0e2c06.zip
external_webkit-d4ff0cc91b5eb975d563f355f9f4c7358e0e2c06.tar.gz
external_webkit-d4ff0cc91b5eb975d563f355f9f4c7358e0e2c06.tar.bz2
HTTP auth for Chromium HTTP stack (C++ side)
On receiving an auth request: - WebRequest (on the IO thread) sends a message to WebUrlLoaderClient - WebUrlLoaderClient (webkit thread) calls WebCoreFrameBridge. - WebCoreFrameBridge makes a JNI call to BrowserFrame.java. Each JNI call has a WebUrlLoaderClient pointer, cast to an int. We use this to recover the context when we're called back, and dispatch a message back to WebRequest. Corresponding Java change: https://android-git.corp.google.com/g/63762 Change-Id: Ieb72f2eaa996a55916c987859f47f6dacf92e06c
Diffstat (limited to 'WebKit/android/jni/WebCoreFrameBridge.cpp')
-rw-r--r--WebKit/android/jni/WebCoreFrameBridge.cpp68
1 files changed, 67 insertions, 1 deletions
diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp
index c1cb907..1d5eacb 100644
--- a/WebKit/android/jni/WebCoreFrameBridge.cpp
+++ b/WebKit/android/jni/WebCoreFrameBridge.cpp
@@ -83,6 +83,7 @@
#include "WebHistory.h"
#include "WebIconDatabase.h"
#include "WebFrameView.h"
+#include "WebUrlLoaderClient.h"
#include "WebViewCore.h"
#include "android_graphics.h"
#include "jni.h"
@@ -209,6 +210,7 @@ struct WebFrame::JavaBrowserFrame
jmethodID mDensity;
jmethodID mGetFileSize;
jmethodID mGetFile;
+ jmethodID mDidReceiveAuthenticationChallenge;
AutoJObject frame(JNIEnv* env) {
return getRealObject(env, mObj);
}
@@ -268,6 +270,8 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page*
mJavaFrame->mDensity = env->GetMethodID(clazz, "density","()F");
mJavaFrame->mGetFileSize = env->GetMethodID(clazz, "getFileSize", "(Ljava/lang/String;)I");
mJavaFrame->mGetFile = env->GetMethodID(clazz, "getFile", "(Ljava/lang/String;[BII)I");
+ mJavaFrame->mDidReceiveAuthenticationChallenge = env->GetMethodID(clazz, "didReceiveAuthenticationChallenge",
+ "(ILjava/lang/String;Ljava/lang/String;Z)V");
LOG_ASSERT(mJavaFrame->mInputStreamForAndroidResource, "Could not find method inputStreamForAndroidResource");
LOG_ASSERT(mJavaFrame->mStartLoadingResource, "Could not find method startLoadingResource");
@@ -290,6 +294,7 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page*
LOG_ASSERT(mJavaFrame->mDensity, "Could not find method density");
LOG_ASSERT(mJavaFrame->mGetFileSize, "Could not find method getFileSize");
LOG_ASSERT(mJavaFrame->mGetFile, "Could not find method getFile");
+ LOG_ASSERT(mJavaFrame->mDidReceiveAuthenticationChallenge, "Could not find method didReceiveAuthenticationChallenge");
mUserAgent = WTF::String();
mUserInitiatedAction = false;
@@ -887,6 +892,24 @@ WebFrame::density() const
return dpi;
}
+void
+WebFrame::didReceiveAuthenticationChallenge(WebUrlLoaderClient* client, const std::string& host, const std::string& realm, bool useCachedCredentials)
+{
+#ifdef ANDROID_INSTRUMENT
+ TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
+#endif
+ JNIEnv* env = getJNIEnv();
+ int jHandle = reinterpret_cast<int>(client);
+ jstring jHost = env->NewStringUTF(host.c_str());
+ jstring jRealm = env->NewStringUTF(realm.c_str());
+
+ env->CallVoidMethod(mJavaFrame->frame(env).get(),
+ mJavaFrame->mDidReceiveAuthenticationChallenge, jHandle, jHost, jRealm, useCachedCredentials);
+ env->DeleteLocalRef(jHost);
+ env->DeleteLocalRef(jRealm);
+ checkException(env);
+}
+
// ----------------------------------------------------------------------------
static void CallPolicyFunction(JNIEnv* env, jobject obj, jint func, jint decision)
{
@@ -1756,6 +1779,45 @@ static void OrientationChanged(JNIEnv *env, jobject obj, int orientation)
pFrame->sendOrientationChangeEvent(orientation);
}
+static std::string jstringToStdString(JNIEnv* env, jstring jstr) {
+ jsize size = env->GetStringUTFLength(jstr);
+ jboolean isCopy;
+ const char* cstr = env->GetStringUTFChars(jstr, &isCopy);
+ std::string result(cstr, cstr + size);
+ env->ReleaseStringUTFChars(jstr, cstr);
+ return result;
+}
+
+#if USE(CHROME_NETWORK_STACK)
+
+static void AuthenticationProceed(JNIEnv *env, jobject obj, int handle, jstring jUsername, jstring jPassword)
+{
+ WebUrlLoaderClient* client = reinterpret_cast<WebUrlLoaderClient*>(handle);
+ std::string username = jstringToStdString(env, jUsername);
+ std::string password = jstringToStdString(env, jPassword);
+ client->setAuth(username, password);
+}
+
+static void AuthenticationCancel(JNIEnv *env, jobject obj, int handle)
+{
+ WebUrlLoaderClient* client = reinterpret_cast<WebUrlLoaderClient*>(handle);
+ client->cancelAuth();
+}
+
+#else
+
+static void AuthenticationProceed(JNIEnv *env, jobject obj, int handle, jstring jUsername, jstring jPassword)
+{
+ LOGW("Chromium authentication API called, but libchromium is not available");
+}
+
+static void AuthenticationCancel(JNIEnv *env, jobject obj, int handle)
+{
+ LOGW("Chromium authentication API called, but libchromium is not available");
+}
+
+#endif // USE(CHROME_NETWORK_STACK)
+
// ----------------------------------------------------------------------------
/*
@@ -1811,7 +1873,11 @@ static JNINativeMethod gBrowserFrameNativeMethods[] = {
{ "getFormTextData", "()Ljava/util/HashMap;",
(void*) GetFormTextData },
{ "nativeOrientationChanged", "(I)V",
- (void*) OrientationChanged }
+ (void*) OrientationChanged },
+ { "nativeAuthenticationProceed", "(ILjava/lang/String;Ljava/lang/String;)V",
+ (void*) AuthenticationProceed },
+ { "nativeAuthenticationCancel", "(I)V",
+ (void*) AuthenticationCancel },
};
int register_webframe(JNIEnv* env)