2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "platform/WebHTTPBody.h"
36 using namespace WebCore;
40 class WebHTTPBodyPrivate : public FormData {
43 void WebHTTPBody::initialize()
45 assign(static_cast<WebHTTPBodyPrivate*>(FormData::create().leakRef()));
48 void WebHTTPBody::reset()
53 void WebHTTPBody::assign(const WebHTTPBody& other)
55 WebHTTPBodyPrivate* p = const_cast<WebHTTPBodyPrivate*>(other.m_private);
61 size_t WebHTTPBody::elementCount() const
64 return m_private->elements().size();
67 bool WebHTTPBody::elementAt(size_t index, Element& result) const
71 if (index >= m_private->elements().size())
74 const FormDataElement& element = m_private->elements()[index];
77 result.filePath.reset();
79 result.fileLength = 0;
80 result.modificationTime = 0.0;
81 result.blobURL = KURL();
83 switch (element.m_type) {
84 case FormDataElement::data:
85 result.type = Element::TypeData;
86 result.data.assign(element.m_data.data(), element.m_data.size());
88 case FormDataElement::encodedFile:
89 result.type = Element::TypeFile;
90 result.filePath = element.m_filename;
92 result.fileStart = element.m_fileStart;
93 result.fileLength = element.m_fileLength;
94 result.modificationTime = element.m_expectedFileModificationTime;
98 case FormDataElement::encodedBlob:
99 result.type = Element::TypeBlob;
100 result.blobURL = element.m_blobURL;
104 ASSERT_NOT_REACHED();
111 void WebHTTPBody::appendData(const WebData& data)
114 // FIXME: FormDataElement::m_data should be a SharedBuffer<char>. Then we
115 // could avoid this buffer copy.
116 m_private->appendData(data.data(), data.size());
119 void WebHTTPBody::appendFile(const WebString& filePath)
122 m_private->appendFile(filePath);
125 void WebHTTPBody::appendFileRange(const WebString& filePath, long long fileStart, long long fileLength, double modificationTime)
129 m_private->appendFileRange(filePath, fileStart, fileLength, modificationTime);
133 void WebHTTPBody::appendBlob(const WebURL& blobURL)
137 m_private->appendBlob(blobURL);
141 long long WebHTTPBody::identifier() const
144 return m_private->identifier();
147 void WebHTTPBody::setIdentifier(long long identifier)
150 return m_private->setIdentifier(identifier);
153 WebHTTPBody::WebHTTPBody(const PassRefPtr<FormData>& data)
154 : m_private(static_cast<WebHTTPBodyPrivate*>(data.leakRef()))
158 WebHTTPBody& WebHTTPBody::operator=(const PassRefPtr<FormData>& data)
160 assign(static_cast<WebHTTPBodyPrivate*>(data.leakRef()));
164 WebHTTPBody::operator PassRefPtr<FormData>() const
169 void WebHTTPBody::assign(WebHTTPBodyPrivate* p)
171 // p is already ref'd for us by the caller
177 void WebHTTPBody::ensureMutable()
180 if (!m_private->hasOneRef())
181 assign(static_cast<WebHTTPBodyPrivate*>(m_private->copy().leakRef()));
184 } // namespace WebKit