android4.0 webkit 请求网络数据的调用流程
1.
PassRefPtr<ResourceLoaderAndroid> ResourceLoaderAndroid::start(
ResourceHandle* handle, const ResourceRequest& request, FrameLoaderClient* client, bool isMainResource, bool isSync)
{
// Called on main thread
FrameLoaderClientAndroid* clientAndroid = static_cast<FrameLoaderClientAndroid*>(client);
#if USE(CHROME_NETWORK_STACK)
WebViewCore* webViewCore = WebViewCore::getWebViewCore(clientAndroid->getFrame()->view());
bool isMainFrame = !(clientAndroid->getFrame()->tree() && clientAndroid->getFrame()->tree()->parent());
return WebUrlLoader::start(client, handle, request, isMainResource, isMainFrame, isSync, webViewCore->webRequestContext());
#else
return clientAndroid->webFrame()->startLoadingResource(handle, request, isMainResource, isSync);
#endif
}
2.
PassRefPtr<WebCore::ResourceLoaderAndroid>
WebFrame::startLoadingResource(WebCore::ResourceHandle* loader,
const WebCore::ResourceRequest& request,
bool mainResource,
bool synchronous)
{
#ifdef ANDROID_INSTRUMENT
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
LOGV("::WebCore:: startLoadingResource(%p, %s)",
loader, request.url().string().latin1().data());
JNIEnv* env = getJNIEnv();
AutoJObject javaFrame = mJavaFrame->frame(env);
if (!javaFrame.get())
return 0;
WTF::String method = request.httpMethod();
WebCore::HTTPHeaderMap headers = request.httpHeaderFields();
WTF::String urlStr = request.url().string();
int colon = urlStr.find(':');
bool allLower = true;
for (int index = 0; index < colon; index++) {
UChar ch = urlStr[index];
if (!WTF::isASCIIAlpha(ch))
break;
allLower &= WTF::isASCIILower(ch);
if (index == colon - 1 && !allLower) {
urlStr = urlStr.substring(0, colon).lower()
+ urlStr.substring(colon);
}
}
LOGV("%s lower=%s", __FUNCTION__, urlStr.latin1().data());
jstring jUrlStr = wtfStringToJstring(env, urlStr);
jstring jMethodStr = NULL;
if (!method.isEmpty())
jMethodStr = wtfStringToJstring(env, method);
WebCore::FormData* formdata = request.httpBody();
jbyteArray jPostDataStr = getPostData(request);
jobject jHeaderMap = createJavaMapFromHTTPHeaders(env, headers);
// Convert the WebCore Cache Policy to a WebView Cache Policy.
int cacheMode = 0; // WebSettings.LOAD_NORMAL
switch (request.cachePolicy()) {
case WebCore::ReloadIgnoringCacheData:
cacheMode = 2; // WebSettings.LOAD_NO_CACHE
break;
case WebCore::ReturnCacheDataDontLoad:
cacheMode = 3; // WebSettings.LOAD_CACHE_ONLY
break;
case WebCore::ReturnCacheDataElseLoad:
cacheMode = 1; // WebSettings.LOAD_CACHE_ELSE_NETWORK
break;
case WebCore::UseProtocolCachePolicy:
default:
break;
}
LOGV("::WebCore:: startLoadingResource %s with cacheMode %d", urlStr.ascii().data(), cacheMode);
ResourceHandleInternal* loaderInternal = loader->getInternal();
jstring jUsernameString = loaderInternal->m_user.isEmpty() ?
NULL : wtfStringToJstring(env, loaderInternal->m_user);
jstring jPasswordString = loaderInternal->m_pass.isEmpty() ?
NULL : wtfStringToJstring(env, loaderInternal->m_pass);
bool isUserGesture = UserGestureIndicator::processingUserGesture();
jobject jLoadListener =
env->CallObjectMethod(javaFrame.get(), mJavaFrame->mStartLoadingResource,
(int)loader, jUrlStr, jMethodStr, jHeaderMap,
jPostDataStr, formdata ? formdata->identifier(): 0,
cacheMode, mainResource, isUserGesture,
synchronous, jUsernameString, jPasswordString);
env->DeleteLocalRef(jUrlStr);
env->DeleteLocalRef(jMethodStr);
env->DeleteLocalRef(jPostDataStr);
env->DeleteLocalRef(jHeaderMap);
env->DeleteLocalRef(jUsernameString);
env->DeleteLocalRef(jPasswordString);
if (checkException(env))
return 0;
PassRefPtr<WebCore::ResourceLoaderAndroid> h;
if (jLoadListener)
h = WebCoreResourceLoader::create(env, jLoadListener);
env->DeleteLocalRef(jLoadListener);
return h;
}
3.
/**
&n
补充:移动开发 , Android ,