1 /* 2 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include "config.h" 32 33 #include "core/platform/network/BlobData.h" 34 #include "public/platform/WebBlobData.h" 35 #include "wtf/PassOwnPtr.h" 36 37 using namespace WebCore; 38 39 namespace WebKit { 40 41 class WebBlobDataPrivate : public BlobData { 42 }; 43 44 void WebBlobData::initialize() 45 { 46 assign(BlobData::create()); 47 } 48 49 void WebBlobData::reset() 50 { 51 assign(nullptr); 52 } 53 54 size_t WebBlobData::itemCount() const 55 { 56 ASSERT(!isNull()); 57 return m_private->items().size(); 58 } 59 60 bool WebBlobData::itemAt(size_t index, Item& result) const 61 { 62 ASSERT(!isNull()); 63 64 if (index >= m_private->items().size()) 65 return false; 66 67 const BlobDataItem& item = m_private->items()[index]; 68 result.data.reset(); 69 result.filePath.reset(); 70 result.blobURL = KURL(); 71 result.offset = item.offset; 72 result.length = item.length; 73 result.expectedModificationTime = item.expectedModificationTime; 74 75 switch (item.type) { 76 case BlobDataItem::Data: 77 result.type = Item::TypeData; 78 result.data = item.data; 79 return true; 80 case BlobDataItem::File: 81 result.type = Item::TypeFile; 82 result.filePath = item.path; 83 return true; 84 case BlobDataItem::Blob: 85 result.type = Item::TypeBlob; 86 result.blobURL = item.url; // FIXME: deprecate this. 87 result.url = item.url; 88 return true; 89 case BlobDataItem::URL: 90 result.type = Item::TypeURL; 91 result.url = item.url; 92 return true; 93 } 94 ASSERT_NOT_REACHED(); 95 return false; 96 } 97 98 WebString WebBlobData::contentType() const 99 { 100 ASSERT(!isNull()); 101 return m_private->contentType(); 102 } 103 104 WebString WebBlobData::contentDisposition() const 105 { 106 ASSERT(!isNull()); 107 return m_private->contentDisposition(); 108 } 109 110 WebBlobData::WebBlobData(const PassOwnPtr<BlobData>& data) 111 : m_private(0) 112 { 113 assign(data); 114 } 115 116 WebBlobData& WebBlobData::operator=(const PassOwnPtr<BlobData>& data) 117 { 118 assign(data); 119 return *this; 120 } 121 122 WebBlobData::operator PassOwnPtr<BlobData>() 123 { 124 WebBlobDataPrivate* temp = m_private; 125 m_private = 0; 126 return adoptPtr(temp); 127 } 128 129 void WebBlobData::assign(const PassOwnPtr<BlobData>& data) 130 { 131 if (m_private) 132 delete m_private; 133 m_private = static_cast<WebBlobDataPrivate*>(data.leakPtr()); 134 } 135 136 } // namespace WebKit 137