OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/webblobregistry_impl.h" | 5 #include "content/common/webblobregistry_impl.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "content/common/webblob_messages.h" | 8 #include "content/common/webblob_messages.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
12 #include "webkit/blob/blob_data.h" | 12 #include "webkit/blob/blob_data.h" |
| 13 #include "webkit/glue/webkit_glue.h" |
13 | 14 |
14 using WebKit::WebBlobData; | 15 using WebKit::WebBlobData; |
15 using WebKit::WebString; | 16 using WebKit::WebString; |
16 using WebKit::WebURL; | 17 using WebKit::WebURL; |
17 | 18 |
18 WebBlobRegistryImpl::WebBlobRegistryImpl(IPC::Message::Sender* sender) | 19 WebBlobRegistryImpl::WebBlobRegistryImpl(IPC::Message::Sender* sender) |
19 : sender_(sender) { | 20 : sender_(sender) { |
20 } | 21 } |
21 | 22 |
22 WebBlobRegistryImpl::~WebBlobRegistryImpl() { | 23 WebBlobRegistryImpl::~WebBlobRegistryImpl() { |
23 } | 24 } |
24 | 25 |
25 void WebBlobRegistryImpl::registerBlobURL( | 26 void WebBlobRegistryImpl::registerBlobURL( |
26 const WebURL& url, WebBlobData& data) { | 27 const WebURL& url, WebBlobData& data) { |
27 scoped_refptr<webkit_blob::BlobData> blob_data( | 28 sender_->Send(new BlobHostMsg_RegisterUnfinalizedBlobUrl(url)); |
28 new webkit_blob::BlobData(data)); | 29 size_t i = 0; |
29 sender_->Send(new BlobHostMsg_RegisterBlobUrl(url, blob_data)); | 30 WebBlobData::Item data_item; |
| 31 while (data.itemAt(i++, data_item)) { |
| 32 webkit_blob::BlobData::Item item; |
| 33 switch (data_item.type) { |
| 34 case WebBlobData::Item::TypeData: { |
| 35 // WebBlobData does not allow partial data. |
| 36 DCHECK(!data_item.offset && data_item.length == -1); |
| 37 const size_t kMaxDataChunkSize = 5 * 1024 * 1024; |
| 38 size_t data_size = data_item.data.size(); |
| 39 const char* data_ptr = data_item.data.data(); |
| 40 while (data_size) { |
| 41 int chunk_size = static_cast<int>( |
| 42 std::min(data_size, kMaxDataChunkSize)); |
| 43 item.SetToData(data_ptr, chunk_size); |
| 44 data_size -= chunk_size; |
| 45 data_ptr += chunk_size; |
| 46 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); |
| 47 } |
| 48 break; |
| 49 } |
| 50 case WebBlobData::Item::TypeFile: |
| 51 item.SetToFile( |
| 52 webkit_glue::WebStringToFilePath(data_item.filePath), |
| 53 static_cast<uint64>(data_item.offset), |
| 54 static_cast<uint64>(data_item.length), |
| 55 base::Time::FromDoubleT(data_item.expectedModificationTime)); |
| 56 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); |
| 57 break; |
| 58 case WebBlobData::Item::TypeBlob: |
| 59 if (data_item.length) { |
| 60 item.SetToBlob( |
| 61 data_item.blobURL, |
| 62 static_cast<uint64>(data_item.offset), |
| 63 static_cast<uint64>(data_item.length)); |
| 64 } |
| 65 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); |
| 66 break; |
| 67 default: |
| 68 NOTREACHED(); |
| 69 } |
| 70 } |
| 71 sender_->Send(new BlobHostMsg_FinalizeBlob( |
| 72 url, data.contentType().utf8().data())); |
30 } | 73 } |
31 | 74 |
32 void WebBlobRegistryImpl::registerBlobURL( | 75 void WebBlobRegistryImpl::registerBlobURL( |
33 const WebURL& url, const WebURL& src_url) { | 76 const WebURL& url, const WebURL& src_url) { |
34 sender_->Send(new BlobHostMsg_RegisterBlobUrlFrom(url, src_url)); | 77 sender_->Send(new BlobHostMsg_RegisterBlobUrlFrom(url, src_url)); |
35 } | 78 } |
36 | 79 |
37 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { | 80 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { |
38 sender_->Send(new BlobHostMsg_UnregisterBlobUrl(url)); | 81 sender_->Send(new BlobHostMsg_UnregisterBlobUrl(url)); |
39 } | 82 } |
OLD | NEW |