| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" |
| 12 #include "webkit/glue/webkit_glue.h" | |
| 13 | 14 |
| 14 using WebKit::WebBlobData; | 15 using WebKit::WebBlobData; |
| 15 using WebKit::WebData; | 16 using WebKit::WebData; |
| 16 using WebKit::WebString; | 17 using WebKit::WebString; |
| 17 | 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 |
| 18 namespace webkit_blob { | 37 namespace webkit_blob { |
| 19 | 38 |
| 20 BlobData::Item::Item() | 39 BlobData::Item::Item() |
| 21 : type(TYPE_DATA), | 40 : type(TYPE_DATA), |
| 22 data_external(NULL), | 41 data_external(NULL), |
| 23 offset(0), | 42 offset(0), |
| 24 length(0) { | 43 length(0) { |
| 25 } | 44 } |
| 26 | 45 |
| 27 BlobData::Item::~Item() {} | 46 BlobData::Item::~Item() {} |
| 28 | 47 |
| 29 BlobData::BlobData() {} | 48 BlobData::BlobData() {} |
| 30 | 49 |
| 31 BlobData::BlobData(const WebBlobData& data) { | 50 BlobData::BlobData(const WebBlobData& data) { |
| 32 size_t i = 0; | 51 size_t i = 0; |
| 33 WebBlobData::Item item; | 52 WebBlobData::Item item; |
| 34 while (data.itemAt(i++, item)) { | 53 while (data.itemAt(i++, item)) { |
| 35 switch (item.type) { | 54 switch (item.type) { |
| 36 case WebBlobData::Item::TypeData: | 55 case WebBlobData::Item::TypeData: |
| 37 if (!item.data.isEmpty()) { | 56 if (!item.data.isEmpty()) { |
| 38 // WebBlobData does not allow partial data. | 57 // WebBlobData does not allow partial data. |
| 39 DCHECK(!item.offset && item.length == -1); | 58 DCHECK(!item.offset && item.length == -1); |
| 40 AppendData(item.data); | 59 AppendData(item.data); |
| 41 } | 60 } |
| 42 break; | 61 break; |
| 43 case WebBlobData::Item::TypeFile: | 62 case WebBlobData::Item::TypeFile: |
| 44 AppendFile( | 63 AppendFile( |
| 45 webkit_glue::WebStringToFilePath(item.filePath), | 64 WebStringToFilePath(item.filePath), |
| 46 static_cast<uint64>(item.offset), | 65 static_cast<uint64>(item.offset), |
| 47 static_cast<uint64>(item.length), | 66 static_cast<uint64>(item.length), |
| 48 base::Time::FromDoubleT(item.expectedModificationTime)); | 67 base::Time::FromDoubleT(item.expectedModificationTime)); |
| 49 break; | 68 break; |
| 50 case WebBlobData::Item::TypeBlob: | 69 case WebBlobData::Item::TypeBlob: |
| 51 if (item.length) { | 70 if (item.length) { |
| 52 AppendBlob( | 71 AppendBlob( |
| 53 item.blobURL, | 72 item.blobURL, |
| 54 static_cast<uint64>(item.offset), | 73 static_cast<uint64>(item.offset), |
| 55 static_cast<uint64>(item.length)); | 74 static_cast<uint64>(item.length)); |
| 56 } | 75 } |
| 57 break; | 76 break; |
| 58 default: | 77 default: |
| 59 NOTREACHED(); | 78 NOTREACHED(); |
| 60 } | 79 } |
| 61 } | 80 } |
| 62 content_type_= data.contentType().utf8().data(); | 81 content_type_= data.contentType().utf8().data(); |
| 63 content_disposition_ = data.contentDisposition().utf8().data(); | 82 content_disposition_ = data.contentDisposition().utf8().data(); |
| 64 } | 83 } |
| 65 | 84 |
| 66 BlobData::~BlobData() {} | 85 BlobData::~BlobData() {} |
| 67 | 86 |
| 68 } // namespace webkit_blob | 87 } // namespace webkit_blob |
| OLD | NEW |