: m_webFrame(webFrame)
, m_resourceHandle(resourceHandle)
, m_isMainResource(false)
+ , m_isCertMimeType(false)
, m_cancelling(false)
, m_sync(false)
, m_finished(false)
return true;
}
+namespace {
+// Check if the mime type is for certificate installation.
+// The items must be consistent with the sCertificateTypeMap
+// in frameworks/base/core/java/android/webkit/CertTool.java.
+bool isMimeTypeForCert(const std::string& mimeType)
+{
+ static std::hash_set<std::string> sCertificateTypeSet;
+ if (sCertificateTypeSet.empty()) {
+ sCertificateTypeSet.insert("application/x-x509-ca-cert");
+ sCertificateTypeSet.insert("application/x-x509-user-cert");
+ sCertificateTypeSet.insert("application/x-pkcs12");
+ }
+ return sCertificateTypeSet.find(mimeType) != sCertificateTypeSet.end();
+}
+}
+
void WebUrlLoaderClient::downloadFile()
{
if (m_response) {
std::string contentDisposition;
m_response->getHeader("content-disposition", &contentDisposition);
m_webFrame->downloadStart(m_request->getUrl(), m_request->getUserAgent(), contentDisposition, m_response->getMimeType(), m_response->getExpectedSize());
+
+ m_isCertMimeType = isMimeTypeForCert(m_response->getMimeType());
+ // Currently, only certificate mime type needs to receive the data.
+ // Other mime type, e.g. wav, will send the url to other application
+ // which will load the data by url.
+ if (!m_isCertMimeType)
+ cancel();
} else {
LOGE("Unexpected call to downloadFile() before didReceiveResponse(). URL: %s", m_request->getUrl().c_str());
// TODO: Turn off asserts crashing before release
void WebUrlLoaderClient::didReceiveData(scoped_refptr<net::IOBuffer> buf, int size)
{
+ if (m_isMainResource && m_isCertMimeType) {
+ m_webFrame->didReceiveData(buf->data(), size);
+ }
+
if (!isActive() || !size)
return;
if (isActive())
m_resourceHandle->client()->didFinishLoading(m_resourceHandle.get(), 0);
+ if (m_isMainResource && m_isCertMimeType) {
+ m_webFrame->didFinishLoading();
+ }
+
// Always finish a request, if not it will leak
finish();
}
jmethodID mDidReceiveAuthenticationChallenge;
jmethodID mReportSslCertError;
jmethodID mDownloadStart;
+ jmethodID mDidReceiveData;
+ jmethodID mDidFinishLoading;
jmethodID mSetCertificate;
AutoJObject frame(JNIEnv* env) {
return getRealObject(env, mObj);
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");
+ 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");
env->DeleteLocalRef(clazz);
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");
+ LOG_ASSERT(mJavaFrame->mDidReceiveData, "Could not find method didReceiveData");
+ LOG_ASSERT(mJavaFrame->mDidFinishLoading, "Could not find method didFinishLoading");
LOG_ASSERT(mJavaFrame->mSetCertificate, "Could not find method setCertificate");
mUserAgent = WTF::String();
env->DeleteLocalRef(jMimetype);
checkException(env);
}
+
+void
+WebFrame::didReceiveData(const char* data, int size) {
+#ifdef ANDROID_INSTRUMENT
+ TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
+#endif
+ JNIEnv* env = getJNIEnv();
+
+ jbyteArray jData = env->NewByteArray(size);
+ jbyte* bytes = env->GetByteArrayElements(jData, NULL);
+ memcpy(reinterpret_cast<char*>(bytes), data, size);
+
+ env->CallVoidMethod(mJavaFrame->frame(env).get(),
+ mJavaFrame->mDidReceiveData, jData, size);
+ env->DeleteLocalRef(jData);
+ checkException(env);
+}
+
+void
+WebFrame::didFinishLoading() {
+#ifdef ANDROID_INSTRUMENT
+ TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
+#endif
+ JNIEnv* env = getJNIEnv();
+
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mDidFinishLoading);
+ checkException(env);
+}
+
#endif
#if USE(CHROME_NETWORK_STACK)