OSDN Git Service

Add/expose postdata identifier so that when we cache
authorGrace Kloba <klobag@google.com>
Mon, 9 Nov 2009 02:45:44 +0000 (18:45 -0800)
committerGrace Kloba <klobag@google.com>
Mon, 9 Nov 2009 02:45:44 +0000 (18:45 -0800)
the post data, we can distinguish them.

add identifier to postUrl().

add identifier when we check whether the post data
can be loaded from cache.

Fix http://b/issue?id=1980031

WebCore/platform/network/android/ResourceHandleAndroid.cpp
WebKit/android/jni/WebCoreFrameBridge.cpp
WebKit/android/jni/WebCoreResourceLoader.cpp
WebKit/android/jni/WebCoreResourceLoader.h
WebKit/android/jni/WebHistory.cpp

index 8da2446..8a9f689 100644 (file)
@@ -98,7 +98,8 @@ bool ResourceHandle::willLoadFromCache(ResourceRequest& request, Frame*)
     // set the cache policy correctly, copied from
     // network/mac/ResourceHandleMac.mm
     request.setCachePolicy(ReturnCacheDataDontLoad);
-    return WebCoreResourceLoader::willLoadFromCache(request.url());
+    FormData* formData = request.httpBody();
+    return WebCoreResourceLoader::willLoadFromCache(request.url(), formData ? formData->identifier() : 0);
 }
 
 bool ResourceHandle::loadsBlocked() 
index 0675bcb..541e878 100644 (file)
@@ -28,6 +28,7 @@
 #include <config.h>
 
 #include <wtf/Platform.h>
+#include <wtf/CurrentTime.h>
 
 #include "android_graphics.h"
 #include "Arena.h"
@@ -169,7 +170,7 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page*
     mJavaFrame->mObj = adoptGlobalRef(env, obj);
     mJavaFrame->mHistoryList = adoptGlobalRef(env, historyList);
     mJavaFrame->mStartLoadingResource = env->GetMethodID(clazz, "startLoadingResource",
-            "(ILjava/lang/String;Ljava/lang/String;Ljava/util/HashMap;[BIZ)Landroid/webkit/LoadListener;");
+            "(ILjava/lang/String;Ljava/lang/String;Ljava/util/HashMap;[BJIZ)Landroid/webkit/LoadListener;");
     mJavaFrame->mLoadStarted = env->GetMethodID(clazz, "loadStarted",
             "(Ljava/lang/String;Landroid/graphics/Bitmap;IZ)V");
     mJavaFrame->mTransitionToCommitted = env->GetMethodID(clazz, "transitionToCommitted",
@@ -441,7 +442,8 @@ WebFrame::startLoadingResource(WebCore::ResourceHandle* loader,
     jobject jLoadListener =
         env->CallObjectMethod(obj.get(), mJavaFrame->mStartLoadingResource,
                                               (int)loader, jUrlStr, jMethodStr, jHeaderMap,
-                                              jPostDataStr, cacheMode, synchronous);
+                                              jPostDataStr, formdata ? formdata->identifier(): 0,
+                                              cacheMode, synchronous);
 
     env->DeleteLocalRef(jUrlStr);
     env->DeleteLocalRef(jMethodStr);
@@ -1000,7 +1002,11 @@ static void PostUrl(JNIEnv *env, jobject obj, jstring url, jbyteArray postData)
     if (postData) {
         jsize size = env->GetArrayLength(postData);
         jbyte* bytes = env->GetByteArrayElements(postData, NULL);
-        request.setHTTPBody(WebCore::FormData::create((const void*)bytes, size));
+        RefPtr<FormData> formData = FormData::create((const void*)bytes, size);
+        // the identifier uses the same logic as generateFormDataIdentifier() in
+        // HTMLFormElement.cpp
+        formData->setIdentifier(static_cast<int64_t>(WTF::currentTime() * 1000000.0));
+        request.setHTTPBody(formData);
         env->ReleaseByteArrayElements(postData, bytes, 0);
     }
 
index 1b40eb6..0891323 100644 (file)
@@ -100,14 +100,14 @@ void WebCoreResourceLoader::downloadFile()
 * the cache. This may be slow, but is only used during a navigation to
 * a POST response.
 */
-bool WebCoreResourceLoader::willLoadFromCache(const WebCore::KURL& url)
+bool WebCoreResourceLoader::willLoadFromCache(const WebCore::KURL& url, int64_t identifier)
 {
     JNIEnv* env = JSC::Bindings::getJNIEnv();
     WebCore::String urlStr = url.string();
     jstring jUrlStr = env->NewString(urlStr.characters(), urlStr.length());
     jclass resourceLoader = env->FindClass("android/webkit/LoadListener");
     bool val = env->CallStaticBooleanMethod(resourceLoader, 
-            gResourceLoader.mWillLoadFromCacheMethodID, jUrlStr);
+            gResourceLoader.mWillLoadFromCacheMethodID, jUrlStr, identifier);
     checkException(env);
     env->DeleteLocalRef(jUrlStr);
 
@@ -318,7 +318,7 @@ int register_resource_loader(JNIEnv* env)
         "Could not find method downloadFile on LoadListener");
 
     gResourceLoader.mWillLoadFromCacheMethodID = 
-        env->GetStaticMethodID(resourceLoader, "willLoadFromCache", "(Ljava/lang/String;)Z");
+        env->GetStaticMethodID(resourceLoader, "willLoadFromCache", "(Ljava/lang/String;J)Z");
     LOG_FATAL_IF(gResourceLoader.mWillLoadFromCacheMethodID == NULL, 
         "Could not find static method willLoadFromCache on LoadListener");
 
index 60c0d0e..7ea1107 100644 (file)
@@ -53,7 +53,7 @@ public:
     /**
     * Call to java to find out if this URL is in the cache
     */
-    static bool willLoadFromCache(const WebCore::KURL& url);
+    static bool willLoadFromCache(const WebCore::KURL& url, int64_t identifier);
 
     // Native jni functions
     static void SetResponseHeader(JNIEnv*, jobject, jint, jstring, jstring);
index d7aacfb..bed0e84 100644 (file)
@@ -420,9 +420,12 @@ static void write_item(WTF::Vector<char>& v, WebCore::HistoryItem* item)
 
     // Form data
     const WebCore::FormData* formData = item->formData();
-    if (formData)
+    if (formData) {
         write_string(v, formData->flattenToString());
-    else
+        // save the identifier as it is not included in the flatten data
+        int64_t id = formData->identifier();
+        v.append((char*)&id, sizeof(int64_t));
+    } else
         write_string(v, WebCore::String()); // Empty constructor does not allocate a buffer.
 
     // Target
@@ -573,6 +576,15 @@ static bool read_item_recursive(WebCore::HistoryItem* newItem,
         else
             return false;
         data += l;
+        // Read the identifier
+        {
+            int64_t id;
+            int size = (int)sizeof(int64_t);
+            memcpy(&id, data, size);
+            data += size;
+            if (id)
+                formData->setIdentifier(id);
+        }
     }
     if (end - data < sizeofUnsigned)
         return false;