| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/blob/blob_data.h" | 5 #include "webkit/blob/blob_data.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebBlobData.
h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" | |
| 14 | |
| 15 using WebKit::WebBlobData; | |
| 16 using WebKit::WebData; | |
| 17 using WebKit::WebString; | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // TODO(dpranke): These two functions are cloned from webkit_glue | |
| 22 // to avoid a dependency on that library. This should be fixed. | |
| 23 FilePath::StringType WebStringToFilePathString(const WebString& str) { | |
| 24 #if defined(OS_POSIX) | |
| 25 return base::SysWideToNativeMB(UTF16ToWideHack(str)); | |
| 26 #elif defined(OS_WIN) | |
| 27 return UTF16ToWideHack(str); | |
| 28 #endif | |
| 29 } | |
| 30 | |
| 31 FilePath WebStringToFilePath(const WebString& str) { | |
| 32 return FilePath(WebStringToFilePathString(str)); | |
| 33 } | |
| 34 | |
| 35 } | |
| 36 | 11 |
| 37 namespace webkit_blob { | 12 namespace webkit_blob { |
| 38 | 13 |
| 39 BlobData::Item::Item() | 14 BlobData::Item::Item() |
| 40 : type(TYPE_DATA), | 15 : type(TYPE_DATA), |
| 41 data_external(NULL), | 16 data_external(NULL), |
| 42 offset(0), | 17 offset(0), |
| 43 length(0) { | 18 length(0) { |
| 44 } | 19 } |
| 45 | 20 |
| 46 BlobData::Item::~Item() {} | 21 BlobData::Item::~Item() {} |
| 47 | 22 |
| 48 BlobData::BlobData() {} | 23 BlobData::BlobData() {} |
| 49 | 24 |
| 50 BlobData::BlobData(const WebBlobData& data) { | |
| 51 size_t i = 0; | |
| 52 WebBlobData::Item item; | |
| 53 while (data.itemAt(i++, item)) { | |
| 54 switch (item.type) { | |
| 55 case WebBlobData::Item::TypeData: | |
| 56 if (!item.data.isEmpty()) { | |
| 57 // WebBlobData does not allow partial data. | |
| 58 DCHECK(!item.offset && item.length == -1); | |
| 59 AppendData(item.data); | |
| 60 } | |
| 61 break; | |
| 62 case WebBlobData::Item::TypeFile: | |
| 63 if (item.length) { | |
| 64 AppendFile( | |
| 65 WebStringToFilePath(item.filePath), | |
| 66 static_cast<uint64>(item.offset), | |
| 67 static_cast<uint64>(item.length), | |
| 68 base::Time::FromDoubleT(item.expectedModificationTime)); | |
| 69 } | |
| 70 break; | |
| 71 case WebBlobData::Item::TypeBlob: | |
| 72 if (item.length) { | |
| 73 AppendBlob( | |
| 74 item.blobURL, | |
| 75 static_cast<uint64>(item.offset), | |
| 76 static_cast<uint64>(item.length)); | |
| 77 } | |
| 78 break; | |
| 79 default: | |
| 80 NOTREACHED(); | |
| 81 } | |
| 82 } | |
| 83 content_type_= data.contentType().utf8().data(); | |
| 84 content_disposition_ = data.contentDisposition().utf8().data(); | |
| 85 } | |
| 86 | |
| 87 BlobData::~BlobData() {} | 25 BlobData::~BlobData() {} |
| 88 | 26 |
| 89 void BlobData::AppendData(const char* data, size_t length) { | 27 void BlobData::AppendData(const char* data, size_t length) { |
| 90 DCHECK(length > 0); | 28 DCHECK(length > 0); |
| 91 items_.push_back(Item()); | 29 items_.push_back(Item()); |
| 92 items_.back().SetToData(data, length); | 30 items_.back().SetToData(data, length); |
| 93 } | 31 } |
| 94 | 32 |
| 95 void BlobData::AppendFile(const FilePath& file_path, uint64 offset, | 33 void BlobData::AppendFile(const FilePath& file_path, uint64 offset, |
| 96 uint64 length, | 34 uint64 length, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 111 int64 memory = 0; | 49 int64 memory = 0; |
| 112 for (std::vector<Item>::const_iterator iter = items_.begin(); | 50 for (std::vector<Item>::const_iterator iter = items_.begin(); |
| 113 iter != items_.end(); ++iter) { | 51 iter != items_.end(); ++iter) { |
| 114 if (iter->type == TYPE_DATA) | 52 if (iter->type == TYPE_DATA) |
| 115 memory += iter->data.size(); | 53 memory += iter->data.size(); |
| 116 } | 54 } |
| 117 return memory; | 55 return memory; |
| 118 } | 56 } |
| 119 | 57 |
| 120 } // namespace webkit_blob | 58 } // namespace webkit_blob |
| OLD | NEW |