From f480367d1f52722c41fd2c8f7b79084088356b34 Mon Sep 17 00:00:00 2001 From: "darin@chromium.org" Date: Fri, 27 Mar 2009 21:45:30 +0000 Subject: Add support for serializing a FormData structure that has no elements. This is important for supporting cached form submissions of empty data, which occurs with some sites like Gmail. R=sky Review URL: http://codereview.chromium.org/56011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12711 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/glue/glue_serialize.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'webkit/glue/glue_serialize.cc') diff --git a/webkit/glue/glue_serialize.cc b/webkit/glue/glue_serialize.cc index 60eab9f9..0850e1b 100644 --- a/webkit/glue/glue_serialize.cc +++ b/webkit/glue/glue_serialize.cc @@ -46,8 +46,9 @@ struct SerializeObject { // 3: Version 2 was broken, it stored number of UChars, not number of bytes. // This version checks and reads v1 and v2 correctly. // 4: Adds support for storing FormData::identifier(). +// 5: Adds support for empty FormData // Should be const, but unit tests may modify it. -int kVersion = 4; +int kVersion = 5; // A bunch of convenience functions to read/write to SerializeObjects. // The serializers assume the input data is in the correct format and so does @@ -191,10 +192,10 @@ static void ReadStringVector(const SerializeObject* obj, Vector* data) { // Writes a FormData object into a SerializeObject for serialization. static void WriteFormData(const FormData* form_data, SerializeObject* obj) { - if (form_data == NULL) { - WriteInteger(0, obj); + WriteBoolean(form_data != NULL, obj); + + if (!form_data) return; - } WriteInteger(static_cast(form_data->elements().size()), obj); for (size_t i = 0, c = form_data->elements().size(); i < c; ++i) { @@ -211,8 +212,13 @@ static void WriteFormData(const FormData* form_data, SerializeObject* obj) { } static PassRefPtr ReadFormData(const SerializeObject* obj) { + // In newer versions, an initial boolean indicates if we have form data. + if (obj->version >= 5 && !ReadBoolean(obj)) + return NULL; + + // In older versions, 0 elements implied no form data. int num_elements = ReadInteger(obj); - if (num_elements == 0) + if (num_elements == 0 && obj->version < 5) return NULL; RefPtr form_data = FormData::create(); -- cgit v1.1