最近对android的webkit的cookies进行学习,下面是我的简单总结:
1,CookiesManager.java-->CookiesSyncManager.java-->WebviewDatabases.java
CookiesManager.java是对cookies的总体管理,它会调用CookiesSyncManager将Ram里面的Cookies存入到databases.所以CookiesSyncManager是对将cookies同步到database的管理,而WebviewDatabases里面的Webview.db的cookies表是对cookies的存储。
2,CookiesSyncManager.java-->WebSyncManager.java
CookiesSyncManager里面正在维护cookies从ram到databases的是WebSyncManager来做的,这里面是开一个thread来维护。
3,JWebCoreJavaBridge.java-->CookiesSyncManager.java
CookiesManager是对cookies的总体管理,那ram的cookies首先是这里传递给CookiesSyncManager的。那个CookiesManager的ram cookies又是从何处得来的呢?那就是从JWebCoreJavaBridge得到的。
private void setCookies(String url, String docUrl, String value) {
if (value.contains("\r") || value.contains("\n")) {
// for security reason, filter out '\r' and '\n' from the cookie
int size = value.length();
StringBuilder buffer = new StringBuilder(size);
int i = 0;
while (i != -1 && i < size) {
int ir = value.indexOf('\r', i);
int in = value.indexOf('\n', i);
int newi = (ir == -1) ? in : (in == -1 ? ir : (ir < in ? ir
: in));
if (newi > i) {
buffer.append(value.subSequence(i, newi));
} else if (newi == -1) {
buffer.append(value.subSequence(i, size));
break;
}
i = newi + 1;
}
value = buffer.toString();
}
CookieManager.getInstance().setCookie(url, value);
}
CookieManager.getInstance().setCookie(url, value);
4,JavaBridge.cpp-->JWebCoreJavaBridge.java
JWebCoreJavaBridge的cookies是从JavaBridge.cpp得来的
void
JavaBridge::setCookies(WebCore::KURL const& url, WebCore::KURL const& docUrl, WebCore::String const& value)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
const WebCore::String& urlStr = url.string();
jstring jUrlStr = env->NewString(urlStr.characters(), urlStr.length());
const WebCore::String& docUrlStr = docUrl.string();
jstring jDocUrlStr = env->NewString(docUrlStr.characters(), docUrlStr.length());
jstring jValueStr = env->NewString(value.characters(), value.length());
AutoJObject obj = getRealObject(env, mJavaObject);
env->CallVoidMethod(obj.get(), mSetCookies, jUrlStr, jDocUrlStr, jValueStr);
env->DeleteLocalRef(jUrlStr);
env->DeleteLocalRef(jDocUrlStr);
env->DeleteLocalRef(jValueStr);
}
mSetCookies = env->GetMethodID(clazz, "setCookies", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
env->CallVoidMethod(obj.get(), mSetCookies, jUrlStr, jDocUrlStr, jValueStr);
5,CookieClient.h-->JavaBridge.cpp
JavaBridger.cpp是继承CookiesClient
6,Cookies.cpp-->CookiesClien.h
就分析到这里,就没往下追了,有空我继续分析。