diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-25 19:55:08 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-25 19:55:08 +0000 |
commit | ccf1ac4398aeb300bc3c005640aaf57500488e2d (patch) | |
tree | 35eadc64a003ec79f2fc77924f5b92928cede2d0 /webkit | |
parent | 059292e77d7fcfbf930ccb8cafdaaadd7a505a2e (diff) | |
download | chromium_src-ccf1ac4398aeb300bc3c005640aaf57500488e2d.zip chromium_src-ccf1ac4398aeb300bc3c005640aaf57500488e2d.tar.gz chromium_src-ccf1ac4398aeb300bc3c005640aaf57500488e2d.tar.bz2 |
Chrome changes to support cached form submissions.
The solution is to add a user-defined identifier to UploadData.
If that identifier is set, and if the request method is POST,
then HttpCache will enable caching for the response. (The cache
key will be a composition of the identifier and the URL.) A
subsequent POST request to the same URL with the same identifier
will "hit" the previously generated cache entry. Reuse from the
cache is subject to all of the standard rules.
For reference, here are the corresponding net changes:
http://codereview.chromium.org/52028
Here are the corresponding WebKit changes:
http://trac.webkit.org/changeset/41919
BUG=2636
R=sky
Review URL: http://codereview.chromium.org/52040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12485 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/glue_serialize.cc | 27 | ||||
-rw-r--r-- | webkit/glue/resource_handle_impl.cc | 1 | ||||
-rw-r--r-- | webkit/glue/resource_loader_bridge.h | 5 | ||||
-rw-r--r-- | webkit/glue/weburlrequest_impl.cc | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_resource_loader_bridge.cc | 7 |
5 files changed, 36 insertions, 8 deletions
diff --git a/webkit/glue/glue_serialize.cc b/webkit/glue/glue_serialize.cc index ecf6879..15f82c5 100644 --- a/webkit/glue/glue_serialize.cc +++ b/webkit/glue/glue_serialize.cc @@ -45,8 +45,9 @@ struct SerializeObject { // data, but not vice versa. // 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(). // Should be const, but unit tests may modify it. -int kVersion = 3; +int kVersion = 4; // A bunch of convenience functions to read/write to SerializeObjects. // The serializers assume the input data is in the correct format and so does @@ -76,11 +77,21 @@ inline void WriteInteger(int data, SerializeObject* obj) { } inline int ReadInteger(const SerializeObject* obj) { - int tmp; + int tmp = 0; obj->pickle.ReadInt(&obj->iter, &tmp); return tmp; } +inline void WriteInteger64(int64 data, SerializeObject* obj) { + obj->pickle.WriteInt64(data); +} + +inline int64 ReadInteger64(const SerializeObject* obj) { + int64 tmp = 0; + obj->pickle.ReadInt64(&obj->iter, &tmp); + return tmp; +} + inline void WriteReal(double data, SerializeObject* obj) { WriteData(&data, sizeof(double), obj); } @@ -124,8 +135,8 @@ inline void WriteString(const String& data, SerializeObject* obj) { data.length() * sizeof(UChar)); } break; - case 3: - // Version 3 writes <length in bytes><string data>. + default: + // Version 3+ writes <length in bytes><string data>. // It uses -1 in the length field to mean String(). if (data.isNull()) { obj->pickle.WriteInt(-1); @@ -135,9 +146,6 @@ inline void WriteString(const String& data, SerializeObject* obj) { data.length() * sizeof(UChar)); } break; - default: - NOTREACHED(); - break; } } @@ -199,6 +207,7 @@ static void WriteFormData(const FormData* form_data, SerializeObject* obj) { WriteString(e.m_filename, obj); } } + WriteInteger64(form_data->identifier(), obj); } static PassRefPtr<FormData> ReadFormData(const SerializeObject* obj) { @@ -219,6 +228,8 @@ static PassRefPtr<FormData> ReadFormData(const SerializeObject* obj) { form_data->appendFile(ReadString(obj)); } } + if (obj->version >= 4) + form_data->setIdentifier(ReadInteger64(obj)); return form_data.release(); } @@ -264,7 +275,7 @@ static PassRefPtr<HistoryItem> ReadHistoryItem(const SerializeObject* obj) { // See note in WriteHistoryItem. on this. obj->version = ReadInteger(obj); - if (obj->version > kVersion) + if (obj->version > kVersion || obj->version < 1) return NULL; RefPtr<HistoryItem> item = HistoryItem::create(); diff --git a/webkit/glue/resource_handle_impl.cc b/webkit/glue/resource_handle_impl.cc index 99290d3..fbf6379 100644 --- a/webkit/glue/resource_handle_impl.cc +++ b/webkit/glue/resource_handle_impl.cc @@ -451,6 +451,7 @@ bool ResourceHandleInternal::Start( webkit_glue::StringToStdWString(e.m_filename)); } } + bridge_->SetUploadIdentifier(request_.httpBody()->identifier()); } if (sync_load_response) { diff --git a/webkit/glue/resource_loader_bridge.h b/webkit/glue/resource_loader_bridge.h index 161c237..0740f54 100644 --- a/webkit/glue/resource_loader_bridge.h +++ b/webkit/glue/resource_loader_bridge.h @@ -200,6 +200,11 @@ class ResourceLoaderBridge { virtual void AppendFileRangeToUpload(const std::wstring& file_path, uint64 offset, uint64 length) = 0; + // Call this method before calling Start() to assign an upload identifier to + // this request. This is used to enable caching of POST responses. A value + // of 0 implies the unspecified identifier. + virtual void SetUploadIdentifier(int64 identifier) = 0; + // Call this method to initiate the request. If this method succeeds, then // the peer's methods will be called asynchronously to report various events. virtual bool Start(Peer* peer) = 0; diff --git a/webkit/glue/weburlrequest_impl.cc b/webkit/glue/weburlrequest_impl.cc index 9a06f92..cf30f7e3 100644 --- a/webkit/glue/weburlrequest_impl.cc +++ b/webkit/glue/weburlrequest_impl.cc @@ -177,6 +177,8 @@ void WebRequestImpl::GetUploadData(net::UploadData* data) const { NOTREACHED(); } } + + data->set_identifier(formdata->identifier()); } void WebRequestImpl::SetUploadData(const net::UploadData& data) @@ -199,6 +201,8 @@ void WebRequestImpl::SetUploadData(const net::UploadData& data) } } + formdata->setIdentifier(data.identifier()); + request_.resourceRequest().setHTTPBody(formdata); } diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc index a714c10..79420ba 100644 --- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc +++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc @@ -464,6 +464,13 @@ class ResourceLoaderBridgeImpl : public ResourceLoaderBridge { params_->upload->AppendFileRange(file_path, offset, length); } + virtual void SetUploadIdentifier(int64 identifier) { + DCHECK(params_.get()); + if (!params_->upload) + params_->upload = new net::UploadData(); + params_->upload->set_identifier(identifier); + } + virtual bool Start(Peer* peer) { DCHECK(!proxy_); |