diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 18:29:24 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 18:29:24 +0000 |
commit | 22339b123c68805c7c293c67f6f47ea45f0fd1a1 (patch) | |
tree | bb05e2e3eb0362338e921a4dce9d5c350437326e /chrome/common | |
parent | e840afdedd33728491639312a268fbf37a48f078 (diff) | |
download | chromium_src-22339b123c68805c7c293c67f6f47ea45f0fd1a1.zip chromium_src-22339b123c68805c7c293c67f6f47ea45f0fd1a1.tar.gz chromium_src-22339b123c68805c7c293c67f6f47ea45f0fd1a1.tar.bz2 |
Support sending BlobData to browser process. Also support sending UploadData
with the blob info to browser process.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3108042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57707 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/common_param_traits.cc | 114 | ||||
-rw-r--r-- | chrome/common/common_param_traits.h | 13 | ||||
-rw-r--r-- | chrome/common/render_messages.cc | 1 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 21 | ||||
-rw-r--r-- | chrome/common/webblobregistry_impl.cc | 41 | ||||
-rw-r--r-- | chrome/common/webblobregistry_impl.h | 35 |
6 files changed, 222 insertions, 3 deletions
diff --git a/chrome/common/common_param_traits.cc b/chrome/common/common_param_traits.cc index 19ef93b..f3c44c1 100644 --- a/chrome/common/common_param_traits.cc +++ b/chrome/common/common_param_traits.cc @@ -17,6 +17,7 @@ #ifndef EXCLUDE_SKIA_DEPENDENCIES #include "third_party/skia/include/core/SkBitmap.h" #endif +#include "webkit/blob/blob_data.h" #include "webkit/glue/dom_operations.h" #include "webkit/glue/password_form.h" @@ -327,11 +328,13 @@ struct ParamTraits<net::UploadData::Element> { WriteParam(m, static_cast<int>(p.type())); if (p.type() == net::UploadData::TYPE_BYTES) { m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size())); - } else { + } else if (p.type() == net::UploadData::TYPE_FILE) { WriteParam(m, p.file_path()); WriteParam(m, p.file_range_offset()); WriteParam(m, p.file_range_length()); WriteParam(m, p.expected_file_modification_time()); + } else { + WriteParam(m, p.blob_url()); } } static bool Read(const Message* m, void** iter, param_type* r) { @@ -344,8 +347,7 @@ struct ParamTraits<net::UploadData::Element> { if (!m->ReadData(iter, &data, &len)) return false; r->SetToBytes(data, len); - } else { - DCHECK(type == net::UploadData::TYPE_FILE); + } else if (type == net::UploadData::TYPE_FILE) { FilePath file_path; uint64 offset, length; base::Time expected_modification_time; @@ -359,6 +361,12 @@ struct ParamTraits<net::UploadData::Element> { return false; r->SetToFilePathRange(file_path, offset, length, expected_modification_time); + } else { + DCHECK(type == net::UploadData::TYPE_BLOB); + GURL blob_url; + if (!ReadParam(m, iter, &blob_url)) + return false; + r->SetToBlobUrl(blob_url); } return true; } @@ -401,6 +409,106 @@ void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, l->append("<net::UploadData>"); } +// Only the webkit_blob::BlobData ParamTraits<> definition needs this +// definition, so keep this in the implementation file so we can forward declare +// BlobData in the header. +template <> +struct ParamTraits<webkit_blob::BlobData::Item> { + typedef webkit_blob::BlobData::Item param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, static_cast<int>(p.type())); + if (p.type() == webkit_blob::BlobData::TYPE_DATA) { + WriteParam(m, p.data()); + } else if (p.type() == webkit_blob::BlobData::TYPE_FILE) { + WriteParam(m, p.file_path()); + WriteParam(m, p.offset()); + WriteParam(m, p.length()); + WriteParam(m, p.expected_modification_time()); + } else { + WriteParam(m, p.blob_url()); + WriteParam(m, p.offset()); + WriteParam(m, p.length()); + } + } + static bool Read(const Message* m, void** iter, param_type* r) { + int type; + if (!ReadParam(m, iter, &type)) + return false; + if (type == webkit_blob::BlobData::TYPE_DATA) { + std::string data; + if (!ReadParam(m, iter, &data)) + return false; + r->SetToData(data); + } else if (type == webkit_blob::BlobData::TYPE_FILE) { + FilePath file_path; + uint64 offset, length; + base::Time expected_modification_time; + if (!ReadParam(m, iter, &file_path)) + return false; + if (!ReadParam(m, iter, &offset)) + return false; + if (!ReadParam(m, iter, &length)) + return false; + if (!ReadParam(m, iter, &expected_modification_time)) + return false; + r->SetToFile(file_path, offset, length, expected_modification_time); + } else { + DCHECK(type == webkit_blob::BlobData::TYPE_BLOB); + GURL blob_url; + uint64 offset, length; + if (!ReadParam(m, iter, &blob_url)) + return false; + if (!ReadParam(m, iter, &offset)) + return false; + if (!ReadParam(m, iter, &length)) + return false; + r->SetToBlob(blob_url, offset, length); + } + return true; + } + static void Log(const param_type& p, std::string* l) { + l->append("<BlobData::Item>"); + } +}; + +void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Write( + Message* m, const param_type& p) { + WriteParam(m, p.get() != NULL); + if (p) { + WriteParam(m, p->items()); + WriteParam(m, p->content_type()); + WriteParam(m, p->content_disposition()); + } +} + +bool ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Read( + const Message* m, void** iter, param_type* r) { + bool has_object; + if (!ReadParam(m, iter, &has_object)) + return false; + if (!has_object) + return true; + std::vector<webkit_blob::BlobData::Item> items; + if (!ReadParam(m, iter, &items)) + return false; + std::string content_type; + if (!ReadParam(m, iter, &content_type)) + return false; + std::string content_disposition; + if (!ReadParam(m, iter, &content_disposition)) + return false; + *r = new webkit_blob::BlobData; + (*r)->swap_items(&items); + (*r)->set_content_type(content_type); + (*r)->set_content_disposition(content_disposition); + return true; +} + +void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Log( + const param_type& p, std::string* l) { + l->append("<webkit_blob::BlobData>"); +} + void ParamTraits<ThumbnailScore>::Write(Message* m, const param_type& p) { IPC::ParamTraits<double>::Write(m, p.boring_score); IPC::ParamTraits<bool>::Write(m, p.good_clipping); diff --git a/chrome/common/common_param_traits.h b/chrome/common/common_param_traits.h index da04edc..d77f15c 100644 --- a/chrome/common/common_param_traits.h +++ b/chrome/common/common_param_traits.h @@ -49,6 +49,10 @@ namespace printing { struct PageRange; } // namespace printing +namespace webkit_blob { +class BlobData; +} + namespace webkit_glue { struct PasswordForm; struct WebApplicationInfo; @@ -272,6 +276,15 @@ struct ParamTraits<scoped_refptr<net::UploadData> > { static void Log(const param_type& p, std::string* l); }; +// Traits for webkit_blob::BlobData. +template <> +struct ParamTraits<scoped_refptr<webkit_blob::BlobData> > { + typedef scoped_refptr<webkit_blob::BlobData> param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + template<> struct ParamTraits<ThumbnailScore> { typedef ThumbnailScore param_type; diff --git a/chrome/common/render_messages.cc b/chrome/common/render_messages.cc index 3e17733..1bc1116 100644 --- a/chrome/common/render_messages.cc +++ b/chrome/common/render_messages.cc @@ -21,6 +21,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h" #include "webkit/appcache/appcache_interfaces.h" +#include "webkit/blob/blob_data.h" #include "webkit/glue/context_menu.h" #include "webkit/glue/form_data.h" #include "webkit/glue/form_field.h" diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 64d5f6c..3b0a13f 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -51,6 +51,10 @@ struct ChannelHandle; class Message; } +namespace webkit_blob { +class BlobData; +} + //----------------------------------------------------------------------------- // RenderView messages // These are messages sent from the browser to the renderer process. @@ -2710,4 +2714,21 @@ IPC_BEGIN_MESSAGES(ViewHost) string16 /* src path */, string16 /* dest path */) + //--------------------------------------------------------------------------- + // Blob messages: + + // Registers a blob URL referring to the specified blob data. + IPC_MESSAGE_CONTROL2(ViewHostMsg_RegisterBlobUrl, + GURL /* url */, + scoped_refptr<webkit_blob::BlobData> /* blob_data */) + + // Registers a blob URL referring to the blob data identified by the specified + // source URL. + IPC_MESSAGE_CONTROL2(ViewHostMsg_RegisterBlobUrlFrom, + GURL /* url */, + GURL /* src_url */) + + // Unregister a blob URL. + IPC_MESSAGE_CONTROL1(ViewHostMsg_UnregisterBlobUrl, GURL /* url */) + IPC_END_MESSAGES(ViewHost) diff --git a/chrome/common/webblobregistry_impl.cc b/chrome/common/webblobregistry_impl.cc new file mode 100644 index 0000000..90bfcbf --- /dev/null +++ b/chrome/common/webblobregistry_impl.cc @@ -0,0 +1,41 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/webblobregistry_impl.h" + +#include "base/ref_counted.h" +#include "chrome/common/render_messages.h" +#include "third_party/WebKit/WebKit/chromium/public/WebBlobData.h" +#include "third_party/WebKit/WebKit/chromium/public/WebBlobStorageData.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/WebKit/chromium/public/WebURL.h" +#include "webkit/blob/blob_data.h" + +using WebKit::WebBlobData; +using WebKit::WebBlobStorageData; +using WebKit::WebString; +using WebKit::WebURL; + +WebBlobRegistryImpl::WebBlobRegistryImpl(IPC::Message::Sender* sender) + : sender_(sender) { +} + +WebBlobRegistryImpl::~WebBlobRegistryImpl() { +} + +void WebBlobRegistryImpl::registerBlobURL( + const WebURL& url, WebBlobData& data) { + scoped_refptr<webkit_blob::BlobData> blob_data( + new webkit_blob::BlobData(data)); + sender_->Send(new ViewHostMsg_RegisterBlobUrl(url, blob_data)); +} + +void WebBlobRegistryImpl::registerBlobURL( + const WebURL& url, const WebURL& src_url) { + sender_->Send(new ViewHostMsg_RegisterBlobUrlFrom(url, src_url)); +} + +void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { + sender_->Send(new ViewHostMsg_UnregisterBlobUrl(url)); +} diff --git a/chrome/common/webblobregistry_impl.h b/chrome/common/webblobregistry_impl.h new file mode 100644 index 0000000..79bd06c --- /dev/null +++ b/chrome/common/webblobregistry_impl.h @@ -0,0 +1,35 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_WEBBLOBREGISTRY_IMPL_H_ +#define CHROME_COMMON_WEBBLOBREGISTRY_IMPL_H_ +#pragma once + +#include "ipc/ipc_message.h" +#include "third_party/WebKit/WebKit/chromium/public/WebBlobRegistry.h" + +namespace WebKit { +class WebBlobData; +class WebBlobStorageData; +class WebString; +class WebURL; +} + +class WebBlobRegistryImpl : public WebKit::WebBlobRegistry { + public: + explicit WebBlobRegistryImpl(IPC::Message::Sender* sender); + virtual ~WebBlobRegistryImpl(); + + // See WebBlobRegistry.h for documentation on these functions. + virtual void registerBlobURL(const WebKit::WebURL& url, + WebKit::WebBlobData& data); + virtual void registerBlobURL(const WebKit::WebURL& url, + const WebKit::WebURL& src_url); + virtual void unregisterBlobURL(const WebKit::WebURL& url); + + private: + IPC::Message::Sender* sender_; +}; + +#endif // CHROME_COMMON_WEBBLOBREGISTRY_IMPL_H_ |