From: Steve Block Date: Thu, 6 Jan 2011 17:35:52 +0000 (+0000) Subject: Add a stdStringToJstring() helper function X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=5e8fa1efdccd0072c3e6e80e265a77568179577e;p=android-x86%2Fexternal-webkit.git Add a stdStringToJstring() helper function Change-Id: I323c753d7ce22e0e23928a126cfb99c781a074f1 --- diff --git a/WebKit/android/jni/CookieManager.cpp b/WebKit/android/jni/CookieManager.cpp index e3644d10d..8dffbe76e 100644 --- a/WebKit/android/jni/CookieManager.cpp +++ b/WebKit/android/jni/CookieManager.cpp @@ -62,7 +62,7 @@ static jstring getCookie(JNIEnv* env, jobject, jstring url) CookieOptions options; options.set_include_httponly(); std::string cookies = WebCookieJar::get(false)->cookieStore()->GetCookieMonster()->GetCookiesWithOptions(gurl, options); - return cookies.empty() ? 0 : env->NewStringUTF(cookies.c_str()); + return stdStringToJstring(env, cookies); #else // The Android HTTP stack is implemented Java-side. ASSERT_NOT_REACHED(); diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 45178bf32..c87fb4795 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -847,6 +847,7 @@ WebFrame::density() const return dpi; } +#if USE(CHROME_NETWORK_STACK) void WebFrame::didReceiveAuthenticationChallenge(WebUrlLoaderClient* client, const std::string& host, const std::string& realm, bool useCachedCredentials) { @@ -855,8 +856,8 @@ WebFrame::didReceiveAuthenticationChallenge(WebUrlLoaderClient* client, const st #endif JNIEnv* env = getJNIEnv(); int jHandle = reinterpret_cast(client); - jstring jHost = env->NewStringUTF(host.c_str()); - jstring jRealm = env->NewStringUTF(realm.c_str()); + jstring jHost = stdStringToJstring(env, host, true); + jstring jRealm = stdStringToJstring(env, realm, true); env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mDidReceiveAuthenticationChallenge, jHandle, jHost, jRealm, useCachedCredentials); @@ -864,6 +865,7 @@ WebFrame::didReceiveAuthenticationChallenge(WebUrlLoaderClient* client, const st env->DeleteLocalRef(jRealm); checkException(env); } +#endif void WebFrame::reportSslCertError(WebUrlLoaderClient* client, int cert_error, const std::string& cert) @@ -885,6 +887,7 @@ WebFrame::reportSslCertError(WebUrlLoaderClient* client, int cert_error, const s checkException(env); } +#if USE(CHROME_NETWORK_STACK) void WebFrame::downloadStart(const std::string& url, const std::string& userAgent, const std::string& contentDisposition, const std::string& mimetype, long long contentLength) { @@ -892,10 +895,10 @@ WebFrame::downloadStart(const std::string& url, const std::string& userAgent, co TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter); #endif JNIEnv* env = getJNIEnv(); - jstring jUrl = env->NewStringUTF(url.c_str()); - jstring jUserAgent = env->NewStringUTF(userAgent.c_str()); - jstring jContentDisposition = env->NewStringUTF(contentDisposition.c_str()); - jstring jMimetype = env->NewStringUTF(mimetype.c_str()); + jstring jUrl = stdStringToJstring(env, url, true); + jstring jUserAgent = stdStringToJstring(env, userAgent, true); + jstring jContentDisposition = stdStringToJstring(env, contentDisposition, true); + jstring jMimetype = stdStringToJstring(env, mimetype, true); env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mDownloadStart, jUrl, jUserAgent, jContentDisposition, jMimetype, contentLength); @@ -906,6 +909,7 @@ WebFrame::downloadStart(const std::string& url, const std::string& userAgent, co env->DeleteLocalRef(jMimetype); checkException(env); } +#endif void WebFrame::maybeSavePassword(WebCore::Frame* frame, const WebCore::ResourceRequest& request) { diff --git a/WebKit/android/jni/WebCoreJni.cpp b/WebKit/android/jni/WebCoreJni.cpp index 070864401..2a07999b4 100644 --- a/WebKit/android/jni/WebCoreJni.cpp +++ b/WebKit/android/jni/WebCoreJni.cpp @@ -92,7 +92,6 @@ string16 jstringToString16(JNIEnv* env, jstring jstr) checkException(env); return str; } -#endif std::string jstringToStdString(JNIEnv* env, jstring jstr) { @@ -108,4 +107,11 @@ std::string jstringToStdString(JNIEnv* env, jstring jstr) return str; } +jstring stdStringToJstring(JNIEnv* env, const std::string& str, bool validOnZeroLength) +{ + return !str.empty() || validOnZeroLength ? env->NewStringUTF(str.c_str()) : 0; +} + +#endif + } diff --git a/WebKit/android/jni/WebCoreJni.h b/WebKit/android/jni/WebCoreJni.h index 7e0191276..6e6a48686 100644 --- a/WebKit/android/jni/WebCoreJni.h +++ b/WebKit/android/jni/WebCoreJni.h @@ -79,9 +79,13 @@ jstring wtfStringToJstring(JNIEnv*, const WTF::String&, bool validOnZeroLength = #if USE(CHROME_NETWORK_STACK) string16 jstringToString16(JNIEnv*, jstring); -#endif std::string jstringToStdString(JNIEnv*, jstring); +// Returns a local reference to a new jstring. If validOnZeroLength is true then +// passing in an empty std::string will result in an empty jstring. Otherwise +// an empty std::string returns 0. +jstring stdStringToJstring(JNIEnv*, const std::string&, bool validOnZeroLength = false); +#endif }