diff options
author | Huahui Wu <hwu@google.com> | 2011-02-10 15:00:15 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-02-10 15:00:15 -0800 |
commit | 246ea84a226462854f9c876c8dd03665271b3f78 (patch) | |
tree | 6e10bad2cb977926ecdd9903171eb4abfb2e0292 | |
parent | f60e7a005a7df326d97263dde7184ad1fe1e0897 (diff) | |
parent | d7e43d41b288f6bec8d577c6fe45994d3900e5a8 (diff) | |
download | external_webkit-246ea84a226462854f9c876c8dd03665271b3f78.zip external_webkit-246ea84a226462854f9c876c8dd03665271b3f78.tar.gz external_webkit-246ea84a226462854f9c876c8dd03665271b3f78.tar.bz2 |
Merge "b/3416864 Pass the certificate info from native to JAVA."
-rw-r--r-- | WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp | 37 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.cpp | 18 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.h | 2 |
3 files changed, 15 insertions, 42 deletions
diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp index 5c54000..636f7be 100644 --- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp +++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp @@ -38,7 +38,6 @@ #include "WebResourceRequest.h" #include <wtf/text/CString.h> -#include <sstream> namespace android { @@ -344,30 +343,6 @@ void WebUrlLoaderClient::maybeCallOnMainThread(Task* task) } } -namespace { -// Convert a CertPrincipal into string readable by Java code. -// The expected format is "CN=xxx, O=xxx, OU=xxx" (see SslCertificate.DName). -// If there are multiple organization names, we print them all. -static std::string certPrincipalToString(const net::CertPrincipal& cp) -{ - std::string result; - if (!cp.common_name.empty()) { - result += "CN="; - result += cp.common_name; - } - std::vector<std::string>::const_iterator i; - for (i = cp.organization_names.begin(); i != cp.organization_names.end(); ++i) { - result += result.empty() ? "O=" : ", O="; - result += *i; - } - for (i = cp.organization_unit_names.begin(); i != cp.organization_unit_names.end(); ++i) { - result += result.empty() ? "OU=" : ", OU="; - result += *i; - } - return result; -} -} - // Response methods void WebUrlLoaderClient::didReceiveResponse(PassOwnPtr<WebResponse> webResponse) { @@ -379,13 +354,11 @@ void WebUrlLoaderClient::didReceiveResponse(PassOwnPtr<WebResponse> webResponse) if (m_isMainResource) { // If we got an SSL certificate, tell the WebView about it. - const net::SSLInfo& ssl = m_response->getSslInfo(); - if (ssl.cert) { - m_webFrame->setCertificate( - certPrincipalToString(ssl.cert->subject()), - certPrincipalToString(ssl.cert->issuer()), - 1000L * ssl.cert->valid_start().ToDoubleT(), - 1000L * ssl.cert->valid_expiry().ToDoubleT()); + const net::SSLInfo& ssl_info = m_response->getSslInfo(); + if (ssl_info.is_valid()) { + std::vector<std::string> chain_bytes; + ssl_info.cert->GetChainDEREncodedBytes(&chain_bytes); + m_webFrame->setCertificate(chain_bytes[0]); } } } diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 1635b1d..c187d92 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -291,8 +291,7 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page* "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V"); mJavaFrame->mDidReceiveData = env->GetMethodID(clazz, "didReceiveData", "([BI)V"); mJavaFrame->mDidFinishLoading = env->GetMethodID(clazz, "didFinishLoading", "()V"); - mJavaFrame->mSetCertificate = env->GetMethodID(clazz, "setCertificate", - "(Ljava/lang/String;Ljava/lang/String;JJ)V"); + mJavaFrame->mSetCertificate = env->GetMethodID(clazz, "setCertificate", "([B)V"); mJavaFrame->mShouldSaveFormData = env->GetMethodID(clazz, "shouldSaveFormData", "()Z"); mJavaFrame->mSaveFormData = env->GetMethodID(clazz, "saveFormData", "(Ljava/util/HashMap;)V"); env->DeleteLocalRef(clazz); @@ -965,20 +964,21 @@ WebFrame::didFinishLoading() { #endif #if USE(CHROME_NETWORK_STACK) -void WebFrame::setCertificate(const std::string& issuedTo, const std::string& issuedBy, long long validNotBeforeMillis, long long validNotAfterMillis) +void WebFrame::setCertificate(const std::string& cert) { #ifdef ANDROID_INSTRUMENT TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter); #endif JNIEnv* env = getJNIEnv(); - jstring jIssuedTo = stdStringToJstring(env, issuedTo, true); - jstring jIssuedBy = stdStringToJstring(env, issuedBy, true); - env->CallVoidMethod(mJavaFrame->frame(env).get(), - mJavaFrame->mSetCertificate, jIssuedTo, jIssuedBy, validNotBeforeMillis, validNotAfterMillis); + int len = cert.length(); + jbyteArray jCert = env->NewByteArray(len); + jbyte* bytes = env->GetByteArrayElements(jCert, NULL); + cert.copy(reinterpret_cast<char*>(bytes), len); + + env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mSetCertificate, jCert); - env->DeleteLocalRef(jIssuedTo); - env->DeleteLocalRef(jIssuedBy); + env->DeleteLocalRef(jCert); checkException(env); } #endif diff --git a/WebKit/android/jni/WebCoreFrameBridge.h b/WebKit/android/jni/WebCoreFrameBridge.h index e507667..af7be60 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.h +++ b/WebKit/android/jni/WebCoreFrameBridge.h @@ -126,7 +126,7 @@ class WebFrame : public WebCoreRefObject { void maybeSavePassword(WebCore::Frame* frame, const WebCore::ResourceRequest& request); - void setCertificate(const std::string& issuedTo, const std::string& issuedBy, long long validNotBeforeMillis, long long validNotAfterMillis); + void setCertificate(const std::string& cert); /** * When the user initiates a click, we set mUserInitiatedAction to true. |