From 1f9212cd9a5e957562b12e8c3294b7f357fa1f85 Mon Sep 17 00:00:00 2001 From: Huahui Wu Date: Wed, 8 Dec 2010 15:22:43 -0800 Subject: b/2864818 Prompt SSL cert error dialog to user and proceed or cancel the request. Java side CL: https://android-git.corp.google.com/g/#change,84530 Change-Id: I2a16be691ba3846f3ecb1fd533905d7b6ac374fc --- WebKit/android/jni/WebCoreFrameBridge.cpp | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'WebKit/android/jni/WebCoreFrameBridge.cpp') diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 5fa5dfb..4fac42d 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -215,6 +215,7 @@ struct WebFrame::JavaBrowserFrame jmethodID mGetFileSize; jmethodID mGetFile; jmethodID mDidReceiveAuthenticationChallenge; + jmethodID mReportSslCertError; jmethodID mDownloadStart; AutoJObject frame(JNIEnv* env) { return getRealObject(env, mObj); @@ -281,6 +282,7 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page* 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"); + mJavaFrame->mReportSslCertError = env->GetMethodID(clazz, "reportSslCertError", "(II[B)V"); mJavaFrame->mDownloadStart = env->GetMethodID(clazz, "downloadStart", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V"); env->DeleteLocalRef(clazz); @@ -308,6 +310,7 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page* 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"); + LOG_ASSERT(mJavaFrame->mReportSslCertError, "Could not find method reportSslCertError"); LOG_ASSERT(mJavaFrame->mDownloadStart, "Could not find method downloadStart"); mUserAgent = WTF::String(); @@ -863,6 +866,26 @@ WebFrame::didReceiveAuthenticationChallenge(WebUrlLoaderClient* client, const st } void +WebFrame::reportSslCertError(WebUrlLoaderClient* client, int cert_error, const std::string& cert) +{ +#ifdef ANDROID_INSTRUMENT + TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter); +#endif + JNIEnv* env = getJNIEnv(); + int jHandle = reinterpret_cast(client); + + int len = cert.length(); + jbyteArray jCert = env->NewByteArray(len); + jbyte* bytes = env->GetByteArrayElements(jCert, NULL); + cert.copy(reinterpret_cast(bytes), len); + + env->CallVoidMethod(mJavaFrame->frame(env).get(), + mJavaFrame->mReportSslCertError, jHandle, cert_error, jCert); + env->DeleteLocalRef(jCert); + checkException(env); +} + +void WebFrame::downloadStart(const std::string& url, const std::string& userAgent, const std::string& contentDisposition, const std::string& mimetype, long long contentLength) { #ifdef ANDROID_INSTRUMENT @@ -1876,6 +1899,18 @@ static void AuthenticationCancel(JNIEnv *env, jobject obj, int handle) client->cancelAuth(); } +static void SslCertErrorProceed(JNIEnv *env, jobject obj, int handle) +{ + WebUrlLoaderClient* client = reinterpret_cast(handle); + client->proceedSslCertError(); +} + +static void SslCertErrorCancel(JNIEnv *env, jobject obj, int handle, int cert_error) +{ + WebUrlLoaderClient* client = reinterpret_cast(handle); + client->cancelSslCertError(cert_error); +} + #else static void AuthenticationProceed(JNIEnv *env, jobject obj, int handle, jstring jUsername, jstring jPassword) @@ -1888,6 +1923,16 @@ static void AuthenticationCancel(JNIEnv *env, jobject obj, int handle) LOGW("Chromium authentication API called, but libchromium is not available"); } +static void SslCertErrorProceed(JNIEnv *env, jobject obj, int handle) +{ + LOGW("Chromium SSL API called, but libchromium is not available"); +} + +static void SslCertErrorCancel(JNIEnv *env, jobject obj, int handle, int cert_error) +{ + LOGW("Chromium SSL API called, but libchromium is not available"); +} + #endif // USE(CHROME_NETWORK_STACK) // ---------------------------------------------------------------------------- @@ -1950,6 +1995,10 @@ static JNINativeMethod gBrowserFrameNativeMethods[] = { (void*) AuthenticationProceed }, { "nativeAuthenticationCancel", "(I)V", (void*) AuthenticationCancel }, + { "nativeSslCertErrorProceed", "(I)V", + (void*) SslCertErrorProceed }, + { "nativeSslCertErrorCancel", "(II)V", + (void*) SslCertErrorCancel }, }; int registerWebFrame(JNIEnv* env) -- cgit v1.1